From c2c9be3785f50e3b2cae3585d0e05d8b0a918283 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Thu, 19 Dec 2024 13:39:39 -0800 Subject: [PATCH 1/2] feat: save the outgoing EC Charter instance and kit --- .../testing/recorded-retired-instances.js | 6 ++ .../src/proposals/replaceElectorate.js | 83 ++++++++++++++++--- 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/packages/builders/scripts/testing/recorded-retired-instances.js b/packages/builders/scripts/testing/recorded-retired-instances.js index 2dae21fd4af..4b0bdf17034 100644 --- a/packages/builders/scripts/testing/recorded-retired-instances.js +++ b/packages/builders/scripts/testing/recorded-retired-instances.js @@ -36,6 +36,12 @@ export const testRecordedRetiredInstances = async ({ const committeeInstance = retiredContractInstances.get(committeeIDs[0]); assert(await E(contractKits).get(committeeInstance)); + const charterIDs = Array.from(retiredContractInstances.keys()).filter(k => + k.startsWith('econCommitteeCharter'), + ); + assert(charterIDs); + assert(charterIDs.length === 1); + trace('done'); }; harden(testRecordedRetiredInstances); diff --git a/packages/inter-protocol/src/proposals/replaceElectorate.js b/packages/inter-protocol/src/proposals/replaceElectorate.js index adde9adf747..301566f66b9 100644 --- a/packages/inter-protocol/src/proposals/replaceElectorate.js +++ b/packages/inter-protocol/src/proposals/replaceElectorate.js @@ -289,33 +289,87 @@ const startNewEconomicCommittee = async ( * Starts a new Economic Committee Charter by creating an instance with the * provided committee specifications. * - * @param {EconomyBootstrapPowers} powers - The resources and capabilities - * required to start the committee. + * @param {EconomyBootstrapPowers & + * PromiseSpaceOf<{ retiredContractInstances: MapStore }>} powers + * - The resources and capabilities required to start the committee. + * * @returns {Promise} A promise that resolves to the * charter kit result. */ const startNewEconCharter = async ({ - consume: { startUpgradable }, - produce: { econCharterKit }, + consume: { + board, + startUpgradable, + contractKits: contractKitsP, + econCharterKit: econCharterKitP, + retiredContractInstances: retiredContractInstancesP, + }, + produce: { + econCharterKit: produceEconCharterKit, + retiredContractInstances: produceRetiredInstances, + }, installation: { consume: { binaryVoteCounter: counterP, econCommitteeCharter: installP }, }, instance: { produce: { econCommitteeCharter }, + consume: { econCommitteeCharter: previousInstanceP }, }, }) => { - const [charterInstall, counterInstall] = await Promise.all([ + const [ + charterInstall, + counterInstall, + previousInstance, + contractKits, + econCharterKit, + retiredInstances, + ] = await Promise.all([ installP, counterP, + previousInstanceP, + contractKitsP, + econCharterKitP, + provideRetiredInstances(retiredContractInstancesP, produceRetiredInstances), ]); - const terms = await harden({ - binaryVoteCounterInstallation: counterInstall, - }); + + const label = 'econCommitteeCharter'; + const previousCharterKit = { label, ...econCharterKit }; + + const boardID = await E(board).getId(previousCharterKit.instance); + const identifier = `${label}-${boardID}`; + trace('Saving previous EC Charter Instance', label); + + // save the old charter instance kit so we can manage it later + if (retiredInstances.has(identifier)) { + // bootstrap tests start having already run this upgrade. Actual upgrades on + // mainNet or testnets should start with the promiseSpace post upgrade-17, + // which doesn't have this entry in the map. + trace( + '⚠️ WARNING: collision on storing Charter in retireInstances not' + + ' expected during chain upgrade. It IS normal during bootstrap tests', + ); + } else { + retiredInstances.init(identifier, previousCharterKit.instance); + } + if (contractKits.has(previousInstance)) { + // bootstrap tests start having already run this upgrade. Actual upgrades on + // mainNet or testnets should start with the promiseSpace post upgrade-17, + // which doesn't have this entry in the map. + trace( + '⚠️ WARNING: collision on storing Charter in contractKits not' + + ' expected during chain upgrade. It IS normal during bootstrap tests', + ); + } else { + contractKits.init(previousInstance, previousCharterKit); + } trace('Starting new EC Charter Instance'); + const terms = await harden({ + binaryVoteCounterInstallation: counterInstall, + }); const startResult = await E(startUpgradable)({ - label: 'econCommitteeCharter', + label, installation: charterInstall, terms, }); @@ -325,8 +379,8 @@ const startNewEconCharter = async ({ econCommitteeCharter.reset(); econCommitteeCharter.resolve(E.get(startResult).instance); - econCharterKit.reset(); - econCharterKit.resolve(startResult); + produceEconCharterKit.reset(); + produceEconCharterKit.resolve(startResult); return startResult; }; @@ -515,6 +569,8 @@ export const getManifestForReplaceAllElectorates = async ( auctionUpgradeNewGovCreator: true, auctionUpgradeNewInstance: true, psmKit: true, + contractKits: true, + econCharterKit: true, governedContractKits: true, chainStorage: true, highPrioritySendersManager: true, @@ -543,7 +599,10 @@ export const getManifestForReplaceAllElectorates = async ( economicCommittee: true, econCommitteeCharter: true, }, - consume: { economicCommittee: true }, + consume: { + economicCommittee: true, + econCommitteeCharter: true, + }, }, }, }, From 355a2e18e11eba3bf90fa7ef2cf990d39dd7f8f0 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Fri, 20 Dec 2024 13:19:39 -0800 Subject: [PATCH 2/2] chore: from review: add trace, minor cleanups --- .../builders/scripts/testing/recorded-retired-instances.js | 5 ++++- packages/inter-protocol/src/proposals/replaceElectorate.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/builders/scripts/testing/recorded-retired-instances.js b/packages/builders/scripts/testing/recorded-retired-instances.js index 4b0bdf17034..1f37e892a0d 100644 --- a/packages/builders/scripts/testing/recorded-retired-instances.js +++ b/packages/builders/scripts/testing/recorded-retired-instances.js @@ -33,14 +33,17 @@ export const testRecordedRetiredInstances = async ({ ); assert(committeeIDs); assert(committeeIDs.length === 1); + trace('found committeeIDs', committeeIDs); + const committeeInstance = retiredContractInstances.get(committeeIDs[0]); assert(await E(contractKits).get(committeeInstance)); - const charterIDs = Array.from(retiredContractInstances.keys()).filter(k => + const charterIDs = [...retiredContractInstances.keys()].filter(k => k.startsWith('econCommitteeCharter'), ); assert(charterIDs); assert(charterIDs.length === 1); + trace('found charterID', charterIDs); trace('done'); }; diff --git a/packages/inter-protocol/src/proposals/replaceElectorate.js b/packages/inter-protocol/src/proposals/replaceElectorate.js index 301566f66b9..efaa4ccd0b1 100644 --- a/packages/inter-protocol/src/proposals/replaceElectorate.js +++ b/packages/inter-protocol/src/proposals/replaceElectorate.js @@ -333,7 +333,7 @@ const startNewEconCharter = async ({ ]); const label = 'econCommitteeCharter'; - const previousCharterKit = { label, ...econCharterKit }; + const previousCharterKit = { ...econCharterKit, label }; const boardID = await E(board).getId(previousCharterKit.instance); const identifier = `${label}-${boardID}`; @@ -365,7 +365,7 @@ const startNewEconCharter = async ({ trace('Starting new EC Charter Instance'); - const terms = await harden({ + const terms = harden({ binaryVoteCounterInstallation: counterInstall, }); const startResult = await E(startUpgradable)({