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

feat(provisionPool): allow overriding PerAccountInitialAmount during contract upgrade #10594

Closed
wants to merge 2 commits into from
Closed
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
75 changes: 49 additions & 26 deletions packages/inter-protocol/src/provisionPool.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// @jessie-check
// @ts-check

import { ParamTypes } from '@agoric/governance';
import {
handleParamGovernance,
ParamTypes,
publicMixinAPI,
} from '@agoric/governance';
import { InvitationShape } from '@agoric/governance/src/typeGuards.js';
GovernorFacetShape,
InvitationShape,
} from '@agoric/governance/src/typeGuards.js';
import { Far } from '@endo/marshal';
import { M } from '@agoric/store';
import { prepareExo } from '@agoric/vat-data';
import { provideSingleton } from '@agoric/zoe/src/contractSupport/durability.js';
import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js';
import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/topics.js';
import { makeDurableZone } from '@agoric/zone/durable.js';
import { makeStoredPublisherKit, SubscriberShape } from '@agoric/notifier';
import { makeParamManagerFromTerms } from '@agoric/governance/src/contractGovernance/typedParamManager.js';
import {
prepareBridgeProvisionTool,
prepareProvisionPoolKit,
Expand Down Expand Up @@ -52,6 +54,7 @@ harden(meta);
* initialPoserInvitation: Invitation;
* storageNode: StorageNode;
* marshaller: Marshal<any>;
* governedParamOverrides?: Record<string, Amount>;
* metricsOverride?: import('./provisionPoolKit.js').MetricsNotification;
* }} privateArgs
* @param {import('@agoric/vat-data').Baggage} baggage
Expand All @@ -64,17 +67,22 @@ export const start = async (zcf, privateArgs, baggage) => {
privateArgs.marshaller,
);

// Governance
const { publicMixin, makeDurableGovernorFacet, params } =
await handleParamGovernance(
zcf,
privateArgs.initialPoserInvitation,
{
PerAccountInitialAmount: ParamTypes.AMOUNT,
},
privateArgs.storageNode,
privateArgs.marshaller,
);
/** @type {import('@agoric/notifier').StoredPublisherKit<GovernanceSubscriptionState>} */
const publisherKit = makeStoredPublisherKit(
privateArgs.storageNode,
privateArgs.marshaller,
'governance',
);
const paramManager = makeParamManagerFromTerms(
publisherKit,
zcf,
{ Electorate: privateArgs.initialPoserInvitation },
{
PerAccountInitialAmount: ParamTypes.AMOUNT,
},
privateArgs.governedParamOverrides,
);
const params = paramManager.readonly();

const zone = makeDurableZone(baggage);

Expand Down Expand Up @@ -107,22 +115,37 @@ export const start = async (zcf, privateArgs, baggage) => {
M.interface('ProvisionPool', {
getMetrics: M.call().returns(M.remotable('MetricsSubscriber')),
getPublicTopics: M.call().returns(TopicsRecordShape),
...publicMixinAPI,
getSubscription: M.call().returns(M.remotable('StoredSubscription')),
getGovernedParams: M.call().returns(M.or(M.record(), M.promise())),
getElectorateSubscription: M.call().returns(SubscriberShape),
}),
{
getMetrics() {
return provisionPoolKit.public.getPublicTopics().metrics.subscriber;
},
getPublicTopics() {
return provisionPoolKit.public.getPublicTopics();
},
...publicMixin,
getMetrics: () =>
provisionPoolKit.public.getPublicTopics().metrics.subscriber,
getPublicTopics: () => provisionPoolKit.public.getPublicTopics(),
getSubscription: () => paramManager.getSubscription(),
getGovernedParams: () => paramManager.getParams(),
getElectorateSubscription: () => paramManager.getSubscription(),
},
);

const creatorFacet = prepareExo(
baggage,
'governorFacet',
M.interface('governorFacet', GovernorFacetShape),
{
getParamMgrRetriever: () =>
Far('paramRetriever', { get: () => paramManager }),
getInvitation: name => paramManager.getInternalParamValue(name),
getLimitedCreatorFacet: () => provisionPoolKit.machine,
getGovernedApis: () => Far('governedAPIs', {}),
getGovernedApiNames: () => Object.keys({}),
setOfferFilter: strings => zcf.setOfferFilter(strings),
},
);

return harden({
creatorFacet: makeDurableGovernorFacet(baggage, provisionPoolKit.machine)
.governorFacet,
creatorFacet,
publicFacet,
});
};
Expand Down
28 changes: 21 additions & 7 deletions packages/vats/src/proposals/upgrade-provisionPool-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { E } from '@endo/far';
import { deeplyFulfilled } from '@endo/marshal';
import { makeTracer } from '@agoric/internal';

const tracer = makeTracer('UpgradeProvisionPool');
const trace = makeTracer('UpgradeProvisionPool');

/**
* @param {BootstrapPowers & {
Expand Down Expand Up @@ -30,7 +30,7 @@ export const upgradeProvisionPool = async (
const { provisionPoolRef } = options.options;

assert(provisionPoolRef.bundleID);
tracer(`PROVISION POOL BUNDLE ID: `, provisionPoolRef);
trace(`PROVISION POOL BUNDLE ID: `, provisionPoolRef);

const [
provisionPoolStartResult,
Expand All @@ -45,9 +45,11 @@ export const upgradeProvisionPool = async (
walletFactoryStartResultP,
provisionWalletBridgeManagerP,
]);

const {
adminFacet,
instance,
publicFacet: ppPublicFacet,
creatorFacet: ppCreatorFacet,
} = provisionPoolStartResult;
const { creatorFacet: wfCreatorFacet } = walletFactoryStartResult;
Expand All @@ -59,35 +61,47 @@ export const upgradeProvisionPool = async (
E(electorateCreatorFacet).getPoserInvitation(),
]);

const readCurrentGovernedParams = async () => {
await null;

const params = await E(ppPublicFacet).getGovernedParams();
return harden({
PerAccountInitialAmount: params.PerAccountInitialAmount.value,
});
};
const governedParamOverrides = await readCurrentGovernedParams();
trace('governedParamOverrides: ', { governedParamOverrides });

const newPrivateArgs = harden({
...originalPrivateArgs,
initialPoserInvitation: poserInvitation,
governedParamOverrides,
});

const upgradeResult = await E(adminFacet).upgradeContract(
provisionPoolRef.bundleID,
newPrivateArgs,
);

tracer('ProvisionPool upgraded: ', upgradeResult);
trace('ProvisionPool upgraded: ', upgradeResult);

const references = {
bankManager,
namesByAddressAdmin,
walletFactory: wfCreatorFacet,
};

tracer('Calling setReferences with: ', references);
trace('Calling setReferences with: ', references);
await E(ppCreatorFacet).setReferences(references);

tracer('Creating bridgeHandler...');
trace('Creating bridgeHandler...');
const bridgeHandler = await E(ppCreatorFacet).makeHandler();

tracer('Setting new bridgeHandler...');
trace('Setting new bridgeHandler...');
// @ts-expect-error casting
await E(provisionWalletBridgeManager).setHandler(bridgeHandler);

tracer('Done.');
trace('Done.');
};

export const getManifestForUpgradingProvisionPool = (
Expand Down
Loading