@agoric/cosmos 0.35.0-u13.0 → 0.35.0-u14.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/Makefile +25 -12
  3. package/ante/ante.go +5 -6
  4. package/app/app.go +142 -96
  5. package/app/export.go +13 -6
  6. package/cmd/agd/main.go +5 -3
  7. package/cmd/libdaemon/main.go +5 -2
  8. package/daemon/cmd/genaccounts.go +13 -9
  9. package/daemon/cmd/root.go +38 -15
  10. package/daemon/cmd/root_test.go +1 -1
  11. package/daemon/cmd/testnet.go +17 -6
  12. package/daemon/main.go +3 -2
  13. package/git-revision.txt +1 -1
  14. package/go.mod +95 -64
  15. package/go.sum +592 -243
  16. package/package.json +3 -3
  17. package/proto/agoric/vstorage/query.proto +53 -1
  18. package/scripts/protocgen.sh +12 -1
  19. package/third_party/proto/buf.yaml +1 -0
  20. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  21. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  22. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  23. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  24. package/third_party/proto/google/api/annotations.proto +1 -1
  25. package/third_party/proto/google/api/http.proto +181 -120
  26. package/third_party/proto/google/api/httpbody.proto +9 -6
  27. package/third_party/proto/google/protobuf/any.proto +1 -7
  28. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  29. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  30. package/upgradegaia.sh +13 -4
  31. package/vm/action.go +133 -0
  32. package/vm/action_test.go +129 -0
  33. package/vm/controller.go +9 -16
  34. package/vm/core_proposals.go +31 -0
  35. package/x/lien/keeper/account.go +3 -3
  36. package/x/lien/keeper/keeper.go +5 -4
  37. package/x/lien/keeper/keeper_test.go +9 -9
  38. package/x/lien/lien.go +6 -4
  39. package/x/lien/lien_test.go +20 -16
  40. package/x/swingset/abci.go +25 -33
  41. package/x/swingset/client/cli/query.go +2 -2
  42. package/x/swingset/client/cli/tx.go +48 -33
  43. package/x/swingset/client/proposal_handler.go +2 -17
  44. package/x/swingset/keeper/keeper.go +30 -15
  45. package/x/swingset/keeper/keeper_test.go +1 -1
  46. package/x/swingset/keeper/msg_server.go +21 -51
  47. package/x/swingset/keeper/proposal.go +14 -8
  48. package/x/swingset/keeper/querier.go +14 -6
  49. package/x/swingset/keeper/swing_store_exports_handler.go +5 -1
  50. package/x/swingset/proposal_handler.go +3 -3
  51. package/x/swingset/swingset.go +4 -2
  52. package/x/swingset/types/codec.go +2 -2
  53. package/x/swingset/types/msgs.pb.go +16 -16
  54. package/x/swingset/types/proposal.go +5 -5
  55. package/x/swingset/types/types.go +30 -28
  56. package/x/vbank/keeper/keeper.go +3 -2
  57. package/x/vbank/keeper/querier.go +6 -2
  58. package/x/vbank/keeper/rewards.go +1 -1
  59. package/x/vbank/vbank.go +19 -17
  60. package/x/vbank/vbank_test.go +18 -18
  61. package/x/vibc/handler.go +3 -8
  62. package/x/vibc/ibc.go +66 -113
  63. package/x/vibc/keeper/keeper.go +19 -18
  64. package/x/vibc/types/expected_keepers.go +13 -5
  65. package/x/vibc/types/msgs.go +1 -1
  66. package/x/vibc/types/msgs.pb.go +1 -1
  67. package/x/vstorage/README.md +138 -0
  68. package/x/vstorage/capdata/capdata.go +298 -0
  69. package/x/vstorage/capdata/capdata_test.go +352 -0
  70. package/x/vstorage/client/cli/query.go +51 -4
  71. package/x/vstorage/keeper/grpc_query.go +221 -0
  72. package/x/vstorage/keeper/keeper.go +3 -2
  73. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  74. package/x/vstorage/keeper/keeper_test.go +1 -1
  75. package/x/vstorage/keeper/querier.go +6 -2
  76. package/x/vstorage/types/query.pb.go +646 -36
  77. package/x/vstorage/types/query.pb.gw.go +119 -0
  78. package/x/vstorage/vstorage.go +16 -15
  79. package/x/vstorage/vstorage_test.go +5 -5
  80. package/ante/fee.go +0 -96
  81. /package/{src/index.cjs → index.cjs} +0 -0
@@ -2,6 +2,7 @@ package swingset
2
2
 
3
3
  import (
4
4
  // "os"
5
+ "context"
5
6
  "fmt"
6
7
  "time"
7
8
 
@@ -9,38 +10,34 @@ import (
9
10
  sdk "github.com/cosmos/cosmos-sdk/types"
10
11
  abci "github.com/tendermint/tendermint/abci/types"
11
12
 
13
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
12
14
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
13
15
  )
14
16
 
15
17
  type beginBlockAction struct {
16
- Type string `json:"type"`
17
- BlockHeight int64 `json:"blockHeight"`
18
- BlockTime int64 `json:"blockTime"`
19
- ChainID string `json:"chainID"`
20
- Params types.Params `json:"params"`
18
+ vm.ActionHeader `actionType:"BEGIN_BLOCK"`
19
+ ChainID string `json:"chainID"`
20
+ Params types.Params `json:"params"`
21
21
  }
22
22
 
23
23
  type endBlockAction struct {
24
- Type string `json:"type"`
25
- BlockHeight int64 `json:"blockHeight"`
26
- BlockTime int64 `json:"blockTime"`
24
+ vm.ActionHeader `actionType:"END_BLOCK"`
27
25
  }
28
26
 
29
27
  type commitBlockAction struct {
30
- Type string `json:"type"`
31
- BlockHeight int64 `json:"blockHeight"`
32
- BlockTime int64 `json:"blockTime"`
28
+ vm.ActionHeader `actionType:"COMMIT_BLOCK"`
29
+ }
30
+
31
+ type afterCommitBlockAction struct {
32
+ vm.ActionHeader `actionType:"AFTER_COMMIT_BLOCK"`
33
33
  }
34
34
 
35
35
  func BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, keeper Keeper) error {
36
36
  defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
37
37
 
38
38
  action := &beginBlockAction{
39
- Type: "BEGIN_BLOCK",
40
- BlockHeight: ctx.BlockHeight(),
41
- BlockTime: ctx.BlockTime().Unix(),
42
- ChainID: ctx.ChainID(),
43
- Params: keeper.GetParams(ctx),
39
+ ChainID: ctx.ChainID(),
40
+ Params: keeper.GetParams(ctx),
44
41
  }
45
42
  _, err := keeper.BlockingSend(ctx, action)
46
43
  // fmt.Fprintf(os.Stderr, "BEGIN_BLOCK Returned from SwingSet: %s, %v\n", out, err)
@@ -59,11 +56,7 @@ var endBlockTime int64
59
56
  func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.ValidatorUpdate, error) {
60
57
  defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
61
58
 
62
- action := &endBlockAction{
63
- Type: "END_BLOCK",
64
- BlockHeight: ctx.BlockHeight(),
65
- BlockTime: ctx.BlockTime().Unix(),
66
- }
59
+ action := &endBlockAction{}
67
60
  _, err := keeper.BlockingSend(ctx, action)
68
61
 
69
62
  // fmt.Fprintf(os.Stderr, "END_BLOCK Returned from SwingSet: %s, %v\n", out, err)
@@ -80,15 +73,18 @@ func EndBlock(ctx sdk.Context, req abci.RequestEndBlock, keeper Keeper) ([]abci.
80
73
  return []abci.ValidatorUpdate{}, nil
81
74
  }
82
75
 
76
+ func getEndBlockContext() sdk.Context {
77
+ return sdk.Context{}.
78
+ WithContext(context.Background()).
79
+ WithBlockHeight(endBlockHeight).
80
+ WithBlockTime(time.Unix(endBlockTime, 0))
81
+ }
82
+
83
83
  func CommitBlock(keeper Keeper) error {
84
84
  defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")
85
85
 
86
- action := &commitBlockAction{
87
- Type: "COMMIT_BLOCK",
88
- BlockHeight: endBlockHeight,
89
- BlockTime: endBlockTime,
90
- }
91
- _, err := keeper.BlockingSend(sdk.Context{}, action)
86
+ action := &commitBlockAction{}
87
+ _, err := keeper.BlockingSend(getEndBlockContext(), action)
92
88
 
93
89
  // fmt.Fprintf(os.Stderr, "COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
94
90
  if err != nil {
@@ -102,12 +98,8 @@ func CommitBlock(keeper Keeper) error {
102
98
  func AfterCommitBlock(keeper Keeper) error {
103
99
  // defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), "commit_blocker")
104
100
 
105
- action := &commitBlockAction{
106
- Type: "AFTER_COMMIT_BLOCK",
107
- BlockHeight: endBlockHeight,
108
- BlockTime: endBlockTime,
109
- }
110
- _, err := keeper.BlockingSend(sdk.Context{}, action)
101
+ action := &afterCommitBlockAction{}
102
+ _, err := keeper.BlockingSend(getEndBlockContext(), action)
111
103
 
112
104
  // fmt.Fprintf(os.Stderr, "AFTER_COMMIT_BLOCK Returned from SwingSet: %s, %v\n", out, err)
113
105
  if err != nil {
@@ -53,7 +53,7 @@ func GetCmdQueryParams(queryRoute string) *cobra.Command {
53
53
 
54
54
  func GetCmdGetEgress(queryRoute string) *cobra.Command {
55
55
  cmd := &cobra.Command{
56
- Use: "egress [account]",
56
+ Use: "egress <account>",
57
57
  Short: "get egress info for account",
58
58
  Args: cobra.ExactArgs(1),
59
59
  RunE: func(cmd *cobra.Command, args []string) error {
@@ -86,7 +86,7 @@ func GetCmdGetEgress(queryRoute string) *cobra.Command {
86
86
  // GetCmdMailbox queries information about a mailbox
87
87
  func GetCmdMailbox(queryRoute string) *cobra.Command {
88
88
  cmd := &cobra.Command{
89
- Use: "mailbox [peer]",
89
+ Use: "mailbox <peer>",
90
90
  Short: "get mailbox for peer",
91
91
  Args: cobra.ExactArgs(1),
92
92
  RunE: func(cmd *cobra.Command, args []string) error {
@@ -2,6 +2,7 @@ package cli
2
2
 
3
3
  import (
4
4
  "fmt"
5
+ "io"
5
6
  "os"
6
7
  "strings"
7
8
 
@@ -12,7 +13,7 @@ import (
12
13
  "github.com/cosmos/cosmos-sdk/client/flags"
13
14
  "github.com/cosmos/cosmos-sdk/client/tx"
14
15
  govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
15
- govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
16
+ govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
16
17
 
17
18
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
18
19
  sdk "github.com/cosmos/cosmos-sdk/types"
@@ -43,11 +44,18 @@ func GetTxCmd(storeKey string) *cobra.Command {
43
44
  }
44
45
 
45
46
  // GetCmdDeliver is the CLI command for sending a DeliverInbound transaction
47
+ // containing mailbox messages.
46
48
  func GetCmdDeliver() *cobra.Command {
47
49
  cmd := &cobra.Command{
48
- Use: "deliver [json string]",
49
- Short: "deliver inbound messages",
50
- Args: cobra.ExactArgs(1),
50
+ Use: "deliver {<messages JSON> | @- | @<file>}",
51
+ Short: "send mailbox messages",
52
+ Long: `send mailbox messages.
53
+ The argument indicates how to read input JSON ("@-" for standard input,
54
+ "@..." for a file path, and otherwise directly as in "deliver '[...]'").
55
+ Input must represent an array in which the first element is an array of
56
+ [messageNum: integer, messageBody: string] pairs and the second element
57
+ is an "Ack" integer.`,
58
+ Args: cobra.ExactArgs(1),
51
59
 
52
60
  RunE: func(cmd *cobra.Command, args []string) error {
53
61
  cctx, err := client.GetClientTxContext(cmd)
@@ -56,20 +64,18 @@ func GetCmdDeliver() *cobra.Command {
56
64
  }
57
65
 
58
66
  jsonIn := args[0]
59
- if jsonIn[0] == '@' {
60
- fname := args[0][1:]
67
+ if strings.HasPrefix(jsonIn, "@") {
68
+ var jsonBytes []byte
69
+ fname := jsonIn[1:]
61
70
  if fname == "-" {
62
- // Reading from stdin.
63
- if _, err := fmt.Scanln(&jsonIn); err != nil {
64
- return err
65
- }
71
+ jsonBytes, err = io.ReadAll(os.Stdin)
66
72
  } else {
67
- jsonBytes, err := os.ReadFile(fname)
68
- if err != nil {
69
- return err
70
- }
71
- jsonIn = string(jsonBytes)
73
+ jsonBytes, err = os.ReadFile(fname)
74
+ }
75
+ if err != nil {
76
+ return err
72
77
  }
78
+ jsonIn = string(jsonBytes)
73
79
  }
74
80
  msgs, err := types.UnmarshalMessagesJSON(jsonIn)
75
81
  if err != nil {
@@ -92,7 +98,14 @@ func GetCmdDeliver() *cobra.Command {
92
98
  // InstallBundle message in a transaction.
93
99
  func GetCmdInstallBundle() *cobra.Command {
94
100
  cmd := &cobra.Command{
95
- Use: "install-bundle <JSON>/@<FILE>/-",
101
+ Use: "install-bundle {<bundle JSON> | @- | @<file>}",
102
+ Short: "install a bundle",
103
+ Long: `install a bundle.
104
+ The argument indicates how to read input JSON ("@-" for standard input,
105
+ "@..." for a file path, and otherwise directly as in
106
+ "install-bundle '{...}'").
107
+ Input should be endoZipBase64 JSON, but this is not verified.
108
+ https://github.com/endojs/endo/tree/master/packages/bundle-source`,
96
109
  Args: cobra.ExactArgs(1),
97
110
 
98
111
  RunE: func(cmd *cobra.Command, args []string) error {
@@ -102,20 +115,18 @@ func GetCmdInstallBundle() *cobra.Command {
102
115
  }
103
116
 
104
117
  jsonIn := args[0]
105
- if jsonIn[0] == '@' {
106
- fname := args[0][1:]
118
+ if strings.HasPrefix(jsonIn, "@") {
119
+ var jsonBytes []byte
120
+ fname := jsonIn[1:]
107
121
  if fname == "-" {
108
- // Reading from stdin.
109
- if _, err := fmt.Scanln(&jsonIn); err != nil {
110
- return err
111
- }
122
+ jsonBytes, err = io.ReadAll(os.Stdin)
112
123
  } else {
113
- jsonBytes, err := os.ReadFile(fname)
114
- if err != nil {
115
- return err
116
- }
117
- jsonIn = string(jsonBytes)
124
+ jsonBytes, err = os.ReadFile(fname)
118
125
  }
126
+ if err != nil {
127
+ return err
128
+ }
129
+ jsonIn = string(jsonBytes)
119
130
  }
120
131
 
121
132
  msg := types.NewMsgInstallBundle(jsonIn, cctx.GetFromAddress())
@@ -150,7 +161,7 @@ func GetCmdInstallBundle() *cobra.Command {
150
161
  // GetCmdProvision is the CLI command for sending a Provision transaction
151
162
  func GetCmdProvisionOne() *cobra.Command {
152
163
  cmd := &cobra.Command{
153
- Use: "provision-one [nickname] [address] [power-flags]",
164
+ Use: "provision-one <nickname> <address> [<power-flag>[,...]]",
154
165
  Short: "provision a single address",
155
166
  Args: cobra.RangeArgs(2, 3),
156
167
 
@@ -160,6 +171,8 @@ func GetCmdProvisionOne() *cobra.Command {
160
171
  return err
161
172
  }
162
173
 
174
+ nickname := args[0]
175
+
163
176
  addr, err := sdk.AccAddressFromBech32(args[1])
164
177
  if err != nil {
165
178
  return err
@@ -170,7 +183,7 @@ func GetCmdProvisionOne() *cobra.Command {
170
183
  powerFlags = strings.Split(args[2], ",")
171
184
  }
172
185
 
173
- msg := types.NewMsgProvision(args[0], addr, powerFlags, cctx.GetFromAddress())
186
+ msg := types.NewMsgProvision(nickname, addr, powerFlags, cctx.GetFromAddress())
174
187
  if err := msg.ValidateBasic(); err != nil {
175
188
  return err
176
189
  }
@@ -186,7 +199,7 @@ func GetCmdProvisionOne() *cobra.Command {
186
199
  // GetCmdWalletAction is the CLI command for sending a WalletAction or WalletSpendAction transaction
187
200
  func GetCmdWalletAction() *cobra.Command {
188
201
  cmd := &cobra.Command{
189
- Use: "wallet-action [json string]",
202
+ Use: "wallet-action <action JSON>",
190
203
  Short: "perform a wallet action",
191
204
  Args: cobra.ExactArgs(1),
192
205
  RunE: func(cmd *cobra.Command, args []string) error {
@@ -221,16 +234,18 @@ func GetCmdWalletAction() *cobra.Command {
221
234
  return cmd
222
235
  }
223
236
 
237
+ // NewCmdSubmitCoreEvalProposal is the CLI command for submitting a "CoreEval"
238
+ // governance proposal via `agd tx gov submit-proposal swingset-core-eval ...`.
224
239
  func NewCmdSubmitCoreEvalProposal() *cobra.Command {
225
240
  cmd := &cobra.Command{
226
- Use: "swingset-core-eval [[permit.json] [code.js]]...",
241
+ Use: "swingset-core-eval <permit.json code.js>...",
227
242
  Args: cobra.MinimumNArgs(2),
228
243
  Short: "Submit a proposal to evaluate code in the SwingSet core",
229
244
  Long: `Submit a SwingSet evaluate core Compartment code proposal along with an initial deposit.
230
245
  Specify at least one pair of permit.json and code.js files`,
231
246
  RunE: func(cmd *cobra.Command, args []string) error {
232
247
  if len(args)%2 != 0 {
233
- return fmt.Errorf("must specify an even number of permit.json and code.js files")
248
+ return fmt.Errorf("must specify paired permit.json and code.js files")
234
249
  }
235
250
 
236
251
  clientCtx, err := client.GetClientTxContext(cmd)
@@ -287,7 +302,7 @@ Specify at least one pair of permit.json and code.js files`,
287
302
  return err
288
303
  }
289
304
 
290
- msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
305
+ msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, from)
291
306
  if err != nil {
292
307
  return err
293
308
  }
@@ -1,25 +1,10 @@
1
1
  package client
2
2
 
3
3
  import (
4
- "net/http"
5
-
6
- "github.com/cosmos/cosmos-sdk/client"
7
- "github.com/cosmos/cosmos-sdk/types/rest"
8
- govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
9
- govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
10
-
11
4
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/client/cli"
5
+ govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
12
6
  )
13
7
 
14
8
  var (
15
- CoreEvalProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitCoreEvalProposal, emptyRestHandler)
9
+ CoreEvalProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitCoreEvalProposal)
16
10
  )
17
-
18
- func emptyRestHandler(client.Context) govrest.ProposalRESTHandler {
19
- return govrest.ProposalRESTHandler{
20
- SubRoute: "unsupported-swingset",
21
- Handler: func(w http.ResponseWriter, r *http.Request) {
22
- rest.WriteErrorResponse(w, http.StatusBadRequest, "Legacy REST Routes are not supported for SwingSet proposals")
23
- },
24
- }
25
- }
@@ -7,11 +7,14 @@ import (
7
7
  stdlog "log"
8
8
  "math"
9
9
 
10
+ sdkmath "cosmossdk.io/math"
11
+
10
12
  "github.com/tendermint/tendermint/libs/log"
11
13
 
12
14
  "github.com/cosmos/cosmos-sdk/baseapp"
13
15
  "github.com/cosmos/cosmos-sdk/codec"
14
16
  "github.com/cosmos/cosmos-sdk/store/prefix"
17
+ storetypes "github.com/cosmos/cosmos-sdk/store/types"
15
18
  sdk "github.com/cosmos/cosmos-sdk/types"
16
19
  bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
17
20
  paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
@@ -69,7 +72,7 @@ type inboundQueueRecord struct {
69
72
 
70
73
  // Keeper maintains the link to data vstorage and exposes getter/setter methods for the various parts of the state machine
71
74
  type Keeper struct {
72
- storeKey sdk.StoreKey
75
+ storeKey storetypes.StoreKey
73
76
  cdc codec.Codec
74
77
  paramSpace paramtypes.Subspace
75
78
 
@@ -87,7 +90,7 @@ var _ ante.SwingsetKeeper = &Keeper{}
87
90
 
88
91
  // NewKeeper creates a new IBC transfer Keeper instance
89
92
  func NewKeeper(
90
- cdc codec.Codec, key sdk.StoreKey, paramSpace paramtypes.Subspace,
93
+ cdc codec.Codec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
91
94
  accountKeeper types.AccountKeeper, bankKeeper bankkeeper.Keeper,
92
95
  vstorageKeeper vstoragekeeper.Keeper, feeCollectorName string,
93
96
  callToController func(ctx sdk.Context, str string) (string, error),
@@ -110,6 +113,16 @@ func NewKeeper(
110
113
  }
111
114
  }
112
115
 
116
+ func populateAction(ctx sdk.Context, action vm.Action) (vm.Action, error) {
117
+ action = vm.PopulateAction(ctx, action)
118
+ ah := action.GetActionHeader()
119
+ if len(ah.Type) == 0 {
120
+ return nil, fmt.Errorf("action %q cannot have an empty ActionHeader.Type", action)
121
+ }
122
+
123
+ return action, nil
124
+ }
125
+
113
126
  // pushAction appends an action to the controller's specified inbound queue.
114
127
  // The queue is kept in the kvstore so that changes are properly reverted if the
115
128
  // kvstore is rolled back. By the time the block manager runs, it can commit
@@ -118,20 +131,18 @@ func NewKeeper(
118
131
  //
119
132
  // The inbound queue's format is documented by `makeChainQueue` in
120
133
  // `packages/cosmic-swingset/src/helpers/make-queue.js`.
121
- func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.Jsonable) error {
134
+ func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.Action) error {
135
+ action, err := populateAction(ctx, action)
136
+ if err != nil {
137
+ return err
138
+ }
122
139
  txHash, txHashOk := ctx.Context().Value(baseapp.TxHashContextKey).(string)
123
140
  if !txHashOk {
124
141
  txHash = "unknown"
125
142
  }
126
143
  msgIdx, msgIdxOk := ctx.Context().Value(baseapp.TxMsgIdxContextKey).(int)
127
144
  if !txHashOk || !msgIdxOk {
128
- switch action.(type) {
129
- case *coreEvalAction:
130
- // This is expected for CORE_EVAL since it's not in a transaction
131
- // (deferred by governance to a BeginBlocker).
132
- default:
133
- stdlog.Printf("error while extracting context for action %q\n", action)
134
- }
145
+ stdlog.Printf("error while extracting context for action %q\n", action)
135
146
  }
136
147
  record := inboundQueueRecord{Action: action, Context: actionContext{BlockHeight: ctx.BlockHeight(), TxHash: txHash, MsgIdx: msgIdx}}
137
148
  bz, err := json.Marshal(record)
@@ -143,12 +154,12 @@ func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.J
143
154
  }
144
155
 
145
156
  // PushAction appends an action to the controller's actionQueue.
146
- func (k Keeper) PushAction(ctx sdk.Context, action vm.Jsonable) error {
157
+ func (k Keeper) PushAction(ctx sdk.Context, action vm.Action) error {
147
158
  return k.pushAction(ctx, StoragePathActionQueue, action)
148
159
  }
149
160
 
150
161
  // PushAction appends an action to the controller's highPriorityQueue.
151
- func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.Jsonable) error {
162
+ func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.Action) error {
152
163
  return k.pushAction(ctx, StoragePathHighPriorityQueue, action)
153
164
  }
154
165
 
@@ -234,7 +245,11 @@ func (k Keeper) UpdateQueueAllowed(ctx sdk.Context) error {
234
245
  // until the response. It is orthogonal to PushAction, and should only be used
235
246
  // by SwingSet to perform block lifecycle events (BEGIN_BLOCK, END_BLOCK,
236
247
  // COMMIT_BLOCK).
237
- func (k Keeper) BlockingSend(ctx sdk.Context, action vm.Jsonable) (string, error) {
248
+ func (k Keeper) BlockingSend(ctx sdk.Context, action vm.Action) (string, error) {
249
+ action, err := populateAction(ctx, action)
250
+ if err != nil {
251
+ return "", err
252
+ }
238
253
  bz, err := json.Marshal(action)
239
254
  if err != nil {
240
255
  return "", err
@@ -286,9 +301,9 @@ func (k Keeper) GetBeansOwing(ctx sdk.Context, addr sdk.AccAddress) sdk.Uint {
286
301
  path := getBeansOwingPathForAddress(addr)
287
302
  entry := k.vstorageKeeper.GetEntry(ctx, path)
288
303
  if !entry.HasValue() {
289
- return sdk.ZeroUint()
304
+ return sdkmath.ZeroUint()
290
305
  }
291
- return sdk.NewUintFromString(entry.StringValue())
306
+ return sdkmath.NewUintFromString(entry.StringValue())
292
307
  }
293
308
 
294
309
  // SetBeansOwing sets the number of beans that the given address owes to the
@@ -196,7 +196,7 @@ var (
196
196
  func makeTestStore() sdk.KVStore {
197
197
  db := dbm.NewMemDB()
198
198
  ms := store.NewCommitMultiStore(db)
199
- ms.MountStoreWithDB(swingsetStoreKey, sdk.StoreTypeIAVL, db)
199
+ ms.MountStoreWithDB(swingsetStoreKey, storetypes.StoreTypeIAVL, db)
200
200
  err := ms.LoadLatestVersion()
201
201
  if err != nil {
202
202
  panic(err)
@@ -21,15 +21,13 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
21
21
  var _ types.MsgServer = msgServer{}
22
22
 
23
23
  type deliverInboundAction struct {
24
- Type string `json:"type"`
25
- Peer string `json:"peer"`
26
- Messages [][]interface{} `json:"messages"`
27
- Ack uint64 `json:"ack"`
28
- BlockHeight int64 `json:"blockHeight"`
29
- BlockTime int64 `json:"blockTime"`
24
+ vm.ActionHeader `actionType:"DELIVER_INBOUND"`
25
+ Peer string `json:"peer"`
26
+ Messages [][]interface{} `json:"messages"`
27
+ Ack uint64 `json:"ack"`
30
28
  }
31
29
 
32
- func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.Jsonable) error {
30
+ func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionMsg, action vm.Action) error {
33
31
  isHighPriority, err := msg.IsHighPriority(ctx, keeper)
34
32
  if err != nil {
35
33
  return err
@@ -45,20 +43,15 @@ func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionM
45
43
  func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeliverInbound) (*types.MsgDeliverInboundResponse, error) {
46
44
  ctx := sdk.UnwrapSDKContext(goCtx)
47
45
 
46
+ // msg.Nums and msg.Messages must be zipped into an array of [num, message] pairs.
48
47
  messages := make([][]interface{}, len(msg.Messages))
49
48
  for i, message := range msg.Messages {
50
- messages[i] = make([]interface{}, 2)
51
- messages[i][0] = msg.Nums[i]
52
- messages[i][1] = message
49
+ messages[i] = []interface{}{msg.Nums[i], message}
53
50
  }
54
-
55
51
  action := &deliverInboundAction{
56
- Type: "DELIVER_INBOUND",
57
- Peer: msg.Submitter.String(),
58
- Messages: messages,
59
- Ack: msg.Ack,
60
- BlockHeight: ctx.BlockHeight(),
61
- BlockTime: ctx.BlockTime().Unix(),
52
+ Peer: msg.Submitter.String(),
53
+ Messages: messages,
54
+ Ack: msg.Ack,
62
55
  }
63
56
 
64
57
  err := keeper.routeAction(ctx, msg, action)
@@ -70,11 +63,9 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
70
63
  }
71
64
 
72
65
  type walletAction struct {
73
- Type string `json:"type"` // WALLET_ACTION
74
- Owner string `json:"owner"`
75
- Action string `json:"action"`
76
- BlockHeight int64 `json:"blockHeight"`
77
- BlockTime int64 `json:"blockTime"`
66
+ vm.ActionHeader `actionType:"WALLET_ACTION"`
67
+ Owner string `json:"owner"`
68
+ Action string `json:"action"`
78
69
  }
79
70
 
80
71
  func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWalletAction) (*types.MsgWalletActionResponse, error) {
@@ -86,11 +77,8 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
86
77
  }
87
78
 
88
79
  action := &walletAction{
89
- Type: "WALLET_ACTION",
90
- Owner: msg.Owner.String(),
91
- Action: msg.Action,
92
- BlockHeight: ctx.BlockHeight(),
93
- BlockTime: ctx.BlockTime().Unix(),
80
+ Owner: msg.Owner.String(),
81
+ Action: msg.Action,
94
82
  }
95
83
  // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
96
84
 
@@ -103,11 +91,9 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
103
91
  }
104
92
 
105
93
  type walletSpendAction struct {
106
- Type string `json:"type"` // WALLET_SPEND_ACTION
107
- Owner string `json:"owner"`
108
- SpendAction string `json:"spendAction"`
109
- BlockHeight int64 `json:"blockHeight"`
110
- BlockTime int64 `json:"blockTime"`
94
+ vm.ActionHeader `actionType:"WALLET_SPEND_ACTION"`
95
+ Owner string `json:"owner"`
96
+ SpendAction string `json:"spendAction"`
111
97
  }
112
98
 
113
99
  func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgWalletSpendAction) (*types.MsgWalletSpendActionResponse, error) {
@@ -119,11 +105,8 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
119
105
  }
120
106
 
121
107
  action := &walletSpendAction{
122
- Type: "WALLET_SPEND_ACTION",
123
108
  Owner: msg.Owner.String(),
124
109
  SpendAction: msg.SpendAction,
125
- BlockHeight: ctx.BlockHeight(),
126
- BlockTime: ctx.BlockTime().Unix(),
127
110
  }
128
111
  // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
129
112
  err = keeper.routeAction(ctx, msg, action)
@@ -134,11 +117,9 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
134
117
  }
135
118
 
136
119
  type provisionAction struct {
120
+ vm.ActionHeader `actionType:"PLEASE_PROVISION"`
137
121
  *types.MsgProvision
138
- Type string `json:"type"` // PLEASE_PROVISION
139
- BlockHeight int64 `json:"blockHeight"`
140
- BlockTime int64 `json:"blockTime"`
141
- AutoProvision bool `json:"autoProvision"`
122
+ AutoProvision bool `json:"autoProvision"`
142
123
  }
143
124
 
144
125
  // provisionIfNeeded generates a provision action if no smart wallet is already
@@ -162,9 +143,6 @@ func (keeper msgServer) provisionIfNeeded(ctx sdk.Context, owner sdk.AccAddress)
162
143
 
163
144
  action := &provisionAction{
164
145
  MsgProvision: msg,
165
- Type: "PLEASE_PROVISION",
166
- BlockHeight: ctx.BlockHeight(),
167
- BlockTime: ctx.BlockTime().Unix(),
168
146
  AutoProvision: true,
169
147
  }
170
148
 
@@ -187,9 +165,6 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
187
165
 
188
166
  action := &provisionAction{
189
167
  MsgProvision: msg,
190
- Type: "PLEASE_PROVISION",
191
- BlockHeight: ctx.BlockHeight(),
192
- BlockTime: ctx.BlockTime().Unix(),
193
168
  }
194
169
 
195
170
  // Create the account, if it doesn't already exist.
@@ -209,10 +184,8 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
209
184
  }
210
185
 
211
186
  type installBundleAction struct {
187
+ vm.ActionHeader `actionType:"INSTALL_BUNDLE"`
212
188
  *types.MsgInstallBundle
213
- Type string `json:"type"` // INSTALL_BUNDLE
214
- BlockHeight int64 `json:"blockHeight"`
215
- BlockTime int64 `json:"blockTime"`
216
189
  }
217
190
 
218
191
  func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInstallBundle) (*types.MsgInstallBundleResponse, error) {
@@ -224,9 +197,6 @@ func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInsta
224
197
  }
225
198
  action := &installBundleAction{
226
199
  MsgInstallBundle: msg,
227
- Type: "INSTALL_BUNDLE",
228
- BlockHeight: ctx.BlockHeight(),
229
- BlockTime: ctx.BlockTime().Unix(),
230
200
  }
231
201
 
232
202
  err = keeper.routeAction(ctx, msg, action)
@@ -1,26 +1,32 @@
1
1
  package keeper
2
2
 
3
3
  import (
4
+ "context"
5
+
4
6
  sdk "github.com/cosmos/cosmos-sdk/types"
5
7
 
8
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
6
9
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
10
+ "github.com/cosmos/cosmos-sdk/baseapp"
7
11
  )
8
12
 
9
13
  type coreEvalAction struct {
10
- Type string `json:"type"` // CORE_EVAL
11
- Evals []types.CoreEval `json:"evals"`
12
- BlockHeight int64 `json:"blockHeight"`
13
- BlockTime int64 `json:"blockTime"`
14
+ vm.ActionHeader `actionType:"CORE_EVAL"`
15
+ Evals []types.CoreEval `json:"evals"`
14
16
  }
15
17
 
16
18
  // CoreEvalProposal tells SwingSet to evaluate the given JS code.
17
19
  func (k Keeper) CoreEvalProposal(ctx sdk.Context, p *types.CoreEvalProposal) error {
18
20
  action := &coreEvalAction{
19
- Type: "CORE_EVAL",
20
- Evals: p.Evals,
21
- BlockHeight: ctx.BlockHeight(),
22
- BlockTime: ctx.BlockTime().Unix(),
21
+ Evals: p.Evals,
23
22
  }
24
23
 
24
+ // While the CoreEvalProposal was originally created by a transaction, by the time it
25
+ // passes by governance, we no longer have its provenance information, so we need to
26
+ // synthesize unique context information.
27
+ // We use a fixed placeholder value for the txHash context. We use `0` for the message
28
+ // index which assumes there is a single proposal per block.
29
+ ctx = ctx.WithContext(context.WithValue(ctx.Context(), baseapp.TxHashContextKey, "x/gov"))
30
+ ctx = ctx.WithContext(context.WithValue(ctx.Context(), baseapp.TxMsgIdxContextKey, 0))
25
31
  return k.PushHighPriorityAction(ctx, action)
26
32
  }