diff --git a/packages/boot/test/bootstrapTests/walletFactory.ts b/packages/boot/test/bootstrapTests/walletFactory.ts index 0b8fea676bc..ce964047233 100644 --- a/packages/boot/test/bootstrapTests/walletFactory.ts +++ b/packages/boot/test/bootstrapTests/walletFactory.ts @@ -9,9 +9,11 @@ import { makeWalletFactoryDriver } from '../../tools/drivers.js'; export const makeWalletFactoryContext = async ( t, configSpecifier = '@agoric/vm-config/decentral-main-vaults-config.json', + opts = {}, ) => { const swingsetTestKit = await makeSwingsetTestKit(t.log, undefined, { configSpecifier, + ...opts, }); const { runUtils, storage } = swingsetTestKit; diff --git a/packages/boot/tools/liquidation.ts b/packages/boot/tools/liquidation.ts index 1b91c228120..2422b8a00fd 100644 --- a/packages/boot/tools/liquidation.ts +++ b/packages/boot/tools/liquidation.ts @@ -9,6 +9,7 @@ import { } from '@agoric/vats/tools/board-utils.js'; import { Offers } from '@agoric/inter-protocol/src/clientSupport.js'; import type { ExecutionContext } from 'ava'; +import { insistManagerType, makePolicyProvider } from './supports.js'; import { type SwingsetTestKit, makeSwingsetTestKit } from './supports.js'; import { type GovernanceDriver, @@ -305,13 +306,28 @@ export const makeLiquidationTestKit = async ({ }; }; +// asserts x is type doesn't work when using arrow functions +// https://github.com/microsoft/TypeScript/issues/34523 +function assertManagerType(specimen: string): asserts specimen is ManagerType { + insistManagerType(specimen); +} + export const makeLiquidationTestContext = async ( t, io: { env?: Record } = {}, ) => { const { env = {} } = io; + const { + SLOGFILE: slogFile, + SWINGSET_WORKER_TYPE: defaultManagerType = 'local', + } = env; + assertManagerType(defaultManagerType); + const perfTool = + defaultManagerType === 'xsnap' ? makePolicyProvider() : undefined; const swingsetTestKit = await makeSwingsetTestKit(t.log, undefined, { - slogFile: env.SLOGFILE, + slogFile, + defaultManagerType, + perfTool, }); console.time('DefaultTestContext'); @@ -369,6 +385,7 @@ export const makeLiquidationTestContext = async ( refreshAgoricNamesRemotes, walletFactoryDriver, governanceDriver, + perfTool, }; }; diff --git a/packages/boot/tools/supports.ts b/packages/boot/tools/supports.ts index 7addf5619a5..7200c699f6d 100644 --- a/packages/boot/tools/supports.ts +++ b/packages/boot/tools/supports.ts @@ -32,6 +32,7 @@ import { Fail } from '@endo/errors'; import { makeRunUtils, type RunUtils, + type RunPolicyMaker, } from '@agoric/swingset-vat/tools/run-utils.js'; import { boardSlottingMarshaller, @@ -47,6 +48,11 @@ import type { BridgeHandler, IBCMethod } from '@agoric/vats'; import type { BootstrapRootObject } from '@agoric/vats/src/core/lib-boot.js'; import type { EProxy } from '@endo/eventual-send'; import type { FastUSDCCorePowers } from '@agoric/fast-usdc/src/fast-usdc.start.js'; +import { + defaultBeansPerVatCreation, + defaultBeansPerXsnapComputron, +} from '@agoric/cosmic-swingset/src/sim-params.js'; +import { computronCounter } from '@agoric/cosmic-swingset/src/computron-counter.js'; import { icaMocks, protoMsgMockMap, protoMsgMocks } from './ibc/mocks.js'; const trace = makeTracer('BSTSupport', false); @@ -77,6 +83,7 @@ type BootstrapEV = EProxy & { const makeBootstrapRunUtils = makeRunUtils as ( controller: SwingsetController, + perfTool?: RunPolicyMaker, ) => Omit & { EV: BootstrapEV }; const keysToObject = ( @@ -308,6 +315,7 @@ export const matchIter = (t: AvaT, iter, valueRef) => { * @param [options.profileVats] * @param [options.debugVats] * @param [options.defaultManagerType] + * @param [options.perfTool] */ export const makeSwingsetTestKit = async ( log: (..._: any[]) => void, @@ -321,6 +329,7 @@ export const makeSwingsetTestKit = async ( profileVats = [] as string[], debugVats = [] as string[], defaultManagerType = 'local' as ManagerType, + perfTool = undefined as RunPolicyMaker | undefined, } = {}, ) => { console.time('makeBaseSwingsetTestKit'); @@ -538,7 +547,7 @@ export const makeSwingsetTestKit = async ( console.timeLog('makeBaseSwingsetTestKit', 'buildSwingset'); - const runUtils = makeBootstrapRunUtils(controller); + const runUtils = makeBootstrapRunUtils(controller, perfTool); const buildProposal = makeProposalExtractor({ childProcess: childProcessAmbient, @@ -660,3 +669,45 @@ export const makeSwingsetTestKit = async ( }; }; export type SwingsetTestKit = Awaited>; + +export const makePolicyProvider = () => { + const c2b = defaultBeansPerXsnapComputron; + const mainParams = { + // see https://cosgov.org/agoric?msgType=parameterChangeProposal&network=main + blockComputeLimit: 65_000_000n * c2b, + vatCreation: defaultBeansPerVatCreation, + xsnapComputron: c2b, + }; + + /** @type {ReturnType | undefined} */ + let policy; + let counting = false; + + const meter = harden({ + provideRunPolicy: () => { + if (counting && !policy) { + policy = computronCounter(mainParams); + } + return policy; + }, + /** @param {boolean} x */ + usePolicy: x => { + counting = x; + if (!counting) { + policy = undefined; + } + }, + totalCount: () => (policy?.totalBeans() || 0n) / c2b, + resetPolicy: () => (policy = undefined), + }); + return meter; +}; + +/** + * + * @param {string} mt + * @returns {asserts mt is ManagerType} + */ +export function insistManagerType(mt) { + assert(['local', 'node-subprocess', 'xsnap', 'xs-worker'].includes(mt)); +}