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

RUN protocol governance to start PSM, runStake, etc. #5165

Merged
merged 7 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default async function deployMain(progname, rawArgs, powers, opts) {
paths: [...paths, path.dirname(moduleFile)],
});
} catch (e) {
return path.resolve(...paths, fileName);
return path.resolve(path.dirname(moduleFile), ...paths, fileName);
Copy link
Member

Choose a reason for hiding this comment

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

Why was path.dirname(moduleFile) added before ...paths ?

Copy link
Member

Choose a reason for hiding this comment

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

Nmv, this is correct and it's the paths for require.resolve above that isn't correct.

}
};
console.warn('running', moduleFile);
Expand Down
22 changes: 15 additions & 7 deletions packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REPOSITORY = agoric/cosmic-swingset
CHAIN_ID = agoric
INITIAL_HEIGHT = 17
GENESIS_TIME = $(shell TZ=UTC date +%Y-%m-%dT%H:%M:%SZ)
VOTING_PERIOD = 2m
VOTING_PERIOD = 45s

EVAL_PERMIT = test/gov-permit.json
EVAL_CODE = test/gov-code.js
Expand Down Expand Up @@ -46,14 +46,22 @@ $(EVAL_CLEAN): $(EVAL_CODE)
./scripts/clean-core-eval.js $< >$@.t || { rm -f $@.t; exit 1; }
mv $@.t $@

start-runStake: test/runStake/gov-start-runStake.js
make EVAL_CODE=test/runStake/gov-start-runStake.js \
EVAL_PERMIT=test/runStake/gov-start-runStake-permit.json \
RUN_PROTO=../run-protocol

start-runStake: $(RUN_PROTO)/gov-runStake.js
make EVAL_CODE=$(RUN_PROTO)/gov-runStake.js \
EVAL_PERMIT=$(RUN_PROTO)/gov-runStake-permit.json \
VOTE_PROPOSAL=$(VOTE_PROPOSAL) scenario2-core-eval scenario2-vote

start-committee: $(RUN_PROTO)/gov-econ-committee.js
make EVAL_CODE=$(RUN_PROTO)/gov-econ-committee.js \
EVAL_PERMIT=$(RUN_PROTO)/gov-econ-committee-permit.json \
VOTE_PROPOSAL=$(VOTE_PROPOSAL) scenario2-core-eval scenario2-vote

start-committee: test/runStake/gov-start-econCommittee.js
make EVAL_CODE=test/runStake/gov-start-econCommittee.js \
EVAL_PERMIT=test/runStake/gov-start-runStake-permit.json \

start-amm-etc: $(RUN_PROTO)/gov-amm-vaults-etc.js
make EVAL_CODE=$(RUN_PROTO)/gov-amm-vaults-etc.js \
EVAL_PERMIT=$(RUN_PROTO)/gov-amm-vaults-etc-permit.json \
VOTE_PROPOSAL=$(VOTE_PROPOSAL) scenario2-core-eval scenario2-vote

gov-q:
Expand Down
8 changes: 8 additions & 0 deletions packages/deploy-script-support/src/coreProposalBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ export const makeCoreProposalBehavior = ({
const restoreRef = overrideRestoreRef || (x => E(board).getValue(x));

// Get the on-chain installation containing the manifest and behaviors.
console.info('restoreRef, evaluateInstallation', {
manifestInstallRef,
exportedGetManifest,
});
const manifestInstallation = await restoreRef(manifestInstallRef);
const behaviors = await evaluateInstallation(manifestInstallation);

console.error('execute', {
exportedGetManifest,
behaviors: Object.keys(behaviors),
});
const {
manifest,
options: rawOptions,
Expand Down
53 changes: 50 additions & 3 deletions packages/deploy-script-support/src/endo-pieces-contract.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
// @ts-check
import { E, Far } from '@endo/far';
import { encodeBase64, decodeBase64 } from '@endo/base64';
import { ZipWriter } from '@endo/zip';

const { details: X, quote: q } = assert;

export const start = () => {
/** @type { Map<string, [string, Uint8Array]>} */
const hashToEntry = new Map();

/** @param { string[] } hashes */
const preFilter = hashes => {
assert(Array.isArray(hashes));
return hashes.filter(hash => {
assert.typeof(hash, 'string');
return hashToEntry.has(hash);
});
};

const makeBundler = ({ zoe }) => {
/** @type { Map<string, [string, Uint8Array]>} */
const nameToContent = new Map();

return Far('Bundler', {
add: (name, encodedContent) => {
nameToContent.set(name, new Uint8Array(decodeBase64(encodedContent)));
preFilter,
/**
* @param {string} name
* @param {string} encodedContent
* @param {string} hash
*/
add: (name, encodedContent, hash) => {
assert.typeof(name, 'string');
assert.typeof(encodedContent, 'string');
assert.typeof(hash, 'string');
// TODO: verify hash
nameToContent.set(name, [
hash,
new Uint8Array(decodeBase64(encodedContent)),
]);
},
/**
* @param {string} name
* @param {string} hash
*/
addByRef: (name, hash) => {
const entry = hashToEntry.get(hash);
assert(entry, X`hash not found: ${q(hash)}`);
const [_n, content] = entry;
nameToContent.set(name, [hash, content]);
},
persist: () => {
for (const [name, [hash, content]] of nameToContent.entries()) {
hashToEntry.set(hash, [name, content]);
}
},
/** @param {{ moduleFormat: string}} bundleShell */
install: bundleShell => {
const writer = new ZipWriter();
for (const [name, content] of nameToContent.entries()) {
for (const [name, [_hash, content]] of nameToContent.entries()) {
writer.write(name, content);
}
const endoZipBase64 = encodeBase64(writer.snapshot());
Expand All @@ -26,8 +71,10 @@ export const start = () => {
},
});
};

const publicFacet = Far('endoCAS', {
makeBundler,
preFilter,
});

return harden({ publicFacet });
Expand Down
39 changes: 34 additions & 5 deletions packages/deploy-script-support/src/installInPieces.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,35 @@
import { E } from '@endo/far';
import { ZipReader } from '@endo/zip';
import { encodeBase64, decodeBase64 } from '@endo/base64';
import crypto from 'crypto';

const computeSha512 = bytes => {
const hash = crypto.createHash('sha512');
hash.update(bytes);
return hash.digest().toString('hex');
};

export const installInPieces = async (
bundle,
bundler,
{ maxBytesInFlight = 800_000, log = console.log } = {},
{ maxBytesInFlight = 800_000, log = console.log, persist = false } = {},
) => {
// It would be nice to detect evaluation errors early like this:
// await importBundle(bundle, { endowments });
// but importBundle only works inside SwingSet; checking here
// may run into stuff like VatData not being available.
const { endoZipBase64, ...bundleShell } = bundle;
const zip = new ZipReader(new Uint8Array(decodeBase64(endoZipBase64)));

const candidates = [];
for await (const [_name, entry] of zip.files.entries()) {
const hash = computeSha512(entry.content);
candidates.push(hash);
}
const preloaded = await E(bundler).preFilter(candidates);
log('preloaded', preloaded.length, 'out of', candidates.length);
const preloadSet = new Set(preloaded);

let approxBytesInFlight = 0;
let inFlightAdditions = [];
for await (const [name, entry] of zip.files.entries()) {
Expand All @@ -23,17 +43,26 @@ export const installInPieces = async (
inFlightAdditions = [];
}

log('adding', name, entry.content.length, '...');
const encodedContent = encodeBase64(entry.content);
approxBytesInFlight += name.length + encodedContent.length;
inFlightAdditions.push(E(bundler).add(name, encodedContent));
const hash = computeSha512(entry.content);
if (preloadSet.has(hash)) {
// log('preloaded', name, entry.content.length, '...');
approxBytesInFlight += name.length + hash.length;
inFlightAdditions.push(E(bundler).addByRef(name, hash));
} else {
log('adding', name, entry.content.length, '...');
const encodedContent = encodeBase64(entry.content);
approxBytesInFlight += name.length + encodedContent.length;
inFlightAdditions.push(E(bundler).add(name, encodedContent, hash));
}
}

log(
`waiting for ${inFlightAdditions.length} (~${approxBytesInFlight}B) final additions...`,
);
await Promise.all(inFlightAdditions);

await (persist && E(bundler).persist());

log('installing...');
const installation = await E(bundler).install(bundleShell);

Expand Down
14 changes: 10 additions & 4 deletions packages/deploy-script-support/src/writeCoreProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export const makeWriteCoreProposal = (
return mergePermits({ mergedPermits, additionalPermits });
};

let mutex = Promise.resolve();
const writeCoreProposal = async (filePrefix, proposalBuilder) => {
let mutex = Promise.resolve();
// Install an entrypoint.
const install = async (entrypoint, bundlePath) => {
const install = async (entrypoint, bundlePath, opts) => {
const bundler = getBundler();
let bundle;
if (bundlePath) {
Expand All @@ -68,13 +68,18 @@ export const makeWriteCoreProposal = (
}

// Serialise the installations.
mutex = mutex.then(() => installInPieces(bundle, bundler));
mutex = mutex.then(() => {
console.log('installing', { filePrefix, entrypoint, bundlePath });

return installInPieces(bundle, bundler, opts);
});
return mutex;
};

// Await a reference then publish to the board.
const publishRef = async refP => {
const ref = await refP;
console.log('published', { filePrefix, ref });
return E(board).getId(ref);
};

Expand All @@ -83,6 +88,7 @@ export const makeWriteCoreProposal = (
harden(proposalBuilder({ publishRef, install })),
);
const { sourceSpec, getManifestCall } = proposal;
console.log('created', { filePrefix, sourceSpec, getManifestCall });

// Extract the top-level permit.
const t = 'writeCoreProposal';
Expand All @@ -95,7 +101,7 @@ export const makeWriteCoreProposal = (

// Get an install
const manifestInstallRef = await publishRef(install(sourceSpec));

console.log('writing', { filePrefix, manifestInstallRef, sourceSpec });
const code = `\
// This is generated by writeCoreProposal; please edit!
/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,24 @@ test('installInPieces', async t => {
const installation = await installInPieces(endoPieces, bundler, {
log: t.log,
maxBytesInFlight: 200_000,
persist: true,
});

t.is(installation, 'INSTALLATION!');
t.deepEqual(installedBundle, endoPieces);

// preload from persisted entries
installedBundle = undefined;
const logged = [];
const install2 = await installInPieces(endoPieces, bundler, {
log: (...args) => {
logged.push(`${args[0]}`);
t.log(...args);
},
maxBytesInFlight: 200_000,
});
t.is(install2, 'INSTALLATION!');
const cacheMiss = logged.filter(s => s.match(/adding/));
t.is(cacheMiss.length, 0);
t.deepEqual(installedBundle, endoPieces);
});
5 changes: 3 additions & 2 deletions packages/vats/src/core/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,17 @@
/**
* @typedef {{
* issuer: |
* 'RUN' | 'BLD' | 'Attestation',
* 'RUN' | 'BLD' | 'Attestation' | 'AUSD',
* installation: |
* 'centralSupply' | 'mintHolder' |
* 'contractGovernor' | 'committee' | 'noActionElectorate' | 'binaryVoteCounter' |
* 'amm' | 'VaultFactory' | 'liquidate' | 'runStake' |
* 'Pegasus' | 'reserve',
* 'Pegasus' | 'reserve' | 'psm',
* instance: |
* 'economicCommittee' |
* 'amm' | 'ammGovernor' | 'VaultFactory' | 'VaultFactoryGovernor' |
* 'runStake' | 'runStakeGovernor' |
* 'psm' | 'psmGovernor' |
* 'Treasury' | 'reserve' | 'reserveGovernor' | 'Pegasus',
* oracleBrand:
* 'USD',
Expand Down
5 changes: 5 additions & 0 deletions packages/vats/src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export const agoricNamesReserved = harden({
BLD: 'Agoric staking token',
RUN: 'Agoric RUN currency',
Attestation: 'Agoric lien attestation',
AUSD: 'Agoric bridged USDC',
},
brand: {
BLD: 'Agoric staking token',
RUN: 'Agoric RUN currency',
Attestation: 'Agoric lien attestation',
AUSD: 'Agoric bridged USDC',
},
installation: {
centralSupply: 'central supply',
Expand All @@ -43,6 +45,7 @@ export const agoricNamesReserved = harden({
runStake: 'runStake',
Pegasus: 'pegasus',
reserve: 'collateral reserve',
psm: 'Parity Stability Module',
},
instance: {
economicCommittee: 'Economic Committee',
Expand All @@ -56,6 +59,8 @@ export const agoricNamesReserved = harden({
Pegasus: 'remote peg',
reserve: 'collateal reserve',
reserveGovernor: 'ReserveGovernor',
psm: 'Parity Stability Module',
psmGovernor: 'PSM Governor',
},
oracleBrand: {
USD: 'US Dollar',
Expand Down