From 950511ef1b9b7520bd3eaf8e97cbc315a945b836 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 28 Aug 2024 13:28:49 -0400 Subject: [PATCH 1/8] feat: Share cosmos-sdk runtime [viper] configuration with the cosmic-swingset VM Ref #9946 --- golang/cosmos/app/app.go | 4 ++++ packages/cosmic-swingset/src/chain-main.js | 1 + 2 files changed, 5 insertions(+) diff --git a/golang/cosmos/app/app.go b/golang/cosmos/app/app.go index 52eb932eaa0..def823d4cdc 100644 --- a/golang/cosmos/app/app.go +++ b/golang/cosmos/app/app.go @@ -361,6 +361,10 @@ func NewAgoricApp( tkeys: tkeys, memKeys: memKeys, } + // The VM is entitled to full awareness of runtime configuration. + if resolvedConfig, ok := appOpts.(*viper.Viper); ok { + app.resolvedConfig = resolvedConfig.AllSettings() + } app.ParamsKeeper = initParamsKeeper( appCodec, diff --git a/packages/cosmic-swingset/src/chain-main.js b/packages/cosmic-swingset/src/chain-main.js index 31bbecd486c..6f584fa6713 100644 --- a/packages/cosmic-swingset/src/chain-main.js +++ b/packages/cosmic-swingset/src/chain-main.js @@ -86,6 +86,7 @@ const makeBootMsg = initAction => { blockHeight, chainID, params, + resolvedConfig, supplyCoins, }; }; From 50b22be79a2fe62a20666c30d86cc5bb8c4f41b7 Mon Sep 17 00:00:00 2001 From: Siarhei Liakh Date: Wed, 28 Aug 2024 23:17:40 +0000 Subject: [PATCH 2/8] feat: Plumb maxVatsOnline from cosmos-sdk config to JS side of swingset Ref: #9574 --- packages/cosmic-swingset/src/chain-main.js | 18 ++++++++++++++++++ packages/cosmic-swingset/src/launch-chain.js | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/packages/cosmic-swingset/src/chain-main.js b/packages/cosmic-swingset/src/chain-main.js index 6f584fa6713..9f93631561e 100644 --- a/packages/cosmic-swingset/src/chain-main.js +++ b/packages/cosmic-swingset/src/chain-main.js @@ -91,6 +91,21 @@ const makeBootMsg = initAction => { }; }; +/** + * Extract local Swingset-specific configuration which is + * not part of the consensus. + * + * @param {any} initAction + */ +const makeSwingsetConfig = initAction => { + const { + maxVatsOnline = 50, + } = initAction; + return { + maxVatsOnline, + }; +}; + /** * @template {unknown} [T=unknown] * @param {(req: string) => string} call @@ -497,6 +512,8 @@ export default async function main(progname, args, { env, homedir, agcc }) { } }; + const swingsetConfig = makeSwingsetConfig(initAction); + const s = await launch({ actionQueueStorage, highPriorityQueueStorage, @@ -516,6 +533,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, }, ); From 59fdc6ff6fbe6f167467c15c153c71b82a54bcf4 Mon Sep 17 00:00:00 2001 From: Siarhei Liakh Date: Fri, 30 Aug 2024 15:32:07 +0000 Subject: [PATCH 3/8] fix(golang/cosmos): fix-up a rebase --- golang/cosmos/app/app.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/golang/cosmos/app/app.go b/golang/cosmos/app/app.go index def823d4cdc..52eb932eaa0 100644 --- a/golang/cosmos/app/app.go +++ b/golang/cosmos/app/app.go @@ -361,10 +361,6 @@ func NewAgoricApp( tkeys: tkeys, memKeys: memKeys, } - // The VM is entitled to full awareness of runtime configuration. - if resolvedConfig, ok := appOpts.(*viper.Viper); ok { - app.resolvedConfig = resolvedConfig.AllSettings() - } app.ParamsKeeper = initParamsKeeper( appCodec, From 45a759a71c8abc724618a12dfd8ae72552b9783e Mon Sep 17 00:00:00 2001 From: Siarhei Liakh Date: Fri, 30 Aug 2024 15:49:04 +0000 Subject: [PATCH 4/8] fix(cosmic-swingset): plumbing for maxVatsOnline --- golang/cosmos/x/swingset/config.go | 3 +++ packages/cosmic-swingset/src/chain-main.js | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/golang/cosmos/x/swingset/config.go b/golang/cosmos/x/swingset/config.go index f3ab6bdc9cf..fa66b26fe85 100644 --- a/golang/cosmos/x/swingset/config.go +++ b/golang/cosmos/x/swingset/config.go @@ -31,6 +31,9 @@ const DefaultConfigTemplate = ` # If relative, it is interpreted against the application home directory # (e.g., ~/.agoric). slogfile = "{{ .Swingset.SlogFile }}" + +# maxVatsOnline is the maximum number of vats that SwingSet kernel will bring online +maxVatsOnline = 50 ` // SwingsetConfig defines configuration for the SwingSet VM. diff --git a/packages/cosmic-swingset/src/chain-main.js b/packages/cosmic-swingset/src/chain-main.js index 9f93631561e..c8a2d0a3e3c 100644 --- a/packages/cosmic-swingset/src/chain-main.js +++ b/packages/cosmic-swingset/src/chain-main.js @@ -86,7 +86,6 @@ const makeBootMsg = initAction => { blockHeight, chainID, params, - resolvedConfig, supplyCoins, }; }; @@ -100,7 +99,7 @@ const makeBootMsg = initAction => { const makeSwingsetConfig = initAction => { const { maxVatsOnline = 50, - } = initAction; + } = initAction.resolvedConfig || {}; return { maxVatsOnline, }; From 887cdd29f140e788df9966838cfb5e27e2bb68be Mon Sep 17 00:00:00 2001 From: Siarhei Liakh Date: Fri, 30 Aug 2024 17:17:24 +0000 Subject: [PATCH 5/8] chore(cosmic-swingset): fix lint --- packages/cosmic-swingset/src/chain-main.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/cosmic-swingset/src/chain-main.js b/packages/cosmic-swingset/src/chain-main.js index c8a2d0a3e3c..235a860c8e9 100644 --- a/packages/cosmic-swingset/src/chain-main.js +++ b/packages/cosmic-swingset/src/chain-main.js @@ -97,9 +97,7 @@ const makeBootMsg = initAction => { * @param {any} initAction */ const makeSwingsetConfig = initAction => { - const { - maxVatsOnline = 50, - } = initAction.resolvedConfig || {}; + const { maxVatsOnline = 50 } = initAction.resolvedConfig || {}; return { maxVatsOnline, }; From 8c0c17752f7439db6f7aee9f88be1dedce2a1bf1 Mon Sep 17 00:00:00 2001 From: Siarhei Liakh Date: Fri, 30 Aug 2024 22:17:23 +0000 Subject: [PATCH 6/8] fix(cosmic-swingset): add missing bits for maxVatsOnline --- golang/cosmos/x/swingset/config.go | 8 ++++++-- packages/cosmic-swingset/src/chain-main.js | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/golang/cosmos/x/swingset/config.go b/golang/cosmos/x/swingset/config.go index fa66b26fe85..fe4d07bee86 100644 --- a/golang/cosmos/x/swingset/config.go +++ b/golang/cosmos/x/swingset/config.go @@ -33,7 +33,7 @@ const DefaultConfigTemplate = ` slogfile = "{{ .Swingset.SlogFile }}" # maxVatsOnline is the maximum number of vats that SwingSet kernel will bring online -maxVatsOnline = 50 +maxVatsOnline = {{ .Swingset.MaxVatsOnline }} ` // SwingsetConfig defines configuration for the SwingSet VM. @@ -41,10 +41,14 @@ maxVatsOnline = 50 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:"maxVatsOnline" 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 235a860c8e9..84d5b79dafa 100644 --- a/packages/cosmic-swingset/src/chain-main.js +++ b/packages/cosmic-swingset/src/chain-main.js @@ -94,10 +94,10 @@ const makeBootMsg = initAction => { * Extract local Swingset-specific configuration which is * not part of the consensus. * - * @param {any} initAction + * @param {any} resolvedConfig */ -const makeSwingsetConfig = initAction => { - const { maxVatsOnline = 50 } = initAction.resolvedConfig || {}; +const makeSwingsetConfig = resolvedConfig => { + const { maxVatsOnline } = resolvedConfig || {}; return { maxVatsOnline, }; @@ -296,6 +296,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 => { @@ -509,8 +511,6 @@ export default async function main(progname, args, { env, homedir, agcc }) { } }; - const swingsetConfig = makeSwingsetConfig(initAction); - const s = await launch({ actionQueueStorage, highPriorityQueueStorage, From c3921f04a6f3dd787d62e996e03ef00419da2a05 Mon Sep 17 00:00:00 2001 From: siarhei-agoric Date: Sat, 31 Aug 2024 08:56:39 -0400 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Mathieu Hofman <86499+mhofman@users.noreply.github.com> --- golang/cosmos/x/swingset/config.go | 8 +++++--- packages/cosmic-swingset/src/chain-main.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/golang/cosmos/x/swingset/config.go b/golang/cosmos/x/swingset/config.go index fe4d07bee86..d96b53e2a13 100644 --- a/golang/cosmos/x/swingset/config.go +++ b/golang/cosmos/x/swingset/config.go @@ -32,8 +32,10 @@ const DefaultConfigTemplate = ` # (e.g., ~/.agoric). slogfile = "{{ .Swingset.SlogFile }}" -# maxVatsOnline is the maximum number of vats that SwingSet kernel will bring online -maxVatsOnline = {{ .Swingset.MaxVatsOnline }} +# 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. @@ -43,7 +45,7 @@ type SwingsetConfig struct { 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:"maxVatsOnline" json:"maxVatsOnline,omitempty"` + MaxVatsOnline int `mapstructure:"max_vats_online" json:"maxVatsOnline,omitempty"` } var DefaultSwingsetConfig = SwingsetConfig{ diff --git a/packages/cosmic-swingset/src/chain-main.js b/packages/cosmic-swingset/src/chain-main.js index 84d5b79dafa..4ab89ebcbb0 100644 --- a/packages/cosmic-swingset/src/chain-main.js +++ b/packages/cosmic-swingset/src/chain-main.js @@ -94,7 +94,7 @@ const makeBootMsg = initAction => { * Extract local Swingset-specific configuration which is * not part of the consensus. * - * @param {any} resolvedConfig + * @param {CosmosSwingsetConfig} [resolvedConfig] */ const makeSwingsetConfig = resolvedConfig => { const { maxVatsOnline } = resolvedConfig || {}; From d3376fae4e80aec08f62cb0fa2bf26ea87d76cd7 Mon Sep 17 00:00:00 2001 From: Siarhei Liakh Date: Sat, 31 Aug 2024 13:06:57 +0000 Subject: [PATCH 8/8] fix(cosmic-swingset):@typedef CosmosSwingsetConfig --- packages/cosmic-swingset/src/chain-main.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/cosmic-swingset/src/chain-main.js b/packages/cosmic-swingset/src/chain-main.js index 4ab89ebcbb0..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}.