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

zoe1 proposal #18

Merged
merged 5 commits into from
Nov 9, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
test-proposals:
runs-on: ubuntu-latest
# UNTIL https://github.com/Agoric/agoric-3-proposals/issues/2
timeout-minutes: 90
timeout-minutes: 120
steps:
- name: free up disk space
run: |
Expand Down
15 changes: 9 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,15 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# We preceed with wildcard to allow for yarn installs below root
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
**/.yarn/*
**/!.yarn/cache
**/!.yarn/patches
**/!.yarn/plugins
**/!.yarn/releases
**/!.yarn/sdks
**/!.yarn/versions

# build in CI
Dockerfile
3 changes: 2 additions & 1 deletion buildTestImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ for (const proposal of proposals) {
const cmd = `docker buildx build --load --tag ${name} --target ${target} .`;
console.log(cmd);
if (!dry) {
execSync(cmd, { stdio: 'inherit' });
// `time` to output how long each build takes
execSync(`time ${cmd}`, { stdio: 'inherit' });
}
}
Binary file removed proposals/34:upgrade-10/.yarn/install-state.gz
Binary file not shown.
Binary file removed proposals/43:upgrade-11/.yarn/install-state.gz
Binary file not shown.
Binary file not shown.
Binary file removed proposals/55:statom-vaults/.yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions proposals/b:zoe1/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
Copy link
Member

Choose a reason for hiding this comment

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

These yarn files are new to me, so I'm reading docs. I can't comment on the .gz file directly...

Why are we committing .yarn/install-state.gz?

.yarn/install-state.gz is an optimization file that you shouldn't ever have to commit
-- https://yarnpkg.com/getting-started/qa

Copy link
Member Author

@turadg turadg Nov 9, 2023

Choose a reason for hiding this comment

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

Thanks for catching that. The .gitignore does ignore it, but the pattern assumes .yarn dir will only be at root. https://github.com/yarnpkg/berry/blob/master/.gitignore

I could change the ignore but WDYT of having one yarn.lock for the repo and making all the other packages workspaces? I've shied away because under the existing structure the root package would have to be in /usr/src of the Docker image, which is icky. I could refactor so that proposals is under upgrade-test-scripts, next to lib, and then upgrade-test-scripts has the one root. Though it would still require changing the gitignore so I"ll probably just do that :)

Copy link
Member

Choose a reason for hiding this comment

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

one yarn.lock for the repo sounds attractive.

I am, as usual, reticent to move things around.

I guess don't feel strongly one way or the other. This repo is still young.

17 changes: 17 additions & 0 deletions proposals/b:zoe1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Proposal to upgrade Zoe to incarnation 1

This uses the Zoe in https://github.com/Agoric/agoric-sdk/pull/8453/

It's currently a draft proposal, built from that branch with,

```
# whatever your checkout
A3P=/opt/agoric/agoric-3-proposals
cd packages/builders
# build the proposal
agoric run scripts/vats/upgrade-zoe.js | tee run-report.txt
Copy link
Member

Choose a reason for hiding this comment

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

I'm not able to reproduce these bundles.

I get 1 bundle that matches but one that does not:

b1-b75c88c4a783b0a0fb2886fea6cf2fa0ced579d25f73cbe5f7d72e4dfdf2d2c06c014875726dc5fbaf2d586b2d4f975bb3a73ac3faaeb789e5b20d556b7a9623.json

b1-a3dc21c56535b4bebdf8c8413650eec2b37a6d9f5669b27f8c571601a6f641ffae2b925dd7e3d67c6953a1f8122c8ba814305e034c9087056816a6f05dd41069.json

# copy the proposal
cp upgrade-zoe* $A3P/proposals/b:zoe1/submission
# copy the bundles built for the proposal
cat run-report.txt | grep install-bundle | sed "s/agd tx swingset install-bundle @//" |xargs -I _ cp _ $A3P/proposals/b:zoe1/submission
```
3 changes: 3 additions & 0 deletions proposals/b:zoe1/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "/agoric.swingset.CoreEvalProposal"
}
152 changes: 152 additions & 0 deletions proposals/b:zoe1/core-eval-support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// @ts-check
import {
Far,
makeMarshal,
makeTranslationTable,
} from '../../upgrade-test-scripts/lib/unmarshal.js';
import { Fail, NonNullish } from '../../upgrade-test-scripts/lib/assert.js';

// TODO: factor out ambient authority from these
// or at least allow caller to supply authority.
Comment on lines +9 to +10
Copy link
Member Author

Choose a reason for hiding this comment

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

not my words! :)

future work #21

import { mintIST } from '../../upgrade-test-scripts/lib/econHelpers.js';
import { agoric } from '../../upgrade-test-scripts/lib/cliHelper.js';

// move to unmarshal.js?
const makeBoardUnmarshal = () => {
const synthesizeRemotable = (_slot, iface) =>
Far(iface.replace(/^Alleged: /, ''), {});

const { convertValToSlot, convertSlotToVal } = makeTranslationTable(
slot => Fail`unknown id: ${slot}`,
synthesizeRemotable,
);

return makeMarshal(convertValToSlot, convertSlotToVal);
};

export const getContractInfo = async (path, io = {}) => {
const m = makeBoardUnmarshal();
const {
agoric: { follow = agoric.follow },
prefix = 'published.',
} = io;
console.log('@@TODO: prevent agoric follow hang', prefix, path);
const txt = await follow('-lF', `:${prefix}${path}`, '-o', 'text');
const { body, slots } = JSON.parse(txt);
return m.fromCapData({ body, slots });
};

// not really core-eval related
export const testIncludes = (t, needle, haystack, label, sense = true) => {
t.log(needle, sense ? 'in' : 'not in', haystack.length, label, '?');
const check = sense ? t.deepEqual : t.notDeepEqual;
if (sense) {
t.deepEqual(
haystack.filter(c => c === needle),
[needle],
);
} else {
t.deepEqual(
haystack.filter(c => c === needle),
[],
);
}
};

/**
* @param {Record<string, string>} record - e.g. { color: 'blue' }
* @returns {string[]} - e.g. ['--color', 'blue']
*/
export const flags = record => {
return Object.entries(record)
.map(([k, v]) => [`--${k}`, v])
.flat();
};

export const txAbbr = tx => {
const { txhash, code, height, gas_used } = tx;
return { txhash, code, height, gas_used };
};

export const loadedBundleIds = swingstore => {
const ids = swingstore`SELECT bundleID FROM bundles`.map(r => r.bundleID);
return ids;
};

/**
* @param {string} cacheFn - e.g. /home/me.agoric/cache/b1-DEADBEEF.json
*/
export const bundleDetail = cacheFn => {
const fileName = NonNullish(cacheFn.split('/').at(-1));
const id = fileName.replace(/\.json$/, '');
const hash = id.replace(/^b1-/, '');
return { fileName, endoZipBase64Sha512: hash, id };
};

const importBundleCost = (bytes, price = 0.002) => {
return bytes * price;
};

/**
* @typedef {{
* bundles: string[],
* evals: { permit: string; script: string }[],
* }} ProposalInfo
*/

const myISTBalance = async (agd, addr, denom = 'uist', unit = 1_000_000) => {
const coins = await agd.query(['bank', 'balances', addr]);
const coin = coins.balances.find(a => a.denom === denom);
return Number(coin.amount) / unit;
};

/**
* @param {number} myIST
* @param {number} cost
* @param {{
* unit?: number, padding?: number, minInitialDebt?: number,
* collateralPrice: number,
* }} opts
* @returns
*/
const mintCalc = (myIST, cost, opts) => {
const {
unit = 1_000_000,
padding = 1,
minInitialDebt = 6,
collateralPrice,
} = opts;
const { round, max } = Math;
const wantMinted = max(round(cost - myIST + padding), minInitialDebt);
const giveCollateral = round(wantMinted / collateralPrice) + 1;
const sendValue = round(giveCollateral * unit);
return { wantMinted, giveCollateral, sendValue };
};

/**
*
* @param {ReturnType<typeof import('../lib/agd-lib.js').makeAgd>} agd
* @param {*} config
* @param {number} bytes total bytes
* @param {{ log: (...args: any[]) => void }} io
* @returns
*/
export const ensureISTForInstall = async (agd, config, bytes, { log }) => {
const cost = importBundleCost(bytes);
log({ totalSize: bytes, cost });
const { installer } = config;
const addr = agd.lookup(installer);
const istBalance = await myISTBalance(agd, addr);

if (istBalance > cost) {
log('balance sufficient', { istBalance, cost });
return;
}
const { sendValue, wantMinted, giveCollateral } = mintCalc(
istBalance,
cost,
config,
);
log({ wantMinted });
await mintIST(addr, sendValue, wantMinted, giveCollateral);
};
15 changes: 15 additions & 0 deletions proposals/b:zoe1/eval.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Exit when any command fails
set -e

source /usr/src/upgrade-test-scripts/env_setup.sh

ls -al

npm install --global tsx

./performActions.ts

# let CORE_EVAL settle
waitForBlock 5
15 changes: 15 additions & 0 deletions proposals/b:zoe1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "module",
"license": "Apache-2.0",
"dependencies": {
"@endo/zip": "^0.2.35",
"ava": "^5.3.1",
"better-sqlite3": "^8.5.1",
"execa": "^7.2.0",
"tmp": "^0.2.1"
},
"scripts": {
"agops": "yarn --cwd /usr/src/agoric-sdk/ --silent agops"
dckc marked this conversation as resolved.
Show resolved Hide resolved
},
"packageManager": "yarn@4.0.1"
}
Loading