@agoric/cosmos 0.34.1 → 0.34.2-calypso-dev-dabccdc.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.
Files changed (193) hide show
  1. package/MAINTAINERS.md +3 -0
  2. package/Makefile +67 -41
  3. package/agoric/config.go +35 -0
  4. package/ante/ante.go +65 -0
  5. package/ante/expected_keepers.go +26 -0
  6. package/ante/inbound.go +137 -0
  7. package/ante/inbound_test.go +228 -0
  8. package/ante/vm_admission.go +65 -0
  9. package/app/app.go +396 -211
  10. package/app/export.go +13 -9
  11. package/app/sim_test.go +4 -4
  12. package/app/upgrade.go +215 -0
  13. package/binding.gyp.in +29 -4
  14. package/buf.work.yaml +4 -0
  15. package/cmd/agd/agvm.go +42 -0
  16. package/cmd/agd/find_binary.go +22 -7
  17. package/cmd/agd/main.go +133 -10
  18. package/cmd/libdaemon/main.go +67 -53
  19. package/cmd/libdaemon/main_test.go +37 -0
  20. package/daemon/cmd/genaccounts.go +22 -18
  21. package/daemon/cmd/root.go +253 -52
  22. package/daemon/cmd/root_test.go +190 -2
  23. package/daemon/cmd/testnet.go +17 -6
  24. package/daemon/main.go +6 -3
  25. package/e2e_test/Makefile +29 -0
  26. package/e2e_test/README.md +100 -0
  27. package/e2e_test/go.mod +217 -0
  28. package/e2e_test/go.sum +1323 -0
  29. package/e2e_test/ibc_conformance_test.go +56 -0
  30. package/e2e_test/pfm_test.go +613 -0
  31. package/e2e_test/util.go +271 -0
  32. package/git-revision.txt +1 -0
  33. package/go.mod +207 -0
  34. package/go.sum +1877 -0
  35. package/package.json +13 -21
  36. package/proto/agoric/swingset/genesis.proto +14 -0
  37. package/proto/agoric/swingset/swingset.proto +6 -3
  38. package/proto/agoric/vlocalchain/.clang-format +7 -0
  39. package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
  40. package/proto/agoric/vstorage/query.proto +53 -1
  41. package/proto/agoric/vtransfer/genesis.proto +18 -0
  42. package/scripts/protocgen.sh +16 -6
  43. package/third_party/proto/buf.yaml +1 -0
  44. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  45. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  46. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  47. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  48. package/third_party/proto/google/api/annotations.proto +1 -1
  49. package/third_party/proto/google/api/http.proto +181 -120
  50. package/third_party/proto/google/api/httpbody.proto +9 -6
  51. package/third_party/proto/google/protobuf/any.proto +1 -7
  52. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  53. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  54. package/tools/tools.go +11 -0
  55. package/types/events.go +41 -0
  56. package/types/kv_entry.go +114 -0
  57. package/types/kv_entry_helpers.go +276 -0
  58. package/types/kv_entry_helpers_test.go +237 -0
  59. package/types/kv_entry_test.go +143 -0
  60. package/upgradegaia.sh +75 -0
  61. package/vm/action.go +134 -0
  62. package/vm/action_test.go +149 -0
  63. package/vm/client.go +113 -0
  64. package/vm/client_test.go +182 -0
  65. package/vm/controller.go +49 -0
  66. package/vm/core_proposals.go +51 -0
  67. package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
  68. package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
  69. package/vm/proto_json.go +38 -0
  70. package/vm/proto_json_test.go +103 -0
  71. package/vm/server.go +124 -0
  72. package/x/swingset/abci.go +26 -37
  73. package/x/swingset/alias.go +9 -6
  74. package/x/swingset/client/cli/query.go +2 -2
  75. package/x/swingset/client/cli/tx.go +52 -33
  76. package/x/swingset/client/proposal_handler.go +2 -17
  77. package/x/swingset/genesis.go +163 -37
  78. package/x/swingset/handler.go +2 -1
  79. package/x/swingset/keeper/extension_snapshotter.go +309 -0
  80. package/x/swingset/keeper/extension_snapshotter_test.go +104 -0
  81. package/x/swingset/keeper/keeper.go +95 -48
  82. package/x/swingset/keeper/keeper_test.go +77 -0
  83. package/x/swingset/keeper/migrations.go +7 -2
  84. package/x/swingset/keeper/msg_server.go +71 -56
  85. package/x/swingset/keeper/proposal.go +15 -9
  86. package/x/swingset/keeper/querier.go +24 -15
  87. package/x/swingset/keeper/swing_store_exports_handler.go +872 -0
  88. package/x/swingset/keeper/swing_store_exports_handler_test.go +247 -0
  89. package/x/swingset/keeper/test_utils.go +16 -0
  90. package/x/swingset/module.go +33 -11
  91. package/x/swingset/proposal_handler.go +5 -4
  92. package/x/swingset/swingset.go +73 -0
  93. package/x/swingset/testing/queue.go +17 -0
  94. package/x/swingset/types/codec.go +2 -2
  95. package/x/swingset/types/default-params.go +23 -17
  96. package/x/swingset/types/expected_keepers.go +14 -2
  97. package/x/swingset/types/genesis.pb.go +361 -18
  98. package/x/swingset/types/msgs.go +87 -26
  99. package/x/swingset/types/msgs.pb.go +16 -16
  100. package/x/swingset/types/params.go +76 -1
  101. package/x/swingset/types/params_test.go +116 -0
  102. package/x/swingset/types/proposal.go +10 -9
  103. package/x/swingset/types/swingset.pb.go +83 -81
  104. package/x/swingset/types/types.go +30 -28
  105. package/x/vbank/genesis.go +0 -2
  106. package/x/vbank/handler.go +2 -1
  107. package/x/vbank/keeper/keeper.go +3 -2
  108. package/x/vbank/keeper/querier.go +9 -4
  109. package/x/vbank/keeper/rewards.go +1 -1
  110. package/x/vbank/module.go +0 -5
  111. package/x/vbank/types/msgs.go +0 -12
  112. package/x/vbank/vbank.go +34 -32
  113. package/x/vbank/vbank_test.go +20 -20
  114. package/x/vibc/alias.go +3 -0
  115. package/x/vibc/handler.go +17 -15
  116. package/x/vibc/keeper/keeper.go +113 -89
  117. package/x/vibc/keeper/triggers.go +101 -0
  118. package/x/vibc/module.go +5 -8
  119. package/x/vibc/types/expected_keepers.go +28 -6
  120. package/x/vibc/types/ibc_module.go +336 -0
  121. package/x/vibc/types/msgs.go +1 -1
  122. package/x/vibc/types/msgs.pb.go +1 -1
  123. package/x/vibc/types/receiver.go +170 -0
  124. package/x/vlocalchain/alias.go +19 -0
  125. package/x/vlocalchain/handler.go +21 -0
  126. package/x/vlocalchain/keeper/keeper.go +279 -0
  127. package/x/vlocalchain/keeper/keeper_test.go +97 -0
  128. package/x/vlocalchain/types/codec.go +34 -0
  129. package/x/vlocalchain/types/key.go +27 -0
  130. package/x/vlocalchain/types/msgs.go +16 -0
  131. package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
  132. package/x/vlocalchain/vlocalchain.go +114 -0
  133. package/x/vlocalchain/vlocalchain_test.go +434 -0
  134. package/x/vstorage/README.md +138 -0
  135. package/x/vstorage/capdata/capdata.go +298 -0
  136. package/x/vstorage/capdata/capdata_test.go +352 -0
  137. package/x/vstorage/client/cli/query.go +51 -4
  138. package/x/vstorage/genesis.go +0 -3
  139. package/x/vstorage/handler.go +2 -1
  140. package/x/vstorage/keeper/grpc_query.go +220 -0
  141. package/x/vstorage/keeper/keeper.go +75 -57
  142. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  143. package/x/vstorage/keeper/keeper_test.go +40 -62
  144. package/x/vstorage/keeper/querier.go +39 -14
  145. package/x/vstorage/keeper/querier_test.go +113 -0
  146. package/x/vstorage/module.go +0 -5
  147. package/x/vstorage/testing/queue.go +27 -0
  148. package/x/vstorage/types/path_keys.go +22 -10
  149. package/x/vstorage/types/path_keys_test.go +84 -18
  150. package/x/vstorage/types/query.pb.go +646 -36
  151. package/x/vstorage/types/query.pb.gw.go +119 -0
  152. package/x/vstorage/types/types.go +0 -66
  153. package/x/vstorage/vstorage.go +33 -35
  154. package/x/vstorage/vstorage_test.go +19 -19
  155. package/x/vtransfer/alias.go +13 -0
  156. package/x/vtransfer/genesis.go +39 -0
  157. package/x/vtransfer/genesis_test.go +12 -0
  158. package/x/vtransfer/handler.go +20 -0
  159. package/x/vtransfer/ibc_middleware.go +186 -0
  160. package/x/vtransfer/ibc_middleware_test.go +448 -0
  161. package/x/vtransfer/keeper/keeper.go +281 -0
  162. package/x/vtransfer/module.go +124 -0
  163. package/x/vtransfer/types/expected_keepers.go +38 -0
  164. package/x/vtransfer/types/genesis.pb.go +327 -0
  165. package/x/vtransfer/types/key.go +9 -0
  166. package/x/vtransfer/types/msgs.go +9 -0
  167. package/app/const.go +0 -6
  168. package/cmd/helper/main.go +0 -21
  169. package/proto/agoric/lien/genesis.proto +0 -25
  170. package/proto/agoric/lien/lien.proto +0 -25
  171. package/x/lien/alias.go +0 -17
  172. package/x/lien/genesis.go +0 -58
  173. package/x/lien/genesis_test.go +0 -101
  174. package/x/lien/keeper/account.go +0 -285
  175. package/x/lien/keeper/keeper.go +0 -254
  176. package/x/lien/keeper/keeper_test.go +0 -623
  177. package/x/lien/lien.go +0 -203
  178. package/x/lien/lien_test.go +0 -529
  179. package/x/lien/module.go +0 -115
  180. package/x/lien/spec/01_concepts.md +0 -146
  181. package/x/lien/spec/02_messages.md +0 -96
  182. package/x/lien/types/accountkeeper.go +0 -81
  183. package/x/lien/types/accountstate.go +0 -27
  184. package/x/lien/types/expected_keepers.go +0 -18
  185. package/x/lien/types/genesis.pb.go +0 -567
  186. package/x/lien/types/key.go +0 -25
  187. package/x/lien/types/lien.pb.go +0 -403
  188. package/x/swingset/keeper/snapshotter.go +0 -491
  189. package/x/swingset/keeper/snapshotter_test.go +0 -185
  190. package/x/swingset/legacy/v32/params.go +0 -37
  191. package/x/swingset/legacy/v32/params_test.go +0 -133
  192. package/x/vibc/ibc.go +0 -442
  193. /package/{src/index.cjs → index.cjs} +0 -0
@@ -7,19 +7,23 @@ 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"
16
+ "github.com/cosmos/cosmos-sdk/store/prefix"
17
+ storetypes "github.com/cosmos/cosmos-sdk/store/types"
14
18
  sdk "github.com/cosmos/cosmos-sdk/types"
15
19
  bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
16
20
  paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
17
21
 
18
22
  "github.com/Agoric/agoric-sdk/golang/cosmos/ante"
23
+ agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
19
24
  "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
20
25
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
21
26
  vstoragekeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/keeper"
22
- vstoragetypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
23
27
  )
24
28
 
25
29
  // Top-level paths for chain storage should remain synchronized with
@@ -36,30 +40,20 @@ const (
36
40
  StoragePathSwingStore = "swingStore"
37
41
  )
38
42
 
39
- const stateKey string = "state"
43
+ const (
44
+ // WalletStoragePathSegment matches the value of WALLET_STORAGE_PATH_SEGMENT
45
+ // packages/vats/src/core/startWalletFactory.js
46
+ WalletStoragePathSegment = "wallet"
47
+ )
40
48
 
41
- // Contextual information about the message source of an action on an inbound queue.
42
- // This context should be unique per inboundQueueRecord.
43
- type actionContext struct {
44
- // The block height in which the corresponding action was enqueued
45
- BlockHeight int64 `json:"blockHeight"`
46
- // The hash of the cosmos transaction that included the message
47
- // If the action didn't result from a transaction message, a substitute value
48
- // may be used. For example the VBANK_BALANCE_UPDATE actions use `x/vbank`.
49
- TxHash string `json:"txHash"`
50
- // The index of the message within the transaction. If the action didn't
51
- // result from a cosmos transaction, a number should be chosen to make the
52
- // actionContext unique. (for example a counter per block and source module).
53
- MsgIdx int `json:"msgIdx"`
54
- }
55
- type inboundQueueRecord struct {
56
- Action vm.Jsonable `json:"action"`
57
- Context actionContext `json:"context"`
58
- }
49
+ const (
50
+ stateKey = "state"
51
+ swingStoreKeyPrefix = "swingStore."
52
+ )
59
53
 
60
54
  // Keeper maintains the link to data vstorage and exposes getter/setter methods for the various parts of the state machine
61
55
  type Keeper struct {
62
- storeKey sdk.StoreKey
56
+ storeKey storetypes.StoreKey
63
57
  cdc codec.Codec
64
58
  paramSpace paramtypes.Subspace
65
59
 
@@ -77,7 +71,7 @@ var _ ante.SwingsetKeeper = &Keeper{}
77
71
 
78
72
  // NewKeeper creates a new IBC transfer Keeper instance
79
73
  func NewKeeper(
80
- cdc codec.Codec, key sdk.StoreKey, paramSpace paramtypes.Subspace,
74
+ cdc codec.Codec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
81
75
  accountKeeper types.AccountKeeper, bankKeeper bankkeeper.Keeper,
82
76
  vstorageKeeper vstoragekeeper.Keeper, feeCollectorName string,
83
77
  callToController func(ctx sdk.Context, str string) (string, error),
@@ -100,6 +94,16 @@ func NewKeeper(
100
94
  }
101
95
  }
102
96
 
97
+ func populateAction(ctx sdk.Context, action vm.Action) (vm.Action, error) {
98
+ action = vm.PopulateAction(ctx, action)
99
+ ah := action.GetActionHeader()
100
+ if len(ah.Type) == 0 {
101
+ return nil, fmt.Errorf("action %q cannot have an empty ActionHeader.Type", action)
102
+ }
103
+
104
+ return action, nil
105
+ }
106
+
103
107
  // pushAction appends an action to the controller's specified inbound queue.
104
108
  // The queue is kept in the kvstore so that changes are properly reverted if the
105
109
  // kvstore is rolled back. By the time the block manager runs, it can commit
@@ -108,22 +112,27 @@ func NewKeeper(
108
112
  //
109
113
  // The inbound queue's format is documented by `makeChainQueue` in
110
114
  // `packages/cosmic-swingset/src/helpers/make-queue.js`.
111
- func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.Jsonable) error {
115
+ func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.Action) error {
116
+ action, err := populateAction(ctx, action)
117
+ if err != nil {
118
+ return err
119
+ }
112
120
  txHash, txHashOk := ctx.Context().Value(baseapp.TxHashContextKey).(string)
113
121
  if !txHashOk {
114
122
  txHash = "unknown"
115
123
  }
116
124
  msgIdx, msgIdxOk := ctx.Context().Value(baseapp.TxMsgIdxContextKey).(int)
117
125
  if !txHashOk || !msgIdxOk {
118
- switch action.(type) {
119
- case *coreEvalAction:
120
- // This is expected for CORE_EVAL since it's not in a transaction
121
- // (deferred by governance to a BeginBlocker).
122
- default:
123
- stdlog.Printf("error while extracting context for action %q\n", action)
124
- }
126
+ stdlog.Printf("error while extracting context for action %q\n", action)
127
+ }
128
+ record := types.InboundQueueRecord{
129
+ Action: action,
130
+ Context: types.ActionContext{
131
+ BlockHeight: ctx.BlockHeight(),
132
+ TxHash: txHash,
133
+ MsgIdx: msgIdx,
134
+ },
125
135
  }
126
- record := inboundQueueRecord{Action: action, Context: actionContext{BlockHeight: ctx.BlockHeight(), TxHash: txHash, MsgIdx: msgIdx}}
127
136
  bz, err := json.Marshal(record)
128
137
  if err != nil {
129
138
  return err
@@ -133,12 +142,12 @@ func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.J
133
142
  }
134
143
 
135
144
  // PushAction appends an action to the controller's actionQueue.
136
- func (k Keeper) PushAction(ctx sdk.Context, action vm.Jsonable) error {
145
+ func (k Keeper) PushAction(ctx sdk.Context, action vm.Action) error {
137
146
  return k.pushAction(ctx, StoragePathActionQueue, action)
138
147
  }
139
148
 
140
149
  // PushAction appends an action to the controller's highPriorityQueue.
141
- func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.Jsonable) error {
150
+ func (k Keeper) PushHighPriorityAction(ctx sdk.Context, action vm.Action) error {
142
151
  return k.pushAction(ctx, StoragePathHighPriorityQueue, action)
143
152
  }
144
153
 
@@ -147,6 +156,20 @@ func (k Keeper) IsHighPriorityAddress(ctx sdk.Context, addr sdk.AccAddress) (boo
147
156
  return k.vstorageKeeper.HasEntry(ctx, path), nil
148
157
  }
149
158
 
159
+ // GetSmartWalletState returns the provision state of the smart wallet for the account address
160
+ func (k Keeper) GetSmartWalletState(ctx sdk.Context, addr sdk.AccAddress) types.SmartWalletState {
161
+ // walletStoragePath is path of `walletStorageNode` constructed in
162
+ // `provideSmartWallet` from packages/smart-wallet/src/walletFactory.js
163
+ walletStoragePath := StoragePathCustom + "." + WalletStoragePathSegment + "." + addr.String()
164
+
165
+ // TODO: implement a pending provision state
166
+ if k.vstorageKeeper.HasEntry(ctx, walletStoragePath) {
167
+ return types.SmartWalletStateProvisioned
168
+ }
169
+
170
+ return types.SmartWalletStateNone
171
+ }
172
+
150
173
  func (k Keeper) InboundQueueLength(ctx sdk.Context) (int32, error) {
151
174
  size := sdk.NewInt(0)
152
175
 
@@ -210,7 +233,11 @@ func (k Keeper) UpdateQueueAllowed(ctx sdk.Context) error {
210
233
  // until the response. It is orthogonal to PushAction, and should only be used
211
234
  // by SwingSet to perform block lifecycle events (BEGIN_BLOCK, END_BLOCK,
212
235
  // COMMIT_BLOCK).
213
- func (k Keeper) BlockingSend(ctx sdk.Context, action vm.Jsonable) (string, error) {
236
+ func (k Keeper) BlockingSend(ctx sdk.Context, action vm.Action) (string, error) {
237
+ action, err := populateAction(ctx, action)
238
+ if err != nil {
239
+ return "", err
240
+ }
214
241
  bz, err := json.Marshal(action)
215
242
  if err != nil {
216
243
  return "", err
@@ -243,9 +270,9 @@ func (k Keeper) SetState(ctx sdk.Context, state types.State) {
243
270
 
244
271
  // GetBeansPerUnit returns a map taken from the current SwingSet parameters from
245
272
  // a unit (key) string to an unsigned integer amount of beans.
246
- func (k Keeper) GetBeansPerUnit(ctx sdk.Context) map[string]sdk.Uint {
273
+ func (k Keeper) GetBeansPerUnit(ctx sdk.Context) map[string]sdkmath.Uint {
247
274
  params := k.GetParams(ctx)
248
- beansPerUnit := make(map[string]sdk.Uint, len(params.BeansPerUnit))
275
+ beansPerUnit := make(map[string]sdkmath.Uint, len(params.BeansPerUnit))
249
276
  for _, bpu := range params.BeansPerUnit {
250
277
  beansPerUnit[bpu.Key] = bpu.Beans
251
278
  }
@@ -258,26 +285,26 @@ func getBeansOwingPathForAddress(addr sdk.AccAddress) string {
258
285
 
259
286
  // GetBeansOwing returns the number of beans that the given address owes to
260
287
  // the FeeAccount but has not yet paid.
261
- func (k Keeper) GetBeansOwing(ctx sdk.Context, addr sdk.AccAddress) sdk.Uint {
288
+ func (k Keeper) GetBeansOwing(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Uint {
262
289
  path := getBeansOwingPathForAddress(addr)
263
290
  entry := k.vstorageKeeper.GetEntry(ctx, path)
264
- if !entry.HasData() {
265
- return sdk.ZeroUint()
291
+ if !entry.HasValue() {
292
+ return sdkmath.ZeroUint()
266
293
  }
267
- return sdk.NewUintFromString(entry.StringValue())
294
+ return sdkmath.NewUintFromString(entry.StringValue())
268
295
  }
269
296
 
270
297
  // SetBeansOwing sets the number of beans that the given address owes to the
271
298
  // feeCollector but has not yet paid.
272
- func (k Keeper) SetBeansOwing(ctx sdk.Context, addr sdk.AccAddress, beans sdk.Uint) {
299
+ func (k Keeper) SetBeansOwing(ctx sdk.Context, addr sdk.AccAddress, beans sdkmath.Uint) {
273
300
  path := getBeansOwingPathForAddress(addr)
274
- k.vstorageKeeper.SetStorage(ctx, vstoragetypes.NewStorageEntry(path, beans.String()))
301
+ k.vstorageKeeper.SetStorage(ctx, agoric.NewKVEntry(path, beans.String()))
275
302
  }
276
303
 
277
304
  // ChargeBeans charges the given address the given number of beans. It divides
278
305
  // the beans into the number to debit immediately vs. the number to store in the
279
306
  // beansOwing.
280
- func (k Keeper) ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdk.Uint) error {
307
+ func (k Keeper) ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdkmath.Uint) error {
281
308
  beansPerUnit := k.GetBeansPerUnit(ctx)
282
309
 
283
310
  wasOwing := k.GetBeansOwing(ctx, addr)
@@ -311,6 +338,25 @@ func (k Keeper) ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdk.Uint
311
338
  return nil
312
339
  }
313
340
 
341
+ // ChargeForSmartWallet charges the fee for provisioning a smart wallet.
342
+ func (k Keeper) ChargeForSmartWallet(ctx sdk.Context, addr sdk.AccAddress) error {
343
+ beansPerUnit := k.GetBeansPerUnit(ctx)
344
+ beans := beansPerUnit[types.BeansPerSmartWalletProvision]
345
+ err := k.ChargeBeans(ctx, addr, beans)
346
+ if err != nil {
347
+ return err
348
+ }
349
+
350
+ // TODO: mark that a smart wallet provision is pending. However in that case,
351
+ // auto-provisioning should still be performed (but without fees being charged),
352
+ // until the controller actually provisions the smart wallet (the operation may
353
+ // transiently fail, requiring retries until success).
354
+ // However the provisioning code is not currently idempotent, and has side
355
+ // effects when the smart wallet is already provisioned.
356
+
357
+ return nil
358
+ }
359
+
314
360
  // makeFeeMenu returns a map from power flag to its fee. In the case of duplicates, the
315
361
  // first one wins.
316
362
  func makeFeeMenu(powerFlagFees []types.PowerFlagFee) map[string]sdk.Coins {
@@ -375,7 +421,7 @@ func (k Keeper) ChargeForProvisioning(ctx sdk.Context, submitter, addr sdk.AccAd
375
421
  func (k Keeper) GetEgress(ctx sdk.Context, addr sdk.AccAddress) types.Egress {
376
422
  path := StoragePathEgress + "." + addr.String()
377
423
  entry := k.vstorageKeeper.GetEntry(ctx, path)
378
- if !entry.HasData() {
424
+ if !entry.HasValue() {
379
425
  return types.Egress{}
380
426
  }
381
427
 
@@ -398,7 +444,7 @@ func (k Keeper) SetEgress(ctx sdk.Context, egress *types.Egress) error {
398
444
  }
399
445
 
400
446
  // FIXME: We should use just SetStorageAndNotify here, but solo needs legacy for now.
401
- k.vstorageKeeper.LegacySetStorageAndNotify(ctx, vstoragetypes.NewStorageEntry(path, string(bz)))
447
+ k.vstorageKeeper.LegacySetStorageAndNotify(ctx, agoric.NewKVEntry(path, string(bz)))
402
448
 
403
449
  // Now make sure the corresponding account has been initialised.
404
450
  if acc := k.accountKeeper.GetAccount(ctx, egress.Peer); acc != nil {
@@ -431,11 +477,12 @@ func (k Keeper) GetMailbox(ctx sdk.Context, peer string) string {
431
477
  func (k Keeper) SetMailbox(ctx sdk.Context, peer string, mailbox string) {
432
478
  path := StoragePathMailbox + "." + peer
433
479
  // FIXME: We should use just SetStorageAndNotify here, but solo needs legacy for now.
434
- k.vstorageKeeper.LegacySetStorageAndNotify(ctx, vstoragetypes.NewStorageEntry(path, mailbox))
480
+ k.vstorageKeeper.LegacySetStorageAndNotify(ctx, agoric.NewKVEntry(path, mailbox))
435
481
  }
436
482
 
437
- func (k Keeper) ExportSwingStore(ctx sdk.Context) []*vstoragetypes.DataEntry {
438
- return k.vstorageKeeper.ExportStorageFromPrefix(ctx, StoragePathSwingStore)
483
+ func (k Keeper) GetSwingStore(ctx sdk.Context) sdk.KVStore {
484
+ store := ctx.KVStore(k.storeKey)
485
+ return prefix.NewStore(store, []byte(swingStoreKeyPrefix))
439
486
  }
440
487
 
441
488
  func (k Keeper) PathToEncodedKey(path string) []byte {
@@ -1,10 +1,17 @@
1
1
  package keeper
2
2
 
3
3
  import (
4
+ "fmt"
5
+ "reflect"
4
6
  "testing"
5
7
 
6
8
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
9
+ "github.com/cosmos/cosmos-sdk/store"
10
+ prefixstore "github.com/cosmos/cosmos-sdk/store/prefix"
11
+ storetypes "github.com/cosmos/cosmos-sdk/store/types"
7
12
  sdk "github.com/cosmos/cosmos-sdk/types"
13
+
14
+ dbm "github.com/tendermint/tm-db"
8
15
  )
9
16
 
10
17
  func mkcoin(denom string) func(amt int64) sdk.Coin {
@@ -181,3 +188,73 @@ func Test_calculateFees(t *testing.T) {
181
188
  })
182
189
  }
183
190
  }
191
+
192
+ var (
193
+ swingsetStoreKey = storetypes.NewKVStoreKey(types.StoreKey)
194
+ )
195
+
196
+ func makeTestStore() sdk.KVStore {
197
+ db := dbm.NewMemDB()
198
+ ms := store.NewCommitMultiStore(db)
199
+ ms.MountStoreWithDB(swingsetStoreKey, storetypes.StoreTypeIAVL, db)
200
+ err := ms.LoadLatestVersion()
201
+ if err != nil {
202
+ panic(err)
203
+ }
204
+ kvStore := ms.GetKVStore(swingsetStoreKey)
205
+ prefixStore := prefixstore.NewStore(kvStore, []byte("swingStore."))
206
+ return prefixStore
207
+ }
208
+
209
+ func TestSwingStore(t *testing.T) {
210
+ store := makeTestStore()
211
+
212
+ // Test that we can store and retrieve a value.
213
+ store.Set([]byte("someKey"), []byte("someValue"))
214
+ if got := string(store.Get([]byte("someKey"))); got != "someValue" {
215
+ t.Errorf("got %q, want %q", got, "someValue")
216
+ }
217
+
218
+ // Test that we can update and retrieve an updated value.
219
+ store.Set([]byte("someKey"), []byte("someNewValue"))
220
+ if got := string(store.Get([]byte("someKey"))); got != "someNewValue" {
221
+ t.Errorf("got %q, want %q", got, "someNewValue")
222
+ }
223
+
224
+ // Test that we can store and retrieve empty values
225
+ store.Set([]byte("someEmptyKey"), []byte(""))
226
+ if got := store.Get([]byte("someEmptyKey")); got == nil || string(got) != "" {
227
+ t.Errorf("got %#v, want empty string", got)
228
+ }
229
+
230
+ // Test that we can store and delete values.
231
+ store.Set([]byte("someOtherKey"), []byte("someOtherValue"))
232
+ store.Delete([]byte("someOtherKey"))
233
+ if store.Has([]byte("someOtherKey")) {
234
+ t.Errorf("has value, expected not")
235
+ }
236
+
237
+ // Test that we can delete non existing keys (e.g. delete twice)
238
+ store.Delete([]byte("someMissingKey"))
239
+
240
+ // Check the iterated values
241
+ expectedEntries := [][2]string{
242
+ {"someEmptyKey", "[]byte{}"},
243
+ {"someKey", "[]byte{0x73, 0x6f, 0x6d, 0x65, 0x4e, 0x65, 0x77, 0x56, 0x61, 0x6c, 0x75, 0x65}"},
244
+ }
245
+
246
+ iter := store.Iterator(nil, nil)
247
+ gotEntries := [][2]string{}
248
+ for ; iter.Valid(); iter.Next() {
249
+ entry := [2]string{
250
+ string(iter.Key()),
251
+ fmt.Sprintf("%#v", iter.Value()),
252
+ }
253
+ gotEntries = append(gotEntries, entry)
254
+ }
255
+ iter.Close()
256
+
257
+ if !reflect.DeepEqual(gotEntries, expectedEntries) {
258
+ t.Errorf("got export %q, want %q", gotEntries, expectedEntries)
259
+ }
260
+ }
@@ -1,7 +1,7 @@
1
1
  package keeper
2
2
 
3
3
  import (
4
- v32 "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/legacy/v32"
4
+ "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
5
5
  sdk "github.com/cosmos/cosmos-sdk/types"
6
6
  )
7
7
 
@@ -17,8 +17,13 @@ func NewMigrator(keeper Keeper) Migrator {
17
17
 
18
18
  // Migrate1to2 migrates from version 1 to 2.
19
19
  func (m Migrator) Migrate1to2(ctx sdk.Context) error {
20
+ return m.MigrateParams(ctx)
21
+ }
22
+
23
+ // MigrateParams migrates params by setting new params to their default value
24
+ func (m Migrator) MigrateParams(ctx sdk.Context) error {
20
25
  params := m.keeper.GetParams(ctx)
21
- newParams, err := v32.UpdateParams(params)
26
+ newParams, err := types.UpdateParams(params)
22
27
  if err != nil {
23
28
  return err
24
29
  }
@@ -21,16 +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
- StoragePort int `json:"storagePort"`
29
- BlockHeight int64 `json:"blockHeight"`
30
- 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"`
31
28
  }
32
29
 
33
- 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 {
34
31
  isHighPriority, err := msg.IsHighPriority(ctx, keeper)
35
32
  if err != nil {
36
33
  return err
@@ -46,21 +43,15 @@ func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionM
46
43
  func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeliverInbound) (*types.MsgDeliverInboundResponse, error) {
47
44
  ctx := sdk.UnwrapSDKContext(goCtx)
48
45
 
46
+ // msg.Nums and msg.Messages must be zipped into an array of [num, message] pairs.
49
47
  messages := make([][]interface{}, len(msg.Messages))
50
48
  for i, message := range msg.Messages {
51
- messages[i] = make([]interface{}, 2)
52
- messages[i][0] = msg.Nums[i]
53
- messages[i][1] = message
49
+ messages[i] = []interface{}{msg.Nums[i], message}
54
50
  }
55
-
56
- action := &deliverInboundAction{
57
- Type: "DELIVER_INBOUND",
58
- Peer: msg.Submitter.String(),
59
- Messages: messages,
60
- Ack: msg.Ack,
61
- StoragePort: vm.GetPort("vstorage"),
62
- BlockHeight: ctx.BlockHeight(),
63
- BlockTime: ctx.BlockTime().Unix(),
51
+ action := deliverInboundAction{
52
+ Peer: msg.Submitter.String(),
53
+ Messages: messages,
54
+ Ack: msg.Ack,
64
55
  }
65
56
 
66
57
  err := keeper.routeAction(ctx, msg, action)
@@ -72,26 +63,26 @@ func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeli
72
63
  }
73
64
 
74
65
  type walletAction struct {
75
- Type string `json:"type"` // WALLET_ACTION
76
- Owner string `json:"owner"`
77
- Action string `json:"action"`
78
- BlockHeight int64 `json:"blockHeight"`
79
- BlockTime int64 `json:"blockTime"`
66
+ *vm.ActionHeader `actionType:"WALLET_ACTION"`
67
+ Owner string `json:"owner"`
68
+ Action string `json:"action"`
80
69
  }
81
70
 
82
71
  func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWalletAction) (*types.MsgWalletActionResponse, error) {
83
72
  ctx := sdk.UnwrapSDKContext(goCtx)
84
73
 
85
- action := &walletAction{
86
- Type: "WALLET_ACTION",
87
- Owner: msg.Owner.String(),
88
- Action: msg.Action,
89
- BlockHeight: ctx.BlockHeight(),
90
- BlockTime: ctx.BlockTime().Unix(),
74
+ err := keeper.provisionIfNeeded(ctx, msg.Owner)
75
+ if err != nil {
76
+ return nil, err
77
+ }
78
+
79
+ action := walletAction{
80
+ Owner: msg.Owner.String(),
81
+ Action: msg.Action,
91
82
  }
92
83
  // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
93
84
 
94
- err := keeper.routeAction(ctx, msg, action)
85
+ err = keeper.routeAction(ctx, msg, action)
95
86
  // fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
96
87
  if err != nil {
97
88
  return nil, err
@@ -100,25 +91,25 @@ func (keeper msgServer) WalletAction(goCtx context.Context, msg *types.MsgWallet
100
91
  }
101
92
 
102
93
  type walletSpendAction struct {
103
- Type string `json:"type"` // WALLET_SPEND_ACTION
104
- Owner string `json:"owner"`
105
- SpendAction string `json:"spendAction"`
106
- BlockHeight int64 `json:"blockHeight"`
107
- BlockTime int64 `json:"blockTime"`
94
+ *vm.ActionHeader `actionType:"WALLET_SPEND_ACTION"`
95
+ Owner string `json:"owner"`
96
+ SpendAction string `json:"spendAction"`
108
97
  }
109
98
 
110
99
  func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgWalletSpendAction) (*types.MsgWalletSpendActionResponse, error) {
111
100
  ctx := sdk.UnwrapSDKContext(goCtx)
112
101
 
113
- action := &walletSpendAction{
114
- Type: "WALLET_SPEND_ACTION",
102
+ err := keeper.provisionIfNeeded(ctx, msg.Owner)
103
+ if err != nil {
104
+ return nil, err
105
+ }
106
+
107
+ action := walletSpendAction{
115
108
  Owner: msg.Owner.String(),
116
109
  SpendAction: msg.SpendAction,
117
- BlockHeight: ctx.BlockHeight(),
118
- BlockTime: ctx.BlockTime().Unix(),
119
110
  }
120
111
  // fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
121
- err := keeper.routeAction(ctx, msg, action)
112
+ err = keeper.routeAction(ctx, msg, action)
122
113
  if err != nil {
123
114
  return nil, err
124
115
  }
@@ -126,10 +117,42 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW
126
117
  }
127
118
 
128
119
  type provisionAction struct {
120
+ *vm.ActionHeader `actionType:"PLEASE_PROVISION"`
129
121
  *types.MsgProvision
130
- Type string `json:"type"` // PLEASE_PROVISION
131
- BlockHeight int64 `json:"blockHeight"`
132
- BlockTime int64 `json:"blockTime"`
122
+ AutoProvision bool `json:"autoProvision"`
123
+ }
124
+
125
+ // provisionIfNeeded generates a provision action if no smart wallet is already
126
+ // provisioned for the account. This assumes that all messages for
127
+ // non-provisioned smart wallets allowed by the admission AnteHandler should
128
+ // auto-provision the smart wallet.
129
+ func (keeper msgServer) provisionIfNeeded(ctx sdk.Context, owner sdk.AccAddress) error {
130
+ // We need to generate a provision action until the smart wallet has
131
+ // been fully provisioned by the controller. This is because a provision is
132
+ // not guaranteed to succeed (e.g. lack of provision pool funds)
133
+ walletState := keeper.GetSmartWalletState(ctx, owner)
134
+ if walletState == types.SmartWalletStateProvisioned {
135
+ return nil
136
+ }
137
+
138
+ msg := &types.MsgProvision{
139
+ Address: owner,
140
+ Submitter: owner,
141
+ PowerFlags: []string{types.PowerFlagSmartWallet},
142
+ }
143
+
144
+ action := provisionAction{
145
+ MsgProvision: msg,
146
+ AutoProvision: true,
147
+ }
148
+
149
+ err := keeper.routeAction(ctx, msg, action)
150
+ // fmt.Fprintln(os.Stderr, "Returned from SwingSet", out, err)
151
+ if err != nil {
152
+ return err
153
+ }
154
+
155
+ return nil
133
156
  }
134
157
 
135
158
  func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision) (*types.MsgProvisionResponse, error) {
@@ -140,11 +163,8 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
140
163
  return nil, err
141
164
  }
142
165
 
143
- action := &provisionAction{
166
+ action := provisionAction{
144
167
  MsgProvision: msg,
145
- Type: "PLEASE_PROVISION",
146
- BlockHeight: ctx.BlockHeight(),
147
- BlockTime: ctx.BlockTime().Unix(),
148
168
  }
149
169
 
150
170
  // Create the account, if it doesn't already exist.
@@ -164,10 +184,8 @@ func (keeper msgServer) Provision(goCtx context.Context, msg *types.MsgProvision
164
184
  }
165
185
 
166
186
  type installBundleAction struct {
187
+ *vm.ActionHeader `actionType:"INSTALL_BUNDLE"`
167
188
  *types.MsgInstallBundle
168
- Type string `json:"type"` // INSTALL_BUNDLE
169
- BlockHeight int64 `json:"blockHeight"`
170
- BlockTime int64 `json:"blockTime"`
171
189
  }
172
190
 
173
191
  func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInstallBundle) (*types.MsgInstallBundleResponse, error) {
@@ -177,11 +195,8 @@ func (keeper msgServer) InstallBundle(goCtx context.Context, msg *types.MsgInsta
177
195
  if err != nil {
178
196
  return nil, err
179
197
  }
180
- action := &installBundleAction{
198
+ action := installBundleAction{
181
199
  MsgInstallBundle: msg,
182
- Type: "INSTALL_BUNDLE",
183
- BlockHeight: ctx.BlockHeight(),
184
- BlockTime: ctx.BlockTime().Unix(),
185
200
  }
186
201
 
187
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
- action := &coreEvalAction{
19
- Type: "CORE_EVAL",
20
- Evals: p.Evals,
21
- BlockHeight: ctx.BlockHeight(),
22
- BlockTime: ctx.BlockTime().Unix(),
20
+ action := coreEvalAction{
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
  }