Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test restarting all PSM instances #7698

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/inter-protocol/src/proposals/econ-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const SECONDS_PER_DAY = 24n * SECONDS_PER_HOUR;

/**
* @typedef {object} PSMKit
* @property {string} label
* @property {Instance} psm
* @property {Instance} psmGovernor
* @property {Awaited<ReturnType<Awaited<ReturnType<import('../psm/psm.js')['prepare']>>['creatorFacet']['getLimitedCreatorFacet']>>} psmCreatorFacet
Expand Down
22 changes: 13 additions & 9 deletions packages/inter-protocol/src/proposals/startPSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const startPSM = async (
consume: {
agoricNamesAdmin,
board,
diagnostics,
zoe,
feeMintAccess: feeMintAccessP,
economicCommitteeCreatorFacet,
Expand Down Expand Up @@ -203,19 +204,20 @@ export const startPSM = async (
},
}),
);
const psmPrivateArgs = {
feeMintAccess,
initialPoserInvitation,
marshaller,
storageNode,
};
/** @type {GovernorStartedInstallationKit<typeof psmInstall>} */
const governorFacets = await E(zoe).startInstance(
contractGovernor,
{},
governorTerms,
harden({
economicCommitteeCreatorFacet,
governed: {
feeMintAccess,
initialPoserInvitation,
marshaller,
storageNode,
},
governed: psmPrivateArgs,
}),
`${instanceKey}.governor`,
);
Expand All @@ -225,6 +227,7 @@ export const startPSM = async (
E(governorFacets.creatorFacet).getCreatorFacet(),
E(governorFacets.creatorFacet).getAdminFacet(),
]);
await E(diagnostics).savePrivateArgs(psm, psmPrivateArgs);

/** @param {MetricsNotification} metrics */
const restoreMetrics = async metrics => {
Expand All @@ -243,9 +246,9 @@ export const startPSM = async (
};
await (oldState.metrics && restoreMetrics(oldState.metrics));

/** @typedef {import('./econ-behaviors.js').PSMKit} psmKit */
/** @type {psmKit} */
/** @type {import('./econ-behaviors.js').PSMKit} */
const newpsmKit = harden({
label: instanceKey,
psm,
psmGovernor: governorFacets.instance,
psmCreatorFacet,
Expand All @@ -256,7 +259,7 @@ export const startPSM = async (
// Provide pattern with a promise.
producepsmKit.resolve(makeScalarBigMapStore('PSM Kits', { durable: true }));

/** @type {MapStore<Brand,psmKit>} */
/** @type {MapStore<Brand, import('./econ-behaviors.js').PSMKit>} */
const psmKitMap = await psmKit;

// TODO init into governedContractKits too to simplify testing
Expand Down Expand Up @@ -436,6 +439,7 @@ export const PSM_MANIFEST = {
agoricNamesAdmin: true,
board: true,
chainStorage: true,
diagnostics: true,
zoe: 'zoe',
feeMintAccess: 'zoe',
economicCommitteeCreatorFacet: 'economicCommittee',
Expand Down
1 change: 0 additions & 1 deletion packages/vats/src/core/basic-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const bootMsgEx = {

/**
* @param {BootstrapPowers & {
* consume: {vatStore: Promise<VatStore> }
* }} powers
*
* @typedef {import('@agoric/swingset-vat').CreateVatResults} CreateVatResults as from createVatByName
Expand Down
1 change: 1 addition & 0 deletions packages/vats/src/core/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
* walletBridgeManager: import('../types.js').ScopedBridgeManager | undefined,
* walletFactoryStartResult: import('./startWalletFactory').WalletFactoryStartResult,
* provisionPoolStartResult: unknown,
* vatStore: import('./utils.js').VatStore,
* zoe: ZoeService,
* }} ChainBootstrapSpaceT
* @typedef {PromiseSpaceOf<ChainBootstrapSpaceT>} ChainBootstrapSpace
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export const makeMyAddressNameAdminKit = address => {
* @param {string} [label]
*
* @typedef {import('@agoric/swingset-vat').CreateVatResults} CreateVatResults as from createVatByName
* @typedef {MapStore<string, Promise<CreateVatResults>>} VatStore
* @typedef {MapStore<string, CreateVatResults>} VatStore
*/
export const makeVatSpace = (
svc,
Expand Down
59 changes: 43 additions & 16 deletions packages/vats/src/proposals/restart-vats-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ const trace = makeTracer('RV');
const HR = '----------------';

/**
* TODO cover each of these collections
* - [x] contractKits
* - [ ] psmKit
* - [x] governedContractKits
* - [ ] vatStore
* Non-contract vats aren't automatically restarted here because doing it would
* break many other tests that are fragile.
*/
const vatUpgradeStatus = {
agoricNames: 'UNTESTED',
bank: 'covered by test-upgrade-vats: upgrade vat-bank',
board: 'covered by test-upgrade-vats: upgrade vat-board',
bridge: 'covered by test-upgrade-vats: upgrade vat-bridge',
priceAuthority: 'covered by test-upgrade-vats: upgrade vat-priceAuthority',
provisioning: 'UNTESTED',
zoe: 'tested in @agoric/zoe',
};

/**
* @param {BootstrapPowers & import('@agoric/inter-protocol/src/proposals/econ-behaviors.js').EconomyBootstrapSpace} space
Expand All @@ -33,12 +39,15 @@ export const restartVats = async ({ consume }, { options }) => {
await consume.vaultFactoryKit;

trace('testing restarts');
const { contractKits, governedContractKits } = await deeplyFulfilledObject(
harden({
contractKits: consume.contractKits,
governedContractKits: consume.governedContractKits,
}),
);
const { contractKits, governedContractKits, psmKit, vatStore } =
await deeplyFulfilledObject(
harden({
contractKits: consume.contractKits,
governedContractKits: consume.governedContractKits,
psmKit: consume.psmKit,
vatStore: consume.vatStore,
}),
);

const instancePrivateArgs = await consume.instancePrivateArgs;

Expand All @@ -49,7 +58,7 @@ export const restartVats = async ({ consume }, { options }) => {
* @param {Instance} instance
* @param {ERef<AdminFacet>} adminFacet
*/
const tryRestart = async (debugName, instance, adminFacet) => {
const tryRestartContract = async (debugName, instance, adminFacet) => {
// TODO document that privateArgs cannot contain promises
// TODO try making all the contract starts take resolved values
const privateArgs = await deeplyFulfilledObject(
Expand All @@ -76,16 +85,17 @@ export const restartVats = async ({ consume }, { options }) => {
}
};

// iterate over the two contractKits and use the adminFacet to restartContract
trace('iterating over contractKits');
for (const kit of contractKits.values()) {
const debugName =
kit.label || getInterfaceOf(kit.publicFacet) || 'UNLABELED';
if (debugName !== kit.label) {
console.warn('MISSING LABEL:', kit);
}
await tryRestart(debugName, kit.instance, kit.adminFacet);
await tryRestartContract(debugName, kit.instance, kit.adminFacet);
}

trace('iterating over governedContractKits');
for (const kit of governedContractKits.values()) {
const debugName =
kit.label || getInterfaceOf(kit.publicFacet) || 'UNLABELED';
Expand All @@ -94,16 +104,31 @@ export const restartVats = async ({ consume }, { options }) => {
}

trace('restarting governed', debugName);
await tryRestart(debugName, kit.instance, kit.adminFacet);
await tryRestartContract(debugName, kit.instance, kit.adminFacet);

trace('restarting governor of', debugName);
await tryRestart(
await tryRestartContract(
`${debugName} [Governor]`,
kit.governor,
kit.governorAdminFacet,
);
}

trace('iterating over psmKit');
for (const kit of psmKit.values()) {
console.log('restarting PSM', kit.label);
await tryRestartContract(kit.label, kit.psm, kit.psmAdminFacet);
}

trace('iterating over vatStore');
for (const [name] of vatStore.entries()) {
const status = vatUpgradeStatus[name];
if (!status) {
Fail`unaudited vat ${name}`;
}
console.log('VAT', name, status);
}

trace('restartVats done with ', failures.length, 'failures');
console.log(HR);
if (failures.length) {
Expand All @@ -121,6 +146,8 @@ export const getManifestForRestart = (_powers, options) => ({
governedContractKits: true,
instancePrivateArgs: true,
loadCriticalVat: true,
psmKit: true,
vatStore: true,
zoe: 'zoe',
provisioning: 'provisioning',
vaultFactoryKit: true,
Expand Down
5 changes: 4 additions & 1 deletion packages/vats/src/vat-agoricNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { E, Far } from '@endo/far';
import { BrandI } from '@agoric/ertp';
import { provide } from '@agoric/vat-data';
import { makeDurableZone } from '@agoric/zone/durable.js';
import { provideLazy } from '@agoric/store';
import { prepareNameHubKit } from './nameHub.js';

/** @param {import('@agoric/zone').Zone} zone */
Expand Down Expand Up @@ -80,6 +81,8 @@ export const buildRootObject = (_vatPowers, _vatParameters, baggage) => {
* @param {DisplayInfo} displayInfo
*/
provideInertBrand: (keyword, displayInfo) =>
provide(brandStore, keyword, () => makeNatBrand(keyword, displayInfo)),
provideLazy(brandStore, keyword, () =>
makeNatBrand(keyword, displayInfo),
),
});
};
3 changes: 2 additions & 1 deletion packages/vats/test/bootstrapTests/test-vats-restart.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { makeSwingsetTestKit, makeWalletFactoryDriver } from './supports.js';
*/
const test = anyTest;

const PLATFORM_CONFIG = '@agoric/vats/decentral-devnet-config.json';
// main/production config doesn't have initialPrice, upon which 'open vaults' depends
const PLATFORM_CONFIG = '@agoric/vats/decentral-test-vaults-config.json';

// presently all these tests use one collateral manager
const collateralBrandKey = 'ATOM';
Expand Down