Skip to content

Commit

Permalink
refactor: Cleanup #10348
Browse files Browse the repository at this point in the history
Rename types/functions/parameters as suggested at:
* #10348 (comment)
* #10348 (comment)
  • Loading branch information
gibson042 committed Dec 2, 2024
1 parent 46dd9e1 commit 58b63b1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
8 changes: 4 additions & 4 deletions packages/SwingSet/tools/run-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions packages/boot/test/bootstrapTests/orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
} from './walletFactory.js';
import {
insistManagerType,
makeRunPolicyProvider,
makeSwingsetHarness,
} from '../../tools/supports.js';

const test: TestFn<
WalletFactoryTestContext & {
perfTool?: ReturnType<typeof makeRunPolicyProvider>;
harness?: ReturnType<typeof makeSwingsetHarness>;
}
> = anyTest;

Expand All @@ -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?.());

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -162,7 +162,7 @@ test.serial('stakeAtom - smart wallet', async t => {
agoricNamesRemotes,
bridgeUtils: { flushInboundQueue },
readPublished,
perfTool,
harness,
} = t.context;

await evalProposal(
Expand All @@ -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: {
Expand All @@ -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(), {
Expand Down
8 changes: 4 additions & 4 deletions packages/boot/test/bootstrapTests/price-feed-replace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions packages/boot/tools/liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -385,7 +385,7 @@ export const makeLiquidationTestContext = async (
refreshAgoricNamesRemotes,
walletFactoryDriver,
governanceDriver,
perfTool,
harness,
};
};

Expand Down
23 changes: 14 additions & 9 deletions packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -83,7 +83,7 @@ type BootstrapEV = EProxy & {

const makeBootstrapRunUtils = makeRunUtils as (
controller: SwingsetController,
perfTool?: RunPolicyMaker,
harness?: RunHarness,
) => Omit<RunUtils, 'EV'> & { EV: BootstrapEV };

const keysToObject = <K extends PropertyKey, V>(
Expand Down Expand Up @@ -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,
Expand All @@ -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');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -670,7 +670,12 @@ export const makeSwingsetTestKit = async (
};
export type SwingsetTestKit = Awaited<ReturnType<typeof makeSwingsetTestKit>>;

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
Expand All @@ -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;
};
Expand Down

0 comments on commit 58b63b1

Please sign in to comment.