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

fix(provisioning): export useful namesByAddress #8821

Merged
merged 4 commits into from
Jan 27, 2024
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
11 changes: 11 additions & 0 deletions packages/boot/test/bootstrapTests/test-demo-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { PowerFlags } from '@agoric/vats/src/walletFlags.js';

import type { TestFn } from 'ava';
import type { NameAdmin, NameHub } from '@agoric/vats';

import { makeSwingsetTestKit, keyArrayEqual } from '../../tools/supports.ts';

const { keys } = Object;
Expand Down Expand Up @@ -69,6 +71,15 @@ test('sim/demo config provides home with .myAddressNameAdmin', async t => {
keyArrayEqual(t, keys(home).sort(), homeKeys);
});

test('namesByAddress contains provisioned account', async t => {
const { EV } = t.context.runUtils;
const addr = 'agoric1234new';
const home = await makeHomeFor(addr, EV);
const namesByAddress =
await EV.vat('bootstrap').consumeItem('namesByAddress');
await t.notThrowsAsync(EV(namesByAddress).lookup(addr));
});

test('sim/demo config launches Vaults as expected by loadgen', async t => {
const { EV } = t.context.runUtils;
const agoricNames = await EV.vat('bootstrap').consumeItem('agoricNames');
Expand Down
23 changes: 23 additions & 0 deletions packages/builders/scripts/vats/replace-provisioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @ts-check

import { makeHelpers } from '@agoric/deploy-script-support';
import { getManifestForProvisioning } from '@agoric/vats/src/proposals/namesByAddress-fix-proposal.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const defaultProposalBuilder = async ({ publishRef, install }) =>
harden({
sourceSpec: '@agoric/vats/src/proposals/namesByAddress-fix-proposal.js',
getManifestCall: [
getManifestForProvisioning.name,
{
provisioningRef: publishRef(
install('@agoric/vats/src/vat-provisioning.js'),
),
},
],
});

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('gov-provisioning', defaultProposalBuilder);
};
55 changes: 55 additions & 0 deletions packages/vats/src/proposals/namesByAddress-fix-proposal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/** @file core eval proposal to fix namesByAddress by upgrading vat-provisioning */
import { E } from '@endo/far';

const vatUpgrade = /** @type {const} */ ({
name: 'provisioning',
opts: {
// vatParameters not used by provisioning vat
upgradeMessage: 'fix namesByAddress',
},
});

/**
* Upgrade provisioning vat and replace namesByAddress in bootstrap promise
* space
*
* @param {BootstrapPowers} powers
* @param {object} options
* @param {{ provisioningRef: { bundleID: string } }} options.options
*
* @typedef {string} BundleID
*/
export const upgradeProvisioningVat = async (powers, options) => {
console.log('upgradeProvisioningVat...');
const { vatStore, vatAdminSvc } = powers.consume;
const { namesByAddress: resolver } = powers.produce;

const { name, opts } = vatUpgrade;
const { bundleID } = options.options.provisioningRef;
const vatInfo = await E(vatStore).get(name);
console.log(vatUpgrade.name, vatInfo, bundleID);
const { root, adminNode } = vatInfo;
const bundleCap = await E(vatAdminSvc).getBundleCap(bundleID);
const incarnation = await E(adminNode).upgrade(bundleCap, opts);
console.log({ ...vatUpgrade, incarnation });

const { namesByAddress } = await E(root).getNamesByAddressKit();
resolver.reset();
resolver.resolve(namesByAddress);
};

export const getManifestForProvisioning = (_powers, { provisioningRef }) => ({
/** @type {import('../core/lib-boot').BootstrapManifest} */
manifest: {
[upgradeProvisioningVat.name]: {
consume: {
vatStore: true,
vatAdminSvc: true,
},
produce: {
namesByAddress: true,
},
},
},
options: { provisioningRef },
});
4 changes: 2 additions & 2 deletions packages/vats/src/vat-provisioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export function buildRootObject(_vatPowers, _vatParameters, baggage) {
const makeNamesByAddressAdmin = prepareSpecializedNameAdmin(zone);

const nameHubKit = provide(baggage, 'nameHubKit', () => makeNameHubKit());
const { nameHub: namesByAddress } = makeNameHubKit();
const namesByAddressAdmin = makeNamesByAddressAdmin(nameHubKit.nameAdmin);

// xxx end-user ag-solo provisioning stuff (devnet only)
Expand Down Expand Up @@ -168,6 +167,7 @@ export function buildRootObject(_vatPowers, _vatParameters, baggage) {
return Far('root', {
register,
pleaseProvision,
getNamesByAddressKit: () => harden({ namesByAddress, namesByAddressAdmin }),
getNamesByAddressKit: () =>
harden({ namesByAddress: nameHubKit.nameHub, namesByAddressAdmin }),
});
}
Loading