Skip to content

Commit

Permalink
feat: Add consensus-independent vat snapshot retention configuration …
Browse files Browse the repository at this point in the history
…to AG_COSMOS_INIT

Fixes #9386
  • Loading branch information
gibson042 committed Sep 5, 2024
1 parent 640860b commit 631dab7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
40 changes: 38 additions & 2 deletions golang/cosmos/x/swingset/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ 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,
Expand Down Expand Up @@ -49,9 +57,16 @@ slogfile = "{{ .Swingset.SlogFile }}"
# be frequently paged out to remain under this limit.
max-vats-online = {{ .Swingset.MaxVatsOnline }}
# 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
# 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)
Expand All @@ -70,9 +85,18 @@ type SwingsetConfig struct {
// 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"`

// 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 ).
Expand All @@ -87,6 +111,7 @@ type SwingsetConfig struct {
var DefaultSwingsetConfig = SwingsetConfig{
SlogFile: "",
MaxVatsOnline: 50,
VatSnapshotRetention: "operational",
VatTranscriptRetention: "default",
}

Expand Down Expand Up @@ -114,7 +139,18 @@ func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetCo
}
ssConfig := &extendedConfig.Swingset

// Default/validate transcript retention.
if ssConfig.VatSnapshotRetention != "" {
// Validate vat snapshot retention.
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
Expand Down
15 changes: 9 additions & 6 deletions packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ const toNumber = specimen => {
* @typedef {object} CosmosSwingsetConfig
* @property {string} [slogfile]
* @property {number} [maxVatsOnline]
* @property {'debug' | 'operational'} [vatSnapshotRetention]
* @property {'archival' | 'operational'} [vatTranscriptRetention]
*/
const SwingsetConfigShape = M.splitRecord(
{},
{
slogfile: M.string(),
maxVatsOnline: M.number(),
vatSnapshotRetention: M.or('debug', 'operational'),
vatTranscriptRetention: M.or('archival', 'operational'),
},
M.any(),
Expand Down Expand Up @@ -307,10 +309,16 @@ export default async function main(progname, args, { env, homedir, agcc }) {
// here so 'sendToChainStorage' can close over the single mutable instance,
// when we updated the 'portNums.storage' value each time toSwingSet was called.
async function launchAndInitializeSwingSet(initAction) {
const { XSNAP_KEEP_SNAPSHOTS, NODE_HEAP_SNAPSHOTS = -1 } = env;

/** @type {CosmosSwingsetConfig} */
const swingsetConfig = harden(initAction.resolvedConfig || {});
validateSwingsetConfig(swingsetConfig);
const { slogfile, vatTranscriptRetention } = swingsetConfig;
const { slogfile, vatSnapshotRetention, vatTranscriptRetention } =
swingsetConfig;
const keepSnapshots =
vatSnapshotRetention === 'debug' ||
(!vatSnapshotRetention && ['1', 'true'].includes(XSNAP_KEEP_SNAPSHOTS));
const keepTranscripts = vatTranscriptRetention === 'archival';

// As a kludge, back-propagate selected configuration into environment variables.
Expand Down Expand Up @@ -451,7 +459,6 @@ export default async function main(progname, args, { env, homedir, agcc }) {
serviceName: TELEMETRY_SERVICE_NAME,
});

const { XSNAP_KEEP_SNAPSHOTS, NODE_HEAP_SNAPSHOTS = -1 } = env;
const slogSender = await makeSlogSender({
stateDir: stateDBDir,
env,
Expand All @@ -464,10 +471,6 @@ export default async function main(progname, args, { env, homedir, agcc }) {
trueValue: pathResolve(stateDBDir, 'store-trace.log'),
});

// TODO: Add to SwingsetConfig (#9386)
const keepSnapshots =
XSNAP_KEEP_SNAPSHOTS === '1' || XSNAP_KEEP_SNAPSHOTS === 'true';

const nodeHeapSnapshots = Number.parseInt(NODE_HEAP_SNAPSHOTS, 10);

let lastCommitTime = 0;
Expand Down

0 comments on commit 631dab7

Please sign in to comment.