@agoric/cosmos 0.35.0-upgrade-14-dev-0169c7e.0 → 0.35.0-upgrade-16-dev-07b0130.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 +121 -77
- package/MAINTAINERS.md +3 -0
- package/Makefile +49 -26
- package/ante/ante.go +11 -11
- package/ante/inbound_test.go +3 -2
- package/ante/vm_admission.go +2 -1
- package/app/app.go +260 -175
- package/app/export.go +13 -6
- package/app/upgrade.go +76 -0
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/main.go +132 -11
- package/cmd/libdaemon/main.go +67 -53
- package/cmd/libdaemon/main_test.go +2 -1
- package/daemon/cmd/genaccounts.go +13 -9
- package/daemon/cmd/root.go +186 -73
- package/daemon/cmd/root_test.go +190 -2
- package/daemon/cmd/testnet.go +17 -6
- package/daemon/main.go +6 -3
- 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 +110 -68
- package/go.sum +601 -248
- package/package.json +9 -5
- 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/vstorage/query.proto +53 -1
- package/proto/agoric/vtransfer/genesis.proto +18 -0
- package/scripts/protocgen.sh +16 -6
- package/third_party/proto/buf.yaml +1 -0
- package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
- package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
- package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
- package/third_party/proto/google/api/annotations.proto +1 -1
- package/third_party/proto/google/api/http.proto +181 -120
- package/third_party/proto/google/api/httpbody.proto +9 -6
- package/third_party/proto/google/protobuf/any.proto +1 -7
- package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
- package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
- package/types/kv_entry_helpers.go +42 -0
- package/upgradegaia.sh +21 -12
- package/vm/action.go +28 -24
- package/vm/action_test.go +36 -16
- package/vm/client.go +113 -0
- package/vm/client_test.go +182 -0
- package/vm/controller.go +18 -42
- 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/query.go +2 -2
- package/x/swingset/client/cli/tx.go +52 -33
- package/x/swingset/client/proposal_handler.go +2 -17
- 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 +21 -36
- package/x/swingset/keeper/keeper_test.go +1 -1
- package/x/swingset/keeper/msg_server.go +20 -22
- package/x/swingset/keeper/proposal.go +13 -3
- package/x/swingset/keeper/querier.go +23 -14
- package/x/swingset/keeper/swing_store_exports_handler.go +21 -6
- package/x/swingset/keeper/test_utils.go +16 -0
- package/x/swingset/module.go +7 -7
- package/x/swingset/proposal_handler.go +5 -4
- package/x/swingset/swingset.go +4 -2
- package/x/swingset/testing/queue.go +17 -0
- package/x/swingset/types/codec.go +2 -2
- 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/msgs.pb.go +16 -16
- package/x/swingset/types/params.go +2 -1
- package/x/swingset/types/proposal.go +10 -9
- package/x/swingset/types/swingset.pb.go +1 -1
- package/x/swingset/types/types.go +30 -28
- package/x/vbank/genesis.go +0 -2
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/keeper.go +3 -2
- package/x/vbank/keeper/querier.go +9 -4
- package/x/vbank/keeper/rewards.go +1 -1
- package/x/vbank/module.go +0 -5
- package/x/vbank/types/msgs.go +0 -12
- package/x/vbank/vbank.go +20 -19
- package/x/vbank/vbank_test.go +10 -10
- package/x/vibc/alias.go +3 -0
- package/x/vibc/handler.go +16 -9
- package/x/vibc/keeper/keeper.go +112 -74
- package/x/vibc/keeper/triggers.go +101 -0
- package/x/vibc/module.go +5 -8
- package/x/vibc/types/expected_keepers.go +26 -5
- package/x/vibc/types/ibc_module.go +336 -0
- package/x/vibc/types/msgs.go +1 -1
- package/x/vibc/types/msgs.pb.go +1 -1
- 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/README.md +138 -0
- package/x/vstorage/capdata/capdata.go +298 -0
- package/x/vstorage/capdata/capdata_test.go +352 -0
- package/x/vstorage/client/cli/query.go +51 -4
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +220 -0
- package/x/vstorage/keeper/keeper.go +16 -22
- package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
- package/x/vstorage/keeper/keeper_test.go +1 -1
- package/x/vstorage/keeper/querier.go +11 -6
- 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/vstorage/types/query.pb.go +646 -36
- package/x/vstorage/types/query.pb.gw.go +119 -0
- package/x/vstorage/vstorage.go +16 -15
- package/x/vstorage/vstorage_test.go +5 -5
- 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/ante/fee.go +0 -96
- 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 -254
- package/x/lien/keeper/keeper_test.go +0 -623
- package/x/lien/lien.go +0 -203
- package/x/lien/lien_test.go +0 -529
- 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 -393
- /package/{src/index.cjs → index.cjs} +0 -0
package/app/export.go
CHANGED
|
@@ -44,9 +44,10 @@ func (app *GaiaApp) ExportAppStateAndValidators(
|
|
|
44
44
|
}, err
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
47
|
+
// prepForZeroHeightGenesis prepares for a fresh start at zero height.
|
|
48
|
+
//
|
|
49
|
+
// NOTE: Zero height genesis is a temporary feature which will be deprecated
|
|
50
|
+
// in favour of export at a block height.
|
|
50
51
|
func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
|
|
51
52
|
applyAllowedAddrs := false
|
|
52
53
|
|
|
@@ -106,7 +107,9 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
|
|
|
106
107
|
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
|
|
107
108
|
app.DistrKeeper.SetFeePool(ctx, feePool)
|
|
108
109
|
|
|
109
|
-
app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
|
|
110
|
+
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err != nil {
|
|
111
|
+
panic(err)
|
|
112
|
+
}
|
|
110
113
|
return false
|
|
111
114
|
})
|
|
112
115
|
|
|
@@ -120,8 +123,12 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
|
|
|
120
123
|
if err != nil {
|
|
121
124
|
panic(err)
|
|
122
125
|
}
|
|
123
|
-
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
|
|
124
|
-
|
|
126
|
+
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
|
|
127
|
+
panic(err)
|
|
128
|
+
}
|
|
129
|
+
if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
|
|
130
|
+
panic(err)
|
|
131
|
+
}
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
// reset context height
|
package/app/upgrade.go
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
}
|
|
14
|
+
|
|
15
|
+
func isFirstTimeUpgradeOfThisVersion(app *GaiaApp, ctx sdk.Context) bool {
|
|
16
|
+
for name := range upgradeNamesOfThisVersion {
|
|
17
|
+
if app.UpgradeKeeper.GetDoneHeight(ctx, name) != 0 {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// upgrade16Handler performs standard upgrade actions plus custom actions for upgrade-16.
|
|
25
|
+
func upgrade16Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgradetypes.Plan, module.VersionMap) (module.VersionMap, error) {
|
|
26
|
+
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVm module.VersionMap) (module.VersionMap, error) {
|
|
27
|
+
app.CheckControllerInited(false)
|
|
28
|
+
|
|
29
|
+
CoreProposalSteps := []vm.CoreProposalStep{}
|
|
30
|
+
|
|
31
|
+
// These CoreProposalSteps are not idempotent and should only be executed
|
|
32
|
+
// as part of the first upgrade using this handler on any given chain.
|
|
33
|
+
if isFirstTimeUpgradeOfThisVersion(app, ctx) {
|
|
34
|
+
// Each CoreProposalStep runs sequentially, and can be constructed from
|
|
35
|
+
// one or more modules executing in parallel within the step.
|
|
36
|
+
CoreProposalSteps = []vm.CoreProposalStep{
|
|
37
|
+
// Upgrade Zoe + ZCF
|
|
38
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/replace-zoe.js"),
|
|
39
|
+
// Revive KREAd characters
|
|
40
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/revive-kread.js"),
|
|
41
|
+
|
|
42
|
+
// upgrade the provisioning vat
|
|
43
|
+
vm.CoreProposalStepForModules("@agoric/builders/scripts/vats/replace-provisioning.js"),
|
|
44
|
+
// Enable low-level Orchestration.
|
|
45
|
+
vm.CoreProposalStepForModules(
|
|
46
|
+
"@agoric/builders/scripts/vats/init-network.js",
|
|
47
|
+
"@agoric/builders/scripts/vats/init-localchain.js",
|
|
48
|
+
"@agoric/builders/scripts/vats/init-transfer.js",
|
|
49
|
+
),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
app.upgradeDetails = &upgradeDetails{
|
|
54
|
+
// Record the plan to send to SwingSet
|
|
55
|
+
Plan: plan,
|
|
56
|
+
// Core proposals that should run during the upgrade block
|
|
57
|
+
// These will be merged with any coreProposals specified in the
|
|
58
|
+
// upgradeInfo field of the upgrade plan ran as subsequent steps
|
|
59
|
+
CoreProposals: vm.CoreProposalsFromSteps(CoreProposalSteps...),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Always run module migrations
|
|
63
|
+
mvm, err := app.mm.RunMigrations(ctx, app.configurator, fromVm)
|
|
64
|
+
if err != nil {
|
|
65
|
+
return mvm, err
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
m := swingsetkeeper.NewMigrator(app.SwingSetKeeper)
|
|
69
|
+
err = m.MigrateParams(ctx)
|
|
70
|
+
if err != nil {
|
|
71
|
+
return mvm, err
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return mvm, nil
|
|
75
|
+
}
|
|
76
|
+
}
|
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,36 +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"
|
|
21
|
+
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
|
12
22
|
)
|
|
13
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.
|
|
14
55
|
func main() {
|
|
15
|
-
|
|
16
|
-
|
|
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 {
|
|
17
85
|
args := []string{"ag-chain-cosmos", "--home", gaia.DefaultNodeHome}
|
|
18
86
|
args = append(args, os.Args[1:]...)
|
|
19
87
|
|
|
20
|
-
binary
|
|
21
|
-
if
|
|
22
|
-
|
|
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())
|
|
23
98
|
}
|
|
24
99
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if
|
|
28
|
-
|
|
100
|
+
// Split the execution between us and the VM.
|
|
101
|
+
agdFromVm, vmToAgd, err := os.Pipe()
|
|
102
|
+
if err != nil {
|
|
103
|
+
return err
|
|
29
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
|
+
|
|
145
|
+
return nil
|
|
30
146
|
}
|
|
31
147
|
|
|
32
|
-
daemoncmd.OnStartHook = launchVM
|
|
33
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
|
+
}
|
|
34
155
|
|
|
35
|
-
daemon.RunWithController(
|
|
156
|
+
daemon.RunWithController(sendToNode)
|
|
36
157
|
}
|
package/cmd/libdaemon/main.go
CHANGED
|
@@ -10,8 +10,9 @@ package main
|
|
|
10
10
|
import "C"
|
|
11
11
|
|
|
12
12
|
import (
|
|
13
|
+
"context"
|
|
13
14
|
"encoding/json"
|
|
14
|
-
"
|
|
15
|
+
"net/rpc"
|
|
15
16
|
"os"
|
|
16
17
|
"path/filepath"
|
|
17
18
|
|
|
@@ -21,6 +22,7 @@ import (
|
|
|
21
22
|
"github.com/Agoric/agoric-sdk/golang/cosmos/daemon"
|
|
22
23
|
daemoncmd "github.com/Agoric/agoric-sdk/golang/cosmos/daemon/cmd"
|
|
23
24
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
25
|
+
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
|
24
26
|
)
|
|
25
27
|
|
|
26
28
|
type goReturn = struct {
|
|
@@ -30,8 +32,32 @@ type goReturn = struct {
|
|
|
30
32
|
|
|
31
33
|
const SwingSetPort = 123
|
|
32
34
|
|
|
33
|
-
var
|
|
34
|
-
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
|
+
}
|
|
35
61
|
|
|
36
62
|
//export RunAgCosmosDaemon
|
|
37
63
|
func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char) C.int {
|
|
@@ -42,46 +68,39 @@ func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char)
|
|
|
42
68
|
|
|
43
69
|
gaia.DefaultNodeHome = filepath.Join(userHomeDir, ".ag-chain-cosmos")
|
|
44
70
|
daemoncmd.AppName = "ag-chain-cosmos"
|
|
71
|
+
if err := os.Setenv(daemoncmd.EmbeddedVmEnvVar, "libdaemon"); err != nil {
|
|
72
|
+
panic(err)
|
|
73
|
+
}
|
|
45
74
|
|
|
46
|
-
|
|
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
|
-
}
|
|
54
|
-
|
|
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
|
-
}
|
|
75
|
+
var sendToNode vm.Sender
|
|
62
76
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
ret := <-replies[rPort]
|
|
66
|
-
delete(replies, rPort)
|
|
67
|
-
// fmt.Fprintln(os.Stderr, "Woken, got", ret)
|
|
68
|
-
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))
|
|
69
79
|
}
|
|
70
80
|
|
|
81
|
+
vmClientCodec, sendToNode = ConnectVMClientCodec(
|
|
82
|
+
context.Background(),
|
|
83
|
+
int(nodePort),
|
|
84
|
+
sendFunc,
|
|
85
|
+
)
|
|
86
|
+
|
|
71
87
|
args := make([]string, len(cosmosArgs))
|
|
72
88
|
for i, s := range cosmosArgs {
|
|
73
89
|
args[i] = C.GoString(s)
|
|
74
90
|
}
|
|
91
|
+
|
|
75
92
|
// fmt.Fprintln(os.Stderr, "Starting Cosmos", args)
|
|
76
93
|
os.Args = args
|
|
77
94
|
go func() {
|
|
78
95
|
// We run in the background, but exit when the job is over.
|
|
79
96
|
// swingset.SendToNode("hello from Initial Go!")
|
|
80
97
|
exitCode := 0
|
|
81
|
-
daemoncmd.OnStartHook = func(logger log.Logger) {
|
|
98
|
+
daemoncmd.OnStartHook = func(srv *vm.AgdServer, logger log.Logger, appOpts servertypes.AppOptions) error {
|
|
99
|
+
agdServer = srv
|
|
82
100
|
// We tried running start, which should never exit, so exit with non-zero
|
|
83
101
|
// code if we ever stop.
|
|
84
102
|
exitCode = 99
|
|
103
|
+
return nil
|
|
85
104
|
}
|
|
86
105
|
daemon.RunWithController(sendToNode)
|
|
87
106
|
// fmt.Fprintln(os.Stderr, "Shutting down Cosmos")
|
|
@@ -94,22 +113,10 @@ func RunAgCosmosDaemon(nodePort C.int, toNode C.sendFunc, cosmosArgs []*C.char)
|
|
|
94
113
|
//export ReplyToGo
|
|
95
114
|
func ReplyToGo(replyPort C.int, isError C.int, resp C.Body) C.int {
|
|
96
115
|
respStr := C.GoString(resp)
|
|
97
|
-
// fmt.
|
|
98
|
-
|
|
99
|
-
|
|
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)
|
|
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)
|
|
104
119
|
}
|
|
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
|
|
113
120
|
return C.int(0)
|
|
114
121
|
}
|
|
115
122
|
|
|
@@ -121,20 +128,27 @@ type errorWrapper struct {
|
|
|
121
128
|
func SendToGo(port C.int, msg C.Body) C.Body {
|
|
122
129
|
msgStr := C.GoString(msg)
|
|
123
130
|
// fmt.Fprintln(os.Stderr, "Send to Go", msgStr)
|
|
124
|
-
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)
|
|
125
148
|
if err != nil {
|
|
126
|
-
|
|
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)
|
|
149
|
+
panic(err)
|
|
136
150
|
}
|
|
137
|
-
return C.CString(
|
|
151
|
+
return C.CString(string(respBytes))
|
|
138
152
|
}
|
|
139
153
|
|
|
140
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.
|
|
@@ -10,6 +10,7 @@ import (
|
|
|
10
10
|
|
|
11
11
|
"github.com/cosmos/cosmos-sdk/client"
|
|
12
12
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
13
|
+
"github.com/cosmos/cosmos-sdk/codec"
|
|
13
14
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
14
15
|
"github.com/cosmos/cosmos-sdk/server"
|
|
15
16
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@@ -27,14 +28,14 @@ const (
|
|
|
27
28
|
)
|
|
28
29
|
|
|
29
30
|
// AddGenesisAccountCmd returns add-genesis-account cobra Command.
|
|
30
|
-
func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command {
|
|
31
|
+
func AddGenesisAccountCmd(cdc codec.Codec, defaultNodeHome string) *cobra.Command {
|
|
31
32
|
cmd := &cobra.Command{
|
|
32
|
-
Use: "add-genesis-account
|
|
33
|
+
Use: "add-genesis-account <address_or_key_name> <coin>[,...]",
|
|
33
34
|
Short: "Add a genesis account to genesis.json",
|
|
34
|
-
Long: `Add a genesis account to genesis.json.
|
|
35
|
-
the
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
Long: `Add a genesis account to genesis.json.
|
|
36
|
+
If the address is specified by name, it will be looked up in the local Keybase.
|
|
37
|
+
The comma-separated list of initial tokens must contain valid denominations.
|
|
38
|
+
Accounts may optionally be supplied with vesting parameters.
|
|
38
39
|
`,
|
|
39
40
|
Args: cobra.ExactArgs(2),
|
|
40
41
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
@@ -54,17 +55,20 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
// attempt to lookup address from Keybase if no address was provided
|
|
57
|
-
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.KeyringDir, inBuf)
|
|
58
|
+
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.KeyringDir, inBuf, cdc)
|
|
58
59
|
if err != nil {
|
|
59
60
|
return err
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
info, err := kb.Key(args[0])
|
|
63
64
|
if err != nil {
|
|
64
|
-
return fmt.Errorf("failed to get
|
|
65
|
+
return fmt.Errorf("failed to get key from Keybase: %s", err)
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
addr = info.GetAddress()
|
|
68
|
+
addr, err = info.GetAddress()
|
|
69
|
+
if err != nil {
|
|
70
|
+
return fmt.Errorf("failed to get address from Keybase: %s", err)
|
|
71
|
+
}
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
coins, err := sdk.ParseCoinsNormalized(args[1])
|