Skip to content

Commit

Permalink
test(boot): thread computron counter thru test context
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Oct 29, 2024
1 parent d699361 commit 8d2793b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/boot/test/bootstrapTests/walletFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion packages/boot/tools/liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -313,8 +314,17 @@ export const makeLiquidationTestContext = async (
io: { env?: Record<string, string | undefined> } = {},
) => {
const { env = {} } = io;
const {
SLOGFILE: slogFile,
SWINGSET_WORKER_TYPE: defaultManagerType = 'local',
} = env;
insistManagerType(defaultManagerType);
const perfTool =
defaultManagerType === 'xsnap' ? makePolicyProvider() : undefined;
const swingsetTestKit = await makeSwingsetTestKit(t.log, undefined, {
slogFile: env.SLOGFILE,
slogFile,
defaultManagerType,
perfTool,
});
console.time('DefaultTestContext');

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

Expand Down
53 changes: 52 additions & 1 deletion packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Fail } from '@endo/errors';
import {
makeRunUtils,
type RunUtils,
type RunPolicyMaker,
} from '@agoric/swingset-vat/tools/run-utils.js';
import {
boardSlottingMarshaller,
Expand All @@ -45,6 +46,11 @@ import type { SwingsetController } from '@agoric/swingset-vat/src/controller/con
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 {
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);
Expand Down Expand Up @@ -73,6 +79,7 @@ type BootstrapEV = EProxy & {

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

const keysToObject = <K extends PropertyKey, V>(
Expand Down Expand Up @@ -304,6 +311,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,
Expand All @@ -317,6 +325,7 @@ export const makeSwingsetTestKit = async (
profileVats = [] as string[],
debugVats = [] as string[],
defaultManagerType = 'local' as ManagerType,
perfTool = undefined as RunPolicyMaker | undefined,
} = {},
) => {
console.time('makeBaseSwingsetTestKit');
Expand Down Expand Up @@ -532,7 +541,7 @@ export const makeSwingsetTestKit = async (

console.timeLog('makeBaseSwingsetTestKit', 'buildSwingset');

const runUtils = makeBootstrapRunUtils(controller);
const runUtils = makeBootstrapRunUtils(controller, perfTool);

const buildProposal = makeProposalExtractor({
childProcess: childProcessAmbient,
Expand Down Expand Up @@ -653,3 +662,45 @@ export const makeSwingsetTestKit = async (
};
};
export type SwingsetTestKit = Awaited<ReturnType<typeof makeSwingsetTestKit>>;

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<typeof computronCounter> | 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));
}

0 comments on commit 8d2793b

Please sign in to comment.