Skip to content

Commit

Permalink
chore: Add post-upgrade core-eval proposal for terminating v26 zcf-b1…
Browse files Browse the repository at this point in the history
…-9f877-ATOM-USD_price_feed-governor

Discovery of magic value "board02963":
```
sqlite> SELECT json_extract(value, '$.name') AS name FROM kvStore WHERE key='v26.options';
zcf-b1-9f877-ATOM-USD_price_feed-governor

sqlite> SELECT * FROM kvStore WHERE key >= 'v2.' AND key < 'v2/' AND value LIKE '%v26%';
v2.vs.vom.o+d13/21|{"vatID":{"body":"#\"v26\"","slots":[]}}

sqlite> SELECT * FROM kvStore WHERE key='v2.c.o+d13/21'; -- v26 admin node
v2.c.o+d13/21|ko326

sqlite> SELECT * FROM kvStore WHERE key='v9.c.ko326';
v9.c.ko326|R o-142

sqlite> SELECT * FROM kvStore WHERE key >= 'v9.' AND key < 'v9/' AND value LIKE '%o-142%';
v9.c.ko326|R o-142
v9.vs.vom.o+d26/14|{"instanceState":{"body":"#\"$0.Alleged: InstanceRecord\"","slots":["o+d27/14"]},"adminNode":{"body":"#\"$0.Alleged: adminNode\"","slots":["o-142"]},"root":{"body":"#\"$0.Alleged: undefined\"","slots":["o-143"]},"functions":{"body":"#\"#undefined\"","slots":[]}}
v9.vs.vom.o+d33/14|{"offerFilterStrings":{"body":"#[]","slots":[]},"publicFacet":{"body":"#\"$0.Alleged: ContractGovernorKit public\"","slots":["o-181"]},"handleOfferObj":{"body":"#\"$0.Alleged: handleOfferObj\"","slots":["o-180"]},"zoeInstanceStorageManager":{"body":"#\"$0.Alleged: InstanceStorageManager instanceStorageManager\"","slots":["o+d26/14:1"]},"seatHandleToZoeSeatAdmin":{"body":"#\"$0.Alleged: weakMapStore\"","slots":["o+d7/24"]},"instanceHandle":{"body":"#\"$0.Alleged: InstanceHandle\"","slots":["o+d29/14"]},"acceptingOffers":{"body":"#true","slots":[]},"zoeSeatAdmins":{"body":"#\"$0.Alleged: setStore\"","slots":["o+d8/56"]},"adminNode":{"body":"#\"$0.Alleged: adminNode\"","slots":["o-142"]}}
v9.vs.vom.o+d34/14|{"instanceStorage":{"body":"#\"$0.Alleged: InstanceStorageManager instanceStorageManager\"","slots":["o+d26/14:1"]},"instanceAdmin":{"body":"#\"$0.Alleged: instanceAdmin instanceAdmin\"","slots":["o+d33/14:1"]},"seatHandleToSeatAdmin":{"body":"#\"$0.Alleged: weakMapStore\"","slots":["o+d7/24"]},"adminNode":{"body":"#\"$0.Alleged: adminNode\"","slots":["o-142"]}}
v9.vs.vom.o+d37/14|{"adminNode":{"body":"#\"$0.Alleged: adminNode\"","slots":["o-142"]},"zcfBundleCap":{"body":"#\"$0.Alleged: device node\"","slots":["d-70"]},"contractBundleCap":{"body":"#\"$0.Alleged: device node\"","slots":["d-75"]}}

sqlite> SELECT * FROM kvStore WHERE key='v9.c.o+d37/14'; -- Zoe contract instance admin facet
v9.c.o+d37/14|ko396

sqlite> SELECT * FROM kvStore WHERE key >= 'v1' AND key < 'v:' AND substr(key, -length('.c.ko396')) = '.c.ko396' AND key LIKE 'v%.c.ko396';
v1.c.ko396|R o-264
v9.c.ko396|R o+d37/14

sqlite> SELECT * FROM kvStore WHERE key >= 'v1.' AND key < 'v1/' AND value LIKE '%o-264%';
v1.c.ko396|R o-264
v1.vs.vc.8.r0000000001:o-268|{"body":"#{\"adminFacet\":\"$0.Alleged: adminFacet\",\"creatorFacet\":\"$1.Alleged: fluxAggregator creator\",\"governor\":\"$2.Alleged: InstanceHandle\",\"governorAdminFacet\":\"$3.Alleged: adminFacet\",\"governorCreatorFacet\":\"$4.Alleged: ContractGovernorKit creator\",\"instance\":\"$5.Alleged: InstanceHandle\",\"label\":\"ATOM-USD_price_feed\",\"publicFacet\":\"$6.Alleged: fluxAggregator public\"}","slots":["o-271","o-270","o-266","o-264","o-265","o-268","o-269"]}

sqlite> SELECT * FROM kvStore WHERE key >= 'v1.' AND key < 'v1/' AND value GLOB '*"o+??/8"*';
v1.vs.vc.1.sGovernedContractKits|{"body":"#\"$0.Alleged: mapStore\"","slots":["o+d6/8"]}
v1.vs.vc.5.sgovernedContractKits|{"body":"#\"$0.Alleged: mapStore\"","slots":["o+d6/8"]}

sqlite> SELECT * FROM kvStore WHERE key >= 'v1.' AND key < 'v1/' AND value GLOB '*"o+??/5"*';
v1.vs.vc.1.sBootstrap Powers|{"body":"#\"$0.Alleged: mapStore\"","slots":["o+d6/5"]}
v1.vs.vc.5.spowerStore|{"body":"#\"$0.Alleged: mapStore\"","slots":["o+d6/5"]}

sqlite> -- v1 bootstrap virtual collection 5 is "Bootstrap Powers" exposed to core eval scripts

sqlite> -- in that collection is "governedContractKits", which contains our contract instance kit by key o-268

sqlite> SELECT * FROM kvStore WHERE key='v1.c.o-268';
v1.c.o-268|ko352

sqlite> SELECT * FROM kvStore WHERE key >= 'v1' AND key < 'v:' AND substr(key, -length('.c.ko352')) = '.c.ko352' AND key LIKE 'v%.c.ko352';
v1.c.ko352|R o-268
v15.c.ko352|R o-59
v26.c.ko352|R o-71
v29.c.ko352|R o-54
v43.c.ko352|R o-104
v6.c.ko352|R o-121
v7.c.ko352|R o-124
v9.c.ko352|R o+d29/17

sqlite> SELECT * FROM kvStore WHERE key >= 'v7.' AND key < 'v7/' AND value LIKE '%o-124%';
v7.c.ko352|R o-124
v7.vs.vc.5.sboard02963|{"body":"#\"$0.Alleged: InstanceHandle\"","slots":["o-124"]}
v7.vs.vom.o+d11/5|{"valueDurability":{"body":"#\"mandatory\"","slots":[]},"publishCount":{"body":"#\"+29\"","slots":[]},"status":{"body":"#\"live\"","slots":[]},"hasValue":{"body":"#true","slots":[]},"value":{"body":"#[[\"ATOM-USD price feed\",\"$0.Alleged: InstanceHandle\"],[\"Crabble\",\"$1.Alleged: InstanceHandle\"],[\"CrabbleCommittee\",\"$2.Alleged: InstanceHandle\"],[\"CrabbleGovernor\",\"$3.Alleged: InstanceHandle\"],[\"VaultFactory\",\"$4.Alleged: InstanceHandle\"],[\"VaultFactoryGovernor\",\"$5.Alleged: InstanceHandle\"],[\"auctioneer\",\"$6.Alleged: InstanceHandle\"],[\"econCommitteeCharter\",\"$7.Alleged: InstanceHandle\"],[\"economicCommittee\",\"$8.Alleged: InstanceHandle\"],[\"feeDistributor\",\"$9.Alleged: InstanceHandle\"],[\"kread\",\"$10.Alleged: InstanceHandle\"],[\"kreadCommittee\",\"$11.Alleged: InstanceHandle\"],[\"kreadCommitteeCharter\",\"$12.Alleged: InstanceHandle\"],[\"provisionPool\",\"$13.Alleged: InstanceHandle\"],[\"psm-IST-DAI_axl\",\"$14.Alleged: InstanceHandle\"],[\"psm-IST-DAI_grv\",\"$15.Alleged: InstanceHandle\"],[\"psm-IST-USDC_axl\",\"$16.Alleged: InstanceHandle\"],[\"psm-IST-USDC_grv\",\"$17.Alleged: InstanceHandle\"],[\"psm-IST-USDT_axl\",\"$18.Alleged: InstanceHandle\"],[\"psm-IST-USDT_grv\",\"$19.Alleged: InstanceHandle\"],[\"reserve\",\"$20.Alleged: InstanceHandle\"],[\"reserveGovernor\",\"$21.Alleged: InstanceHandle\"],[\"scaledPriceAuthority-stATOM\",\"$22.Alleged: InstanceHandle\"],[\"stATOM-USD price feed\",\"$23.Alleged: InstanceHandle\"],[\"walletFactory\",\"$24.Alleged: InstanceHandle\"]]","slots":["o-124","o-183","o-178","o-184","o-121","o-134","o-193","o-122","o-105","o-123","o-167","o-163","o-160","o-125","o-128","o-129","o-130","o-131","o-132","o-133","o-119","o-126","o-176","o-175","o-127"]}}

sqlite> -- our Bootstrap Powers key (v1:o-268/ko352/v7:o-124) can be retrieved from the board with key "board02963"
```
  • Loading branch information
gibson042 committed Dec 23, 2024
1 parent 3693637 commit 7240276
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 1 deletion.
2 changes: 2 additions & 0 deletions a3p-integration/proposals/n:upgrade-next/initial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const vats = {
transfer: { incarnation: 1 },
walletFactory: { incarnation: 5 },
zoe: { incarnation: 3 },
// Terminated in a future proposal.
'-ATOM-USD_price_feed-governor': { incarnation: 0 },
};

test(`vat details`, async t => {
Expand Down
3 changes: 2 additions & 1 deletion a3p-integration/proposals/p:upgrade-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"vats/upgrade-agoricNames.js agoricNamesCoreEvals/upgradeAgoricNames",
"testing/add-USD-OLIVES.js agoricNamesCoreEvals/addUsdOlives",
"testing/publish-test-info.js agoricNamesCoreEvals/publishTestInfo",
"vats/upgrade-mintHolder.js upgrade-mintHolder A3P_INTEGRATION"
"vats/upgrade-mintHolder.js upgrade-mintHolder A3P_INTEGRATION",
"vats/terminate-governor-instance.js terminate-governor board02963:ATOM-USD_price_feed"
]
},
"type": "module",
Expand Down
19 changes: 19 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/terminateGovernor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'ava';
import '@endo/init/debug.js';

import { getDetailsMatchingVats } from './vatDetails.js';

test('verify governor termination', async t => {
const details = await getDetailsMatchingVats(
'-ATOM-USD_price_feed-governor',
true,
);
t.log(details);
if (details.length === 0) {
// Cleanup already done.
t.pass();
return;
}
t.is(details.length, 1);
t.true(details[0].terminated);
});
1 change: 1 addition & 0 deletions a3p-integration/proposals/p:upgrade-19/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

yarn ava terminateGovernor.test.js
yarn ava replaceFeeDistributor.test.js
yarn ava upgradedBoard.test.js
yarn ava mintHolder.test.js
Expand Down
129 changes: 129 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/vatDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Temporary fork of
// https://github.com/Agoric/agoric-3-proposals/blob/main/packages/synthetic-chain/src/lib/vat-status.js
// for deleted vat information.
// See https://github.com/Agoric/agoric-3-proposals/issues/208
/* eslint-env node */

import dbOpenAmbient from 'better-sqlite3';

const HOME = process.env.HOME;

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

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

const swingstorePath = `${HOME}/.agoric/data/agoric/swingstore.sqlite`;

/**
* SQL short-hand
*
* @param {import('better-sqlite3').Database} db
*/
export 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 */
// @ts-expect-error cast
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}`,
getTerminated: () => kvGetJSON('vats.terminated').includes(vatID),
});
};

/**
* @param {string} vatName
* @param {boolean} [includeTerminated]
* @returns {string[]}
*/
const findDynamicVatIDs = (vatName, includeTerminated = false) => {
/** @type {string[]} */
const terminatedVatIDs = kvGetJSON('vats.terminated');
/** @type {string[]} */
const allDynamicIDs = kvGetJSON('vat.dynamicIDs');
const dynamicIDs = includeTerminated
? allDynamicIDs
: allDynamicIDs.filter(vatID => !terminatedVatIDs.includes(vatID));
const matchingIDs = dynamicIDs.filter(vatID =>
lookupVat(vatID).options().name.includes(vatName),
);
return matchingIDs;
};

return Object.freeze({
/**
* @param {string} vatName
* @param {boolean} [includeTerminated]
* @returns {string}
*/
findVat: (vatName, includeTerminated = false) => {
/** @type {string[]} */
const matchingIDs = findDynamicVatIDs(vatName, includeTerminated);
if (matchingIDs.length === 0) throw Error(`vat not found: ${vatName}`);
return matchingIDs[0];
},
findVats: findDynamicVatIDs,
lookupVat,
});
};

/**
* @param {string} vatName
* @param {boolean} [includeTerminated]
*/
export const getDetailsMatchingVats = async (
vatName,
includeTerminated = false,
) => {
const kStore = makeSwingstore(
dbOpenAmbient(swingstorePath, { readonly: true }),
);

const vatIDs = kStore.findVats(vatName, includeTerminated);
const infos = [];
for (const vatID of vatIDs) {
const vatInfo = kStore.lookupVat(vatID);
const name = vatInfo.options().name;
const source = vatInfo.source();
const terminated = includeTerminated && vatInfo.getTerminated();
// @ts-expect-error cast
const { incarnation } = vatInfo.currentSpan();
infos.push({ vatName: name, vatID, incarnation, terminated, ...source });
}

return infos;
};

0 comments on commit 7240276

Please sign in to comment.