-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cosmos-sdk vat snapshot/transcript retention configuration #10032
Changes from all commits
3cc8ce7
ea99c6d
3cf6b57
766c1bb
a5311b5
b01c033
8b3a6d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import ( | |
"github.com/spf13/viper" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types" | ||
serverconfig "github.com/cosmos/cosmos-sdk/server/config" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
|
||
"github.com/Agoric/agoric-sdk/golang/cosmos/util" | ||
|
@@ -15,8 +17,24 @@ import ( | |
const ( | ||
ConfigPrefix = "swingset" | ||
FlagSlogfile = ConfigPrefix + ".slogfile" | ||
|
||
SnapshotRetentionOptionDebug = "debug" | ||
SnapshotRetentionOptionOperational = "operational" | ||
|
||
TranscriptRetentionOptionArchival = "archival" | ||
TranscriptRetentionOptionOperational = "operational" | ||
) | ||
|
||
var snapshotRetentionValues []string = []string{ | ||
SnapshotRetentionOptionDebug, | ||
SnapshotRetentionOptionOperational, | ||
} | ||
|
||
var transcriptRetentionValues []string = []string{ | ||
TranscriptRetentionOptionArchival, | ||
TranscriptRetentionOptionOperational, | ||
} | ||
|
||
// DefaultConfigTemplate defines a default TOML configuration section for the SwingSet VM. | ||
// Values are pulled from a "Swingset" property, in accord with CustomAppConfig from | ||
// ../../daemon/cmd/root.go. | ||
|
@@ -27,30 +45,74 @@ const DefaultConfigTemplate = ` | |
############################################################################### | ||
|
||
[swingset] | ||
# slogfile is the path at which a SwingSet log "slog" file should be written. | ||
# The path at which a SwingSet log "slog" file should be written. | ||
# If relative, it is interpreted against the application home directory | ||
# (e.g., ~/.agoric). | ||
# May be overridden by a SLOGFILE environment variable, which if relative is | ||
# interpreted against the working directory. | ||
slogfile = "{{ .Swingset.SlogFile }}" | ||
|
||
# The maximum number of vats that the SwingSet kernel will bring online. A lower number | ||
# requires less memory but may have a negative performance impact if vats need to | ||
# be frequently paged out to remain under this limit. | ||
max_vats_online = {{ .Swingset.MaxVatsOnline }} | ||
max-vats-online = {{ .Swingset.MaxVatsOnline }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @siarhei-agoric @mhofman This aligns with existing cosmos-sdk conventions; cf. https://github.com/cosmos/cosmos-sdk/blob/68cb1635a0a0c7b3bd923ec9a51d0530e47d8040/server/config/config.toml.tpl There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh it's tendermint that uses underscore ! |
||
|
||
# Retention of vat snapshots, with values analogous to those of export | ||
# 'artifactMode' (cf. | ||
# https://github.com/Agoric/agoric-sdk/blob/master/packages/swing-store/docs/data-export.md#optional--historical-data ). | ||
# * "debug": keep all snapshots | ||
# * "operational": keep only the last snapshot | ||
vat-snapshot-retention = "{{ .Swingset.VatSnapshotRetention }}" | ||
|
||
# Retention of vat transcript spans, with values analogous to those of export | ||
# 'artifactMode' (cf. | ||
# https://github.com/Agoric/agoric-sdk/blob/master/packages/swing-store/docs/data-export.md#optional--historical-data ). | ||
# * "archival": keep all transcript spans | ||
# * "operational": keep only necessary transcript spans (i.e., since the | ||
# last snapshot of their vat) | ||
# * "default": determined by 'pruning' ("archival" if 'pruning' is "nothing", | ||
# otherwise "operational") | ||
vat-transcript-retention = "{{ .Swingset.VatTranscriptRetention }}" | ||
` | ||
|
||
// SwingsetConfig defines configuration for the SwingSet VM. | ||
// "mapstructure" tag data is used to direct reads from app.toml; | ||
// "json" tag data is used to populate init messages for the VM. | ||
// This should be kept in sync with SwingsetConfigShape in | ||
// ../../../../packages/cosmic-swingset/src/chain-main.js. | ||
// TODO: Consider extensions from docs/env.md. | ||
type SwingsetConfig struct { | ||
// SlogFile is the absolute path at which a SwingSet log "slog" file should be written. | ||
// SlogFile is the path at which a SwingSet log "slog" file should be written. | ||
// If relative, it is interpreted against the application home directory | ||
SlogFile string `mapstructure:"slogfile" json:"slogfile,omitempty"` | ||
|
||
// MaxVatsOnline is the maximum number of vats that the SwingSet kernel will have online | ||
// at any given time. | ||
MaxVatsOnline int `mapstructure:"max_vats_online" json:"maxVatsOnline,omitempty"` | ||
MaxVatsOnline int `mapstructure:"max-vats-online" json:"maxVatsOnline,omitempty"` | ||
|
||
// VatSnapshotRetention controls retention of vat snapshots, | ||
// and has values analogous to those of export `artifactMode` (cf. | ||
// ../../../../packages/swing-store/docs/data-export.md#optional--historical-data ). | ||
// * "debug": keep all snapshots | ||
// * "operational": keep only the last snapshot | ||
VatSnapshotRetention string `mapstructure:"vat-snapshot-retention" json:"vatSnapshotRetention,omitempty"` | ||
|
||
// VatTranscriptRetention controls retention of vat transcript spans, | ||
// and has values analogous to those of export `artifactMode` (cf. | ||
// ../../../../packages/swing-store/docs/data-export.md#optional--historical-data ). | ||
// * "archival": keep all transcript spans | ||
// * "operational": keep only necessary transcript spans (i.e., since the | ||
// last snapshot of their vat) | ||
// * "default": determined by `pruning` ("archival" if `pruning` is | ||
// "nothing", otherwise "operational") | ||
VatTranscriptRetention string `mapstructure:"vat-transcript-retention" json:"vatTranscriptRetention,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh, I'd rather not send an empty string only for this field if that ever comes up. If it truly were required, we'd enforce that on the JS side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how it could ever be empty given the resolution logic |
||
} | ||
|
||
var DefaultSwingsetConfig = SwingsetConfig{ | ||
SlogFile: "", | ||
MaxVatsOnline: 50, | ||
SlogFile: "", | ||
MaxVatsOnline: 50, | ||
VatSnapshotRetention: "operational", | ||
VatTranscriptRetention: "default", | ||
} | ||
|
||
func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetConfig, error) { | ||
|
@@ -66,11 +128,44 @@ func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetCo | |
return nil, nil | ||
} | ||
v.MustBindEnv(FlagSlogfile, "SLOGFILE") | ||
wrapper := struct{ Swingset SwingsetConfig }{} | ||
if err := v.Unmarshal(&wrapper); err != nil { | ||
// See CustomAppConfig in ../../daemon/cmd/root.go. | ||
type ExtendedConfig struct { | ||
serverconfig.Config `mapstructure:",squash"` | ||
Swingset SwingsetConfig `mapstructure:"swingset"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yikes I missed the missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think so. |
||
} | ||
extendedConfig := ExtendedConfig{} | ||
if err := v.Unmarshal(&extendedConfig); err != nil { | ||
return nil, err | ||
} | ||
ssConfig := &extendedConfig.Swingset | ||
|
||
// Validate vat snapshot retention only if non-empty (because otherwise it | ||
// it will be omitted, leaving the VM to apply its own defaults). | ||
if ssConfig.VatSnapshotRetention != "" { | ||
gibson042 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if util.IndexOf(snapshotRetentionValues, ssConfig.VatSnapshotRetention) == -1 { | ||
err := fmt.Errorf( | ||
"value for vat-snapshot-retention must be in %q", | ||
snapshotRetentionValues, | ||
) | ||
return nil, err | ||
} | ||
} | ||
|
||
// Default/validate vat transcript retention. | ||
if ssConfig.VatTranscriptRetention == "" || ssConfig.VatTranscriptRetention == "default" { | ||
if extendedConfig.Pruning == pruningtypes.PruningOptionNothing { | ||
ssConfig.VatTranscriptRetention = TranscriptRetentionOptionArchival | ||
} else { | ||
ssConfig.VatTranscriptRetention = TranscriptRetentionOptionOperational | ||
} | ||
} | ||
if util.IndexOf(transcriptRetentionValues, ssConfig.VatTranscriptRetention) == -1 { | ||
err := fmt.Errorf( | ||
"value for vat-transcript-retention must be in %q", | ||
transcriptRetentionValues, | ||
) | ||
return nil, err | ||
} | ||
config := &wrapper.Swingset | ||
|
||
// Interpret relative paths from config files against the application home | ||
// directory and from other sources (e.g. env vars) against the current | ||
|
@@ -101,11 +196,11 @@ func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetCo | |
return filepath.Abs(path) | ||
} | ||
|
||
resolvedSlogFile, err := resolvePath(config.SlogFile, FlagSlogfile) | ||
resolvedSlogFile, err := resolvePath(ssConfig.SlogFile, FlagSlogfile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
config.SlogFile = resolvedSlogFile | ||
ssConfig.SlogFile = resolvedSlogFile | ||
|
||
return config, nil | ||
return ssConfig, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overridden? I thought the config took precedence if present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, CLI option > environment variable > config file: https://github.com/spf13/viper?tab=readme-ov-file#why-viper