@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.
Files changed (169) hide show
  1. package/CHANGELOG.md +121 -77
  2. package/MAINTAINERS.md +3 -0
  3. package/Makefile +49 -26
  4. package/ante/ante.go +11 -11
  5. package/ante/inbound_test.go +3 -2
  6. package/ante/vm_admission.go +2 -1
  7. package/app/app.go +260 -175
  8. package/app/export.go +13 -6
  9. package/app/upgrade.go +76 -0
  10. package/cmd/agd/agvm.go +42 -0
  11. package/cmd/agd/main.go +132 -11
  12. package/cmd/libdaemon/main.go +67 -53
  13. package/cmd/libdaemon/main_test.go +2 -1
  14. package/daemon/cmd/genaccounts.go +13 -9
  15. package/daemon/cmd/root.go +186 -73
  16. package/daemon/cmd/root_test.go +190 -2
  17. package/daemon/cmd/testnet.go +17 -6
  18. package/daemon/main.go +6 -3
  19. package/e2e_test/Makefile +29 -0
  20. package/e2e_test/README.md +100 -0
  21. package/e2e_test/go.mod +217 -0
  22. package/e2e_test/go.sum +1323 -0
  23. package/e2e_test/ibc_conformance_test.go +56 -0
  24. package/e2e_test/pfm_test.go +613 -0
  25. package/e2e_test/util.go +271 -0
  26. package/git-revision.txt +1 -1
  27. package/go.mod +110 -68
  28. package/go.sum +601 -248
  29. package/package.json +9 -5
  30. package/proto/agoric/swingset/genesis.proto +4 -0
  31. package/proto/agoric/swingset/swingset.proto +1 -1
  32. package/proto/agoric/vlocalchain/.clang-format +7 -0
  33. package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
  34. package/proto/agoric/vstorage/query.proto +53 -1
  35. package/proto/agoric/vtransfer/genesis.proto +18 -0
  36. package/scripts/protocgen.sh +16 -6
  37. package/third_party/proto/buf.yaml +1 -0
  38. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  39. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  40. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  41. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  42. package/third_party/proto/google/api/annotations.proto +1 -1
  43. package/third_party/proto/google/api/http.proto +181 -120
  44. package/third_party/proto/google/api/httpbody.proto +9 -6
  45. package/third_party/proto/google/protobuf/any.proto +1 -7
  46. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  47. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  48. package/types/kv_entry_helpers.go +42 -0
  49. package/upgradegaia.sh +21 -12
  50. package/vm/action.go +28 -24
  51. package/vm/action_test.go +36 -16
  52. package/vm/client.go +113 -0
  53. package/vm/client_test.go +182 -0
  54. package/vm/controller.go +18 -42
  55. package/vm/core_proposals.go +22 -2
  56. package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
  57. package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
  58. package/vm/proto_json.go +38 -0
  59. package/vm/proto_json_test.go +103 -0
  60. package/vm/server.go +124 -0
  61. package/x/swingset/abci.go +10 -10
  62. package/x/swingset/alias.go +2 -0
  63. package/x/swingset/client/cli/query.go +2 -2
  64. package/x/swingset/client/cli/tx.go +52 -33
  65. package/x/swingset/client/proposal_handler.go +2 -17
  66. package/x/swingset/genesis.go +84 -24
  67. package/x/swingset/handler.go +2 -1
  68. package/x/swingset/keeper/extension_snapshotter.go +2 -2
  69. package/x/swingset/keeper/keeper.go +21 -36
  70. package/x/swingset/keeper/keeper_test.go +1 -1
  71. package/x/swingset/keeper/msg_server.go +20 -22
  72. package/x/swingset/keeper/proposal.go +13 -3
  73. package/x/swingset/keeper/querier.go +23 -14
  74. package/x/swingset/keeper/swing_store_exports_handler.go +21 -6
  75. package/x/swingset/keeper/test_utils.go +16 -0
  76. package/x/swingset/module.go +7 -7
  77. package/x/swingset/proposal_handler.go +5 -4
  78. package/x/swingset/swingset.go +4 -2
  79. package/x/swingset/testing/queue.go +17 -0
  80. package/x/swingset/types/codec.go +2 -2
  81. package/x/swingset/types/default-params.go +1 -1
  82. package/x/swingset/types/expected_keepers.go +3 -2
  83. package/x/swingset/types/genesis.pb.go +78 -25
  84. package/x/swingset/types/msgs.go +44 -24
  85. package/x/swingset/types/msgs.pb.go +16 -16
  86. package/x/swingset/types/params.go +2 -1
  87. package/x/swingset/types/proposal.go +10 -9
  88. package/x/swingset/types/swingset.pb.go +1 -1
  89. package/x/swingset/types/types.go +30 -28
  90. package/x/vbank/genesis.go +0 -2
  91. package/x/vbank/handler.go +2 -1
  92. package/x/vbank/keeper/keeper.go +3 -2
  93. package/x/vbank/keeper/querier.go +9 -4
  94. package/x/vbank/keeper/rewards.go +1 -1
  95. package/x/vbank/module.go +0 -5
  96. package/x/vbank/types/msgs.go +0 -12
  97. package/x/vbank/vbank.go +20 -19
  98. package/x/vbank/vbank_test.go +10 -10
  99. package/x/vibc/alias.go +3 -0
  100. package/x/vibc/handler.go +16 -9
  101. package/x/vibc/keeper/keeper.go +112 -74
  102. package/x/vibc/keeper/triggers.go +101 -0
  103. package/x/vibc/module.go +5 -8
  104. package/x/vibc/types/expected_keepers.go +26 -5
  105. package/x/vibc/types/ibc_module.go +336 -0
  106. package/x/vibc/types/msgs.go +1 -1
  107. package/x/vibc/types/msgs.pb.go +1 -1
  108. package/x/vibc/types/receiver.go +170 -0
  109. package/x/vlocalchain/alias.go +19 -0
  110. package/x/vlocalchain/handler.go +21 -0
  111. package/x/vlocalchain/keeper/keeper.go +279 -0
  112. package/x/vlocalchain/keeper/keeper_test.go +97 -0
  113. package/x/vlocalchain/types/codec.go +34 -0
  114. package/x/vlocalchain/types/key.go +27 -0
  115. package/x/vlocalchain/types/msgs.go +16 -0
  116. package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
  117. package/x/vlocalchain/vlocalchain.go +114 -0
  118. package/x/vlocalchain/vlocalchain_test.go +434 -0
  119. package/x/vstorage/README.md +138 -0
  120. package/x/vstorage/capdata/capdata.go +298 -0
  121. package/x/vstorage/capdata/capdata_test.go +352 -0
  122. package/x/vstorage/client/cli/query.go +51 -4
  123. package/x/vstorage/handler.go +2 -1
  124. package/x/vstorage/keeper/grpc_query.go +220 -0
  125. package/x/vstorage/keeper/keeper.go +16 -22
  126. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  127. package/x/vstorage/keeper/keeper_test.go +1 -1
  128. package/x/vstorage/keeper/querier.go +11 -6
  129. package/x/vstorage/keeper/querier_test.go +4 -3
  130. package/x/vstorage/module.go +0 -5
  131. package/x/vstorage/testing/queue.go +27 -0
  132. package/x/vstorage/types/query.pb.go +646 -36
  133. package/x/vstorage/types/query.pb.gw.go +119 -0
  134. package/x/vstorage/vstorage.go +16 -15
  135. package/x/vstorage/vstorage_test.go +5 -5
  136. package/x/vtransfer/alias.go +13 -0
  137. package/x/vtransfer/genesis.go +39 -0
  138. package/x/vtransfer/genesis_test.go +12 -0
  139. package/x/vtransfer/handler.go +20 -0
  140. package/x/vtransfer/ibc_middleware.go +186 -0
  141. package/x/vtransfer/ibc_middleware_test.go +448 -0
  142. package/x/vtransfer/keeper/keeper.go +281 -0
  143. package/x/vtransfer/module.go +124 -0
  144. package/x/vtransfer/types/expected_keepers.go +38 -0
  145. package/x/vtransfer/types/genesis.pb.go +327 -0
  146. package/x/vtransfer/types/key.go +9 -0
  147. package/x/vtransfer/types/msgs.go +9 -0
  148. package/ante/fee.go +0 -96
  149. package/proto/agoric/lien/genesis.proto +0 -25
  150. package/proto/agoric/lien/lien.proto +0 -25
  151. package/x/lien/alias.go +0 -17
  152. package/x/lien/genesis.go +0 -58
  153. package/x/lien/genesis_test.go +0 -101
  154. package/x/lien/keeper/account.go +0 -290
  155. package/x/lien/keeper/keeper.go +0 -254
  156. package/x/lien/keeper/keeper_test.go +0 -623
  157. package/x/lien/lien.go +0 -203
  158. package/x/lien/lien_test.go +0 -529
  159. package/x/lien/module.go +0 -115
  160. package/x/lien/spec/01_concepts.md +0 -146
  161. package/x/lien/spec/02_messages.md +0 -96
  162. package/x/lien/types/accountkeeper.go +0 -81
  163. package/x/lien/types/accountstate.go +0 -27
  164. package/x/lien/types/expected_keepers.go +0 -18
  165. package/x/lien/types/genesis.pb.go +0 -567
  166. package/x/lien/types/key.go +0 -25
  167. package/x/lien/types/lien.pb.go +0 -403
  168. package/x/vibc/ibc.go +0 -393
  169. /package/{src/index.cjs → index.cjs} +0 -0
@@ -2,23 +2,23 @@ package cmd
2
2
 
3
3
  import (
4
4
  "errors"
5
+ "fmt"
5
6
  "io"
6
7
  "os"
7
8
  "path/filepath"
8
9
 
9
10
  serverconfig "github.com/cosmos/cosmos-sdk/server/config"
10
11
 
11
- "github.com/cosmos/cosmos-sdk/baseapp"
12
12
  "github.com/cosmos/cosmos-sdk/client"
13
13
  "github.com/cosmos/cosmos-sdk/client/config"
14
14
  "github.com/cosmos/cosmos-sdk/client/debug"
15
15
  "github.com/cosmos/cosmos-sdk/client/flags"
16
16
  "github.com/cosmos/cosmos-sdk/client/keys"
17
+ "github.com/cosmos/cosmos-sdk/client/pruning"
17
18
  "github.com/cosmos/cosmos-sdk/client/rpc"
19
+ "github.com/cosmos/cosmos-sdk/client/snapshot"
18
20
  "github.com/cosmos/cosmos-sdk/server"
19
21
  servertypes "github.com/cosmos/cosmos-sdk/server/types"
20
- "github.com/cosmos/cosmos-sdk/snapshots"
21
- "github.com/cosmos/cosmos-sdk/store"
22
22
  sdk "github.com/cosmos/cosmos-sdk/types"
23
23
  authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
24
24
  "github.com/cosmos/cosmos-sdk/x/auth/types"
@@ -28,24 +28,24 @@ import (
28
28
  "github.com/spf13/cast"
29
29
  "github.com/spf13/cobra"
30
30
  "github.com/spf13/viper"
31
+ tmcfg "github.com/tendermint/tendermint/config"
31
32
  tmcli "github.com/tendermint/tendermint/libs/cli"
32
33
  "github.com/tendermint/tendermint/libs/log"
33
34
  dbm "github.com/tendermint/tm-db"
34
35
 
35
36
  gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
36
37
  "github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
38
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
39
+ swingsetkeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
37
40
  )
38
41
 
39
- // Sender is a function that sends a request to the controller.
40
- type Sender func(needReply bool, str string) (string, error)
41
-
42
42
  var AppName = "agd"
43
- var OnStartHook func(logger log.Logger)
44
- var OnExportHook func(logger log.Logger)
43
+ var OnStartHook func(*vm.AgdServer, log.Logger, servertypes.AppOptions) error
44
+ var OnExportHook func(*vm.AgdServer, log.Logger, servertypes.AppOptions) error
45
45
 
46
46
  // NewRootCmd creates a new root command for simd. It is called once in the
47
47
  // main function.
48
- func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
48
+ func NewRootCmd(sender vm.Sender) (*cobra.Command, params.EncodingConfig) {
49
49
  encodingConfig := gaia.MakeEncodingConfig()
50
50
  initClientCtx := client.Context{}.
51
51
  WithCodec(encodingConfig.Marshaler).
@@ -59,7 +59,7 @@ func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
59
59
 
60
60
  rootCmd := &cobra.Command{
61
61
  Use: AppName,
62
- Short: "Stargate Agoric App",
62
+ Short: "Agoric Cosmos App",
63
63
  PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
64
64
  // set the default command outputs
65
65
  cmd.SetOut(cmd.OutOrStdout())
@@ -80,7 +80,8 @@ func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
80
80
  }
81
81
 
82
82
  customAppTemplate, customAppConfig := initAppConfig()
83
- return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig)
83
+ customTMConfig := initTendermintConfig()
84
+ return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig)
84
85
  },
85
86
  }
86
87
 
@@ -89,6 +90,12 @@ func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
89
90
  return rootCmd, encodingConfig
90
91
  }
91
92
 
93
+ func initTendermintConfig() *tmcfg.Config {
94
+ cfg := tmcfg.DefaultConfig()
95
+ // customize config here
96
+ return cfg
97
+ }
98
+
92
99
  // initAppConfig helps to override default appConfig template and configs.
93
100
  // return "", nil if no custom configuration is required for the application.
94
101
  func initAppConfig() (string, interface{}) {
@@ -112,33 +119,48 @@ func initAppConfig() (string, interface{}) {
112
119
  return serverconfig.DefaultConfigTemplate, *srvCfg
113
120
  }
114
121
 
115
- func initRootCmd(sender Sender, rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
122
+ func initRootCmd(sender vm.Sender, rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
116
123
  cfg := sdk.GetConfig()
117
124
  cfg.Seal()
118
125
 
126
+ ac := appCreator{
127
+ encCfg: encodingConfig,
128
+ sender: sender,
129
+ agdServer: vm.NewAgdServer(),
130
+ }
131
+
119
132
  rootCmd.AddCommand(
120
133
  genutilcli.InitCmd(gaia.ModuleBasics, gaia.DefaultNodeHome),
121
134
  genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, gaia.DefaultNodeHome),
135
+ genutilcli.MigrateGenesisCmd(),
122
136
  genutilcli.GenTxCmd(gaia.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, gaia.DefaultNodeHome),
123
137
  genutilcli.ValidateGenesisCmd(gaia.ModuleBasics),
124
- AddGenesisAccountCmd(gaia.DefaultNodeHome),
138
+ AddGenesisAccountCmd(encodingConfig.Marshaler, gaia.DefaultNodeHome),
125
139
  tmcli.NewCompletionCmd(rootCmd, true),
126
140
  testnetCmd(gaia.ModuleBasics, banktypes.GenesisBalancesIterator{}),
127
141
  debug.Cmd(),
128
142
  config.Cmd(),
143
+ pruning.Cmd(ac.newSnapshotsApp, gaia.DefaultNodeHome),
144
+ snapshot.Cmd(ac.newSnapshotsApp),
129
145
  )
130
146
 
131
- ac := appCreator{
132
- encCfg: encodingConfig,
133
- sender: sender,
134
- }
135
147
  server.AddCommands(rootCmd, gaia.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags)
136
148
 
137
- hasVMController := sender != nil
138
149
  for _, command := range rootCmd.Commands() {
139
- if command.Name() == "export" {
140
- extendCosmosExportCommand(command, hasVMController)
141
- break
150
+ switch command.Name() {
151
+ case "export":
152
+ addAgoricVMFlags(command)
153
+ extendCosmosExportCommand(command)
154
+ case "snapshots":
155
+ for _, subCommand := range command.Commands() {
156
+ switch subCommand.Name() {
157
+ case "restore":
158
+ addAgoricVMFlags(subCommand)
159
+ case "export":
160
+ addAgoricVMFlags(subCommand)
161
+ replaceCosmosSnapshotExportCommand(subCommand, ac)
162
+ }
163
+ }
142
164
  }
143
165
  }
144
166
 
@@ -153,7 +175,30 @@ func initRootCmd(sender Sender, rootCmd *cobra.Command, encodingConfig params.En
153
175
  rootCmd.AddCommand(server.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))
154
176
  }
155
177
 
178
+ const (
179
+ // FlagSplitVm is the command-line flag for subcommands that can use a
180
+ // split-process Agoric VM. The default is to use an embedded VM.
181
+ FlagSplitVm = "split-vm"
182
+ EmbeddedVmEnvVar = "AGD_EMBEDDED_VM"
183
+ )
184
+
185
+ // hasVMController returns true if we have a VM (are running in split-vm mode,
186
+ // or with an embedded VM).
187
+ func hasVMController(serverCtx *server.Context) bool {
188
+ return serverCtx.Viper.GetString(FlagSplitVm) != "" ||
189
+ os.Getenv(EmbeddedVmEnvVar) != ""
190
+ }
191
+
192
+ func addAgoricVMFlags(cmd *cobra.Command) {
193
+ cmd.PersistentFlags().String(
194
+ FlagSplitVm,
195
+ "",
196
+ "Specify the external Agoric VM program",
197
+ )
198
+ }
199
+
156
200
  func addModuleInitFlags(startCmd *cobra.Command) {
201
+ addAgoricVMFlags(startCmd)
157
202
  }
158
203
 
159
204
  func queryCommand() *cobra.Command {
@@ -199,6 +244,7 @@ func txCommand() *cobra.Command {
199
244
  authcmd.GetBroadcastCommand(),
200
245
  authcmd.GetEncodeCommand(),
201
246
  authcmd.GetDecodeCommand(),
247
+ authcmd.GetAuxToFeeCommand(),
202
248
  flags.LineBreak,
203
249
  vestingcli.GetTxCmd(),
204
250
  )
@@ -210,8 +256,9 @@ func txCommand() *cobra.Command {
210
256
  }
211
257
 
212
258
  type appCreator struct {
213
- encCfg params.EncodingConfig
214
- sender Sender
259
+ encCfg params.EncodingConfig
260
+ sender vm.Sender
261
+ agdServer *vm.AgdServer
215
262
  }
216
263
 
217
264
  func (ac appCreator) newApp(
@@ -221,25 +268,18 @@ func (ac appCreator) newApp(
221
268
  appOpts servertypes.AppOptions,
222
269
  ) servertypes.Application {
223
270
  if OnStartHook != nil {
224
- OnStartHook(logger)
271
+ if err := OnStartHook(ac.agdServer, logger, appOpts); err != nil {
272
+ panic(err)
273
+ }
225
274
  }
226
275
 
227
- var cache sdk.MultiStorePersistentCache
228
-
229
- if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
230
- cache = store.NewCommitKVStoreCacheManager()
231
- }
276
+ baseappOptions := server.DefaultBaseappOptions(appOpts)
232
277
 
233
278
  skipUpgradeHeights := make(map[int64]bool)
234
279
  for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
235
280
  skipUpgradeHeights[int64(h)] = true
236
281
  }
237
282
 
238
- pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts)
239
- if err != nil {
240
- panic(err)
241
- }
242
-
243
283
  homePath := cast.ToString(appOpts.Get(flags.FlagHome))
244
284
 
245
285
  // Set a default value for FlagSwingStoreExportDir based on the homePath
@@ -249,34 +289,41 @@ func (ac appCreator) newApp(
249
289
  viper.Set(gaia.FlagSwingStoreExportDir, filepath.Join(homePath, "config", ExportedSwingStoreDirectoryName))
250
290
  }
251
291
 
252
- snapshotDir := filepath.Join(homePath, "data", "snapshots")
253
- snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
254
- if err != nil {
255
- panic(err)
256
- }
257
- snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
258
- if err != nil {
259
- panic(err)
292
+ return gaia.NewAgoricApp(
293
+ ac.sender, ac.agdServer,
294
+ logger, db, traceStore, true, skipUpgradeHeights,
295
+ homePath,
296
+ cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
297
+ ac.encCfg,
298
+ appOpts,
299
+ baseappOptions...,
300
+ )
301
+ }
302
+
303
+ func (ac appCreator) newSnapshotsApp(
304
+ logger log.Logger,
305
+ db dbm.DB,
306
+ traceStore io.Writer,
307
+ appOpts servertypes.AppOptions,
308
+ ) servertypes.Application {
309
+ if OnExportHook != nil {
310
+ if err := OnExportHook(ac.agdServer, logger, appOpts); err != nil {
311
+ panic(err)
312
+ }
260
313
  }
261
314
 
315
+ baseappOptions := server.DefaultBaseappOptions(appOpts)
316
+
317
+ homePath := cast.ToString(appOpts.Get(flags.FlagHome))
318
+
262
319
  return gaia.NewAgoricApp(
263
- ac.sender,
264
- logger, db, traceStore, true, skipUpgradeHeights,
320
+ ac.sender, ac.agdServer,
321
+ logger, db, traceStore, true, map[int64]bool{},
265
322
  homePath,
266
323
  cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
267
324
  ac.encCfg,
268
325
  appOpts,
269
- baseapp.SetPruning(pruningOpts),
270
- baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
271
- baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
272
- baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))),
273
- baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))),
274
- baseapp.SetInterBlockCache(cache),
275
- baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
276
- baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
277
- baseapp.SetSnapshotStore(snapshotStore),
278
- baseapp.SetSnapshotInterval(cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval))),
279
- baseapp.SetSnapshotKeepRecent(cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent))),
326
+ baseappOptions...,
280
327
  )
281
328
  }
282
329
 
@@ -295,8 +342,8 @@ const (
295
342
 
296
343
  // extendCosmosExportCommand monkey-patches the "export" command added by
297
344
  // cosmos-sdk to add a required "export-dir" command-line flag, and create the
298
- // genesis export in the specified directory.
299
- func extendCosmosExportCommand(cmd *cobra.Command, hasVMController bool) {
345
+ // genesis export in the specified directory if the VM is running.
346
+ func extendCosmosExportCommand(cmd *cobra.Command) {
300
347
  cmd.Flags().String(FlagExportDir, "", "The directory where to create the genesis export")
301
348
  err := cmd.MarkFlagRequired(FlagExportDir)
302
349
  if err != nil {
@@ -327,25 +374,28 @@ func extendCosmosExportCommand(cmd *cobra.Command, hasVMController bool) {
327
374
  // current genesis.
328
375
  serverCtx.Viper.Set(gaia.FlagSwingStoreExportDir, swingStoreExportPath)
329
376
 
330
- // This will fail is a genesis.json already exists in the export-dir
331
- genesisFile, err := os.OpenFile(genesisPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, os.ModePerm)
332
- if err != nil {
333
- return err
377
+ if hasVMController(serverCtx) {
378
+ // Capture the export in the genesisPath.
379
+ // This will fail if a genesis.json already exists in the export-dir
380
+ genesisFile, err := os.OpenFile(
381
+ genesisPath,
382
+ os.O_CREATE|os.O_EXCL|os.O_WRONLY,
383
+ os.ModePerm,
384
+ )
385
+ if err != nil {
386
+ return err
387
+ }
388
+ defer genesisFile.Close()
389
+ cmd.SetOut(genesisFile)
334
390
  }
335
- defer genesisFile.Close()
336
-
337
- cmd.SetOut(genesisFile)
338
391
 
392
+ // If we don't have a VM, appExport will just use the OnExportHook to exec
393
+ // the VM program, which will result in reentering this function with the VM
394
+ // controller set, and activate the above condition.
339
395
  return originalRunE(cmd, args)
340
396
  }
341
397
 
342
- // Only modify the command handler when we have a VM controller to handle
343
- // the full export logic. Otherwise, appExport will just exec the VM program
344
- // (OnExportHook), which will result in re-entering this flow with the VM
345
- // controller set.
346
- if hasVMController {
347
- cmd.RunE = extendedRunE
348
- }
398
+ cmd.RunE = extendedRunE
349
399
  }
350
400
 
351
401
  func (ac appCreator) appExport(
@@ -358,7 +408,9 @@ func (ac appCreator) appExport(
358
408
  appOpts servertypes.AppOptions,
359
409
  ) (servertypes.ExportedApp, error) {
360
410
  if OnExportHook != nil {
361
- OnExportHook(logger)
411
+ if err := OnExportHook(ac.agdServer, logger, appOpts); err != nil {
412
+ return servertypes.ExportedApp{}, err
413
+ }
362
414
  }
363
415
 
364
416
  homePath, ok := appOpts.Get(flags.FlagHome).(string)
@@ -372,7 +424,7 @@ func (ac appCreator) appExport(
372
424
  }
373
425
 
374
426
  gaiaApp := gaia.NewAgoricApp(
375
- ac.sender,
427
+ ac.sender, ac.agdServer,
376
428
  logger,
377
429
  db,
378
430
  traceStore,
@@ -392,3 +444,64 @@ func (ac appCreator) appExport(
392
444
 
393
445
  return gaiaApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
394
446
  }
447
+
448
+ // replaceCosmosSnapshotExportCommand monkey-patches the "snapshots export" command
449
+ // added by cosmos-sdk and replaces its implementation with one suitable for
450
+ // our modifications to the cosmos snapshots process
451
+ func replaceCosmosSnapshotExportCommand(cmd *cobra.Command, ac appCreator) {
452
+ // Copy of RunE is cosmos-sdk/client/snapshot/export.go
453
+ replacedRunE := func(cmd *cobra.Command, args []string) error {
454
+ ctx := server.GetServerContextFromCmd(cmd)
455
+
456
+ heightFlag, err := cmd.Flags().GetInt64("height")
457
+ if err != nil {
458
+ return err
459
+ }
460
+
461
+ home := ctx.Config.RootDir
462
+ dataDir := filepath.Join(home, "data")
463
+ db, err := dbm.NewDB("application", server.GetAppDBBackend(ctx.Viper), dataDir)
464
+ if err != nil {
465
+ return err
466
+ }
467
+
468
+ app := ac.newSnapshotsApp(ctx.Logger, db, nil, ctx.Viper)
469
+ gaiaApp := app.(*gaia.GaiaApp)
470
+
471
+ latestHeight := app.CommitMultiStore().LastCommitID().Version
472
+
473
+ if heightFlag != 0 && latestHeight != heightFlag {
474
+ return fmt.Errorf("cannot export at height %d, only latest height %d is supported", heightFlag, latestHeight)
475
+ }
476
+
477
+ cmd.Printf("Exporting snapshot for height %d\n", latestHeight)
478
+
479
+ err = gaiaApp.SwingSetSnapshotter.InitiateSnapshot(latestHeight)
480
+ if err != nil {
481
+ return err
482
+ }
483
+
484
+ err = swingsetkeeper.WaitUntilSwingStoreExportDone()
485
+ if err != nil {
486
+ return err
487
+ }
488
+
489
+ snapshotList, err := app.SnapshotManager().List()
490
+ if err != nil {
491
+ return err
492
+ }
493
+
494
+ snapshotHeight := uint64(latestHeight)
495
+
496
+ for _, snapshot := range snapshotList {
497
+ if snapshot.Height == snapshotHeight {
498
+ cmd.Printf("Snapshot created at height %d, format %d, chunks %d\n", snapshot.Height, snapshot.Format, snapshot.Chunks)
499
+ break
500
+ }
501
+ }
502
+
503
+ return nil
504
+ }
505
+
506
+ cmd.RunE = replacedRunE
507
+ }
@@ -1,13 +1,24 @@
1
1
  package cmd_test
2
2
 
3
3
  import (
4
+ "bytes"
5
+ "io"
6
+ "os"
4
7
  "testing"
8
+ "text/template"
5
9
 
10
+ "github.com/spf13/pflag"
11
+ "github.com/stretchr/testify/require"
12
+
13
+ "github.com/cosmos/cosmos-sdk/server"
6
14
  svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
15
+ serverconfig "github.com/cosmos/cosmos-sdk/server/config"
16
+ servertypes "github.com/cosmos/cosmos-sdk/server/types"
17
+ "github.com/tendermint/tendermint/libs/log"
18
+ dbm "github.com/tendermint/tm-db"
7
19
 
8
20
  app "github.com/Agoric/agoric-sdk/golang/cosmos/app"
9
21
  "github.com/Agoric/agoric-sdk/golang/cosmos/daemon/cmd"
10
- "github.com/stretchr/testify/require"
11
22
  )
12
23
 
13
24
  func TestRootCmdConfig(t *testing.T) {
@@ -19,5 +30,182 @@ func TestRootCmdConfig(t *testing.T) {
19
30
  "test", // value
20
31
  })
21
32
 
22
- require.NoError(t, svrcmd.Execute(rootCmd, app.DefaultNodeHome))
33
+ require.NoError(t, svrcmd.Execute(rootCmd, "", app.DefaultNodeHome))
34
+ }
35
+
36
+ func TestCLIFlags(t *testing.T) {
37
+ // List of flags we have so far observed as used by the base cosmos sdk
38
+ // Before adding any flag to this list, the author should audit if explicit
39
+ // handling should not be added in the Agoric app (most likely in root.go)
40
+ expectedFlagNames := map[string]interface{}{
41
+ "abci": "",
42
+ "abci-client-type": "",
43
+ "address": "",
44
+ "app-db-backend": "",
45
+ "cpu-profile": "",
46
+ "db_backend": "",
47
+ "db_dir": "",
48
+ "fast_sync": "",
49
+ "genesis_hash": "",
50
+ "grpc-only": "",
51
+ "halt-height": "",
52
+ "halt-time": "",
53
+ "home": "",
54
+ "iavl-cache-size": "",
55
+ "iavl-disable-fastnode": "",
56
+ "iavl-lazy-loading": "",
57
+ "index-events": "",
58
+ "inter-block-cache": "",
59
+ "inv-check-period": "",
60
+ "min-retain-blocks": "",
61
+ "minimum-gas-prices": "",
62
+ "moniker": "",
63
+ "priv_validator_laddr": "",
64
+ "proxy_app": "",
65
+ "pruning": "default",
66
+ "pruning-interval": "",
67
+ "pruning-keep-recent": "",
68
+ "trace": "",
69
+ "trace-store": "",
70
+ "transport": "",
71
+ "unsafe-skip-upgrades": "",
72
+ "with-tendermint": "",
73
+
74
+ "api.address": "",
75
+ "api.enable": "",
76
+ "api.enabled-unsafe-cors": "",
77
+ "api.max-open-connections": "",
78
+ "api.rpc-max-body-bytes": "",
79
+ "api.rpc-read-timeout": "",
80
+ "api.rpc-write-timeout": "",
81
+ "api.swagger": "",
82
+
83
+ "consensus.create_empty_blocks": "",
84
+ "consensus.create_empty_blocks_interval": "",
85
+ "consensus.double_sign_check_height": "",
86
+
87
+ "grpc-web.address": "",
88
+ "grpc-web.enable": "",
89
+ "grpc-web.enable-unsafe-cors": "",
90
+
91
+ "grpc.address": "",
92
+ "grpc.enable": "",
93
+ "grpc.max-recv-msg-size": "",
94
+ "grpc.max-send-msg-size": "",
95
+
96
+ "p2p.external-address": "",
97
+ "p2p.laddr": "",
98
+ "p2p.persistent_peers": "",
99
+ "p2p.pex": "",
100
+ "p2p.private_peer_ids": "",
101
+ "p2p.seed_mode": "",
102
+ "p2p.seeds": "",
103
+ "p2p.unconditional_peer_ids": "",
104
+ "p2p.upnp": "",
105
+
106
+ "rpc.grpc_laddr": "",
107
+ "rpc.laddr": "",
108
+ "rpc.pprof_laddr": "",
109
+ "rpc.unsafe": "",
110
+
111
+ "rosetta.address": "",
112
+ "rosetta.blockchain": "",
113
+ "rosetta.denom-to-suggest": "",
114
+ "rosetta.enable-fee-suggestion": "",
115
+ "rosetta.enable": "",
116
+ "rosetta.gas-to-suggest": "",
117
+ "rosetta.network": "",
118
+ "rosetta.offline": "",
119
+ "rosetta.retries": "",
120
+
121
+ "state-sync.snapshot-interval": "",
122
+ "state-sync.snapshot-keep-recent": "",
123
+
124
+ "store.streamers": "",
125
+
126
+ "streamers.file.fsync": "",
127
+ "streamers.file.keys": "",
128
+ "streamers.file.output-metadata": "",
129
+ "streamers.file.prefix": "",
130
+ "streamers.file.stop-node-on-error": "",
131
+ "streamers.file.write_dir": "",
132
+
133
+ "telemetry.enable-hostname-label": "",
134
+ "telemetry.enable-hostname": "",
135
+ "telemetry.enable-service-label": "",
136
+ "telemetry.enabled": "",
137
+ "telemetry.global-labels": "",
138
+ "telemetry.prometheus-retention-time": "",
139
+ "telemetry.service-name": "",
140
+ }
141
+ unknownFlagNames := []string{}
142
+ missingFlagNames := map[string]bool{}
143
+ for name := range expectedFlagNames {
144
+ missingFlagNames[name] = true
145
+ }
146
+ readFlag := func(name string) interface{} {
147
+ if defaultValue, found := expectedFlagNames[name]; found {
148
+ delete(missingFlagNames, name)
149
+ return defaultValue
150
+ }
151
+ unknownFlagNames = append(unknownFlagNames, name)
152
+ return nil
153
+ }
154
+
155
+ homeDir, err := os.MkdirTemp("", "cosmos-sdk-home")
156
+ if err != nil {
157
+ panic(err)
158
+ }
159
+ defer os.RemoveAll(homeDir)
160
+
161
+ // First get the command line flags that the base cosmos-sdk defines
162
+ dummyAppCreator := func(
163
+ logger log.Logger,
164
+ db dbm.DB,
165
+ traceStore io.Writer,
166
+ appOpts servertypes.AppOptions,
167
+ ) servertypes.Application {
168
+ return new(app.GaiaApp)
169
+ }
170
+ cmd := server.StartCmd(dummyAppCreator, homeDir)
171
+ flags := cmd.Flags()
172
+ flags.SortFlags = true
173
+ flags.VisitAll(func(flag *pflag.Flag) {
174
+ readFlag(flag.Name)
175
+ })
176
+
177
+ // Then get the options parsing the default config file.
178
+ serverCtx := server.NewDefaultContext()
179
+ // appTemplate, appConfig := initAppConfig()
180
+ appTemplate := serverconfig.DefaultConfigTemplate
181
+ appConfig := serverconfig.DefaultConfig()
182
+ configTemplate := template.Must(template.New("").Parse(appTemplate))
183
+ var buffer bytes.Buffer
184
+ if err := configTemplate.Execute(&buffer, appConfig); err != nil {
185
+ panic(err)
186
+ }
187
+ serverCtx.Viper.SetConfigType("toml")
188
+ if err := serverCtx.Viper.MergeConfig(&buffer); err != nil {
189
+ panic(err)
190
+ }
191
+ for _, configKey := range serverCtx.Viper.AllKeys() {
192
+ readFlag(configKey)
193
+ }
194
+
195
+ if len(unknownFlagNames) != 0 {
196
+ t.Error(
197
+ "unknown CLI flags in cosmos-sdk; incorporate as needed and update this test",
198
+ unknownFlagNames,
199
+ )
200
+ }
201
+ if len(missingFlagNames) != 0 {
202
+ missing := []string{}
203
+ for name := range missingFlagNames {
204
+ missing = append(missing, name)
205
+ }
206
+ t.Error(
207
+ "expected CLI flags missing from cosmos-sdk; remove from this test",
208
+ missing,
209
+ )
210
+ }
23
211
  }