Skip to content

Commit

Permalink
chore: get rid of ephemera, address change requests
Browse files Browse the repository at this point in the history
Refs: #10395
Refs: #10425
  • Loading branch information
anilhelvaci committed Nov 27, 2024
1 parent a8b124a commit a7d00fc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 83 deletions.
2 changes: 1 addition & 1 deletion a3p-integration/proposals/p:upgrade-19/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
replaceFeeDistributor/
addUsdLemons/
upgradeProvisionPool/
upgradeProvisionPool/
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"instancePrivateArgs": true,
"economicCommitteeCreatorFacet": true
}
}
}
6 changes: 3 additions & 3 deletions golang/cosmos/app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ func unreleasedUpgradeHandler(app *GaiaApp, targetUpgrade string) func(sdk.Conte
// Upgrade to include a cleanup from https://github.com/Agoric/agoric-sdk/pull/10319
"@agoric/builders/scripts/smart-wallet/build-wallet-factory2-upgrade.js",
),
vm.CoreProposalStepForModules(
"@agoric/builders/scripts/vats/upgrade-bank.js",
),
)

// //// CoreProposals for Upgrade 19 ////
Expand All @@ -225,6 +222,9 @@ func unreleasedUpgradeHandler(app *GaiaApp, targetUpgrade string) func(sdk.Conte
// vm.CoreProposalStepForModules(
// "@agoric/builders/scripts/vats/upgrade-provisionPool.js",
// ),
// vm.CoreProposalStepForModules(
// "@agoric/builders/scripts/vats/upgrade-bank.js",
// ),
// )
}

Expand Down
8 changes: 7 additions & 1 deletion packages/inter-protocol/src/provisionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ 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 { prepareProvisionPoolKit } from './provisionPoolKit.js';
import {
prepareBridgeProvisionTool,
prepareProvisionPoolKit,
} from './provisionPoolKit.js';

/** @import {Marshal} from '@endo/marshal'; */

Expand Down Expand Up @@ -74,11 +77,14 @@ export const start = async (zcf, privateArgs, baggage) => {
);

const zone = makeDurableZone(baggage);

const makeBridgeProvisionTool = prepareBridgeProvisionTool(zone);
const makeProvisionPoolKit = prepareProvisionPoolKit(zone, {
makeRecorderKit,
params,
poolBank,
zcf,
makeBridgeProvisionTool,
});

const provisionPoolKit = await provideSingleton(
Expand Down
120 changes: 48 additions & 72 deletions packages/inter-protocol/src/provisionPoolKit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { X, q, Fail } from '@endo/errors';
import { E, Far } from '@endo/far';
import { E } from '@endo/far';

import { AmountMath, BrandShape } from '@agoric/ertp';
import { deeplyFulfilledObject, makeTracer } from '@agoric/internal';
Expand All @@ -22,19 +22,13 @@ import {
} from '@agoric/zoe/src/contractSupport/topics.js';
import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';
import { makeEphemeraProvider } from '@agoric/zoe/src/contractSupport/durability.js';

const trace = makeTracer('ProvPool');

const FIRST_UPPER_KEYWORD = /^[A-Z][a-zA-Z0-9_$]*$/;
// see https://github.com/Agoric/agoric-sdk/issues/8238
const FIRST_LOWER_NEAR_KEYWORD = /^[a-z][a-zA-Z0-9_$]*$/;

const provisionPoolEphemera = makeEphemeraProvider(
() => /** @type {any} */ ({}),
);
const ephemeralToolsHandle = Far('EphemeralTools', {});

/**
* @import {ERef} from '@endo/far'
* @import {Amount} from '@agoric/ertp/src/types.js'
Expand Down Expand Up @@ -80,23 +74,18 @@ const ephemeralToolsHandle = Far('EphemeralTools', {});
* smart wallets.
*
* @param {import('@agoric/zone').Zone} zone
* @param {(bank: ERef<Bank>) => Promise<void>} sendInitialPayment
* @param {() => void} onProvisioned
*/
export const prepareBridgeProvisionTool = (
zone,
sendInitialPayment,
onProvisioned,
) =>
export const prepareBridgeProvisionTool = zone =>
zone.exoClass(
'smartWalletProvisioningHandler',
M.interface('ProvisionBridgeHandlerMaker', {
fromBridge: M.callWhen(M.record()).returns(),
}),
(bankManager, walletFactory, namesByAddressAdmin) => ({
(bankManager, walletFactory, namesByAddressAdmin, helperFacet) => ({
bankManager,
walletFactory,
namesByAddressAdmin,
helperFacet,
}),
{
async fromBridge(obj) {
Expand All @@ -107,21 +96,22 @@ export const prepareBridgeProvisionTool = (
powerFlags.includes(PowerFlags.SMART_WALLET) ||
Fail`missing SMART_WALLET in powerFlags`;

const { bankManager, walletFactory, namesByAddressAdmin } = this.state;
const { bankManager, walletFactory, namesByAddressAdmin, helperFacet } =
this.state;

trace({ bankManager, walletFactory, namesByAddressAdmin });

const bank = E(bankManager).getBankForAddress(address);
// only proceed if we can provide funds
await sendInitialPayment(bank);
await helperFacet.sendInitialPayment(bank);

const [_, created] = await E(walletFactory).provideSmartWallet(
address,
bank,
namesByAddressAdmin,
);
if (created) {
onProvisioned();
helperFacet.onProvisioned();
}
trace(created ? 'provisioned' : 're-provisioned', address);
},
Expand All @@ -135,11 +125,12 @@ export const prepareBridgeProvisionTool = (
* params: any;
* poolBank: import('@endo/far').ERef<Bank>;
* zcf: ZCF;
* makeBridgeProvisionTool: ReturnType<typeof prepareBridgeProvisionTool>;
* }} powers
*/
export const prepareProvisionPoolKit = (
zone,
{ makeRecorderKit, params, poolBank, zcf },
{ makeRecorderKit, params, poolBank, zcf, makeBridgeProvisionTool },
) => {
const zoe = zcf.getZoeService();

Expand All @@ -156,7 +147,7 @@ export const prepareProvisionPoolKit = (
namesByAddressAdmin: M.eref(M.remotable('nameAdmin')),
walletFactory: M.eref(M.remotable('walletFactory')),
}).returns(),
makeHandler: M.callWhen().returns(M.remotable('handler')),
makeHandler: M.call().returns(M.remotable('BridgeHandler')),
initPSM: M.call(BrandShape, InstanceHandleShape).returns(),
}),
walletReviver: M.interface('ProvisionPoolKit wallet reviver', {
Expand All @@ -166,6 +157,7 @@ export const prepareProvisionPoolKit = (
ackWallet: M.call(M.string()).returns(M.boolean()),
}),
helper: UnguardedHelperI,
forHandler: UnguardedHelperI,
public: M.interface('ProvisionPoolKit public', {
getPublicTopics: M.call().returns({ metrics: PublicTopicShape }),
}),
Expand Down Expand Up @@ -240,21 +232,13 @@ export const prepareProvisionPoolKit = (
throw Fail`must set references before handling requests`;
}

const ephemera = provisionPoolEphemera(ephemeralToolsHandle);
if (!ephemera.makeBridgeProvisionTool) {
throw Fail`makeBridgeProvisionTool must be set to ephemera first`;
}

trace({
bankManager,
namesByAddressAdmin,
walletFactory,
});
const { forHandler } = this.facets;

const provisionHandler = ephemera.makeBridgeProvisionTool(
const provisionHandler = makeBridgeProvisionTool(
bankManager,
walletFactory,
namesByAddressAdmin,
forHandler,
);

return provisionHandler;
Expand Down Expand Up @@ -335,37 +319,6 @@ export const prepareProvisionPoolKit = (
);
facets.helper.publishMetrics();
},
onProvisioned() {
const { state, facets } = this;
state.walletsProvisioned += 1n;
facets.helper.publishMetrics();
},
/** @param {ERef<Bank>} destBank */
async sendInitialPayment(destBank) {
const {
facets: { helper },
state: { fundPurse, poolBrand },
} = this;
const perAccountInitialAmount = /** @type {Amount<'nat'>} */ (
params.getPerAccountInitialAmount()
);
const initialPmt = await E(fundPurse).withdraw(
perAccountInitialAmount,
);

const destPurse = E(destBank).getPurse(poolBrand);
return E(destPurse)
.deposit(initialPmt)
.then(amt => {
helper.onSendFunds(perAccountInitialAmount);
trace('provisionPool sent', amt);
})
.catch(reason => {
console.error(X`initial deposit failed: ${q(reason)}`);
void E(fundPurse).deposit(initialPmt);
throw reason;
});
},
/**
* @param {ERef<Purse>} exchangePurse
* @param {ERef<Brand>} brand
Expand Down Expand Up @@ -476,16 +429,6 @@ export const prepareProvisionPoolKit = (

void helper.watchAssetSubscription();

const handlerZone = zone.subZone('ProvisionHandlerZone');
const makeBridgeProvisionTool = prepareBridgeProvisionTool(
handlerZone,
bank => helper.sendInitialPayment(bank),
() => helper.onProvisioned(),
);

const ephemera = provisionPoolEphemera(ephemeralToolsHandle);
ephemera.makeBridgeProvisionTool = makeBridgeProvisionTool;

if (metrics) {
// Restore state.
// we publishMetrics() below
Expand Down Expand Up @@ -525,6 +468,39 @@ export const prepareProvisionPoolKit = (
return rxd;
},
},
forHandler: {
onProvisioned() {
const { state, facets } = this;
state.walletsProvisioned += 1n;
facets.helper.publishMetrics();
},
/** @param {ERef<Bank>} destBank */
async sendInitialPayment(destBank) {
const {
facets: { helper },
state: { fundPurse, poolBrand },
} = this;
const perAccountInitialAmount = /** @type {Amount<'nat'>} */ (
params.getPerAccountInitialAmount()
);
const initialPmt = await E(fundPurse).withdraw(
perAccountInitialAmount,
);

const destPurse = E(destBank).getPurse(poolBrand);
return E(destPurse)
.deposit(initialPmt)
.then(amt => {
helper.onSendFunds(perAccountInitialAmount);
trace('provisionPool sent', amt);
})
.catch(reason => {
console.error(X`initial deposit failed: ${q(reason)}`);
void E(fundPurse).deposit(initialPmt);
throw reason;
});
},
},
public: {
getPublicTopics() {
return {
Expand Down
7 changes: 2 additions & 5 deletions packages/inter-protocol/test/provisionPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,12 @@ test('makeBridgeProvisionTool handles duplicate requests', async t => {
makeNameHubKit();
const publishMetrics = () => {};
const zone = makeHeapZone();
const makeBridgeProvisionTool = prepareBridgeProvisionTool(
zone,
bank => sendInitialPayment(bank),
() => publishMetrics(),
);
const makeBridgeProvisionTool = prepareBridgeProvisionTool(zone);
const handler = makeBridgeProvisionTool(
bankManager,
walletFactory,
namesByAddressAdmin,
Far('helpers', { sendInitialPayment, onProvisioned: publishMetrics }),
);

t.log('1st request to provision a SMART_WALLET for', address);
Expand Down

0 comments on commit a7d00fc

Please sign in to comment.