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 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 proposals/c: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/c:crabble-start/assets/bundle-contract.json

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions proposals/c: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/c: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-3af8183538129ce433d368dc0bdb6082733fc0fa6449c18d5f212f104f971d8ea8b033074067b807bffd5eb2f17821c5e2e9b26ba312795368ae8e7446606b85";
const governorBundleID = "b1-0bfb8a189cda652bc43c488e079e6362870e49039a247156f9430f4f0dfa054970f01c108b79c476baddc8b814546ad88578358452fe2919d11fdcc224bbe4b3";

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/c: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