From c6ae87332c2952932b5ca1629d77c7fed4411367 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 2 Dec 2024 15:35:20 -0500 Subject: [PATCH 1/3] refactor: Cleanup #10348 https://github.com/Agoric/agoric-sdk/pull/10348#discussion_r1855150615 --- packages/boot/tools/supports.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/boot/tools/supports.ts b/packages/boot/tools/supports.ts index 967fe12d257..603b8f54cd0 100644 --- a/packages/boot/tools/supports.ts +++ b/packages/boot/tools/supports.ts @@ -681,19 +681,19 @@ export const makeRunPolicyProvider = () => { /** @type {ReturnType | undefined} */ let policy; - let counting = false; + let policyEnabled = false; const meter = harden({ provideRunPolicy: () => { - if (counting && !policy) { + if (policyEnabled && !policy) { policy = computronCounter({ beansPerUnit }); } return policy; }, - /** @param {boolean} x */ - usePolicy: x => { - counting = x; - if (!counting) { + /** @param {boolean} forceEnabled */ + usePolicy: forceEnabled => { + policyEnabled = forceEnabled; + if (!policyEnabled) { policy = undefined; } }, From 50fda75f54adb4558cadb97aec76d2b1c85a67e3 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 2 Dec 2024 15:35:20 -0500 Subject: [PATCH 2/3] refactor: Cleanup #10348 https://github.com/Agoric/agoric-sdk/pull/10348#discussion_r1855204572 --- packages/cosmic-swingset/src/computron-counter.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/cosmic-swingset/src/computron-counter.js b/packages/cosmic-swingset/src/computron-counter.js index 4db024ca7a0..c21f4150be1 100644 --- a/packages/cosmic-swingset/src/computron-counter.js +++ b/packages/cosmic-swingset/src/computron-counter.js @@ -50,10 +50,7 @@ export function computronCounter( const defaultCleanupBudget = remainingCleanups.default; let cleanupStarted = false; let cleanupDone = false; - const cleanupPossible = - Object.values(remainingCleanups).length > 0 - ? Object.values(remainingCleanups).some(n => n > 0) - : defaultCleanupBudget > 0; + const cleanupPossible = Object.values(remainingCleanups).some(n => n > 0); if (!cleanupPossible) cleanupDone = true; /** @type {() => (false | import('@agoric/swingset-vat').CleanupBudget)} */ const allowCleanup = () => From a0798d295a66753944ff98ba9d570caf4aa47454 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 2 Dec 2024 15:35:20 -0500 Subject: [PATCH 3/3] refactor: Cleanup #10348 Rename types/functions/parameters as suggested at: * https://github.com/Agoric/agoric-sdk/pull/10348#discussion_r1855147470 * https://github.com/Agoric/agoric-sdk/pull/10348#discussion_r1855150764 --- packages/SwingSet/tools/run-utils.js | 8 +++---- .../test/bootstrapTests/orchestration.test.ts | 22 +++++++++--------- .../bootstrapTests/price-feed-replace.test.ts | 8 +++---- packages/boot/tools/liquidation.ts | 10 ++++---- packages/boot/tools/supports.ts | 23 +++++++++++-------- 5 files changed, 38 insertions(+), 33 deletions(-) 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; };