@agoric/cosmos 0.34.1 → 0.34.2-calypso-dev-84eb287.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
@@ -2,49 +2,50 @@ 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"
25
25
  vestingcli "github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli"
26
26
  banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
27
- "github.com/cosmos/cosmos-sdk/x/crisis"
28
27
  genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
29
28
  "github.com/spf13/cast"
30
29
  "github.com/spf13/cobra"
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(log.Logger)
43
+ var OnStartHook func(*vm.AgdServer, log.Logger, servertypes.AppOptions) error
44
+ var OnExportHook func(*vm.AgdServer, log.Logger, servertypes.AppOptions) error
44
45
 
45
46
  // NewRootCmd creates a new root command for simd. It is called once in the
46
47
  // main function.
47
- func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
48
+ func NewRootCmd(sender vm.Sender) (*cobra.Command, params.EncodingConfig) {
48
49
  encodingConfig := gaia.MakeEncodingConfig()
49
50
  initClientCtx := client.Context{}.
50
51
  WithCodec(encodingConfig.Marshaler).
@@ -58,7 +59,7 @@ func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
58
59
 
59
60
  rootCmd := &cobra.Command{
60
61
  Use: AppName,
61
- Short: "Stargate Agoric App",
62
+ Short: "Agoric Cosmos App",
62
63
  PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
63
64
  // set the default command outputs
64
65
  cmd.SetOut(cmd.OutOrStdout())
@@ -79,7 +80,8 @@ func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
79
80
  }
80
81
 
81
82
  customAppTemplate, customAppConfig := initAppConfig()
82
- return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig)
83
+ customTMConfig := initTendermintConfig()
84
+ return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig)
83
85
  },
84
86
  }
85
87
 
@@ -88,6 +90,12 @@ func NewRootCmd(sender Sender) (*cobra.Command, params.EncodingConfig) {
88
90
  return rootCmd, encodingConfig
89
91
  }
90
92
 
93
+ func initTendermintConfig() *tmcfg.Config {
94
+ cfg := tmcfg.DefaultConfig()
95
+ // customize config here
96
+ return cfg
97
+ }
98
+
91
99
  // initAppConfig helps to override default appConfig template and configs.
92
100
  // return "", nil if no custom configuration is required for the application.
93
101
  func initAppConfig() (string, interface{}) {
@@ -111,28 +119,51 @@ func initAppConfig() (string, interface{}) {
111
119
  return serverconfig.DefaultConfigTemplate, *srvCfg
112
120
  }
113
121
 
114
- func initRootCmd(sender Sender, rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
122
+ func initRootCmd(sender vm.Sender, rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
115
123
  cfg := sdk.GetConfig()
116
124
  cfg.Seal()
117
125
 
126
+ ac := appCreator{
127
+ encCfg: encodingConfig,
128
+ sender: sender,
129
+ agdServer: vm.NewAgdServer(),
130
+ }
131
+
118
132
  rootCmd.AddCommand(
119
133
  genutilcli.InitCmd(gaia.ModuleBasics, gaia.DefaultNodeHome),
120
134
  genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, gaia.DefaultNodeHome),
135
+ genutilcli.MigrateGenesisCmd(),
121
136
  genutilcli.GenTxCmd(gaia.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, gaia.DefaultNodeHome),
122
137
  genutilcli.ValidateGenesisCmd(gaia.ModuleBasics),
123
- AddGenesisAccountCmd(gaia.DefaultNodeHome),
138
+ AddGenesisAccountCmd(encodingConfig.Marshaler, gaia.DefaultNodeHome),
124
139
  tmcli.NewCompletionCmd(rootCmd, true),
125
140
  testnetCmd(gaia.ModuleBasics, banktypes.GenesisBalancesIterator{}),
126
141
  debug.Cmd(),
127
142
  config.Cmd(),
143
+ pruning.Cmd(ac.newSnapshotsApp, gaia.DefaultNodeHome),
144
+ snapshot.Cmd(ac.newSnapshotsApp),
128
145
  )
129
146
 
130
- ac := appCreator{
131
- encCfg: encodingConfig,
132
- sender: sender,
133
- }
134
147
  server.AddCommands(rootCmd, gaia.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags)
135
148
 
149
+ for _, command := range rootCmd.Commands() {
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
+ }
164
+ }
165
+ }
166
+
136
167
  // add keybase, auxiliary RPC, query, and tx child commands
137
168
  rootCmd.AddCommand(
138
169
  rpc.StatusCommand(),
@@ -144,8 +175,30 @@ func initRootCmd(sender Sender, rootCmd *cobra.Command, encodingConfig params.En
144
175
  rootCmd.AddCommand(server.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))
145
176
  }
146
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
+
147
200
  func addModuleInitFlags(startCmd *cobra.Command) {
148
- crisis.AddModuleInitFlags(startCmd)
201
+ addAgoricVMFlags(startCmd)
149
202
  }
150
203
 
151
204
  func queryCommand() *cobra.Command {
@@ -191,6 +244,7 @@ func txCommand() *cobra.Command {
191
244
  authcmd.GetBroadcastCommand(),
192
245
  authcmd.GetEncodeCommand(),
193
246
  authcmd.GetDecodeCommand(),
247
+ authcmd.GetAuxToFeeCommand(),
194
248
  flags.LineBreak,
195
249
  vestingcli.GetTxCmd(),
196
250
  )
@@ -202,8 +256,9 @@ func txCommand() *cobra.Command {
202
256
  }
203
257
 
204
258
  type appCreator struct {
205
- encCfg params.EncodingConfig
206
- sender Sender
259
+ encCfg params.EncodingConfig
260
+ sender vm.Sender
261
+ agdServer *vm.AgdServer
207
262
  }
208
263
 
209
264
  func (ac appCreator) newApp(
@@ -213,56 +268,136 @@ func (ac appCreator) newApp(
213
268
  appOpts servertypes.AppOptions,
214
269
  ) servertypes.Application {
215
270
  if OnStartHook != nil {
216
- OnStartHook(logger)
271
+ if err := OnStartHook(ac.agdServer, logger, appOpts); err != nil {
272
+ panic(err)
273
+ }
217
274
  }
218
275
 
219
- var cache sdk.MultiStorePersistentCache
220
-
221
- if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
222
- cache = store.NewCommitKVStoreCacheManager()
223
- }
276
+ baseappOptions := server.DefaultBaseappOptions(appOpts)
224
277
 
225
278
  skipUpgradeHeights := make(map[int64]bool)
226
279
  for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
227
280
  skipUpgradeHeights[int64(h)] = true
228
281
  }
229
282
 
230
- pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts)
231
- if err != nil {
232
- panic(err)
233
- }
283
+ homePath := cast.ToString(appOpts.Get(flags.FlagHome))
234
284
 
235
- snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
236
- snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
237
- if err != nil {
238
- panic(err)
239
- }
240
- snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
241
- if err != nil {
242
- panic(err)
285
+ // Set a default value for FlagSwingStoreExportDir based on the homePath
286
+ // in case we need to InitGenesis with swing-store data
287
+ viper, ok := appOpts.(*viper.Viper)
288
+ if ok && cast.ToString(appOpts.Get(gaia.FlagSwingStoreExportDir)) == "" {
289
+ viper.Set(gaia.FlagSwingStoreExportDir, filepath.Join(homePath, "config", ExportedSwingStoreDirectoryName))
243
290
  }
244
291
 
245
292
  return gaia.NewAgoricApp(
246
- ac.sender,
293
+ ac.sender, ac.agdServer,
247
294
  logger, db, traceStore, true, skipUpgradeHeights,
248
- cast.ToString(appOpts.Get(flags.FlagHome)),
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
+ }
313
+ }
314
+
315
+ baseappOptions := server.DefaultBaseappOptions(appOpts)
316
+
317
+ homePath := cast.ToString(appOpts.Get(flags.FlagHome))
318
+
319
+ return gaia.NewAgoricApp(
320
+ ac.sender, ac.agdServer,
321
+ logger, db, traceStore, true, map[int64]bool{},
322
+ homePath,
249
323
  cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
250
324
  ac.encCfg,
251
325
  appOpts,
252
- baseapp.SetPruning(pruningOpts),
253
- baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
254
- baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
255
- baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))),
256
- baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))),
257
- baseapp.SetInterBlockCache(cache),
258
- baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
259
- baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
260
- baseapp.SetSnapshotStore(snapshotStore),
261
- baseapp.SetSnapshotInterval(cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval))),
262
- baseapp.SetSnapshotKeepRecent(cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent))),
326
+ baseappOptions...,
263
327
  )
264
328
  }
265
329
 
330
+ const (
331
+ // FlagExportDir is the command-line flag for the "export" command specifying
332
+ // where the output of the export should be placed. It contains both the
333
+ // items names below: the genesis file, and a directory containing the
334
+ // exported swing-store artifacts
335
+ FlagExportDir = "export-dir"
336
+ // ExportedGenesisFileName is the file name used to save the genesis in the export-dir
337
+ ExportedGenesisFileName = "genesis.json"
338
+ // ExportedSwingStoreDirectoryName is the directory name used to save the swing-store
339
+ // export (artifacts only) in the export-dir
340
+ ExportedSwingStoreDirectoryName = "swing-store"
341
+ )
342
+
343
+ // extendCosmosExportCommand monkey-patches the "export" command added by
344
+ // cosmos-sdk to add a required "export-dir" command-line flag, and create the
345
+ // genesis export in the specified directory if the VM is running.
346
+ func extendCosmosExportCommand(cmd *cobra.Command) {
347
+ cmd.Flags().String(FlagExportDir, "", "The directory where to create the genesis export")
348
+ err := cmd.MarkFlagRequired(FlagExportDir)
349
+ if err != nil {
350
+ panic(err)
351
+ }
352
+
353
+ originalRunE := cmd.RunE
354
+
355
+ extendedRunE := func(cmd *cobra.Command, args []string) error {
356
+ serverCtx := server.GetServerContextFromCmd(cmd)
357
+
358
+ exportDir, _ := cmd.Flags().GetString(FlagExportDir)
359
+ err := os.MkdirAll(exportDir, os.ModePerm)
360
+ if err != nil {
361
+ return err
362
+ }
363
+
364
+ genesisPath := filepath.Join(exportDir, ExportedGenesisFileName)
365
+ swingStoreExportPath := filepath.Join(exportDir, ExportedSwingStoreDirectoryName)
366
+
367
+ err = os.MkdirAll(swingStoreExportPath, os.ModePerm)
368
+ if err != nil {
369
+ return err
370
+ }
371
+ // We unconditionally set FlagSwingStoreExportDir as for export, it makes
372
+ // little sense for users to control this location separately, and we don't
373
+ // want to override any swing-store artifacts that may be associated to the
374
+ // current genesis.
375
+ serverCtx.Viper.Set(gaia.FlagSwingStoreExportDir, swingStoreExportPath)
376
+
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)
390
+ }
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.
395
+ return originalRunE(cmd, args)
396
+ }
397
+
398
+ cmd.RunE = extendedRunE
399
+ }
400
+
266
401
  func (ac appCreator) appExport(
267
402
  logger log.Logger,
268
403
  db dbm.DB,
@@ -272,6 +407,11 @@ func (ac appCreator) appExport(
272
407
  jailAllowedAddrs []string,
273
408
  appOpts servertypes.AppOptions,
274
409
  ) (servertypes.ExportedApp, error) {
410
+ if OnExportHook != nil {
411
+ if err := OnExportHook(ac.agdServer, logger, appOpts); err != nil {
412
+ return servertypes.ExportedApp{}, err
413
+ }
414
+ }
275
415
 
276
416
  homePath, ok := appOpts.Get(flags.FlagHome).(string)
277
417
  if !ok || homePath == "" {
@@ -284,7 +424,7 @@ func (ac appCreator) appExport(
284
424
  }
285
425
 
286
426
  gaiaApp := gaia.NewAgoricApp(
287
- ac.sender,
427
+ ac.sender, ac.agdServer,
288
428
  logger,
289
429
  db,
290
430
  traceStore,
@@ -304,3 +444,64 @@ func (ac appCreator) appExport(
304
444
 
305
445
  return gaiaApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
306
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
  }