Skip to content

Commit

Permalink
feat: record instances that will be replaced so we can manage them
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Dec 11, 2024
1 parent 34f026b commit 09465d3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/inter-protocol/src/proposals/add-auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const trace = makeTracer('NewAuction', true);
* auctionUpgradeNewInstance: Instance;
* auctionUpgradeNewGovCreator: any;
* newContractGovBundleId: string;
* retiredContractInstances: MapStore<string, Instance>;
* }>} interlockPowers
*/

Expand All @@ -35,6 +36,7 @@ export const addAuction = async (
economicCommitteeCreatorFacet: electorateCreatorFacet,
governedContractKits: governedContractKitsP,
priceAuthority8400,
retiredContractInstances: retiredContractInstancesP,
zoe,
},
produce: {
Expand Down Expand Up @@ -79,6 +81,10 @@ export const addAuction = async (
auctioneerInstallationP,
]);

// save the auctioneer instance so we can manage it later
const retiredContractInstances = await retiredContractInstancesP;
retiredContractInstances.init('auction-vat157', legacyKit.instance);

// Each field has an extra layer of type + value:
// AuctionStartDelay: { type: 'relativeTime', value: { relValue: 2n, timerBrand: Object [Alleged: timerBrand] {} } }
/** @type {any} */
Expand Down Expand Up @@ -210,6 +216,7 @@ export const ADD_AUCTION_MANIFEST = harden({
economicCommitteeCreatorFacet: true,
governedContractKits: true,
priceAuthority8400: true,
retiredContractInstances: true,
zoe: true,
},
produce: {
Expand Down
20 changes: 17 additions & 3 deletions packages/inter-protocol/src/proposals/deploy-price-feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const ensureOracleBrand = async (
};

/**
* @param {EconomyBootstrapPowers} powers
* @param {EconomyBootstrapPowers &
* PromiseSpaceOf<{ retiredContractInstances: MapStore<string, Instance> }>} powers
* @param {{
* AGORIC_INSTANCE_NAME: string;
* contractTerms: import('@agoric/inter-protocol/src/price/fluxAggregatorKit.js').ChainlinkConfig;
Expand All @@ -103,8 +104,9 @@ const startPriceAggregatorInstance = async (
highPrioritySendersManager,
namesByAddressAdmin,
startGovernedUpgradable,
retiredContractInstances: retiredContractInstancesP,
},
instance: { produce: produceInstance },
instance: { produce: produceInstance, consume: consumeInstance },
},
{ AGORIC_INSTANCE_NAME, contractTerms, brandIn, brandOut },
installation,
Expand Down Expand Up @@ -139,6 +141,15 @@ const startPriceAggregatorInstance = async (
// @ts-expect-error GovernableStartFn vs. fluxAggregatorContract.js start
installation,
});
const retiringInstance = consumeInstance[AGORIC_INSTANCE_NAME];
const retiredContractInstances = await retiredContractInstancesP;
retiredContractInstances.init(
// XXX tail of label needs to vary with upgrade. BundleId would be different
// from previous, but is not necessarily unique.
`priceFeed-${AGORIC_INSTANCE_NAME}-u18`,
retiringInstance,
);

produceInstance[AGORIC_INSTANCE_NAME].reset();
produceInstance[AGORIC_INSTANCE_NAME].resolve(governedKit.instance);
trace(
Expand Down Expand Up @@ -191,7 +202,9 @@ const distributeInvitations = async (
};

/**
* @param {EconomyBootstrapPowers & NamedVatPowers} powers
* @param {EconomyBootstrapPowers &
* NamedVatPowers &
* PromiseSpaceOf<{ retiredContractInstances: MapStore<string, Instance> }>} powers
* @param {{
* options: PriceFeedConfig & {
* priceAggregatorRef: { bundleID: string };
Expand Down Expand Up @@ -307,6 +320,7 @@ export const getManifestForPriceFeeds = async (
installation: { produce: { priceAggregator: t } },
instance: {
produce: t,
consume: t,
},
oracleBrand: { produce: t },
produce: { priceAuthority8400: t },
Expand Down
26 changes: 23 additions & 3 deletions packages/inter-protocol/src/proposals/replaceElectorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
assertPathSegment,
makeStorageNodeChild,
} from '@agoric/internal/src/lib-chainStorage.js';
import { makeScalarBigMapStore } from '@agoric/vat-data';
import { reserveThenDeposit } from './utils.js';

/** @import {EconomyBootstrapPowers} from './econ-behaviors.js' */
Expand Down Expand Up @@ -181,8 +182,10 @@ const inviteToEconCharter = async (
* Starts a new Economic Committee (EC) 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<string, Instance> }>} powers
* - The resources and capabilities required to start the committee.
*
* @param {{
* options: {
* committeeName: string;
Expand All @@ -197,11 +200,16 @@ const inviteToEconCharter = async (
const startNewEconomicCommittee = async (
{
consume: { board, chainStorage, startUpgradable },
produce: { economicCommitteeKit, economicCommitteeCreatorFacet },
produce: {
economicCommitteeKit,
economicCommitteeCreatorFacet,
retiredContractInstances,
},
installation: {
consume: { committee },
},
instance: {
consume: { economicCommittee: economicCommitteeOriginalP },
produce: { economicCommittee },
},
},
Expand All @@ -214,6 +222,15 @@ const startNewEconomicCommittee = async (
trace(`committeeName ${committeeName}`);
trace(`committeeSize ${committeeSize}`);

// Record the retired electorate vat so we can manage it later.
const contractInstanceMap = makeScalarBigMapStore(
'retiredContractInstances',
{ durable: true },
);
const econeconomicCommitteeOriginal = await economicCommitteeOriginalP;
contractInstanceMap.init('electorate-v24', econeconomicCommitteeOriginal);
retiredContractInstances.resolve(contractInstanceMap);

const committeesNode = await makeStorageNodeChild(
chainStorage,
COMMITTEES_ROOT,
Expand Down Expand Up @@ -309,6 +326,7 @@ const startNewEconCharter = async ({
* @typedef {PromiseSpaceOf<{
* auctionUpgradeNewInstance: Instance;
* auctionUpgradeNewGovCreator: any;
* retiredContractInstances: MapStore<string, Instance>;
* }>} interlockPowers
*/

Expand Down Expand Up @@ -492,6 +510,7 @@ export const getManifestForReplaceAllElectorates = async (
chainStorage: true,
highPrioritySendersManager: true,
namesByAddressAdmin: true,
retiredContractInstances: true,
// Rest of these are designed to be widely shared
board: true,
startUpgradable: true,
Expand All @@ -514,6 +533,7 @@ export const getManifestForReplaceAllElectorates = async (
economicCommittee: true,
econCommitteeCharter: true,
},
consume: { economicCommittee: true },
},
},
},
Expand Down

0 comments on commit 09465d3

Please sign in to comment.