@agoric/cosmos 0.34.2-dev-ef9ed26.0 → 0.34.2-dev-a7d06d8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/app.go CHANGED
@@ -214,6 +214,7 @@ var (
214
214
  // capabilities aren't needed for testing.
215
215
  type GaiaApp struct { // nolint: golint
216
216
  *baseapp.BaseApp
217
+ resolvedConfig servertypes.AppOptions
217
218
  legacyAmino *codec.LegacyAmino
218
219
  appCodec codec.Codec
219
220
  interfaceRegistry types.InterfaceRegistry
@@ -314,9 +315,18 @@ func NewGaiaApp(
314
315
  }
315
316
 
316
317
  func NewAgoricApp(
317
- sendToController vm.Sender, agdServer *vm.AgdServer,
318
- logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
319
- homePath string, invCheckPeriod uint, encodingConfig gaiaappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
318
+ sendToController vm.Sender,
319
+ agdServer *vm.AgdServer,
320
+ logger log.Logger,
321
+ db dbm.DB,
322
+ traceStore io.Writer,
323
+ loadLatest bool,
324
+ skipUpgradeHeights map[int64]bool,
325
+ homePath string,
326
+ invCheckPeriod uint,
327
+ encodingConfig gaiaappparams.EncodingConfig,
328
+ appOpts servertypes.AppOptions,
329
+ baseAppOptions ...func(*baseapp.BaseApp),
320
330
  ) *GaiaApp {
321
331
  appCodec := encodingConfig.Marshaler
322
332
  legacyAmino := encodingConfig.Amino
@@ -342,6 +352,7 @@ func NewAgoricApp(
342
352
  app := &GaiaApp{
343
353
  BaseApp: bApp,
344
354
  AgdServer: agdServer,
355
+ resolvedConfig: appOpts,
345
356
  legacyAmino: legacyAmino,
346
357
  appCodec: appCodec,
347
358
  interfaceRegistry: interfaceRegistry,
@@ -927,11 +938,12 @@ type upgradeDetails struct {
927
938
 
928
939
  type cosmosInitAction struct {
929
940
  vm.ActionHeader `actionType:"AG_COSMOS_INIT"`
930
- ChainID string `json:"chainID"`
931
- IsBootstrap bool `json:"isBootstrap"`
932
- UpgradeDetails *upgradeDetails `json:"upgradeDetails,omitempty"`
933
- Params swingset.Params `json:"params"`
934
- SupplyCoins sdk.Coins `json:"supplyCoins"`
941
+ ChainID string `json:"chainID"`
942
+ IsBootstrap bool `json:"isBootstrap"`
943
+ Params swingset.Params `json:"params"`
944
+ ResolvedConfig *swingset.SwingsetConfig `json:"resolvedConfig"`
945
+ SupplyCoins sdk.Coins `json:"supplyCoins"`
946
+ UpgradeDetails *upgradeDetails `json:"upgradeDetails,omitempty"`
935
947
  // CAVEAT: Every property ending in "Port" is saved in chain-main.js/portNums
936
948
  // with a key consisting of this name with the "Port" stripped.
937
949
  StoragePort int `json:"storagePort"`
@@ -963,10 +975,15 @@ func (app *GaiaApp) initController(ctx sdk.Context, bootstrap bool) {
963
975
  app.controllerInited = true
964
976
 
965
977
  // Begin initializing the controller here.
978
+ swingsetConfig, err := swingset.SwingsetConfigFromViper(app.resolvedConfig)
979
+ if err != nil {
980
+ panic(err)
981
+ }
966
982
  action := &cosmosInitAction{
967
983
  ChainID: ctx.ChainID(),
968
984
  IsBootstrap: bootstrap,
969
985
  Params: app.SwingSetKeeper.GetParams(ctx),
986
+ ResolvedConfig: swingsetConfig,
970
987
  SupplyCoins: sdk.NewCoins(app.BankKeeper.GetSupply(ctx, "uist")),
971
988
  UpgradeDetails: app.upgradeDetails,
972
989
  // See CAVEAT in cosmosInitAction.
@@ -6,6 +6,7 @@ import (
6
6
  "io"
7
7
  "os"
8
8
  "path/filepath"
9
+ "strings"
9
10
 
10
11
  serverconfig "github.com/cosmos/cosmos-sdk/server/config"
11
12
 
@@ -36,6 +37,7 @@ import (
36
37
  gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
37
38
  "github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
38
39
  "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
40
+ swingset "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset"
39
41
  swingsetkeeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
40
42
  )
41
43
 
@@ -43,6 +45,31 @@ var AppName = "agd"
43
45
  var OnStartHook func(*vm.AgdServer, log.Logger, servertypes.AppOptions) error
44
46
  var OnExportHook func(*vm.AgdServer, log.Logger, servertypes.AppOptions) error
45
47
 
48
+ // CustomAppConfig extends the base config struct.
49
+ type CustomAppConfig struct {
50
+ serverconfig.Config `mapstructure:",squash"`
51
+ // Swingset must be named as expected by swingset.DefaultConfigTemplate
52
+ // and must use a mapstructure key matching swingset.ConfigPrefix.
53
+ Swingset swingset.SwingsetConfig `mapstructure:"swingset"`
54
+ }
55
+
56
+ type cobraRunE func(cmd *cobra.Command, args []string) error
57
+
58
+ func appendToPreRunE(cmd *cobra.Command, fn cobraRunE) {
59
+ preRunE := cmd.PreRunE
60
+ if preRunE == nil {
61
+ cmd.PreRunE = fn
62
+ return
63
+ }
64
+ composite := func(cmd *cobra.Command, args []string) error {
65
+ if err := preRunE(cmd, args); err != nil {
66
+ return err
67
+ }
68
+ return fn(cmd, args)
69
+ }
70
+ cmd.PreRunE = composite
71
+ }
72
+
46
73
  // NewRootCmd creates a new root command for simd. It is called once in the
47
74
  // main function.
48
75
  func NewRootCmd(sender vm.Sender) (*cobra.Command, params.EncodingConfig) {
@@ -99,24 +126,25 @@ func initTendermintConfig() *tmcfg.Config {
99
126
  // initAppConfig helps to override default appConfig template and configs.
100
127
  // return "", nil if no custom configuration is required for the application.
101
128
  func initAppConfig() (string, interface{}) {
102
- // Allow us to overwrite the SDK's default server config.
103
129
  srvCfg := serverconfig.DefaultConfig()
104
- // The SDK's default minimum gas price is set to "" (empty value) inside
105
- // app.toml. If left empty by validators, the node will halt on startup.
106
- // However, the chain developer can set a default app.toml value for their
107
- // validators here.
108
- //
109
- // In summary:
110
- // - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their
111
- // own app.toml config,
112
- // - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their
113
- // own app.toml to override, or use this default value.
114
- //
115
- // FIXME: We may want to have Agoric set a min gas price in uist.
116
- // For now, we set it to zero so that validators don't have to worry about it.
130
+
131
+ // FIXME: We may want a non-zero min gas price.
132
+ // For now, we set it to zero to reduce friction (the default "" fails
133
+ // startup, forcing each validator to set their own value).
117
134
  srvCfg.MinGasPrices = "0uist"
118
135
 
119
- return serverconfig.DefaultConfigTemplate, *srvCfg
136
+ customAppConfig := CustomAppConfig{
137
+ Config: *srvCfg,
138
+ Swingset: swingset.DefaultSwingsetConfig,
139
+ }
140
+
141
+ // Config TOML.
142
+ customAppTemplate := strings.Join([]string{
143
+ serverconfig.DefaultConfigTemplate,
144
+ swingset.DefaultConfigTemplate,
145
+ }, "")
146
+
147
+ return customAppTemplate, customAppConfig
120
148
  }
121
149
 
122
150
  func initRootCmd(sender vm.Sender, rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
@@ -144,10 +172,27 @@ func initRootCmd(sender vm.Sender, rootCmd *cobra.Command, encodingConfig params
144
172
  snapshot.Cmd(ac.newSnapshotsApp),
145
173
  )
146
174
 
147
- server.AddCommands(rootCmd, gaia.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags)
175
+ server.AddCommands(rootCmd, gaia.DefaultNodeHome, ac.newApp, ac.appExport, addStartFlags)
148
176
 
149
177
  for _, command := range rootCmd.Commands() {
150
178
  switch command.Name() {
179
+ case "start":
180
+ var preRunE cobraRunE = func(cmd *cobra.Command, _ []string) error {
181
+ // Consume and validate config.
182
+ viper := server.GetServerContextFromCmd(cmd).Viper
183
+ baseConfig, err := serverconfig.GetConfig(viper)
184
+ if err != nil {
185
+ return err
186
+ }
187
+ if err = baseConfig.ValidateBasic(); err != nil {
188
+ return err
189
+ }
190
+ if _, err = swingset.SwingsetConfigFromViper(viper); err != nil {
191
+ return err
192
+ }
193
+ return nil
194
+ }
195
+ appendToPreRunE(command, preRunE)
151
196
  case "export":
152
197
  addAgoricVMFlags(command)
153
198
  extendCosmosExportCommand(command)
@@ -197,7 +242,7 @@ func addAgoricVMFlags(cmd *cobra.Command) {
197
242
  )
198
243
  }
199
244
 
200
- func addModuleInitFlags(startCmd *cobra.Command) {
245
+ func addStartFlags(startCmd *cobra.Command) {
201
246
  addAgoricVMFlags(startCmd)
202
247
  }
203
248
 
@@ -282,11 +327,12 @@ func (ac appCreator) newApp(
282
327
 
283
328
  homePath := cast.ToString(appOpts.Get(flags.FlagHome))
284
329
 
285
- // Set a default value for FlagSwingStoreExportDir based on the homePath
330
+ // Set a default value for FlagSwingStoreExportDir based on homePath
286
331
  // in case we need to InitGenesis with swing-store data
287
332
  viper, ok := appOpts.(*viper.Viper)
288
- if ok && cast.ToString(appOpts.Get(gaia.FlagSwingStoreExportDir)) == "" {
289
- viper.Set(gaia.FlagSwingStoreExportDir, filepath.Join(homePath, "config", ExportedSwingStoreDirectoryName))
333
+ if ok && viper.GetString(gaia.FlagSwingStoreExportDir) == "" {
334
+ exportDir := filepath.Join(homePath, "config", ExportedSwingStoreDirectoryName)
335
+ viper.Set(gaia.FlagSwingStoreExportDir, exportDir)
290
336
  }
291
337
 
292
338
  return gaia.NewAgoricApp(
package/git-revision.txt CHANGED
@@ -1 +1 @@
1
- ef9ed26
1
+ a7d06d8
package/go.mod CHANGED
@@ -17,6 +17,7 @@ require (
17
17
  github.com/rakyll/statik v0.1.7
18
18
  github.com/spf13/cast v1.5.0
19
19
  github.com/spf13/cobra v1.7.0
20
+ github.com/spf13/pflag v1.0.5
20
21
  github.com/spf13/viper v1.14.0
21
22
  github.com/stretchr/testify v1.8.4
22
23
  github.com/tendermint/tendermint v0.34.29
@@ -133,7 +134,6 @@ require (
133
134
  github.com/sasha-s/go-deadlock v0.3.1 // indirect
134
135
  github.com/spf13/afero v1.9.2 // indirect
135
136
  github.com/spf13/jwalterweatherman v1.1.0 // indirect
136
- github.com/spf13/pflag v1.0.5 // indirect
137
137
  github.com/subosito/gotenv v1.4.1 // indirect
138
138
  github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
139
139
  github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-ef9ed26.0+ef9ed26",
3
+ "version": "0.34.2-dev-a7d06d8.0+a7d06d8",
4
4
  "description": "Connect JS to the Cosmos blockchain SDK",
5
5
  "parsers": {
6
6
  "js": "mjs"
@@ -39,5 +39,5 @@
39
39
  "typeCoverage": {
40
40
  "atLeast": 0
41
41
  },
42
- "gitHead": "ef9ed2694e965f093b0d72affdb45fb1a322adec"
42
+ "gitHead": "a7d06d8884c22e8190916d0bb1454bf9f5e92b57"
43
43
  }
package/util/util.go ADDED
@@ -0,0 +1,12 @@
1
+ package util
2
+
3
+ import (
4
+ "github.com/spf13/viper"
5
+ )
6
+
7
+ func NewFileOnlyViper(v1 *viper.Viper) (*viper.Viper, error) {
8
+ v2 := viper.New()
9
+ v2.SetConfigFile(v1.ConfigFileUsed())
10
+ err := v2.ReadInConfig()
11
+ return v2, err
12
+ }
@@ -0,0 +1,102 @@
1
+ package swingset
2
+
3
+ import (
4
+ "fmt"
5
+ "path/filepath"
6
+
7
+ "github.com/spf13/viper"
8
+
9
+ "github.com/cosmos/cosmos-sdk/client/flags"
10
+ servertypes "github.com/cosmos/cosmos-sdk/server/types"
11
+
12
+ "github.com/Agoric/agoric-sdk/golang/cosmos/util"
13
+ )
14
+
15
+ const (
16
+ ConfigPrefix = "swingset"
17
+ FlagSlogfile = ConfigPrefix + ".slogfile"
18
+ )
19
+
20
+ // DefaultConfigTemplate defines a default TOML configuration section for the SwingSet VM.
21
+ // Values are pulled from a "Swingset" property, in accord with CustomAppConfig from
22
+ // ../../daemon/cmd/root.go.
23
+ // See https://github.com/cosmos/cosmos-sdk/issues/20097 for auto-synchronization ideas.
24
+ const DefaultConfigTemplate = `
25
+ ###############################################################################
26
+ ### SwingSet Configuration ###
27
+ ###############################################################################
28
+
29
+ [swingset]
30
+ # slogfile is the path at which a SwingSet log "slog" file should be written.
31
+ # If relative, it is interpreted against the application home directory
32
+ # (e.g., ~/.agoric).
33
+ slogfile = "{{ .Swingset.SlogFile }}"
34
+ `
35
+
36
+ // SwingsetConfig defines configuration for the SwingSet VM.
37
+ // TODO: Consider extensions from docs/env.md.
38
+ type SwingsetConfig struct {
39
+ // SlogFile is the absolute path at which a SwingSet log "slog" file should be written.
40
+ SlogFile string `mapstructure:"slogfile" json:"slogfile,omitempty"`
41
+ }
42
+
43
+ var DefaultSwingsetConfig = SwingsetConfig{
44
+ SlogFile: "",
45
+ }
46
+
47
+ func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetConfig, error) {
48
+ v, ok := resolvedConfig.(*viper.Viper)
49
+ if !ok {
50
+ // Tolerate an apparently empty configuration such as
51
+ // cosmos/cosmos-sdk/simapp EmptyAppOptions, but otherwise require viper.
52
+ if resolvedConfig.Get(flags.FlagHome) != nil {
53
+ return nil, fmt.Errorf("expected an instance of viper!")
54
+ }
55
+ }
56
+ if v == nil {
57
+ return nil, nil
58
+ }
59
+ v.MustBindEnv(FlagSlogfile, "SLOGFILE")
60
+ wrapper := struct{ Swingset SwingsetConfig }{}
61
+ if err := v.Unmarshal(&wrapper); err != nil {
62
+ return nil, err
63
+ }
64
+ config := &wrapper.Swingset
65
+
66
+ // Interpret relative paths from config files against the application home
67
+ // directory and from other sources (e.g. env vars) against the current
68
+ // working directory.
69
+ var fileOnlyViper *viper.Viper
70
+ resolvePath := func(path, configKey string) (string, error) {
71
+ if path == "" || filepath.IsAbs(path) {
72
+ return path, nil
73
+ }
74
+ if v.InConfig(configKey) {
75
+ if fileOnlyViper == nil {
76
+ var err error
77
+ fileOnlyViper, err = util.NewFileOnlyViper(v)
78
+ if err != nil {
79
+ return "", err
80
+ }
81
+ }
82
+ pathFromFile := fileOnlyViper.GetString(configKey)
83
+ if path == pathFromFile {
84
+ homePath := viper.GetString(flags.FlagHome)
85
+ if homePath == "" {
86
+ return "", fmt.Errorf("cannot resolve path against empty application home")
87
+ }
88
+ absHomePath, err := filepath.Abs(homePath)
89
+ return filepath.Join(absHomePath, path), err
90
+ }
91
+ }
92
+ return filepath.Abs(path)
93
+ }
94
+
95
+ resolvedSlogFile, err := resolvePath(config.SlogFile, FlagSlogfile)
96
+ if err != nil {
97
+ return nil, err
98
+ }
99
+ config.SlogFile = resolvedSlogFile
100
+
101
+ return config, nil
102
+ }