diff --git a/golang/cosmos/x/swingset/config.go b/golang/cosmos/x/swingset/config.go index f3ab6bdc9cf..d96b53e2a13 100644 --- a/golang/cosmos/x/swingset/config.go +++ b/golang/cosmos/x/swingset/config.go @@ -31,6 +31,11 @@ const DefaultConfigTemplate = ` # If relative, it is interpreted against the application home directory # (e.g., ~/.agoric). 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 }} ` // SwingsetConfig defines configuration for the SwingSet VM. @@ -38,10 +43,14 @@ slogfile = "{{ .Swingset.SlogFile }}" type SwingsetConfig struct { // SlogFile is the absolute path at which a SwingSet log "slog" file should be written. 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"` } var DefaultSwingsetConfig = SwingsetConfig{ - SlogFile: "", + SlogFile: "", + MaxVatsOnline: 50, } func SwingsetConfigFromViper(resolvedConfig servertypes.AppOptions) (*SwingsetConfig, error) { diff --git a/packages/cosmic-swingset/src/chain-main.js b/packages/cosmic-swingset/src/chain-main.js index 31bbecd486c..95dd92f4e6f 100644 --- a/packages/cosmic-swingset/src/chain-main.js +++ b/packages/cosmic-swingset/src/chain-main.js @@ -64,6 +64,16 @@ const toNumber = specimen => { return number; }; +/** + * The swingset config object parsed and resolved by cosmos in + * `golang/cosmos/x/swingset/config.go`. The shape should be kept in sync + * with `SwingsetConfig` defined there. + * + * @typedef {object} CosmosSwingsetConfig + * @property {string} [slogfile] + * @property {number} [maxVatsOnline] + */ + /** * A boot message consists of cosmosInitAction fields that are subject to * consensus. See cosmosInitAction in {@link ../../../golang/cosmos/app/app.go}. @@ -90,6 +100,19 @@ const makeBootMsg = initAction => { }; }; +/** + * Extract local Swingset-specific configuration which is + * not part of the consensus. + * + * @param {CosmosSwingsetConfig} [resolvedConfig] + */ +const makeSwingsetConfig = resolvedConfig => { + const { maxVatsOnline } = resolvedConfig || {}; + return { + maxVatsOnline, + }; +}; + /** * @template {unknown} [T=unknown] * @param {(req: string) => string} call @@ -283,6 +306,8 @@ export default async function main(progname, args, { env, homedir, agcc }) { // eslint-disable-next-line dot-notation if (slogfile) env['SLOGFILE'] = slogfile; + const swingsetConfig = makeSwingsetConfig(initAction.resolvedConfig); + const sendToChainStorage = msg => chainSend(portNums.storage, msg); // this object is used to store the mailbox state. const fromBridgeMailbox = data => { @@ -515,6 +540,7 @@ export default async function main(progname, args, { env, homedir, agcc }) { swingStoreTraceFile, keepSnapshots, afterCommitCallback, + swingsetConfig, }); const { blockingSend, shutdown } = s; diff --git a/packages/cosmic-swingset/src/launch-chain.js b/packages/cosmic-swingset/src/launch-chain.js index 8a2f6112117..2fbcc151542 100644 --- a/packages/cosmic-swingset/src/launch-chain.js +++ b/packages/cosmic-swingset/src/launch-chain.js @@ -119,6 +119,7 @@ export async function buildSwingset( verbose, profileVats, debugVats, + warehousePolicy, }, ) { const debugPrefix = debugName === undefined ? '' : `${debugName}:`; @@ -226,6 +227,7 @@ export async function buildSwingset( verbose, profileVats, debugVats, + warehousePolicy, }, ); @@ -330,6 +332,7 @@ export async function launch({ swingStoreExportCallback, keepSnapshots, afterCommitCallback = async () => ({}), + swingsetConfig, }) { console.info('Launching SwingSet kernel'); @@ -394,6 +397,9 @@ export async function launch({ }); console.debug(`buildSwingset`); + const warehousePolicy = { + maxVatsOnline: swingsetConfig.maxVatsOnline, + }; const { coreProposals: bootstrapCoreProposals, controller, @@ -411,6 +417,7 @@ export async function launch({ debugName, slogCallbacks, slogSender, + warehousePolicy, }, );