Skip to content

Commit

Permalink
Merge pull request #7793 from Agoric/dc-zoe-system-upgrade
Browse files Browse the repository at this point in the history
test: zoe null upgrade by swingset.CoreEval governance decision
  • Loading branch information
dckc authored and mhofman committed Aug 7, 2023
2 parents 0e45850 + 39d50ee commit 60c841c
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

. ./upgrade-test-scripts/env_setup.sh

# Core-eval contract upgrade
# CWD is agoric-sdk
here=./upgrade-test-scripts/agoric-upgrade-11

# run zoe thru "null upgrade"
$here/zoe-upgrade/zoe-upgrade-driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

. ./upgrade-test-scripts/env_setup.sh

echo Wait for upgrade to settle
waitForBlock 5

# CWD is agoric-sdk
here=./upgrade-test-scripts/agoric-upgrade-11

# zoe vat is at incarnation 0
test_val "$(yarn --silent node $here/zoe-upgrade/vat-status.mjs zoe)" "0" "zoe vat incarnation"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

. ./upgrade-test-scripts/env_setup.sh

echo Wait for actions to settle
waitForBlock 2

# CWD is agoric-sdk
here=./upgrade-test-scripts/agoric-upgrade-11

# zoe vat is at incarnation 1
test_val "$(yarn --silent node $here/zoe-upgrade/vat-status.mjs zoe)" "1" "zoe vat incarnation"
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// @ts-check
import processAmbient from 'process';
import dbOpenAmbient from 'better-sqlite3';

/**
* @file look up vat incarnation from kernel DB
* @see {main}
*/

const swingstorePath = '~/.agoric/data/agoric/swingstore.sqlite';

/**
* SQL short-hand
*
* @param {import('better-sqlite3').Database} db
*/
const dbTool = db => {
const prepare = (strings, ...params) => {
const dml = strings.join('?');
return { stmt: db.prepare(dml), params };
};
const sql = (strings, ...args) => {
const { stmt, params } = prepare(strings, ...args);
return stmt.all(...params);
};
sql.get = (strings, ...args) => {
const { stmt, params } = prepare(strings, ...args);
return stmt.get(...params);
};
return sql;
};

/**
* @param {import('better-sqlite3').Database} db
*/
const makeSwingstore = db => {
const sql = dbTool(db);

/** @param {string} key */
const kvGet = key => sql.get`select * from kvStore where key = ${key}`.value;
/** @param {string} key */
const kvGetJSON = key => JSON.parse(kvGet(key));

/** @param {string} vatID */
const lookupVat = vatID => {
return Object.freeze({
source: () => kvGetJSON(`${vatID}.source`),
options: () => kvGetJSON(`${vatID}.options`),
currentSpan: () =>
sql.get`select * from transcriptSpans where isCurrent = 1 and vatID = ${vatID}`,
});
};

return Object.freeze({
/** @param {string} vatName */
findVat: vatName => {
/** @type {string[]} */
const dynamicIDs = kvGetJSON('vat.dynamicIDs');
const targetVat = dynamicIDs.find(
vatID => lookupVat(vatID).options().name === vatName,
);
if (!targetVat) throw Error(vatName);
return targetVat;
},
lookupVat,
});
};

/** @type {<T>(val: T | undefined) => T} */
const NonNullish = val => {
if (!val) throw Error('required');
return val;
};

/**
* @param {string[]} argv
* @param {{ dbOpen: typeof import('better-sqlite3'), HOME?: string }} io
*/
const main = async (argv, { dbOpen, HOME }) => {
const [_node, _script, vatName] = argv;
if (!vatName) throw Error('vatName required');

const fullPath = swingstorePath.replace(/^~/, NonNullish(HOME));
const kStore = makeSwingstore(dbOpen(fullPath, { readonly: true }));

const vatID = kStore.findVat(vatName);
const vatInfo = kStore.lookupVat(vatID);

const source = vatInfo.source();
const { incarnation } = vatInfo.currentSpan();

// misc info to stderr
console.error(JSON.stringify({ vatName, vatID, incarnation, ...source }));

// incarnation to stdout
console.log(incarnation);
};

main(processAmbient.argv, {
dbOpen: dbOpenAmbient,
HOME: processAmbient.env.HOME,
}).catch(err => {
console.error(err);
processAmbient.exit(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

. ./upgrade-test-scripts/env_setup.sh

set -euo pipefail

here='upgrade-test-scripts/agoric-upgrade-11/zoe-upgrade'

agd --chain-id=agoriclocal \
tx gov submit-proposal swingset-core-eval \
${here}/zoe-upgrade-permit.json ${here}/zoe-upgrade-script.js \
--title="Zoe Upgrade" --description="zoe upgrade test" \
--deposit=10000000ubld \
--gas=auto --gas-adjustment=1.2 \
--yes -o json --from=validator --keyring-backend=test -b block

agd --chain-id=agoriclocal query gov proposals --output json | \
jq -c '.proposals[] | [.proposal_id,.voting_end_time,.status]';

voteLatestProposalAndWait

# then tes some stuff???
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"consume": {
"vatStore": true,
"vatAdminSvc": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @ts-no-check
/* global E */

// to turn on ts-check:
// Xmport { E } from '@endo/far';

console.info('zoe upgrade: evaluating script');

/**
* Test "upgrading" zoe.
* It's a so-called "null" upgrade, since we don't mean to change the code.
* This (re-)uses the code originally bundled at swingset bootstrap.
*
* @param { BootstrapPowers } powers
*/
const restartZoe = async powers => {
console.info('restartZoe()');
const {
consume: { vatStore, vatAdminSvc },
} = powers;
console.info('restartZoe - destructured powers');

const bundleName = 'zoe';
const bundleCap = await E(vatAdminSvc).getNamedBundleCap(bundleName);
const { adminNode } = await E(vatStore).get('zoe');
console.info('restartZoe', { bundleName, bundleCap, adminNode });

const result = await E(adminNode).upgrade(bundleCap, {});
console.info('restartZoe', { result });
};

restartZoe;

0 comments on commit 60c841c

Please sign in to comment.