diff --git a/packages/SwingSet/tools/run-utils.js b/packages/SwingSet/tools/run-utils.js index d2676f1055b..bdb1a435390 100644 --- a/packages/SwingSet/tools/run-utils.js +++ b/packages/SwingSet/tools/run-utils.js @@ -7,13 +7,13 @@ import { makeQueue } from '@endo/stream'; * @import { RunPolicy } from '../src/types-external.js' */ -/** @typedef {{ provideRunPolicy: () => RunPolicy | undefined }} RunPolicyMaker */ +/** @typedef {{ provideRunPolicy: () => RunPolicy | undefined }} RunHarness */ /** * @param {import('../src/controller/controller.js').SwingsetController} controller - * @param {RunPolicyMaker} [perfTool] + * @param {RunHarness} [harness] */ -export const makeRunUtils = (controller, perfTool) => { +export const makeRunUtils = (controller, harness) => { const mutex = makeQueue(); const logRunFailure = reason => console.log('controller.run() failure', reason); @@ -31,7 +31,7 @@ export const makeRunUtils = (controller, perfTool) => { const queueAndRun = async (deliveryThunk, voidResult = false) => { await mutex.get(); const kpid = await deliveryThunk(); - const runPolicy = perfTool && perfTool.provideRunPolicy(); + const runPolicy = harness && harness.provideRunPolicy(); const runResultP = controller.run(runPolicy); mutex.put(runResultP.catch(logRunFailure)); await runResultP; diff --git a/packages/boot/test/bootstrapTests/orchestration.test.ts b/packages/boot/test/bootstrapTests/orchestration.test.ts index ec95a0c95ef..b51f13e6568 100644 --- a/packages/boot/test/bootstrapTests/orchestration.test.ts +++ b/packages/boot/test/bootstrapTests/orchestration.test.ts @@ -16,12 +16,12 @@ import { } from './walletFactory.js'; import { insistManagerType, - makeRunPolicyProvider, + makeSwingsetHarness, } from '../../tools/supports.js'; const test: TestFn< WalletFactoryTestContext & { - perfTool?: ReturnType; + harness?: ReturnType; } > = anyTest; @@ -40,14 +40,14 @@ const { test.before(async t => { insistManagerType(defaultManagerType); - const perfTool = - defaultManagerType === 'xsnap' ? makeRunPolicyProvider() : undefined; + const harness = + defaultManagerType === 'xsnap' ? makeSwingsetHarness() : undefined; const ctx = await makeWalletFactoryContext( t, '@agoric/vm-config/decentral-itest-orchestration-config.json', - { slogFile, defaultManagerType, perfTool }, + { slogFile, defaultManagerType, harness }, ); - t.context = { ...ctx, perfTool }; + t.context = { ...ctx, harness }; }); test.after.always(t => t.context.shutdown?.()); @@ -123,7 +123,7 @@ test.skip('stakeOsmo - queries', async t => { buildProposal, evalProposal, runUtils: { EV }, - perfTool, + harness, } = t.context; await evalProposal( buildProposal('@agoric/builders/scripts/orchestration/init-stakeOsmo.js'), @@ -162,7 +162,7 @@ test.serial('stakeAtom - smart wallet', async t => { agoricNamesRemotes, bridgeUtils: { flushInboundQueue }, readPublished, - perfTool, + harness, } = t.context; await evalProposal( @@ -173,7 +173,7 @@ test.serial('stakeAtom - smart wallet', async t => { 'agoric1testStakAtom', ); - perfTool?.usePolicy(true); + harness?.useRunPolicy(true); await wd.sendOffer({ id: 'request-account', invitationSpec: { @@ -183,8 +183,8 @@ test.serial('stakeAtom - smart wallet', async t => { }, proposal: {}, }); - perfTool && t.log('makeAccount computrons', perfTool.totalCount()); - perfTool?.usePolicy(false); + harness && t.log('makeAccount computrons', harness.totalComputronCount()); + harness?.useRunPolicy(false); await flushInboundQueue(); t.like(wd.getCurrentWalletRecord(), { diff --git a/packages/boot/test/bootstrapTests/price-feed-replace.test.ts b/packages/boot/test/bootstrapTests/price-feed-replace.test.ts index 3e7876b694c..c9a6178f0fd 100644 --- a/packages/boot/test/bootstrapTests/price-feed-replace.test.ts +++ b/packages/boot/test/bootstrapTests/price-feed-replace.test.ts @@ -64,7 +64,7 @@ test.serial('setupVaults; run updatePriceFeeds proposals', async t => { setupVaults, governanceDriver: gd, readPublished, - perfTool, + harness, } = t.context; await setupVaults(collateralBrandKey, managerIndex, setup); @@ -75,10 +75,10 @@ test.serial('setupVaults; run updatePriceFeeds proposals', async t => { roundId: 1n, }); - perfTool && perfTool.usePolicy(true); + harness && harness.useRunPolicy(true); await priceFeedDrivers[collateralBrandKey].setPrice(15.99); - perfTool && t.log('setPrice computrons', perfTool.totalCount()); - perfTool && perfTool.usePolicy(false); + harness && t.log('setPrice computrons', harness.totalComputronCount()); + harness && harness.useRunPolicy(false); t.like(readPublished('priceFeed.ATOM-USD_price_feed.latestRound'), { roundId: 2n, diff --git a/packages/boot/tools/liquidation.ts b/packages/boot/tools/liquidation.ts index 04fbe9e6499..6b386535ef0 100644 --- a/packages/boot/tools/liquidation.ts +++ b/packages/boot/tools/liquidation.ts @@ -9,7 +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, makeRunPolicyProvider } from './supports.js'; +import { insistManagerType, makeSwingsetHarness } from './supports.js'; import { type SwingsetTestKit, makeSwingsetTestKit } from './supports.js'; import { type GovernanceDriver, @@ -322,12 +322,12 @@ export const makeLiquidationTestContext = async ( SWINGSET_WORKER_TYPE: defaultManagerType = 'local', } = env; assertManagerType(defaultManagerType); - const perfTool = - defaultManagerType === 'xsnap' ? makeRunPolicyProvider() : undefined; + const harness = + defaultManagerType === 'xsnap' ? makeSwingsetHarness() : undefined; const swingsetTestKit = await makeSwingsetTestKit(t.log, undefined, { slogFile, defaultManagerType, - perfTool, + harness, }); console.time('DefaultTestContext'); @@ -385,7 +385,7 @@ export const makeLiquidationTestContext = async ( refreshAgoricNamesRemotes, walletFactoryDriver, governanceDriver, - perfTool, + harness, }; }; diff --git a/packages/boot/tools/supports.ts b/packages/boot/tools/supports.ts index 603b8f54cd0..0be39b19fa0 100644 --- a/packages/boot/tools/supports.ts +++ b/packages/boot/tools/supports.ts @@ -32,7 +32,7 @@ import { Fail } from '@endo/errors'; import { makeRunUtils, type RunUtils, - type RunPolicyMaker, + type RunHarness, } from '@agoric/swingset-vat/tools/run-utils.js'; import { boardSlottingMarshaller, @@ -83,7 +83,7 @@ type BootstrapEV = EProxy & { const makeBootstrapRunUtils = makeRunUtils as ( controller: SwingsetController, - perfTool?: RunPolicyMaker, + harness?: RunHarness, ) => Omit & { EV: BootstrapEV }; const keysToObject = ( @@ -315,7 +315,7 @@ export const matchIter = (t: AvaT, iter, valueRef) => { * @param [options.profileVats] * @param [options.debugVats] * @param [options.defaultManagerType] - * @param [options.perfTool] + * @param [options.harness] */ export const makeSwingsetTestKit = async ( log: (..._: any[]) => void, @@ -329,7 +329,7 @@ export const makeSwingsetTestKit = async ( profileVats = [] as string[], debugVats = [] as string[], defaultManagerType = 'local' as ManagerType, - perfTool = undefined as RunPolicyMaker | undefined, + harness = undefined as RunHarness | undefined, } = {}, ) => { console.time('makeBaseSwingsetTestKit'); @@ -547,7 +547,7 @@ export const makeSwingsetTestKit = async ( console.timeLog('makeBaseSwingsetTestKit', 'buildSwingset'); - const runUtils = makeBootstrapRunUtils(controller, perfTool); + const runUtils = makeBootstrapRunUtils(controller, harness); const buildProposal = makeProposalExtractor({ childProcess: childProcessAmbient, @@ -670,7 +670,12 @@ export const makeSwingsetTestKit = async ( }; export type SwingsetTestKit = Awaited>; -export const makeRunPolicyProvider = () => { +/** + * Return a harness that can be dynamically configured to provide a computron- + * counting run policy (and queried for the count of computrons recorded since + * the last reset). + */ +export const makeSwingsetHarness = () => { const c2b = defaultBeansPerXsnapComputron; const beansPerUnit = { // see https://cosgov.org/agoric?msgType=parameterChangeProposal&network=main @@ -691,14 +696,14 @@ export const makeRunPolicyProvider = () => { return policy; }, /** @param {boolean} forceEnabled */ - usePolicy: forceEnabled => { + useRunPolicy: forceEnabled => { policyEnabled = forceEnabled; if (!policyEnabled) { policy = undefined; } }, - totalCount: () => (policy?.totalBeans() || 0n) / c2b, - resetPolicy: () => (policy = undefined), + totalComputronCount: () => (policy?.totalBeans() || 0n) / c2b, + resetRunPolicy: () => (policy = undefined), }); return meter; };