@agoric/cosmos 0.35.0-u15.0 → 0.35.0-u16.1
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 +123 -143
- package/MAINTAINERS.md +3 -0
- package/Makefile +36 -26
- package/ante/ante.go +6 -5
- package/ante/inbound_test.go +3 -2
- package/ante/vm_admission.go +2 -1
- package/app/app.go +206 -147
- package/app/upgrade.go +77 -0
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/main.go +130 -11
- package/cmd/libdaemon/main.go +64 -53
- package/cmd/libdaemon/main_test.go +2 -1
- package/daemon/cmd/root.go +164 -74
- package/daemon/cmd/root_test.go +189 -1
- package/daemon/main.go +4 -2
- package/e2e_test/Makefile +29 -0
- package/e2e_test/README.md +100 -0
- package/e2e_test/go.mod +217 -0
- package/e2e_test/go.sum +1323 -0
- package/e2e_test/ibc_conformance_test.go +56 -0
- package/e2e_test/pfm_test.go +613 -0
- package/e2e_test/util.go +271 -0
- package/git-revision.txt +1 -1
- package/go.mod +12 -7
- package/go.sum +13 -9
- package/package.json +8 -4
- package/proto/agoric/swingset/genesis.proto +4 -0
- package/proto/agoric/swingset/swingset.proto +1 -1
- package/proto/agoric/vlocalchain/.clang-format +7 -0
- package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
- package/proto/agoric/vtransfer/genesis.proto +18 -0
- package/scripts/protocgen.sh +7 -8
- package/types/kv_entry_helpers.go +42 -0
- package/upgradegaia.sh +8 -8
- package/vm/action.go +5 -4
- package/vm/action_test.go +31 -11
- package/vm/client.go +113 -0
- package/vm/client_test.go +182 -0
- package/vm/controller.go +17 -40
- package/vm/core_proposals.go +22 -2
- package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
- package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
- package/vm/proto_json.go +38 -0
- package/vm/proto_json_test.go +103 -0
- package/vm/server.go +124 -0
- package/x/swingset/abci.go +10 -10
- package/x/swingset/alias.go +2 -0
- package/x/swingset/client/cli/tx.go +4 -0
- package/x/swingset/genesis.go +84 -24
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +2 -2
- package/x/swingset/keeper/keeper.go +13 -25
- package/x/swingset/keeper/msg_server.go +18 -18
- package/x/swingset/keeper/proposal.go +3 -3
- package/x/swingset/keeper/querier.go +12 -11
- package/x/swingset/keeper/swing_store_exports_handler.go +16 -5
- package/x/swingset/keeper/test_utils.go +16 -0
- package/x/swingset/module.go +7 -7
- package/x/swingset/proposal_handler.go +2 -1
- package/x/swingset/testing/queue.go +17 -0
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/expected_keepers.go +3 -2
- package/x/swingset/types/genesis.pb.go +78 -25
- package/x/swingset/types/msgs.go +44 -24
- package/x/swingset/types/params.go +2 -1
- package/x/swingset/types/proposal.go +5 -4
- package/x/swingset/types/swingset.pb.go +1 -1
- package/x/vbank/genesis.go +0 -2
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/querier.go +4 -3
- package/x/vbank/module.go +0 -5
- package/x/vbank/types/msgs.go +0 -12
- package/x/vbank/vbank.go +9 -9
- package/x/vbank/vbank_test.go +2 -2
- package/x/vibc/alias.go +3 -0
- package/x/vibc/handler.go +16 -9
- package/x/vibc/keeper/keeper.go +102 -65
- package/x/vibc/keeper/triggers.go +101 -0
- package/x/vibc/module.go +5 -8
- package/x/vibc/types/expected_keepers.go +13 -0
- package/x/vibc/types/ibc_module.go +336 -0
- package/x/vibc/types/receiver.go +170 -0
- package/x/vlocalchain/alias.go +19 -0
- package/x/vlocalchain/handler.go +21 -0
- package/x/vlocalchain/keeper/keeper.go +279 -0
- package/x/vlocalchain/keeper/keeper_test.go +97 -0
- package/x/vlocalchain/types/codec.go +34 -0
- package/x/vlocalchain/types/key.go +27 -0
- package/x/vlocalchain/types/msgs.go +16 -0
- package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
- package/x/vlocalchain/vlocalchain.go +114 -0
- package/x/vlocalchain/vlocalchain_test.go +434 -0
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +0 -1
- package/x/vstorage/keeper/keeper.go +13 -20
- package/x/vstorage/keeper/querier.go +6 -5
- package/x/vstorage/keeper/querier_test.go +4 -3
- package/x/vstorage/module.go +0 -5
- package/x/vstorage/testing/queue.go +27 -0
- package/x/vtransfer/alias.go +13 -0
- package/x/vtransfer/genesis.go +39 -0
- package/x/vtransfer/genesis_test.go +12 -0
- package/x/vtransfer/handler.go +20 -0
- package/x/vtransfer/ibc_middleware.go +186 -0
- package/x/vtransfer/ibc_middleware_test.go +448 -0
- package/x/vtransfer/keeper/keeper.go +281 -0
- package/x/vtransfer/module.go +124 -0
- package/x/vtransfer/types/expected_keepers.go +38 -0
- package/x/vtransfer/types/genesis.pb.go +327 -0
- package/x/vtransfer/types/key.go +9 -0
- package/x/vtransfer/types/msgs.go +9 -0
- package/proto/agoric/lien/genesis.proto +0 -25
- package/proto/agoric/lien/lien.proto +0 -25
- package/x/lien/alias.go +0 -17
- package/x/lien/genesis.go +0 -58
- package/x/lien/genesis_test.go +0 -101
- package/x/lien/keeper/account.go +0 -290
- package/x/lien/keeper/keeper.go +0 -255
- package/x/lien/keeper/keeper_test.go +0 -623
- package/x/lien/lien.go +0 -205
- package/x/lien/lien_test.go +0 -533
- package/x/lien/module.go +0 -115
- package/x/lien/spec/01_concepts.md +0 -146
- package/x/lien/spec/02_messages.md +0 -96
- package/x/lien/types/accountkeeper.go +0 -81
- package/x/lien/types/accountstate.go +0 -27
- package/x/lien/types/expected_keepers.go +0 -18
- package/x/lien/types/genesis.pb.go +0 -567
- package/x/lien/types/key.go +0 -25
- package/x/lien/types/lien.pb.go +0 -403
- package/x/vibc/ibc.go +0 -394
package/app/upgrade.go
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
package gaia
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
5
|
+
swingsetkeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
|
|
6
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
7
|
+
"github.com/cosmos/cosmos-sdk/types/module"
|
|
8
|
+
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
var upgradeNamesOfThisVersion = map[string]bool{
|
|
12
|
+
"agoric-upgrade-16": true,
|
|
13
|
+
"agoric-upgrade-16-2": true,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func isFirstTimeUpgradeOfThisVersion(app *GaiaApp, ctx sdk.Context) bool {
|
|
17
|
+
for name := range upgradeNamesOfThisVersion {
|
|
18
|
+
if app.UpgradeKeeper.GetDoneHeight(ctx, name) != 0 {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// upgrade16Handler performs standard upgrade actions plus custom actions for upgrade-16.
|
|
26
|
+
func upgrade16Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
|
|
27
|
+
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
|
|
28
|
+
app.CheckControllerInited(false)
|
|
29
|
+
|
|
30
|
+
CoreProposalSteps := []vm.CoreProposalStep{}
|
|
31
|
+
|
|
32
|
+
// These CoreProposalSteps are not idempotent and should only be executed
|
|
33
|
+
// as part of the first upgrade using this handler on any given chain.
|
|
34
|
+
if isFirstTimeUpgradeOfThisVersion(app, ctx) {
|
|
35
|
+
// Each CoreProposalStep runs sequentially, and can be constructed from
|
|
36
|
+
// one or more modules executing in parallel within the step.
|
|
37
|
+
CoreProposalSteps = []vm.CoreProposalStep{
|
|
38
|
+
// Upgrade Zoe + ZCF
|
|
39
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/replace-zoe.js"),
|
|
40
|
+
// Revive KREAd characters
|
|
41
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/revive-kread.js"),
|
|
42
|
+
|
|
43
|
+
// upgrade the provisioning vat
|
|
44
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/replace-provisioning.js"),
|
|
45
|
+
// Enable low-level Orchestration.
|
|
46
|
+
vm.CoreProposalStepForModules(
|
|
47
|
+
"@agoric/builders/scripts/vats/init-network.js",
|
|
48
|
+
"@agoric/builders/scripts/vats/init-localchain.js",
|
|
49
|
+
"@agoric/builders/scripts/vats/init-transfer.js",
|
|
50
|
+
),
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
app.upgradeDetails = &upgradeDetails{
|
|
55
|
+
// Record the plan to send to SwingSet
|
|
56
|
+
Plan: plan,
|
|
57
|
+
// Core proposals that should run during the upgrade block
|
|
58
|
+
// These will be merged with any coreProposals specified in the
|
|
59
|
+
// upgradeInfo field of the upgrade plan ran as subsequent steps
|
|
60
|
+
CoreProposals: vm.CoreProposalsFromSteps(CoreProposalSteps...),
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Always run module migrations
|
|
64
|
+
mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
|
|
65
|
+
if err != nil {
|
|
66
|
+
return mvm, err
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
m := swingsetkeeper.NewMigrator(app.SwingSetKeeper)
|
|
70
|
+
err = m.MigrateParams(ctx)
|
|
71
|
+
if err != nil {
|
|
72
|
+
return mvm, err
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return mvm, nil
|
|
76
|
+
}
|
|
77
|
+
}
|
package/cmd/agd/agvm.go
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"os"
|
|
6
|
+
"os/exec"
|
|
7
|
+
|
|
8
|
+
"github.com/tendermint/tendermint/libs/log"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
// NewVMCommand creates a new OS command to run the Agoric VM. It sets up the
|
|
12
|
+
// file descriptors for the VM to communicate with agd, and passes their numbers
|
|
13
|
+
// via AGVM_FROM_AGD and AGVM_TO_AGD environment variables.
|
|
14
|
+
func NewVMCommand(logger log.Logger, binary string, args []string, vmFromAgd, vmToAgd *os.File) *exec.Cmd {
|
|
15
|
+
logger.Info("agd connecting to VM", "binary", binary, "args", args)
|
|
16
|
+
cmd := exec.Command(binary, args[1:]...)
|
|
17
|
+
|
|
18
|
+
// Manage the file descriptors.
|
|
19
|
+
cmd.Stdout = os.Stdout
|
|
20
|
+
cmd.Stderr = os.Stderr
|
|
21
|
+
cmd.Stdin = os.Stdin
|
|
22
|
+
numStdFiles := 3 // stdin, stdout, stderr
|
|
23
|
+
|
|
24
|
+
// We start our file descriptor allocations after the standard ones, including
|
|
25
|
+
// Node.js IPC (fd=3).
|
|
26
|
+
fdFromAgd := 4
|
|
27
|
+
fdToAgd := fdFromAgd + 1
|
|
28
|
+
|
|
29
|
+
// ExtraFiles begins at fd numStdFiles, so we need to compute the array.
|
|
30
|
+
cmd.ExtraFiles = make([]*os.File, fdToAgd - numStdFiles + 1)
|
|
31
|
+
cmd.ExtraFiles[fdFromAgd - numStdFiles] = vmFromAgd
|
|
32
|
+
cmd.ExtraFiles[fdToAgd - numStdFiles] = vmToAgd
|
|
33
|
+
|
|
34
|
+
// Pass the file descriptor numbers in the environment.
|
|
35
|
+
cmd.Env = append(
|
|
36
|
+
os.Environ(),
|
|
37
|
+
fmt.Sprintf("AGVM_FROM_AGD=%d", fdFromAgd),
|
|
38
|
+
fmt.Sprintf("AGVM_TO_AGD=%d", fdToAgd),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return cmd
|
|
42
|
+
}
|
package/cmd/agd/main.go
CHANGED
|
@@ -1,38 +1,157 @@
|
|
|
1
1
|
package main
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
5
|
+
"errors"
|
|
6
|
+
"net/rpc"
|
|
7
|
+
"net/rpc/jsonrpc"
|
|
4
8
|
"os"
|
|
9
|
+
"os/exec"
|
|
5
10
|
"syscall"
|
|
11
|
+
"time"
|
|
6
12
|
|
|
13
|
+
"github.com/spf13/cast"
|
|
7
14
|
"github.com/tendermint/tendermint/libs/log"
|
|
8
15
|
|
|
9
16
|
gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
|
|
10
17
|
"github.com/Agoric/agoric-sdk/golang/cosmos/daemon"
|
|
11
18
|
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"
|
|
12
21
|
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
|
13
22
|
)
|
|
14
23
|
|
|
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
|
+
// main is the entry point of the agd daemon. It determines whether to
|
|
53
|
+
// initialize JSON-RPC communications with the separate `--split-vm` VM process,
|
|
54
|
+
// or just to give up control entirely to another binary.
|
|
15
55
|
func main() {
|
|
16
|
-
|
|
17
|
-
|
|
56
|
+
var vmClient *rpc.Client
|
|
57
|
+
var shutdown func() error
|
|
58
|
+
|
|
59
|
+
nodePort := 1
|
|
60
|
+
var sendToNode vm.Sender = func(ctx context.Context, needReply bool, jsonRequest string) (jsonReply string, err error) {
|
|
61
|
+
if vmClient == nil {
|
|
62
|
+
return "", errors.New("sendToVM called without VM client set up")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if jsonRequest == "shutdown" {
|
|
66
|
+
// We could ask nicely, but don't bother.
|
|
67
|
+
if shutdown != nil {
|
|
68
|
+
return "", shutdown()
|
|
69
|
+
}
|
|
70
|
+
return "", nil
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
msg := vm.Message{
|
|
74
|
+
Port: nodePort,
|
|
75
|
+
NeedsReply: needReply,
|
|
76
|
+
Data: jsonRequest,
|
|
77
|
+
}
|
|
78
|
+
var reply string
|
|
79
|
+
err = vmClient.Call(vm.ReceiveMessageMethod, msg, &reply)
|
|
80
|
+
return reply, err
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exitCode := 0
|
|
84
|
+
launchVM := func(agdServer *vm.AgdServer, logger log.Logger, appOpts servertypes.AppOptions) error {
|
|
18
85
|
args := []string{"ag-chain-cosmos", "--home", gaia.DefaultNodeHome}
|
|
19
86
|
args = append(args, os.Args[1:]...)
|
|
20
87
|
|
|
21
|
-
binary
|
|
22
|
-
if
|
|
23
|
-
|
|
88
|
+
binary := cast.ToString(appOpts.Get(daemoncmd.FlagSplitVm))
|
|
89
|
+
if binary == "" {
|
|
90
|
+
binary, lookErr := FindCosmicSwingsetBinary()
|
|
91
|
+
if lookErr != nil {
|
|
92
|
+
return lookErr
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// We completely delegate to our default app for running the actual chain.
|
|
96
|
+
logger.Info("agd delegating to JS executable", "binary", binary, "args", args)
|
|
97
|
+
return syscall.Exec(binary, args, os.Environ())
|
|
24
98
|
}
|
|
25
99
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if
|
|
29
|
-
return
|
|
100
|
+
// Split the execution between us and the VM.
|
|
101
|
+
agdFromVm, vmToAgd, err := os.Pipe()
|
|
102
|
+
if err != nil {
|
|
103
|
+
return err
|
|
30
104
|
}
|
|
105
|
+
vmFromAgd, agdToVm, err := os.Pipe()
|
|
106
|
+
if err != nil {
|
|
107
|
+
return err
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Start the command running, then continue.
|
|
111
|
+
args[0] = binary
|
|
112
|
+
cmd := NewVMCommand(logger, binary, args, vmFromAgd, vmToAgd)
|
|
113
|
+
shutdown = makeShutdown(cmd, agdToVm)
|
|
114
|
+
|
|
115
|
+
if err := cmd.Start(); err != nil {
|
|
116
|
+
return err
|
|
117
|
+
}
|
|
118
|
+
if vmFromAgd.Close() != nil {
|
|
119
|
+
return err
|
|
120
|
+
}
|
|
121
|
+
if vmToAgd.Close() != nil {
|
|
122
|
+
return err
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Multiplex bidirectional JSON-RPC over the pipes.
|
|
126
|
+
agvmConn := jsonrpcconn.NewConn(agdFromVm, agdToVm)
|
|
127
|
+
clientConn, serverConn := jsonrpcconn.ClientServerConn(agvmConn)
|
|
128
|
+
|
|
129
|
+
// Set up the VM server.
|
|
130
|
+
vmServer := rpc.NewServer()
|
|
131
|
+
if err := vmServer.RegisterName("agd", agdServer); err != nil {
|
|
132
|
+
return err
|
|
133
|
+
}
|
|
134
|
+
go vmServer.ServeCodec(jsonrpc.NewServerCodec(serverConn))
|
|
135
|
+
|
|
136
|
+
// Set up the VM client.
|
|
137
|
+
vmClient = jsonrpc.NewClient(clientConn)
|
|
138
|
+
|
|
139
|
+
go func() {
|
|
140
|
+
// Premature exit from `agd start` should exit the process.
|
|
141
|
+
_ = cmd.Wait()
|
|
142
|
+
os.Exit(exitCode)
|
|
143
|
+
}()
|
|
144
|
+
|
|
31
145
|
return nil
|
|
32
146
|
}
|
|
33
147
|
|
|
34
|
-
daemoncmd.OnStartHook = launchVM
|
|
35
148
|
daemoncmd.OnExportHook = launchVM
|
|
149
|
+
daemoncmd.OnStartHook = func(agdServer *vm.AgdServer, logger log.Logger, appOpts servertypes.AppOptions) error {
|
|
150
|
+
// We tried running start, which should never exit, so exit with non-zero
|
|
151
|
+
// code if we do.
|
|
152
|
+
exitCode = 99
|
|
153
|
+
return launchVM(agdServer, logger, appOpts)
|
|
154
|
+
}
|
|
36
155
|
|
|
37
|
-
daemon.RunWithController(
|
|
156
|
+
daemon.RunWithController(sendToNode)
|
|
38
157
|
}
|
package/cmd/libdaemon/main.go
CHANGED
|
@@ -12,7 +12,7 @@ import "C"
|
|
|
12
12
|
import (
|
|
13
13
|
"context"
|
|
14
14
|
"encoding/json"
|
|
15
|
-
"
|
|
15
|
+
"net/rpc"
|
|
16
16
|
"os"
|
|
17
17
|
"path/filepath"
|
|
18
18
|
|
|
@@ -32,8 +32,32 @@ type goReturn = struct {
|
|
|
32
32
|
|
|
33
33
|
const SwingSetPort = 123
|
|
34
34
|
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var vmClientCodec *vm.ClientCodec
|
|
36
|
+
var agdServer *vm.AgdServer
|
|
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, vm.Sender) {
|
|
41
|
+
vmClientCodec = vm.NewClientCodec(ctx, sendFunc)
|
|
42
|
+
vmClient := rpc.NewClientWithCodec(vmClientCodec)
|
|
43
|
+
|
|
44
|
+
var sendToNode vm.Sender = func(ctx context.Context, needReply bool, jsonRequest string) (jsonReply string, err error) {
|
|
45
|
+
if jsonRequest == "shutdown" {
|
|
46
|
+
return "", vmClientCodec.Close()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
msg := vm.Message{
|
|
50
|
+
Port: nodePort,
|
|
51
|
+
NeedsReply: needReply,
|
|
52
|
+
Data: jsonRequest,
|
|
53
|
+
}
|
|
54
|
+
var reply string
|
|
55
|
+
err = vmClient.Call(vm.ReceiveMessageMethod, msg, &reply)
|
|
56
|
+
return reply, err
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return vmClientCodec, sendToNode
|
|
60
|
+
}
|
|
37
61
|
|
|
38
62
|
//export RunAgCosmosDaemon
|
|
39
63
|
func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char) C.int {
|
|
@@ -44,43 +68,35 @@ func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char)
|
|
|
44
68
|
|
|
45
69
|
gaia.DefaultNodeHome = filepath.Join(userHomeDir, ".ag-chain-cosmos")
|
|
46
70
|
daemoncmd.AppName = "ag-chain-cosmos"
|
|
71
|
+
if err := os.Setenv(daemoncmd.EmbeddedVmEnvVar, "libdaemon"); err != nil {
|
|
72
|
+
panic(err)
|
|
73
|
+
}
|
|
47
74
|
|
|
48
|
-
|
|
49
|
-
sendToNode := func(ctx context.Context, needReply bool, str string) (string, error) {
|
|
50
|
-
var rPort int
|
|
51
|
-
if needReply {
|
|
52
|
-
lastReply++
|
|
53
|
-
rPort = lastReply
|
|
54
|
-
replies[rPort] = make(chan goReturn)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Send the message
|
|
58
|
-
C.invokeSendFunc(toNode, nodePort, C.int(rPort), C.CString(str))
|
|
59
|
-
if !needReply {
|
|
60
|
-
// Return immediately
|
|
61
|
-
// fmt.Fprintln(os.Stderr, "Don't wait")
|
|
62
|
-
return "<no-reply-requested>", nil
|
|
63
|
-
}
|
|
75
|
+
var sendToNode vm.Sender
|
|
64
76
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
ret := <-replies[rPort]
|
|
68
|
-
delete(replies, rPort)
|
|
69
|
-
// fmt.Fprintln(os.Stderr, "Woken, got", ret)
|
|
70
|
-
return ret.str, ret.err
|
|
77
|
+
sendFunc := func(port int, reply int, str string) {
|
|
78
|
+
C.invokeSendFunc(toNode, C.int(port), C.int(reply), C.CString(str))
|
|
71
79
|
}
|
|
72
80
|
|
|
81
|
+
vmClientCodec, sendToNode = ConnectVMClientCodec(
|
|
82
|
+
context.Background(),
|
|
83
|
+
int(nodePort),
|
|
84
|
+
sendFunc,
|
|
85
|
+
)
|
|
86
|
+
|
|
73
87
|
args := make([]string, len(cosmosArgs))
|
|
74
88
|
for i, s := range cosmosArgs {
|
|
75
89
|
args[i] = C.GoString(s)
|
|
76
90
|
}
|
|
91
|
+
|
|
77
92
|
// fmt.Fprintln(os.Stderr, "Starting Cosmos", args)
|
|
78
93
|
os.Args = args
|
|
79
94
|
go func() {
|
|
80
95
|
// We run in the background, but exit when the job is over.
|
|
81
96
|
// swingset.SendToNode("hello from Initial Go!")
|
|
82
97
|
exitCode := 0
|
|
83
|
-
daemoncmd.OnStartHook = func(logger log.Logger, appOpts servertypes.AppOptions) error {
|
|
98
|
+
daemoncmd.OnStartHook = func(srv *vm.AgdServer, logger log.Logger, appOpts servertypes.AppOptions) error {
|
|
99
|
+
agdServer = srv
|
|
84
100
|
// We tried running start, which should never exit, so exit with non-zero
|
|
85
101
|
// code if we ever stop.
|
|
86
102
|
exitCode = 99
|
|
@@ -97,22 +113,10 @@ func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char)
|
|
|
97
113
|
//export ReplyToGo
|
|
98
114
|
func ReplyToGo(replyPort C.int, isError C.int, resp C.Body) C.int {
|
|
99
115
|
respStr := C.GoString(resp)
|
|
100
|
-
// fmt.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// Unexpected reply.
|
|
104
|
-
// This is okay, since the caller decides whether or
|
|
105
|
-
// not she wants to listen for replies.
|
|
106
|
-
return C.int(0)
|
|
116
|
+
// fmt.Printf("Reply to Go %d %s\n", replyPort, respStr)
|
|
117
|
+
if err := vmClientCodec.Receive(int(replyPort), int(isError) != 0, respStr); err != nil {
|
|
118
|
+
return C.int(1)
|
|
107
119
|
}
|
|
108
|
-
// Wake up the waiting goroutine
|
|
109
|
-
ret := goReturn{}
|
|
110
|
-
if int(isError) == 0 {
|
|
111
|
-
ret.str = respStr
|
|
112
|
-
} else {
|
|
113
|
-
ret.err = errors.New(respStr)
|
|
114
|
-
}
|
|
115
|
-
returnCh <- ret
|
|
116
120
|
return C.int(0)
|
|
117
121
|
}
|
|
118
122
|
|
|
@@ -124,20 +128,27 @@ type errorWrapper struct {
|
|
|
124
128
|
func SendToGo(port C.int, msg C.Body) C.Body {
|
|
125
129
|
msgStr := C.GoString(msg)
|
|
126
130
|
// fmt.Fprintln(os.Stderr, "Send to Go", msgStr)
|
|
127
|
-
respStr
|
|
131
|
+
var respStr string
|
|
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)
|
|
128
148
|
if err != nil {
|
|
129
|
-
|
|
130
|
-
errResp := errorWrapper{
|
|
131
|
-
Error: err.Error(),
|
|
132
|
-
}
|
|
133
|
-
respBytes, err := json.Marshal(&errResp)
|
|
134
|
-
if err != nil {
|
|
135
|
-
panic(err)
|
|
136
|
-
}
|
|
137
|
-
// fmt.Fprintln(os.Stderr, "Marshaled", errResp, respBytes)
|
|
138
|
-
respStr = string(respBytes)
|
|
149
|
+
panic(err)
|
|
139
150
|
}
|
|
140
|
-
return C.CString(
|
|
151
|
+
return C.CString(string(respBytes))
|
|
141
152
|
}
|
|
142
153
|
|
|
143
154
|
// Do nothing in main.
|
|
@@ -5,11 +5,12 @@ import (
|
|
|
5
5
|
"strings"
|
|
6
6
|
"testing"
|
|
7
7
|
|
|
8
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
8
9
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
9
10
|
)
|
|
10
11
|
|
|
11
12
|
func TestErrorStackTraces(t *testing.T) {
|
|
12
|
-
err :=
|
|
13
|
+
err := sdkioerrors.Wrapf(sdkerrors.ErrInsufficientFee, "my error %d", 123)
|
|
13
14
|
expected := "my error 123: insufficient fee"
|
|
14
15
|
|
|
15
16
|
// Check that sdkerrors.Wrapf(...).Error() does not leak stack.
|