Skip to content

Commit

Permalink
chore: remove unused publishAgoricNames
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 10, 2024
1 parent b0f5399 commit 84875d4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 90 deletions.
48 changes: 46 additions & 2 deletions packages/inter-protocol/test/smartWallet/boot-psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
makeChainStorage,
noProvisioner,
produceHighPrioritySendersManager,
publishAgoricNames,
startTimerService,
} from '@agoric/vats/src/core/chain-behaviors.js';
import { makePromiseSpace } from '@agoric/vats/src/core/promise-space.js';
Expand All @@ -35,6 +34,8 @@ import {
import * as utils from '@agoric/vats/src/core/utils.js';
import { makeHeapZone } from '@agoric/zone';
import { Stable, Stake } from '@agoric/internal/src/tokens.js';
import { makeScalarBigMapStore } from '@agoric/vat-data';
import { prepareRecorderKit } from '@agoric/zoe/src/contractSupport/recorder.js';
import {
ECON_COMMITTEE_MANIFEST,
startEconomicCommittee,
Expand Down Expand Up @@ -177,6 +178,49 @@ export const ParametersShape = M.splitRecord(
},
);

/**
* @deprecated use publishAgoricNamesToChainStorage
* @param {BootstrapPowers} powers
* @param {{
* options?: {
* agoricNamesOptions?: {
* topLevel?: string[];
* };
* };
* }} config
*/
export const legacyPublishAgoricNames = async (
{ consume: { agoricNamesAdmin, board, chainStorage: rootP } },
{ options: { agoricNamesOptions } = {} } = {},
) => {
const root = await rootP;
assert(root, 'legacyPublishAgoricNames requires chainStorage');
const nameStorage = E(root).makeChildNode('agoricNames');
const marshaller = E(board).getPublishingMarshaller();

// XXX will fail upon restart, but so would the makeStoredPublishKit this is replacing
// Since we expect the bootstrap vat to be replaced instead of upgraded this should be
// fine. See {@link ./README.md bootstrap documentation} for details.
const fakeBaggage = makeScalarBigMapStore(
'fake baggage for AgoricNames kinds',
);
const makeRecorderKit = prepareRecorderKit(fakeBaggage, marshaller);

// brand, issuer, ...
const { topLevel = Object.keys(agoricNamesReserved) } =
agoricNamesOptions || {};
await Promise.all(
topLevel.map(async kind => {
const kindAdmin = await E(agoricNamesAdmin).lookupAdmin(kind);

const kindNode = await E(nameStorage).makeChildNode(kind);
const { recorder } = makeRecorderKit(kindNode);
kindAdmin.onUpdate(recorder);
return recorder.write([]);
}),
);
};

/**
* Build root object of the PSM-only bootstrap vat.
*
Expand Down Expand Up @@ -267,7 +311,7 @@ export const buildRootObject = async (vatPowers, vatParameters) => {
bridgeProvisioner(powersFor('bridgeProvisioner')),
makeChainStorage(powersFor('makeChainStorage')),
makeAddressNameHubs(allPowers),
publishAgoricNames(allPowers, {
legacyPublishAgoricNames(allPowers, {
options: {
agoricNamesOptions: { topLevel: Object.keys(agoricNamesReserved) },
},
Expand Down
44 changes: 0 additions & 44 deletions packages/vats/src/core/chain-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
makeSubscriptionKit,
observeIteration,
} from '@agoric/notifier';
import { makeScalarBigMapStore } from '@agoric/vat-data';
import { prepareRecorderKit } from '@agoric/zoe/src/contractSupport/recorder.js';
import * as farExports from '@endo/far';
import { E, Far } from '@endo/far';
import { importBundle } from '@endo/import-bundle';
Expand Down Expand Up @@ -438,48 +436,6 @@ export const publishAgoricNamesToChainStorage = async ({
);
};

/**
* @deprecated use publishAgoricNamesToChainStorage
* @param {BootstrapPowers} powers
* @param {{
* options?: {
* agoricNamesOptions?: {
* topLevel?: string[];
* };
* };
* }} config
*/
export const publishAgoricNames = async (
{ consume: { agoricNamesAdmin, board, chainStorage: rootP } },
{ options: { agoricNamesOptions } = {} } = {},
) => {
const root = await rootP;
assert(root, 'publishAgoricNames requires chainStorage');
const nameStorage = E(root).makeChildNode('agoricNames');
const marshaller = E(board).getPublishingMarshaller();

// XXX will fail upon restart, but so would the makeStoredPublishKit this is replacing
// Since we expect the bootstrap vat to be replaced instead of upgraded this should be
// fine. See {@link ./README.md bootstrap documentation} for details.
const fakeBaggage = makeScalarBigMapStore(
'fake baggage for AgoricNames kinds',
);
const makeRecorderKit = prepareRecorderKit(fakeBaggage, marshaller);

// brand, issuer, ...
const { topLevel = keys(agoricNamesReserved) } = agoricNamesOptions || {};
await Promise.all(
topLevel.map(async kind => {
const kindAdmin = await E(agoricNamesAdmin).lookupAdmin(kind);

const kindNode = await E(nameStorage).makeChildNode(kind);
const { recorder } = makeRecorderKit(kindNode);
kindAdmin.onUpdate(recorder);
return recorder.write([]);
}),
);
};

/**
* no free lunch on chain
*
Expand Down
49 changes: 5 additions & 44 deletions packages/vats/test/name-hub-published.test.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,12 @@
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';

import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js';
import { makeHandle } from '@agoric/zoe/src/makeHandle.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import {
makeAgoricNamesAccess,
makePromiseSpaceForNameHub,
} from '../src/core/utils.js';
import { makePromiseSpace } from '../src/core/promise-space.js';
import {
publishAgoricNames,
setupClientManager,
} from '../src/core/chain-behaviors.js';
import { makeFakeBoard } from '../tools/board-utils.js';
import { makeAddressNameHubs } from '../src/core/basic-behaviors.js';
import { makePromiseSpaceForNameHub } from '../src/core/utils.js';
import { makeNameHubKit } from '../src/nameHub.js';

test('publishAgoricNames publishes AMM instance', async t => {
const space = makePromiseSpace();
const storageRoot = makeMockChainStorageRoot();
const { agoricNames, agoricNamesAdmin } = await makeAgoricNamesAccess();
const board = makeFakeBoard();
const marshaller = board.getPublishingMarshaller();
space.produce.agoricNames.resolve(agoricNames);
space.produce.agoricNamesAdmin.resolve(agoricNamesAdmin);
space.produce.chainStorage.resolve(storageRoot);
space.produce.board.resolve(board);

await Promise.all([
setupClientManager(/** @type {any} */ (space)),
makeAddressNameHubs(/** @type {any} */ (space)),
publishAgoricNames(/** @type {any} */ (space)),
]);
const ammInstance = makeHandle('instance');
const instanceAdmin = await agoricNamesAdmin.lookupAdmin('instance');
instanceAdmin.update('amm', ammInstance);

await eventLoopIteration(); // wait for publication to settle

t.deepEqual(
storageRoot.getBody(
'mockChainStorageRoot.agoricNames.instance',
marshaller,
),
[['amm', ammInstance]],
);
});
// This suite used to also test publishAgoricNames but that code wasn't used
// anywhere so the test was removed. Its replacement,
// publishAgoricNamesToChainStorage, requires more more context so it's tested
// through integration instead of as a unit test.

test('promise space reserves non-well-known names', async t => {
const { nameHub, nameAdmin } = makeNameHubKit();
Expand Down

0 comments on commit 84875d4

Please sign in to comment.