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

Add Crabble proposal #41

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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 proposals/64:crabble-start/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
1 change: 1 addition & 0 deletions proposals/64:crabble-start/assets/bundle-contract.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions proposals/64:crabble-start/assets/bundle-governor.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions proposals/64:crabble-start/assets/crabble-permit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"consume": {
"board": true,
"chainStorage": true,
"chainTimerService": true,
"agoricNames": true,
"zoe": true,
"namesByAddressAdmin": true,
"startCrabbleGovernedUpgradable": true,
"startUpgradable": true
},
"installation": {
"consume": {
"committee": true
}
},
"instance": {
"produce": {
"Crabble": true,
"CrabbleCommittee": true,
"CrabbleGovernor": true
}
}
}
250 changes: 250 additions & 0 deletions proposals/64:crabble-start/assets/crabbleCoreEval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
// @ts-check
// XMPORT: { E } from '@endo/far';

const fail = (msg) => {
throw Error(msg);
};

const { fromEntries, keys, values } = Object;

/** @type {<X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
const zip = (xs, ys) => harden(xs.map((x, i) => [x, ys[+i]]));

/**
* @type {<T extends Record<string, ERef<any>>>(
* obj: T,
* ) => Promise<{ [K in keyof T]: Awaited<T[K]> }>}
*/
const allValues = async (obj) => {
const resolved = await Promise.all(values(obj));
// @ts-expect-error cast
return harden(fromEntries(zip(keys(obj), resolved)));
};

const logger = (...args) => {
console.log('[CRABBLE_CORE_EVAL]', ...args);
};

/**
* @template T
* @typedef {{
* resolve: (v: ERef<T>) => void;
* reject: (r: unknown) => void;
* reset: (reason?: unknown) => void;
* }} ProducerX<T>
*/

/**
* @param {{
* consume: {
* agoricNames: ERef<XMPORT('@agoric/vats').NameHub>;
* board: ERef<XMPORT('@agoric/vats').Board>;
* startUpgradable: Promise<Function>;
* namesByAddressAdmin: ERef<XMPORT('@agoric/vats').NameAdmin>;
* };
* instance: { produce: Record<'CrabbleCommittee', ProducerX<Instance>> }
* }} powers
* @param {*} config
* @param {ERef<StorageNode>} crabbleNode
*/
const startCommittee = async (
{
consume: {
board,
// namesByAddress should suffice, but...
// https://github.com/Agoric/agoric-sdk/issues/8113
namesByAddressAdmin,
startUpgradable,
},
installation: {
consume: { committee: committeeInstallationP },
},
instance: { produce: produceInstance },
},
config,
crabbleNode,
) => {
const committeeSize = 3;
const committeeName = "CrabbleCommittee";
const members = ["agoric1ag5a8lhn00h4u9h2shpfpjpaq6v4kku54zk69m","agoric140y0mqnq7ng5vvxxwpfe67988e5vqar9whg309","agoric1wqfu6hu5q2qtey9jtjapaae4df9zd492z4448k"];

logger('Getting nameHubs, depositFacets...');
const getDepositFacet = async (address) => {
const hub = E(E(namesByAddressAdmin).lookupAdmin(address)).readonly();
return E(hub).lookup('depositFacet');
};
const memberDeposits = await Promise.all(members.map(getDepositFacet));

logger('Gathering info...');
const { committeeInstallation, marshaller, committeeNode } = await allValues({
committeeInstallation: committeeInstallationP,
marshaller: E(board).getPublishingMarshaller(),
committeeNode: E(crabbleNode).makeChildNode('committee'),
});

logger('Starting committee...');
const committeeKit = await E(startUpgradable)({
installation: committeeInstallation,
terms: { committeeSize, committeeName },
privateArgs: { storageNode: committeeNode, marshaller },
label: committeeName,
});
logger({ committeeKit });

logger('Updating agoricNames with committee instance...');
produceInstance.CrabbleCommittee.resolve(committeeKit.instance);

logger('Getting the member and voter invitations...');
const voterInvitations = await E(
committeeKit.creatorFacet,
).getVoterInvitations();

logger('Sending committeeinvitations...');
await Promise.all(
zip(memberDeposits, voterInvitations).map(([depositFacet, invitation]) =>
E(depositFacet).receive(invitation),
),
);

logger('Done.');
return { committeeCreatorFacet: committeeKit.creatorFacet, memberDeposits };
};

/**
*
* @param {{
* consume: {
* zoe: Promise<ZoeService>;
* board: ERef<XMPORT('@agoric/vats').Board>,
* startCrabbleGovernedUpgradable: Promise<Function>,
* chainTimerService: ERef<XMPORT('@agoric/time/src/types').TimerService>;
* agoricNames: ERef<XMPORT('@agoric/vats').NameHub>;
* },
* instance: { produce: Record<'Crabble' | 'CrabbleGovernor', ProducerX<Instance>>}
* }} powers
* @param {*} config
* @param {ERef<StorageNode>} crabbleNode
* @param {Promise<{
* committeeCreatorFacet: ERef<any>;
* memberDeposits: ERef<DepositFacet>[]
* }>} committeeInfoP
*/
const startCrabble = async (powers, config, crabbleNode, committeeInfoP) => {
const contractBundleID = "b1-145f84363c784c96bc5a5d456edf1853bf2bb04388a250f010a53234b333af46d8d08e3c58d6e3bac61c45b18e82a09199938466616016a22d9191448f8e505c";
const governorBundleID = "b1-d67b9ac5100bf45a3369d393fe2cb38e0718f770cac936292a18270ed331865ffa817719f5c6ceacdb1a580572d71084db0545e8e13efaee38c7df76f51f756c";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in #41 (comment) , I'm not able to reproduce these bundle hashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's how everything happened when I tried it:

anil@Anils-MacBook-Pro source_code % make prepare-evals
node /Users/anil/WebstormProjects/agoric-samples/a3p-bundle-experiment/crabbleProtocol/source_code/contract/src/proposals/prepareCoreEval.js
{
  OUT_DIR_ROOT: '/Users/anil/WebstormProjects/agoric-samples/a3p-bundle-experiment/crabbleProtocol/source_code',
  RENDER_EVALS: undefined
}
{
  value: [
    'agoric1ag5a8lhn00h4u9h2shpfpjpaq6v4kku54zk69m',
    'agoric140y0mqnq7ng5vvxxwpfe67988e5vqar9whg309',
    'agoric1wqfu6hu5q2qtey9jtjapaae4df9zd492z4448k'
  ]
}
{ value: 3 }
{ value: 'CrabbleCommittee' }
[bundleTool] /Users/anil/WebstormProjects/agoric-samples/a3p-bundle-experiment/crabbleProtocol/source_code/bundles add: crabble from /Users/anil/WebstormProjects/agoric-samples/a3p-bundle-experiment/crabbleProtocol/source_code/contract/src/crabble.js 
[bundleTool] /Users/anil/WebstormProjects/agoric-samples/a3p-bundle-experiment/crabbleProtocol/source_code/bundles bundled 205 files in bundle-crabble.js at 2023-12-12T20:07:51.192Z 
[bundleTool] /Users/anil/WebstormProjects/agoric-samples/a3p-bundle-experiment/crabbleProtocol/source_code/bundles add: crabbleGovernor from /Users/anil/WebstormProjects/agoric-samples/a3p-bundle-experiment/crabbleProtocol/source_code/contract/src/crabbleGovernor.js 
[bundleTool] /Users/anil/WebstormProjects/agoric-samples/a3p-bundle-experiment/crabbleProtocol/source_code/bundles bundled 137 files in bundle-crabbleGovernor.js at 2023-12-12T20:07:52.208Z 
DONE
anil@Anils-MacBook-Pro source_code % diff -ur assets ../../../crabbleProtocol/source_code/assets
anil@Anils-MacBook-Pro source_code % diff -ur assets ../../../crabbleProtocol/source_code/assets | cut -c 1-200
anil@Anils-MacBook-Pro source_code % jq ".endoZipBase64Sha512" assets/bundle-contract.json
"145f84363c784c96bc5a5d456edf1853bf2bb04388a250f010a53234b333af46d8d08e3c58d6e3bac61c45b18e82a09199938466616016a22d9191448f8e505c"
anil@Anils-MacBook-Pro source_code % jq ".endoZipBase64Sha512" assets/bundle-governor.json 
"d67b9ac5100bf45a3369d393fe2cb38e0718f770cac936292a18270ed331865ffa817719f5c6ceacdb1a580572d71084db0545e8e13efaee38c7df76f51f756c"

Is there any chance you forgot to check out the commit hash I provided in the release docs? @dckc

git checkout 0cb86ed3ce19f211ee033fcad9fa95ce2097e0d3


const {
consume: {
board,
startCrabbleGovernedUpgradable,
zoe: zoeI, // only used for installation, not for startInstance
chainTimerService,
agoricNames: agoricNamesP,
},
instance: { produce: produceInstance },
} = powers;
logger('Gathering info...');
const {
contractInstallation,
governorInstallation,
binaryVoteCounterInstallation,
committeeInstallation,
marshaller,
timer,
info: { committeeCreatorFacet, memberDeposits },
agoricNames,
} = await allValues({
contractInstallation: E(zoeI).installBundleID(contractBundleID),
governorInstallation: E(zoeI).installBundleID(governorBundleID),
binaryVoteCounterInstallation: E(agoricNamesP).lookup(
'installation',
'binaryVoteCounter',
),
committeeInstallation: E(agoricNamesP).lookup('installation', 'committee'),
marshaller: E(board).getPublishingMarshaller(),
timer: chainTimerService,
info: committeeInfoP,
agoricNames: agoricNamesP,
});

logger({
contractInstallation,
binaryVoteCounterInstallation,
committeeInstallation,
marshaller,
crabbleNode,
});

logger('---Starting Crabble with governor---');
const crabbleTerms = {
agoricNames,
};

const crabblePrivateArgs = {
storageNode: crabbleNode,
marshaller,
timer,
};

logger({
crabbleTerms,
crabblePrivateArgs,
});

logger('Deeply fulfill governorTerms...');
const governorTerms = harden({
timer, // ISSUE: TIMER IN TERMS
governedContractInstallation: contractInstallation,
binaryVoteCounterInstallation,
});

logger({
governorTerms,
});

logger('Starting governor, governed...');
const kit = await E(startCrabbleGovernedUpgradable)({
installation: contractInstallation,
committeeCreatorFacet,
contractGovernor: governorInstallation,
governorTerms,
terms: crabbleTerms,
privateArgs: crabblePrivateArgs,
label: 'Crabble',
});

logger({
kit,
});

logger('Updating agoricNames with instances...');
produceInstance.Crabble.resolve(kit.instance);
produceInstance.CrabbleGovernor.resolve(kit.governor);

logger('Sending member invitations...');
await Promise.all(
memberDeposits.map(async (df) => {
const inv = await E(
kit.governorCreatorFacet,
).makeCommitteeMemberInvitation();
return E(df).receive(inv);
}),
);

logger('Done.');
};

harden(startCrabble);

const start = async (powers, config) => {
const {
consume: { chainStorage },
} = powers;
const crabbleNode = await E(chainStorage).makeChildNode('crabble');

const committeeInfo = startCommittee(powers, config, crabbleNode);
await startCrabble(powers, config, crabbleNode, committeeInfo);
};
harden(start);

start;
11 changes: 11 additions & 0 deletions proposals/64:crabble-start/assets/gov-permit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"consume": {
"chainTimerService": true,
"governedContractKits": true,
"diagnostics": true,
"zoe": true
},
"produce": {
"startCrabbleGovernedUpgradable": true
}
}
Loading
Loading