Skip to content

Commit

Permalink
Merge pull request #4387 from Agoric/bootstrap-core
Browse files Browse the repository at this point in the history
Bootstrap core: refactor, diagnostics, chain support
  • Loading branch information
mergify[bot] authored Jan 26, 2022
2 parents d49cd68 + ce94710 commit 8a8335e
Show file tree
Hide file tree
Showing 18 changed files with 1,164 additions and 458 deletions.
36 changes: 1 addition & 35 deletions packages/vats/decentral-core-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,7 @@
"bootstrap": "bootstrap",
"vats": {
"bootstrap": {
"sourceSpec": "./src/core/boot.js",
"parameters": {
"bootstrapManifest": {
"connectVattpWithMailbox": {
"vatPowers": { "D": true },
"vats": { "vattp": true },
"devices": { "mailbox": true }
},
"makeVatsFromBundles": {
"vats": { "vatAdmin": true },
"devices": { "vatAdmin": true },
"produce": { "vatAdminSvc": true, "loadVat": true }
},
"buildZoe": {
"consume": { "vatAdminSvc": true, "loadVat": true, "client": true },
"produce": { "zoe": true, "feeMintAccess": true }
},
"makeBoard": {
"consume": { "loadVat": true, "client": true },
"produce": { "board": true }
},
"makeAddressNameHubs": {
"consume": { "client": true },
"produce": { "agoricNames": true, "agoricNamesAdmin": true, "nameAdmins": true }
},
"makeClientBanks": {
"consume": {
"loadVat": true,
"client": true,
"bridgeManager": true
},
"produce": { "bankManager": true }
}
}
}
"sourceSpec": "./src/core/boot.js"
}
},
"bundles": {
Expand Down
53 changes: 53 additions & 0 deletions packages/vats/decentral-demo-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"bootstrap": "bootstrap",
"vats": {
"bootstrap": {
"sourceSpec": "./src/core/boot.js",
"parameters": {
"governanceActions": true
}
}
},
"bundles": {
"zcf": {
"sourceSpec": "@agoric/zoe/contractFacet.js"
},
"bank": {
"sourceSpec": "./src/vat-bank.js"
},
"board": {
"sourceSpec": "./src/vat-board.js"
},
"distributeFees": {
"sourceSpec": "./src/vat-distributeFees.js"
},
"ibc": {
"sourceSpec": "./src/vat-ibc.js"
},
"mints": {
"sourceSpec": "./src/vat-mints.js"
},
"network": {
"sourceSpec": "./src/vat-network.js"
},
"priceAuthority": {
"sourceSpec": "./src/vat-priceAuthority.js"
},
"provisioning": {
"sourceSpec": "./src/vat-provisioning.js"
},
"sharing": {
"sourceSpec": "./src/vat-sharing.js"
},
"walletManager": {
"sourceSpec": "./src/vat-walletManager.js"
},
"zoe": {
"sourceSpec": "./src/vat-zoe.js",
"parameters": {
"zcfBundleName": "zcf"
}
}
},
"defaultManagerType": "xs-worker"
}
2 changes: 1 addition & 1 deletion packages/vats/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
fromCosmosIssuerEntries,
BLD_ISSUER_ENTRY,
} from './issuers';
import { feeIssuerConfig } from './core/behaviors.js';
import { feeIssuerConfig } from './core/utils.js';

const { multiply, floorDivide } = natSafeMath;

Expand Down
191 changes: 191 additions & 0 deletions packages/vats/src/core/basic-behaviors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// @ts-check
import { E, Far } from '@agoric/far';
import { makeIssuerKit } from '@agoric/ertp';

import { makeStore } from '@agoric/store';

import { makeNameHubKit } from '../nameHub.js';
import { BLD_ISSUER_ENTRY } from '../issuers.js';

import { feeIssuerConfig, collectNameAdmins, shared } from './utils.js';

const { keys } = Object;

/**
* TODO: review behaviors carefully for powers that go out of scope,
* since we may want/need them later.
*/

/** @param {BootstrapPowers} powers */
export const makeVatsFromBundles = ({
vats,
devices,
produce: { vatAdminSvc, loadVat },
}) => {
const svc = E(vats.vatAdmin).createVatAdminService(devices.vatAdmin);
vatAdminSvc.resolve(svc);
// TODO: getVat? do we need to memoize this by name?
// TODO: rename loadVat to createVatByName?
loadVat.resolve(bundleName => {
console.info(`createVatByName(${bundleName})`);
const root = E(svc)
.createVatByName(bundleName)
.then(r => r.root);
return root;
});
};
harden(makeVatsFromBundles);

/**
* @param { BootstrapPowers & {
* consume: { loadVat: ERef<VatLoader<ZoeVat>> }
* }} powers
*
* @typedef {ERef<ReturnType<import('../vat-zoe.js').buildRootObject>>} ZoeVat
*/
export const buildZoe = async ({
consume: { agoricNames, vatAdminSvc, loadVat, client, nameAdmins },
produce: { zoe, feeMintAccess },
}) => {
const { zoeService, feeMintAccess: fma } = await E(
E(loadVat)('zoe'),
).buildZoe(vatAdminSvc, feeIssuerConfig);

zoe.resolve(zoeService);

const runIssuer = await E(zoeService).getFeeIssuer();
const runBrand = await E(runIssuer).getBrand();
const [issuerAdmin, brandAdmin] = await collectNameAdmins(
['issuer', 'brand'],
agoricNames,
nameAdmins,
);

feeMintAccess.resolve(fma);
return Promise.all([
E(issuerAdmin).update('RUN', runIssuer),
E(brandAdmin).update('RUN', runBrand),
E(client).assignBundle({ zoe: _addr => zoeService }),
]);
};
harden(buildZoe);

/**
* TODO: rename this to getBoard?
*
* @param {BootstrapPowers & {
* consume: { loadVat: ERef<VatLoader<BoardVat>>
* }}} powers
* @typedef {ERef<ReturnType<import('../vat-board.js').buildRootObject>>} BoardVat
*/
export const makeBoard = async ({
consume: { loadVat, client },
produce: {
board: { resolve: resolveBoard },
},
}) => {
const board = E(E(loadVat)('board')).getBoard();
resolveBoard(board);
return E(client).assignBundle({ board: _addr => board });
};
harden(makeBoard);

/** @param {BootstrapPowers} powers */
export const makeAddressNameHubs = async ({ consume: { client }, produce }) => {
const {
nameHub: agoricNames,
nameAdmin: agoricNamesAdmin,
} = makeNameHubKit();

const {
nameHub: namesByAddress,
nameAdmin: namesByAddressAdmin,
} = makeNameHubKit();

/** @type {Store<NameHub, NameAdmin>} */
const nameAdmins = makeStore('nameHub');
await Promise.all(
['brand', 'installation', 'issuer', 'instance', 'uiConfig'].map(
async nm => {
const { nameHub, nameAdmin } = makeNameHubKit();
await E(agoricNamesAdmin).update(nm, nameHub);
nameAdmins.init(nameHub, nameAdmin);
if (nm === 'uiConfig') {
// Reserve the Vault Factory's config until we've populated it.
nameAdmin.reserve('vaultFactory');
} else if (['issuer', 'brand'].includes(nm)) {
keys(shared.assets).forEach(k => nameAdmin.reserve(k));
} else if (['installation', 'instance'].includes(nm)) {
keys(shared.contract).forEach(k => nameAdmin.reserve(k));
}
},
),
);
produce.nameAdmins.resolve(nameAdmins);
produce.agoricNames.resolve(agoricNames);
produce.agoricNamesAdmin.resolve(agoricNamesAdmin);

const perAddress = address => {
// Create a name hub for this address.
const {
nameHub: myAddressNameHub,
nameAdmin: rawMyAddressNameAdmin,
} = makeNameHubKit();
// Register it with the namesByAddress hub.
namesByAddressAdmin.update(address, myAddressNameHub);

/** @type {MyAddressNameAdmin} */
const myAddressNameAdmin = Far('myAddressNameAdmin', {
...rawMyAddressNameAdmin,
getMyAddress: () => address,
});
return myAddressNameAdmin;
};

return E(client).assignBundle({
agoricNames: _ => agoricNames,
namesByAddress: _ => namesByAddress,
myAddressNameAdmin: perAddress,
});
};
harden(makeAddressNameHubs);

/**
* @param {BootstrapPowers & {
* consume: { loadVat: ERef<VatLoader<BankVat>> },
* }} powers
* @typedef {ERef<ReturnType<import('../vat-bank.js').buildRootObject>>} BankVat
*/
export const makeClientBanks = async ({
consume: { loadVat, client, bridgeManager },
produce: { bankManager },
}) => {
const settledBridge = await bridgeManager; // ISSUE: why await? it's remote, no?
const mgr = E(E(loadVat)('bank')).makeBankManager(settledBridge);
bankManager.resolve(mgr);
return E(client).assignBundle({
bank: address => E(mgr).getBankForAddress(address),
});
};
harden(makeClientBanks);

/** @param {BootstrapPowers} powers */
export const makeBLDKit = async ({
consume: { agoricNames, bankManager, nameAdmins },
}) => {
const [issuerName, { bankDenom, bankPurse, issuerArgs }] = BLD_ISSUER_ENTRY;
assert(issuerArgs);
const kit = makeIssuerKit(issuerName, ...issuerArgs); // TODO: should this live in another vat???
await E(bankManager).addAsset(bankDenom, issuerName, bankPurse, kit);
const { brand, issuer } = kit;
const [issuerAdmin, brandAdmin] = await collectNameAdmins(
['issuer', 'brand'],
agoricNames,
nameAdmins,
);
return Promise.all([
E(issuerAdmin).update(issuerName, issuer),
E(brandAdmin).update(issuerName, brand),
]);
};
harden(makeBLDKit);
Loading

0 comments on commit 8a8335e

Please sign in to comment.