@agoric/cosmos 0.34.2-dev-fb3af6c.0 → 0.34.2-dev-d6f50e3.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/git-revision.txt CHANGED
@@ -1 +1 @@
1
- fb3af6c
1
+ d6f50e3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-fb3af6c.0+fb3af6c",
3
+ "version": "0.34.2-dev-d6f50e3.0+d6f50e3",
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": "fb3af6c419a81e243809ebee78c5de0763b19412"
42
+ "gitHead": "d6f50e32f6f19bb14cfe4530812609dff00d21b8"
43
43
  }
package/util/util.go CHANGED
@@ -4,6 +4,15 @@ import (
4
4
  "github.com/spf13/viper"
5
5
  )
6
6
 
7
+ func IndexOf[T comparable](a []T, x T) int {
8
+ for i, s := range a {
9
+ if s == x {
10
+ return i
11
+ }
12
+ }
13
+ return -1
14
+ }
15
+
7
16
  func NewFileOnlyViper(v1 *viper.Viper) (*viper.Viper, error) {
8
17
  v2 := viper.New()
9
18
  v2.SetConfigFile(v1.ConfigFileUsed())
@@ -7,6 +7,8 @@ import (
7
7
  "github.com/spf13/viper"
8
8
 
9
9
  "github.com/cosmos/cosmos-sdk/client/flags"
10
+ pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
11
+ serverconfig "github.com/cosmos/cosmos-sdk/server/config"
10
12
  servertypes "github.com/cosmos/cosmos-sdk/server/types"
11
13
 
12
14
  "github.com/Agoric/agoric-sdk/golang/cosmos/util"
@@ -15,8 +17,24 @@ import (
15
17
  const (
16
18
  ConfigPrefix = "swingset"
17
19
  FlagSlogfile = ConfigPrefix + ".slogfile"
20
+
21
+ SnapshotRetentionOptionDebug = "debug"
22
+ SnapshotRetentionOptionOperational = "operational"
23
+
24
+ TranscriptRetentionOptionArchival = "archival"
25
+ TranscriptRetentionOptionOperational = "operational"
18
26
  )
19
27
 
28
+ var snapshotRetentionValues []string = []string{
29
+ SnapshotRetentionOptionDebug,
30
+ SnapshotRetentionOptionOperational,
31
+ }
32
+
33
+ var transcriptRetentionValues []string = []string{
34
+ TranscriptRetentionOptionArchival,
35
+ TranscriptRetentionOptionOperational,
36
+ }
37
+
20
38
  // DefaultConfigTemplate defines a default TOML configuration section for the SwingSet VM.
21
39
  // Values are pulled from a "Swingset" property, in accord with CustomAppConfig from
22
40
  // ../../daemon/cmd/root.go.
@@ -27,30 +45,74 @@ const DefaultConfigTemplate = `
27
45
  ###############################################################################
28
46
 
29
47
  [swingset]
30
- # slogfile is the path at which a SwingSet log "slog" file should be written.
48
+ # The path at which a SwingSet log "slog" file should be written.
31
49
  # If relative, it is interpreted against the application home directory
32
50
  # (e.g., ~/.agoric).
51
+ # May be overridden by a SLOGFILE environment variable, which if relative is
52
+ # interpreted against the working directory.
33
53
  slogfile = "{{ .Swingset.SlogFile }}"
34
54
 
35
55
  # The maximum number of vats that the SwingSet kernel will bring online. A lower number
36
56
  # requires less memory but may have a negative performance impact if vats need to
37
57
  # be frequently paged out to remain under this limit.
38
- max_vats_online = {{ .Swingset.MaxVatsOnline }}
58
+ max-vats-online = {{ .Swingset.MaxVatsOnline }}
59
+
60
+ # Retention of vat snapshots, with values analogous to those of export
61
+ # 'artifactMode' (cf.
62
+ # https://github.com/Agoric/agoric-sdk/blob/master/packages/swing-store/docs/data-export.md#optional--historical-data ).
63
+ # * "debug": keep all snapshots
64
+ # * "operational": keep only the last snapshot
65
+ vat-snapshot-retention = "{{ .Swingset.VatSnapshotRetention }}"
66
+
67
+ # Retention of vat transcript spans, with values analogous to those of export
68
+ # 'artifactMode' (cf.
69
+ # https://github.com/Agoric/agoric-sdk/blob/master/packages/swing-store/docs/data-export.md#optional--historical-data ).
70
+ # * "archival": keep all transcript spans
71
+ # * "operational": keep only necessary transcript spans (i.e., since the
72
+ # last snapshot of their vat)
73
+ # * "default": determined by 'pruning' ("archival" if 'pruning' is "nothing",
74
+ # otherwise "operational")
75
+ vat-transcript-retention = "{{ .Swingset.VatTranscriptRetention }}"
39
76
  `
40
77
 
41
78
  // SwingsetConfig defines configuration for the SwingSet VM.
79
+ // "mapstructure" tag data is used to direct reads from app.toml;
80
+ // "json" tag data is used to populate init messages for the VM.
81
+ // This should be kept in sync with SwingsetConfigShape in
82
+ // ../../../../packages/cosmic-swingset/src/chain-main.js.
42
83
  // TODO: Consider extensions from docs/env.md.
43
84
  type SwingsetConfig struct {
44
- // SlogFile is the absolute path at which a SwingSet log "slog" file should be written.
85
+ // SlogFile is the path at which a SwingSet log "slog" file should be written.
86
+ // If relative, it is interpreted against the application home directory
45
87
  SlogFile string `mapstructure:"slogfile" json:"slogfile,omitempty"`
88
+
46
89
  // MaxVatsOnline is the maximum number of vats that the SwingSet kernel will have online
47
90
  // at any given time.
48
- MaxVatsOnline int `mapstructure:"max_vats_online" json:"maxVatsOnline,omitempty"`
91
+ MaxVatsOnline int `mapstructure:"max-vats-online" json:"maxVatsOnline,omitempty"`
92
+
93
+ // VatSnapshotRetention controls retention of vat snapshots,
94
+ // and has values analogous to those of export `artifactMode` (cf.
95
+ // ../../../../packages/swing-store/docs/data-export.md#optional--historical-data ).
96
+ // * "debug": keep all snapshots
97
+ // * "operational": keep only the last snapshot
98
+ VatSnapshotRetention string `mapstructure:"vat-snapshot-retention" json:"vatSnapshotRetention,omitempty"`
99
+
100
+ // VatTranscriptRetention controls retention of vat transcript spans,
101
+ // and has values analogous to those of export `artifactMode` (cf.
102
+ // ../../../../packages/swing-store/docs/data-export.md#optional--historical-data ).
103
+ // * "archival": keep all transcript spans
104
+ // * "operational": keep only necessary transcript spans (i.e., since the
105
+ // last snapshot of their vat)
106
+ // * "default": determined by `pruning` ("archival" if `pruning` is
107
+ // "nothing", otherwise "operational")
108
+ VatTranscriptRetention string `mapstructure:"vat-transcript-retention" json:"vatTranscriptRetention,omitempty"`
49
109
  }
50
110
 
51
111
  var DefaultSwingsetConfig = SwingsetConfig{
52
- SlogFile: "",
53
- MaxVatsOnline: 50,
112
+ SlogFile: "",
113
+ MaxVatsOnline: 50,
114
+ VatSnapshotRetention: "operational",
115
+ VatTranscriptRetention: "default",
54
116
  }
55
117
 
56
118
  func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetConfig, error) {
@@ -66,11 +128,44 @@ func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetCo
66
128
  return nil, nil
67
129
  }
68
130
  v.MustBindEnv(FlagSlogfile, "SLOGFILE")
69
- wrapper := struct{ Swingset SwingsetConfig }{}
70
- if err := v.Unmarshal(&wrapper); err != nil {
131
+ // See CustomAppConfig in ../../daemon/cmd/root.go.
132
+ type ExtendedConfig struct {
133
+ serverconfig.Config `mapstructure:",squash"`
134
+ Swingset SwingsetConfig `mapstructure:"swingset"`
135
+ }
136
+ extendedConfig := ExtendedConfig{}
137
+ if err := v.Unmarshal(&extendedConfig); err != nil {
138
+ return nil, err
139
+ }
140
+ ssConfig := &extendedConfig.Swingset
141
+
142
+ // Validate vat snapshot retention only if non-empty (because otherwise it
143
+ // it will be omitted, leaving the VM to apply its own defaults).
144
+ if ssConfig.VatSnapshotRetention != "" {
145
+ if util.IndexOf(snapshotRetentionValues, ssConfig.VatSnapshotRetention) == -1 {
146
+ err := fmt.Errorf(
147
+ "value for vat-snapshot-retention must be in %q",
148
+ snapshotRetentionValues,
149
+ )
150
+ return nil, err
151
+ }
152
+ }
153
+
154
+ // Default/validate vat transcript retention.
155
+ if ssConfig.VatTranscriptRetention == "" || ssConfig.VatTranscriptRetention == "default" {
156
+ if extendedConfig.Pruning == pruningtypes.PruningOptionNothing {
157
+ ssConfig.VatTranscriptRetention = TranscriptRetentionOptionArchival
158
+ } else {
159
+ ssConfig.VatTranscriptRetention = TranscriptRetentionOptionOperational
160
+ }
161
+ }
162
+ if util.IndexOf(transcriptRetentionValues, ssConfig.VatTranscriptRetention) == -1 {
163
+ err := fmt.Errorf(
164
+ "value for vat-transcript-retention must be in %q",
165
+ transcriptRetentionValues,
166
+ )
71
167
  return nil, err
72
168
  }
73
- config := &wrapper.Swingset
74
169
 
75
170
  // Interpret relative paths from config files against the application home
76
171
  // directory and from other sources (e.g. env vars) against the current
@@ -101,11 +196,11 @@ func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetCo
101
196
  return filepath.Abs(path)
102
197
  }
103
198
 
104
- resolvedSlogFile, err := resolvePath(config.SlogFile, FlagSlogfile)
199
+ resolvedSlogFile, err := resolvePath(ssConfig.SlogFile, FlagSlogfile)
105
200
  if err != nil {
106
201
  return nil, err
107
202
  }
108
- config.SlogFile = resolvedSlogFile
203
+ ssConfig.SlogFile = resolvedSlogFile
109
204
 
110
- return config, nil
205
+ return ssConfig, nil
111
206
  }