@agoric/cosmos 0.34.2-dev-5dc325b.0 → 0.35.0-getting-started-dev-26244e8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/app/app.go +4 -5
- package/cmd/agd/main.go +11 -133
- package/cmd/libdaemon/main.go +53 -67
- package/daemon/cmd/root.go +24 -55
- package/daemon/main.go +1 -3
- package/git-revision.txt +1 -1
- package/package.json +3 -6
- package/proto/agoric/vstorage/query.proto +1 -53
- package/vm/controller.go +18 -8
- package/x/lien/lien.go +4 -6
- package/x/lien/lien_test.go +15 -19
- package/x/swingset/abci.go +2 -3
- package/x/swingset/swingset.go +2 -4
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/msgs.pb.go +16 -16
- package/x/vbank/vbank.go +10 -11
- package/x/vbank/vbank_test.go +5 -5
- package/x/vibc/ibc.go +9 -11
- package/x/vstorage/keeper/grpc_query.go +0 -221
- package/x/vstorage/types/query.pb.go +36 -646
- package/x/vstorage/types/query.pb.gw.go +0 -119
- package/x/vstorage/vstorage.go +15 -16
- package/x/vstorage/vstorage_test.go +4 -4
- package/cmd/agd/agvm.go +0 -42
- package/vm/client.go +0 -113
- package/vm/client_test.go +0 -184
- package/vm/jsonrpcconn/jsonrpcconn.go +0 -160
- package/vm/jsonrpcconn/jsonrpcconn_test.go +0 -126
- package/vm/server.go +0 -23
- package/x/vstorage/README.md +0 -140
- package/x/vstorage/capdata/capdata.go +0 -298
- package/x/vstorage/capdata/capdata_test.go +0 -352
- package/x/vstorage/keeper/keeper_grpc_test.go +0 -300
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,79 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.35.0-u12.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cosmos@0.35.0-u11wf.0...@agoric/cosmos@0.35.0-u12.0) (2023-11-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ⚠ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **vstorage:** Enforce path validation
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **cosmos:** Lower `BlockParams.MaxBytes` to 5MB ([84908e5](https://github.com/Agoric/agoric-sdk/commit/84908e5a5a181e3f64da0e298d0105fedb97570a))
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **vibc:** accommodate ibc-go v3 breaking changes ([f582901](https://github.com/Agoric/agoric-sdk/commit/f582901fb3835d95d493c777aac6a63fc3ee4681))
|
|
20
|
+
* **vibc:** put extraneous `CounterpartyChannelID` in `Counterparty` struct ([9469971](https://github.com/Agoric/agoric-sdk/commit/946997192cec0ed6b07fdaa18d8f380f460ab004))
|
|
21
|
+
* **vstorage:** Enforce path validation ([d8db331](https://github.com/Agoric/agoric-sdk/commit/d8db3310fb21a8546388694752889f3563733010)), closes [#8337](https://github.com/Agoric/agoric-sdk/issues/8337)
|
|
22
|
+
* **cosmos:** Update cosmos-sdk with fix for state-sync restore of large payloads ([e04b398](https://github.com/Agoric/agoric-sdk/commit/e04b398bf16d884fa4708c16d4c03b39cc4e0f1b)), closes [#8325](https://github.com/Agoric/agoric-sdk/issues/8325)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## [0.35.0-u11wf.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cosmos@0.35.0-u11.0...@agoric/cosmos@0.35.0-u11wf.0) (2023-09-23)
|
|
27
|
+
|
|
28
|
+
**Note:** Version bump only for package @agoric/cosmos
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## [0.35.0-u11.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cosmos@0.34.1...@agoric/cosmos@0.35.0-u11.0) (2023-08-24)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### ⚠ BREAKING CHANGES
|
|
38
|
+
|
|
39
|
+
* **cosmos:** add required export-dir export cmd option
|
|
40
|
+
* remove deprecated `ag-cosmos-helper`
|
|
41
|
+
|
|
42
|
+
### Features
|
|
43
|
+
|
|
44
|
+
* **agd:** try harder to find cosmic-swingset ([a1d1666](https://github.com/Agoric/agoric-sdk/commit/a1d1666997c2f5b9c7bf14748f6d9603c0b3c5f9))
|
|
45
|
+
* **cosmic-swingset:** add repair-metadata snapshot restore option ([ebbb982](https://github.com/Agoric/agoric-sdk/commit/ebbb9829f1f845c0932ae92b23d0d43be9a0e196))
|
|
46
|
+
* **cosmic-swingset:** replace import/export options ([393b91b](https://github.com/Agoric/agoric-sdk/commit/393b91baaa25c61364955102e8cfcdcaec90870d))
|
|
47
|
+
* **cosmic-swingset:** use x/swingset for swing-store export data ([3336b62](https://github.com/Agoric/agoric-sdk/commit/3336b62fbb10bd2293a832f8c30e590530d14213))
|
|
48
|
+
* **cosmos:** add required export-dir export cmd option ([8d2571c](https://github.com/Agoric/agoric-sdk/commit/8d2571c51c2fe08d630dd2897d7e5e1b45ab45c9))
|
|
49
|
+
* **cosmos:** fix and migrate swing-store ([6ba1957](https://github.com/Agoric/agoric-sdk/commit/6ba19571688518dcfdc4553a0c822695a61908b1))
|
|
50
|
+
* **cosmos:** KVEntry implements json Marshaler and Unmarshaller ([6d2fe11](https://github.com/Agoric/agoric-sdk/commit/6d2fe11d144c5bbdc1611b59c84b6842e8084cb9))
|
|
51
|
+
* **cosmos:** spawn JS on export command ([fe4eb56](https://github.com/Agoric/agoric-sdk/commit/fe4eb56facf83569aa343f098e97c6229556afa9))
|
|
52
|
+
* **cosmos:** wire new swingset port handler ([3361b25](https://github.com/Agoric/agoric-sdk/commit/3361b25ddaa00116476d3de1107e800499ab5c21))
|
|
53
|
+
* **x/swingset:** add store data to genesis ([df72903](https://github.com/Agoric/agoric-sdk/commit/df729030643a097262ad1393503d380e243107eb))
|
|
54
|
+
* **x/swingset:** add WaitUntilSwingStoreExportDone ([f8acd22](https://github.com/Agoric/agoric-sdk/commit/f8acd22381ff3da4682bcb0cdcf71665095506a4))
|
|
55
|
+
* **x/swingset:** allow taking snapshot latest height ([0c0e742](https://github.com/Agoric/agoric-sdk/commit/0c0e74227d34d49ac7ce76ce8e92715816d5ea6a))
|
|
56
|
+
* **x/swingset:** export swing store in genesis ([e5f9425](https://github.com/Agoric/agoric-sdk/commit/e5f9425e74c7235323cd6b1b88540b73b57a69a6))
|
|
57
|
+
* **x/swingset:** import swing store from genesis state ([2446cf4](https://github.com/Agoric/agoric-sdk/commit/2446cf43bb13aad7de0805cd7e33c966d2e31016))
|
|
58
|
+
* Cosmos upgrade handler calls swingset ([66f7bcc](https://github.com/Agoric/agoric-sdk/commit/66f7bccce7ce30cf5b9e1e5321710567c05723cb))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### Bug Fixes
|
|
62
|
+
|
|
63
|
+
* **cosmos:** don't init controller before upgrade ([e567c21](https://github.com/Agoric/agoric-sdk/commit/e567c21a224d239c467f740bb937f84b18db9dd7))
|
|
64
|
+
* **cosmos:** module order independent init and bootstrap ([3ce4012](https://github.com/Agoric/agoric-sdk/commit/3ce4012ea99b39b2d6bfd422b1d7ea7a7e904568))
|
|
65
|
+
* **cosmos:** prevent Golang error wrapping stack frame divergence ([1d8acf6](https://github.com/Agoric/agoric-sdk/commit/1d8acf6270cadfbcdafb1081360155260d031ac1))
|
|
66
|
+
* **cosmos:** Support building on Linux aarch64 ([475708e](https://github.com/Agoric/agoric-sdk/commit/475708e63bb95d75184072547ca92586a978c5a0))
|
|
67
|
+
* **x/swingset:** enforce snapshot restore before init ([c946d58](https://github.com/Agoric/agoric-sdk/commit/c946d5866ef956c198d7ea14936eb9904aa272ae))
|
|
68
|
+
* **x/swingset:** guard snapshot restore for concurrency ([5320a30](https://github.com/Agoric/agoric-sdk/commit/5320a30a873455764104e13d89131e30a93a238c))
|
|
69
|
+
* **x/swingset:** switch export/import to replay artifact level ([c037ea3](https://github.com/Agoric/agoric-sdk/commit/c037ea3931877fe4d56df5b82cc7c3eb77a84a53))
|
|
70
|
+
* **x/vstorage:** value can be empty in genesis data ([9a51df5](https://github.com/Agoric/agoric-sdk/commit/9a51df515b87638b869564ab08445a0ce0d55707))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### Build System
|
|
74
|
+
|
|
75
|
+
* remove deprecated `ag-cosmos-helper` ([ee43112](https://github.com/Agoric/agoric-sdk/commit/ee431121e3f93406896f8a9e7d949fbf1427c44e))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
6
79
|
### [0.34.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/cosmos@0.34.0...@agoric/cosmos@0.34.1) (2023-06-09)
|
|
7
80
|
|
|
8
81
|
**Note:** Version bump only for package @agoric/cosmos
|
package/app/app.go
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package gaia
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"context"
|
|
5
4
|
"encoding/json"
|
|
6
5
|
"fmt"
|
|
7
6
|
"io"
|
|
@@ -289,7 +288,7 @@ func NewGaiaApp(
|
|
|
289
288
|
appOpts servertypes.AppOptions,
|
|
290
289
|
baseAppOptions ...func(*baseapp.BaseApp),
|
|
291
290
|
) *GaiaApp {
|
|
292
|
-
defaultController := func(
|
|
291
|
+
defaultController := func(needReply bool, str string) (string, error) {
|
|
293
292
|
fmt.Fprintln(os.Stderr, "FIXME: Would upcall to controller with", str)
|
|
294
293
|
return "", nil
|
|
295
294
|
}
|
|
@@ -301,7 +300,7 @@ func NewGaiaApp(
|
|
|
301
300
|
}
|
|
302
301
|
|
|
303
302
|
func NewAgoricApp(
|
|
304
|
-
sendToController func(
|
|
303
|
+
sendToController func(bool, string) (string, error),
|
|
305
304
|
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
|
|
306
305
|
homePath string, invCheckPeriod uint, encodingConfig gaiaappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
|
|
307
306
|
) *GaiaApp {
|
|
@@ -451,7 +450,7 @@ func NewAgoricApp(
|
|
|
451
450
|
app.CheckControllerInited(true)
|
|
452
451
|
// We use SwingSet-level metering to charge the user for the call.
|
|
453
452
|
defer vm.SetControllerContext(ctx)()
|
|
454
|
-
return sendToController(
|
|
453
|
+
return sendToController(true, str)
|
|
455
454
|
}
|
|
456
455
|
|
|
457
456
|
setBootstrapNeeded := func() {
|
|
@@ -483,7 +482,7 @@ func NewAgoricApp(
|
|
|
483
482
|
if err != nil {
|
|
484
483
|
return "", err
|
|
485
484
|
}
|
|
486
|
-
return sendToController(
|
|
485
|
+
return sendToController(true, string(bz))
|
|
487
486
|
},
|
|
488
487
|
)
|
|
489
488
|
|
package/cmd/agd/main.go
CHANGED
|
@@ -1,158 +1,36 @@
|
|
|
1
1
|
package main
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"context"
|
|
5
|
-
"errors"
|
|
6
|
-
"net/rpc"
|
|
7
|
-
"net/rpc/jsonrpc"
|
|
8
4
|
"os"
|
|
9
|
-
"os/exec"
|
|
10
5
|
"syscall"
|
|
11
|
-
"time"
|
|
12
6
|
|
|
13
|
-
"github.com/spf13/cast"
|
|
14
7
|
"github.com/tendermint/tendermint/libs/log"
|
|
15
8
|
|
|
16
9
|
gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
|
|
17
10
|
"github.com/Agoric/agoric-sdk/golang/cosmos/daemon"
|
|
18
11
|
daemoncmd "github.com/Agoric/agoric-sdk/golang/cosmos/daemon/cmd"
|
|
19
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
20
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/vm/jsonrpcconn"
|
|
21
|
-
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
|
22
12
|
)
|
|
23
13
|
|
|
24
|
-
// TerminateSubprocessGracePeriod is how long we wait between closing the pipe
|
|
25
|
-
// waiting for it to exit, then sending a termination signal.
|
|
26
|
-
const TerminateSubprocessGracePeriod = 3 * time.Second
|
|
27
|
-
|
|
28
|
-
// KillSubprocessGracePeriod is how long we wait between sending a subprocess a
|
|
29
|
-
// termination signal, waiting for it to exit, then killing it.
|
|
30
|
-
const KillSubprocessGracePeriod = 5 * time.Second
|
|
31
|
-
|
|
32
|
-
// makeShutdown returns a function that terminates the vm.
|
|
33
|
-
func makeShutdown(cmd *exec.Cmd, writer *os.File) func() error {
|
|
34
|
-
return func() error {
|
|
35
|
-
// Stop talking to the subprocess.
|
|
36
|
-
_ = writer.Close()
|
|
37
|
-
go func() {
|
|
38
|
-
// Wait a bit.
|
|
39
|
-
time.Sleep(TerminateSubprocessGracePeriod)
|
|
40
|
-
// Then punch it in the shoulder.
|
|
41
|
-
_ = cmd.Process.Signal(os.Interrupt)
|
|
42
|
-
// Wait a bit.
|
|
43
|
-
time.Sleep(KillSubprocessGracePeriod)
|
|
44
|
-
// Then blow it away.
|
|
45
|
-
_ = cmd.Process.Kill()
|
|
46
|
-
}()
|
|
47
|
-
// Wait for it to keel over.
|
|
48
|
-
return cmd.Wait()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// main is the entry point of the agd daemon. It determines whether to
|
|
54
|
-
// initialize JSON-RPC communications with the separate `--split-vm` VM process,
|
|
55
|
-
// or just to give up control entirely to another binary.
|
|
56
14
|
func main() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
nodePort := 1
|
|
61
|
-
sendToNode := func(ctx context.Context, needReply bool, str string) (string, error) {
|
|
62
|
-
if vmClient == nil {
|
|
63
|
-
return "", errors.New("sendToVM called without VM client set up")
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if str == "shutdown" {
|
|
67
|
-
// We could ask nicely, but don't bother.
|
|
68
|
-
if shutdown != nil {
|
|
69
|
-
return "", shutdown()
|
|
70
|
-
}
|
|
71
|
-
return "", nil
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
msg := vm.Message{
|
|
75
|
-
Port: nodePort,
|
|
76
|
-
NeedsReply: needReply,
|
|
77
|
-
Data: str,
|
|
78
|
-
}
|
|
79
|
-
var reply string
|
|
80
|
-
err := vmClient.Call(vm.ReceiveMessageMethod, msg, &reply)
|
|
81
|
-
return reply, err
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exitCode := 0
|
|
85
|
-
launchVM := func(logger log.Logger, appOpts servertypes.AppOptions) error {
|
|
15
|
+
// We need to delegate to our default app for running the actual chain.
|
|
16
|
+
launchVM := func(logger log.Logger) {
|
|
86
17
|
args := []string{"ag-chain-cosmos", "--home", gaia.DefaultNodeHome}
|
|
87
18
|
args = append(args, os.Args[1:]...)
|
|
88
19
|
|
|
89
|
-
binary :=
|
|
90
|
-
if
|
|
91
|
-
|
|
92
|
-
if lookErr != nil {
|
|
93
|
-
return lookErr
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// We completely delegate to our default app for running the actual chain.
|
|
97
|
-
logger.Info("agd delegating to JS executable", "binary", binary, "args", args)
|
|
98
|
-
return syscall.Exec(binary, args, os.Environ())
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Split the execution between us and the VM.
|
|
102
|
-
agdFromVm, vmToAgd, err := os.Pipe()
|
|
103
|
-
if err != nil {
|
|
104
|
-
return err
|
|
105
|
-
}
|
|
106
|
-
vmFromAgd, agdToVm, err := os.Pipe()
|
|
107
|
-
if err != nil {
|
|
108
|
-
return err
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Start the command running, then continue.
|
|
112
|
-
args[0] = binary
|
|
113
|
-
cmd := NewVMCommand(logger, binary, args, vmFromAgd, vmToAgd)
|
|
114
|
-
shutdown = makeShutdown(cmd, agdToVm)
|
|
115
|
-
|
|
116
|
-
if err := cmd.Start(); err != nil {
|
|
117
|
-
return err
|
|
118
|
-
}
|
|
119
|
-
if vmFromAgd.Close() != nil {
|
|
120
|
-
return err
|
|
121
|
-
}
|
|
122
|
-
if vmToAgd.Close() != nil {
|
|
123
|
-
return err
|
|
20
|
+
binary, lookErr := FindCosmicSwingsetBinary()
|
|
21
|
+
if lookErr != nil {
|
|
22
|
+
panic(lookErr)
|
|
124
23
|
}
|
|
125
24
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// Set up the VM server.
|
|
131
|
-
vmServer := rpc.NewServer()
|
|
132
|
-
if err := vmServer.RegisterName("agd", vm.NewAgdServer()); err != nil {
|
|
133
|
-
return err
|
|
25
|
+
logger.Info("agd delegating to JS executable", "binary", binary, "args", args)
|
|
26
|
+
execErr := syscall.Exec(binary, args, os.Environ())
|
|
27
|
+
if execErr != nil {
|
|
28
|
+
panic(execErr)
|
|
134
29
|
}
|
|
135
|
-
go vmServer.ServeCodec(jsonrpc.NewServerCodec(serverConn))
|
|
136
|
-
|
|
137
|
-
// Set up the VM client.
|
|
138
|
-
vmClient = jsonrpc.NewClient(clientConn)
|
|
139
|
-
|
|
140
|
-
go func() {
|
|
141
|
-
// Premature exit from `agd start` should exit the process.
|
|
142
|
-
_ = cmd.Wait()
|
|
143
|
-
os.Exit(exitCode)
|
|
144
|
-
}()
|
|
145
|
-
|
|
146
|
-
return nil
|
|
147
30
|
}
|
|
148
31
|
|
|
32
|
+
daemoncmd.OnStartHook = launchVM
|
|
149
33
|
daemoncmd.OnExportHook = launchVM
|
|
150
|
-
daemoncmd.OnStartHook = func (logger log.Logger, appOpts servertypes.AppOptions) error {
|
|
151
|
-
// We tried running start, which should never exit, so exit with non-zero
|
|
152
|
-
// code if we do.
|
|
153
|
-
exitCode = 99
|
|
154
|
-
return launchVM(logger, appOpts)
|
|
155
|
-
}
|
|
156
34
|
|
|
157
|
-
daemon.RunWithController(
|
|
35
|
+
daemon.RunWithController(nil)
|
|
158
36
|
}
|
package/cmd/libdaemon/main.go
CHANGED
|
@@ -10,9 +10,8 @@ package main
|
|
|
10
10
|
import "C"
|
|
11
11
|
|
|
12
12
|
import (
|
|
13
|
-
"context"
|
|
14
13
|
"encoding/json"
|
|
15
|
-
"
|
|
14
|
+
"errors"
|
|
16
15
|
"os"
|
|
17
16
|
"path/filepath"
|
|
18
17
|
|
|
@@ -22,7 +21,6 @@ import (
|
|
|
22
21
|
"github.com/Agoric/agoric-sdk/golang/cosmos/daemon"
|
|
23
22
|
daemoncmd "github.com/Agoric/agoric-sdk/golang/cosmos/daemon/cmd"
|
|
24
23
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
25
|
-
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
|
26
24
|
)
|
|
27
25
|
|
|
28
26
|
type goReturn = struct {
|
|
@@ -32,32 +30,8 @@ type goReturn = struct {
|
|
|
32
30
|
|
|
33
31
|
const SwingSetPort = 123
|
|
34
32
|
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
// ConnectVMClientCodec creates an RPC client codec and a sender to the
|
|
39
|
-
// in-process implementation of the VM.
|
|
40
|
-
func ConnectVMClientCodec(ctx context.Context, nodePort int, sendFunc func(int, int, string)) (*vm.ClientCodec, daemoncmd.Sender) {
|
|
41
|
-
vmClientCodec = vm.NewClientCodec(context.Background(), sendFunc)
|
|
42
|
-
vmClient := rpc.NewClientWithCodec(vmClientCodec)
|
|
43
|
-
|
|
44
|
-
sendToNode := func(ctx context.Context, needReply bool, str string) (string, error) {
|
|
45
|
-
if str == "shutdown" {
|
|
46
|
-
return "", vmClientCodec.Close()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
msg := vm.Message{
|
|
50
|
-
Port: nodePort,
|
|
51
|
-
NeedsReply: needReply,
|
|
52
|
-
Data: str,
|
|
53
|
-
}
|
|
54
|
-
var reply string
|
|
55
|
-
err := vmClient.Call(vm.ReceiveMessageMethod, msg, &reply)
|
|
56
|
-
return reply, err
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return vmClientCodec, sendToNode
|
|
60
|
-
}
|
|
33
|
+
var replies = map[int]chan goReturn{}
|
|
34
|
+
var lastReply = 0
|
|
61
35
|
|
|
62
36
|
//export RunAgCosmosDaemon
|
|
63
37
|
func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char) C.int {
|
|
@@ -68,39 +42,46 @@ func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char)
|
|
|
68
42
|
|
|
69
43
|
gaia.DefaultNodeHome = filepath.Join(userHomeDir, ".ag-chain-cosmos")
|
|
70
44
|
daemoncmd.AppName = "ag-chain-cosmos"
|
|
71
|
-
if err := os.Setenv(daemoncmd.EmbeddedVmEnvVar, "libdaemon"); err != nil {
|
|
72
|
-
panic(err)
|
|
73
|
-
}
|
|
74
45
|
|
|
75
|
-
|
|
46
|
+
// FIXME: Decouple the sending logic from the Cosmos app.
|
|
47
|
+
sendToNode := func(needReply bool, str string) (string, error) {
|
|
48
|
+
var rPort int
|
|
49
|
+
if needReply {
|
|
50
|
+
lastReply++
|
|
51
|
+
rPort = lastReply
|
|
52
|
+
replies[rPort] = make(chan goReturn)
|
|
53
|
+
}
|
|
76
54
|
|
|
77
|
-
|
|
78
|
-
C.invokeSendFunc(toNode,
|
|
79
|
-
|
|
55
|
+
// Send the message
|
|
56
|
+
C.invokeSendFunc(toNode, nodePort, C.int(rPort), C.CString(str))
|
|
57
|
+
if !needReply {
|
|
58
|
+
// Return immediately
|
|
59
|
+
// fmt.Fprintln(os.Stderr, "Don't wait")
|
|
60
|
+
return "<no-reply-requested>", nil
|
|
61
|
+
}
|
|
80
62
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
// Block the sending goroutine while we wait for the reply
|
|
64
|
+
// fmt.Fprintln(os.Stderr, "Waiting for", rPort)
|
|
65
|
+
ret := <-replies[rPort]
|
|
66
|
+
delete(replies, rPort)
|
|
67
|
+
// fmt.Fprintln(os.Stderr, "Woken, got", ret)
|
|
68
|
+
return ret.str, ret.err
|
|
69
|
+
}
|
|
87
70
|
|
|
88
71
|
args := make([]string, len(cosmosArgs))
|
|
89
72
|
for i, s := range cosmosArgs {
|
|
90
73
|
args[i] = C.GoString(s)
|
|
91
74
|
}
|
|
92
|
-
|
|
93
75
|
// fmt.Fprintln(os.Stderr, "Starting Cosmos", args)
|
|
94
76
|
os.Args = args
|
|
95
77
|
go func() {
|
|
96
78
|
// We run in the background, but exit when the job is over.
|
|
97
79
|
// swingset.SendToNode("hello from Initial Go!")
|
|
98
80
|
exitCode := 0
|
|
99
|
-
daemoncmd.OnStartHook = func(logger log.Logger
|
|
81
|
+
daemoncmd.OnStartHook = func(logger log.Logger) {
|
|
100
82
|
// We tried running start, which should never exit, so exit with non-zero
|
|
101
83
|
// code if we ever stop.
|
|
102
84
|
exitCode = 99
|
|
103
|
-
return nil
|
|
104
85
|
}
|
|
105
86
|
daemon.RunWithController(sendToNode)
|
|
106
87
|
// fmt.Fprintln(os.Stderr, "Shutting down Cosmos")
|
|
@@ -113,10 +94,22 @@ func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char)
|
|
|
113
94
|
//export ReplyToGo
|
|
114
95
|
func ReplyToGo(replyPort C.int, isError C.int, resp C.Body) C.int {
|
|
115
96
|
respStr := C.GoString(resp)
|
|
116
|
-
// fmt.
|
|
117
|
-
|
|
118
|
-
|
|
97
|
+
// fmt.Fprintln(os.Stderr, "Reply to Go", respStr)
|
|
98
|
+
returnCh := replies[int(replyPort)]
|
|
99
|
+
if returnCh == nil {
|
|
100
|
+
// Unexpected reply.
|
|
101
|
+
// This is okay, since the caller decides whether or
|
|
102
|
+
// not she wants to listen for replies.
|
|
103
|
+
return C.int(0)
|
|
119
104
|
}
|
|
105
|
+
// Wake up the waiting goroutine
|
|
106
|
+
ret := goReturn{}
|
|
107
|
+
if int(isError) == 0 {
|
|
108
|
+
ret.str = respStr
|
|
109
|
+
} else {
|
|
110
|
+
ret.err = errors.New(respStr)
|
|
111
|
+
}
|
|
112
|
+
returnCh <- ret
|
|
120
113
|
return C.int(0)
|
|
121
114
|
}
|
|
122
115
|
|
|
@@ -128,27 +121,20 @@ type errorWrapper struct {
|
|
|
128
121
|
func SendToGo(port C.int, msg C.Body) C.Body {
|
|
129
122
|
msgStr := C.GoString(msg)
|
|
130
123
|
// fmt.Fprintln(os.Stderr, "Send to Go", msgStr)
|
|
131
|
-
|
|
132
|
-
message := &vm.Message{
|
|
133
|
-
Port: int(port),
|
|
134
|
-
NeedsReply: true,
|
|
135
|
-
Data: msgStr,
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
err := agdServer.ReceiveMessage(message, &respStr)
|
|
139
|
-
if err == nil {
|
|
140
|
-
return C.CString(respStr)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// fmt.Fprintln(os.Stderr, "Cannot receive from controller", err)
|
|
144
|
-
errResp := errorWrapper{
|
|
145
|
-
Error: err.Error(),
|
|
146
|
-
}
|
|
147
|
-
respBytes, err := json.Marshal(&errResp)
|
|
124
|
+
respStr, err := vm.ReceiveFromController(int(port), msgStr)
|
|
148
125
|
if err != nil {
|
|
149
|
-
|
|
126
|
+
// fmt.Fprintln(os.Stderr, "Cannot receive from controller", err)
|
|
127
|
+
errResp := errorWrapper{
|
|
128
|
+
Error: err.Error(),
|
|
129
|
+
}
|
|
130
|
+
respBytes, err := json.Marshal(&errResp)
|
|
131
|
+
if err != nil {
|
|
132
|
+
panic(err)
|
|
133
|
+
}
|
|
134
|
+
// fmt.Fprintln(os.Stderr, "Marshaled", errResp, respBytes)
|
|
135
|
+
respStr = string(respBytes)
|
|
150
136
|
}
|
|
151
|
-
return C.CString(
|
|
137
|
+
return C.CString(respStr)
|
|
152
138
|
}
|
|
153
139
|
|
|
154
140
|
// Do nothing in main.
|
package/daemon/cmd/root.go
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package cmd
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"context"
|
|
5
4
|
"errors"
|
|
6
5
|
"io"
|
|
7
6
|
"os"
|
|
@@ -39,11 +38,11 @@ import (
|
|
|
39
38
|
)
|
|
40
39
|
|
|
41
40
|
// Sender is a function that sends a request to the controller.
|
|
42
|
-
type Sender func(
|
|
41
|
+
type Sender func(needReply bool, str string) (string, error)
|
|
43
42
|
|
|
44
43
|
var AppName = "agd"
|
|
45
|
-
var OnStartHook func(log.Logger
|
|
46
|
-
var OnExportHook func(log.Logger
|
|
44
|
+
var OnStartHook func(logger log.Logger)
|
|
45
|
+
var OnExportHook func(logger log.Logger)
|
|
47
46
|
|
|
48
47
|
// NewRootCmd creates a new root command for simd. It is called once in the
|
|
49
48
|
// main function.
|
|
@@ -61,7 +60,7 @@ func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
|
|
|
61
60
|
|
|
62
61
|
rootCmd := &cobra.Command{
|
|
63
62
|
Use: AppName,
|
|
64
|
-
Short: "Agoric
|
|
63
|
+
Short: "Stargate Agoric App",
|
|
65
64
|
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
|
66
65
|
// set the default command outputs
|
|
67
66
|
cmd.SetOut(cmd.OutOrStdout())
|
|
@@ -136,9 +135,10 @@ func initRootCmd(sender Sender, rootCmd *cobra.Command, encodingConfig params.En
|
|
|
136
135
|
}
|
|
137
136
|
server.AddCommands(rootCmd, gaia.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags)
|
|
138
137
|
|
|
138
|
+
hasVMController := sender != nil
|
|
139
139
|
for _, command := range rootCmd.Commands() {
|
|
140
140
|
if command.Name() == "export" {
|
|
141
|
-
extendCosmosExportCommand(command)
|
|
141
|
+
extendCosmosExportCommand(command, hasVMController)
|
|
142
142
|
break
|
|
143
143
|
}
|
|
144
144
|
}
|
|
@@ -154,31 +154,8 @@ func initRootCmd(sender Sender, rootCmd *cobra.Command, encodingConfig params.En
|
|
|
154
154
|
rootCmd.AddCommand(server.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
const (
|
|
158
|
-
// FlagSplitVm is the command-line flag for subcommands that can use a
|
|
159
|
-
// split-process Agoric VM. The default is to use an embedded VM.
|
|
160
|
-
FlagSplitVm = "split-vm"
|
|
161
|
-
EmbeddedVmEnvVar = "AGD_EMBEDDED_VM"
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
// hasVMController returns true if we have a VM (are running in split-vm mode,
|
|
165
|
-
// or with an embedded VM).
|
|
166
|
-
func hasVMController(serverCtx *server.Context) bool {
|
|
167
|
-
return serverCtx.Viper.GetString(FlagSplitVm) != "" ||
|
|
168
|
-
os.Getenv(EmbeddedVmEnvVar) != ""
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
func addAgoricVMFlags(cmd *cobra.Command) {
|
|
172
|
-
cmd.PersistentFlags().String(
|
|
173
|
-
FlagSplitVm,
|
|
174
|
-
"",
|
|
175
|
-
"Specify the external Agoric VM program",
|
|
176
|
-
)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
157
|
func addModuleInitFlags(startCmd *cobra.Command) {
|
|
180
158
|
crisis.AddModuleInitFlags(startCmd)
|
|
181
|
-
addAgoricVMFlags(startCmd)
|
|
182
159
|
}
|
|
183
160
|
|
|
184
161
|
func queryCommand() *cobra.Command {
|
|
@@ -246,9 +223,7 @@ func (ac appCreator) newApp(
|
|
|
246
223
|
appOpts servertypes.AppOptions,
|
|
247
224
|
) servertypes.Application {
|
|
248
225
|
if OnStartHook != nil {
|
|
249
|
-
|
|
250
|
-
panic(err)
|
|
251
|
-
}
|
|
226
|
+
OnStartHook(logger)
|
|
252
227
|
}
|
|
253
228
|
|
|
254
229
|
var cache sdk.MultiStorePersistentCache
|
|
@@ -322,9 +297,8 @@ const (
|
|
|
322
297
|
|
|
323
298
|
// extendCosmosExportCommand monkey-patches the "export" command added by
|
|
324
299
|
// cosmos-sdk to add a required "export-dir" command-line flag, and create the
|
|
325
|
-
// genesis export in the specified directory
|
|
326
|
-
func extendCosmosExportCommand(cmd *cobra.Command) {
|
|
327
|
-
addAgoricVMFlags(cmd)
|
|
300
|
+
// genesis export in the specified directory.
|
|
301
|
+
func extendCosmosExportCommand(cmd *cobra.Command, hasVMController bool) {
|
|
328
302
|
cmd.Flags().String(FlagExportDir, "", "The directory where to create the genesis export")
|
|
329
303
|
err := cmd.MarkFlagRequired(FlagExportDir)
|
|
330
304
|
if err != nil {
|
|
@@ -355,28 +329,25 @@ func extendCosmosExportCommand(cmd *cobra.Command) {
|
|
|
355
329
|
// current genesis.
|
|
356
330
|
serverCtx.Viper.Set(gaia.FlagSwingStoreExportDir, swingStoreExportPath)
|
|
357
331
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
genesisPath,
|
|
363
|
-
os.O_CREATE|os.O_EXCL|os.O_WRONLY,
|
|
364
|
-
os.ModePerm,
|
|
365
|
-
)
|
|
366
|
-
if err != nil {
|
|
367
|
-
return err
|
|
368
|
-
}
|
|
369
|
-
defer genesisFile.Close()
|
|
370
|
-
cmd.SetOut(genesisFile)
|
|
332
|
+
// This will fail is a genesis.json already exists in the export-dir
|
|
333
|
+
genesisFile, err := os.OpenFile(genesisPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, os.ModePerm)
|
|
334
|
+
if err != nil {
|
|
335
|
+
return err
|
|
371
336
|
}
|
|
337
|
+
defer genesisFile.Close()
|
|
338
|
+
|
|
339
|
+
cmd.SetOut(genesisFile)
|
|
372
340
|
|
|
373
|
-
// If we don't have a VM, appExport will just use the OnExportHook to exec
|
|
374
|
-
// the VM program, which will result in reentering this function with the VM
|
|
375
|
-
// controller set, and activate the above condition.
|
|
376
341
|
return originalRunE(cmd, args)
|
|
377
342
|
}
|
|
378
343
|
|
|
379
|
-
|
|
344
|
+
// Only modify the command handler when we have a VM controller to handle
|
|
345
|
+
// the full export logic. Otherwise, appExport will just exec the VM program
|
|
346
|
+
// (OnExportHook), which will result in re-entering this flow with the VM
|
|
347
|
+
// controller set.
|
|
348
|
+
if hasVMController {
|
|
349
|
+
cmd.RunE = extendedRunE
|
|
350
|
+
}
|
|
380
351
|
}
|
|
381
352
|
|
|
382
353
|
func (ac appCreator) appExport(
|
|
@@ -389,9 +360,7 @@ func (ac appCreator) appExport(
|
|
|
389
360
|
appOpts servertypes.AppOptions,
|
|
390
361
|
) (servertypes.ExportedApp, error) {
|
|
391
362
|
if OnExportHook != nil {
|
|
392
|
-
|
|
393
|
-
return servertypes.ExportedApp{}, err
|
|
394
|
-
}
|
|
363
|
+
OnExportHook(logger)
|
|
395
364
|
}
|
|
396
365
|
|
|
397
366
|
homePath, ok := appOpts.Get(flags.FlagHome).(string)
|
package/daemon/main.go
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package daemon
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"context"
|
|
5
4
|
"fmt"
|
|
6
5
|
"os"
|
|
7
6
|
"os/signal"
|
|
@@ -18,7 +17,7 @@ import (
|
|
|
18
17
|
)
|
|
19
18
|
|
|
20
19
|
// DefaultController is a stub controller.
|
|
21
|
-
var DefaultController = func(
|
|
20
|
+
var DefaultController = func(needReply bool, str string) (string, error) {
|
|
22
21
|
return "", fmt.Errorf("Controller not configured; did you mean to use `ag-chain-cosmos` instead?")
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -35,7 +34,6 @@ func RunWithController(sendToController cmd.Sender) {
|
|
|
35
34
|
signal.Notify(sigs, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
|
36
35
|
go func() {
|
|
37
36
|
<-sigs
|
|
38
|
-
_, _ = sendToController(context.Background(), false, "shutdown")
|
|
39
37
|
os.Exit(98)
|
|
40
38
|
}()
|
|
41
39
|
|
package/git-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
26244e8
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/cosmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0-getting-started-dev-26244e8.0+26244e8",
|
|
4
4
|
"description": "Connect JS to the Cosmos blockchain SDK",
|
|
5
5
|
"parsers": {
|
|
6
6
|
"js": "mjs"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"postpack": "git clean -f git-revision.txt",
|
|
20
20
|
"build": "exit 0",
|
|
21
21
|
"lint-fix": "yarn lint:eslint --fix",
|
|
22
|
-
"lint": "
|
|
22
|
+
"lint": "eslint '**/*.{cjs,js}'"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"bindings": "^1.2.1",
|
|
@@ -35,8 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"
|
|
39
|
-
"atLeast": 0
|
|
40
|
-
},
|
|
41
|
-
"gitHead": "5dc325b8cc1d94f46ecc18a7c67a14989feade11"
|
|
38
|
+
"gitHead": "26244e821f1a83cd5868f0c7d54aa480c8c17e5e"
|
|
42
39
|
}
|