Skip to content

Commit

Permalink
Merge branch 'mhofman/9541-retriable' into 9303-orchestrate-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 29, 2024
2 parents ec10e71 + a36498a commit a3b92fa
Show file tree
Hide file tree
Showing 16 changed files with 394 additions and 35 deletions.
20 changes: 19 additions & 1 deletion packages/internal/src/upgrade-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,23 @@ harden(makeUpgradeDisconnection);
* @returns {reason is UpgradeDisconnection}
*/
export const isUpgradeDisconnection = reason =>
isFrozen(reason) && matches(reason, UpgradeDisconnectionShape);
reason != null && // eslint-disable-line eqeqeq
isFrozen(reason) &&
matches(reason, UpgradeDisconnectionShape);
harden(isUpgradeDisconnection);

/**
* Returns whether a reason is a 'vat terminated' error generated when an object
* is abandoned by a vat during an upgrade.
*
* @param {any} reason
* @returns {reason is Error}
*/
export const isAbandonedError = reason =>
reason != null && // eslint-disable-line eqeqeq
isFrozen(reason) &&
matches(reason, M.error()) &&
// We're not using a constant here since this special value is already
// sprinkled throughout the SDK
reason.message === 'vat terminated';
harden(isAbandonedError);
15 changes: 15 additions & 0 deletions packages/internal/test/upgrade-api.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// @ts-check
import test from 'ava';
import { makeMarshal } from '@endo/marshal';

import {
makeUpgradeDisconnection,
isUpgradeDisconnection,
isAbandonedError,
} from '../src/upgrade-api.js';

test('isUpgradeDisconnection must recognize disconnection objects', t => {
Expand All @@ -18,3 +21,15 @@ test('isUpgradeDisconnection must recognize original-format disconnection object
});
t.true(isUpgradeDisconnection(disconnection));
});

test('isAbandonedError recognizes marshalled vat terminated errors', t => {
const { fromCapData, toCapData } = makeMarshal(undefined, undefined, {
serializeBodyFormat: 'smallcaps',
errorIdNum: 70_000,
marshalSaveError: () => {},
});
const error = harden(Error('vat terminated'));
const remoteError = fromCapData(toCapData(error));

t.true(isAbandonedError(remoteError));
});
2 changes: 1 addition & 1 deletion packages/orchestration/src/examples/stakeBld.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const start = async (zcf, privateArgs, baggage) => {
zcf,
privateArgs.timerService,
vowTools,
makeChainHub(privateArgs.agoricNames, vowTools),
makeChainHub(zone.subZone('chainHub'), privateArgs.agoricNames, vowTools),
);

// ----------------
Expand Down
7 changes: 3 additions & 4 deletions packages/orchestration/src/exos/chain-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { M } from '@endo/patterns';
import { BrandShape } from '@agoric/ertp/src/typeGuards.js';

import { VowShape } from '@agoric/vow';
import { makeHeapZone } from '@agoric/zone';
import { CosmosChainInfoShape, IBCConnectionInfoShape } from '../typeGuards.js';

/**
Expand Down Expand Up @@ -169,18 +168,18 @@ const ChainHubI = M.interface('ChainHub', {
});

/**
* Make a new ChainHub in the zone (or in the heap if no zone is provided).
* Make a new ChainHub in the zone.
*
* The resulting object is an Exo singleton. It has no precious state. It's only
* state is a cache of queries to agoricNames and whatever info was provided in
* registration calls. When you need a newer version you can simply make a hub
* hub and repeat the registrations.
*
* @param {Zone} zone
* @param {Remote<NameHub>} agoricNames
* @param {VowTools} vowTools
*/
export const makeChainHub = (agoricNames, vowTools) => {
const zone = makeHeapZone();
export const makeChainHub = (zone, agoricNames, vowTools) => {
/** @type {MapStore<string, CosmosChainInfo>} */
const chainInfos = zone.mapStore('chainInfos', {
keyShape: M.string(),
Expand Down
9 changes: 7 additions & 2 deletions packages/orchestration/src/proposals/start-stakeAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ export const startStakeAtom = async ({
const storageNode = await makeStorageNodeChild(chainStorage, VSTORAGE_PATH);
const marshaller = await E(board).getPublishingMarshaller();

const vt = prepareVowTools(makeHeapZone());
const chainHub = makeChainHub(await agoricNames, vt);
const zone = makeHeapZone();
const vt = prepareVowTools(zone.subZone('vows'));
const chainHub = makeChainHub(
zone.subZone('chainHub'),
await agoricNames,
vt,
);

const [_, cosmoshub, connectionInfo] = await vt.when(
chainHub.getChainsAndConnection('agoric', 'cosmoshub'),
Expand Down
9 changes: 7 additions & 2 deletions packages/orchestration/src/proposals/start-stakeOsmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ export const startStakeOsmo = async ({
const storageNode = await makeStorageNodeChild(chainStorage, VSTORAGE_PATH);
const marshaller = await E(board).getPublishingMarshaller();

const vt = prepareVowTools(makeHeapZone());
const chainHub = makeChainHub(await agoricNames, vt);
const zone = makeHeapZone();
const vt = prepareVowTools(zone.subZone('vows'));
const chainHub = makeChainHub(
zone.subZone('chainHub'),
await agoricNames,
vt,
);

const [_, osmosis, connectionInfo] = await vt.when(
chainHub.getChainsAndConnection('agoric', 'osmosis'),
Expand Down
3 changes: 2 additions & 1 deletion packages/orchestration/src/utils/start-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const provideOrchestration = (
/** for contract-provided names */
contract: zone.subZone('contract'),
orchestration: zone.subZone('orchestration'),
chainHub: zone.subZone('chainHub'),
vows: zone.subZone('vows'),
zoe: zone.subZone('zoe'),
};
Expand All @@ -71,7 +72,7 @@ export const provideOrchestration = (

const vowTools = prepareVowTools(zones.vows);

const chainHub = makeChainHub(agoricNames, vowTools);
const chainHub = makeChainHub(zones.chainHub, agoricNames, vowTools);

const zoeTools = makeZoeTools(zones.zoe, { zcf, vowTools });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@ Generated by [AVA](https://avajs.dev).
flowForOutcomeVow: {},
unwrapMap: 'Alleged: weakMapStore',
},
chainHub: {
ChainHub_kindHandle: 'Alleged: kind',
ChainHub_singleton: 'Alleged: ChainHub',
chainInfos: {},
connectionInfos: {},
denom: {},
lookupChainInfo_kindHandle: 'Alleged: kind',
lookupChainsAndConnection_kindHandle: 'Alleged: kind',
lookupConnectionInfo_kindHandle: 'Alleged: kind',
},
contract: {
'ChainHub Admin_kindHandle': 'Alleged: kind',
'ChainHub Admin_singleton': 'Alleged: ChainHub Admin',
'Send PF_kindHandle': 'Alleged: kind',
'Send PF_singleton': 'Alleged: Send PF',
findBrandInVBank_kindHandle: 'Alleged: kind',
},
orchestration: {
'Cosmos Orchestration Account Holder_kindHandle': 'Alleged: kind',
Expand All @@ -52,9 +63,14 @@ Generated by [AVA](https://avajs.dev).
},
},
vows: {
AdminRetriableFlow_kindHandle: 'Alleged: kind',
AdminRetriableFlow_singleton: 'Alleged: AdminRetriableFlow',
PromiseWatcher_kindHandle: 'Alleged: kind',
VowInternalsKit_kindHandle: 'Alleged: kind',
WatchUtils_kindHandle: 'Alleged: kind',
retriableFlowForOutcomeVow: {},
},
zoe: {
localTransfer_kindHandle: 'Alleged: kind',
},
zoe: {},
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,87 @@ Generated by [AVA](https://avajs.dev).
flowForOutcomeVow: {},
unwrapMap: 'Alleged: weakMapStore',
},
chainHub: {
ChainHub_kindHandle: 'Alleged: kind',
ChainHub_singleton: 'Alleged: ChainHub',
chainInfos: {
agoric: {
chainId: 'agoric-3',
icqEnabled: false,
stakingTokens: [
{
denom: 'ubld',
},
],
},
omniflixhub: {
chainId: 'omniflixhub-1',
icqEnabled: false,
stakingTokens: [
{
denom: 'uflix',
},
],
},
stride: {
chainId: 'stride-1',
icqEnabled: false,
stakingTokens: [
{
denom: 'ustrd',
},
],
},
},
connectionInfos: {
'agoric-3_omniflixhub-1': {
client_id: '07-tendermint-73',
counterparty: {
client_id: '07-tendermint-47',
connection_id: 'connection-40',
prefix: {
key_prefix: 'FIXME',
},
},
id: 'connection-67',
state: 3,
transferChannel: {
channelId: 'channel-58',
counterPartyChannelId: 'channel-30',
counterPartyPortId: 'transfer',
ordering: 0,
portId: 'transfer',
state: 3,
version: 'ics20-1',
},
},
'agoric-3_stride-1': {
client_id: '07-tendermint-74',
counterparty: {
client_id: '07-tendermint-129',
connection_id: 'connection-118',
prefix: {
key_prefix: 'FIXME',
},
},
id: 'connection-68',
state: 3,
transferChannel: {
channelId: 'channel-59',
counterPartyChannelId: 'channel-148',
counterPartyPortId: 'transfer',
ordering: 0,
portId: 'transfer',
state: 3,
version: 'ics20-1',
},
},
},
denom: {},
lookupChainInfo_kindHandle: 'Alleged: kind',
lookupChainsAndConnection_kindHandle: 'Alleged: kind',
lookupConnectionInfo_kindHandle: 'Alleged: kind',
},
contract: {
publicFacet_kindHandle: 'Alleged: kind',
publicFacet_singleton: 'Alleged: publicFacet',
Expand All @@ -43,9 +124,14 @@ Generated by [AVA](https://avajs.dev).
},
},
vows: {
AdminRetriableFlow_kindHandle: 'Alleged: kind',
AdminRetriableFlow_singleton: 'Alleged: AdminRetriableFlow',
PromiseWatcher_kindHandle: 'Alleged: kind',
VowInternalsKit_kindHandle: 'Alleged: kind',
WatchUtils_kindHandle: 'Alleged: kind',
retriableFlowForOutcomeVow: {},
},
zoe: {
localTransfer_kindHandle: 'Alleged: kind',
},
zoe: {},
}
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/orchestration/test/exos/chain-hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const connection = {
// fresh state for each test
const setup = () => {
const zone = provideDurableZone('root');
const vt = prepareSwingsetVowTools(zone);
const vt = prepareSwingsetVowTools(zone.subZone('vows'));
const { nameHub, nameAdmin } = makeNameHubKit();
const chainHub = makeChainHub(nameHub, vt);
const chainHub = makeChainHub(zone.subZone('chainHub'), nameHub, vt);

return { chainHub, nameAdmin, vt };
};
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestration/test/exos/make-test-loa-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const prepareMakeTestLOAKit = (
zcf,
timer,
vowTools,
makeChainHub(agoricNames, vowTools),
makeChainHub(rootZone.subZone('chainHub'), agoricNames, vowTools),
);

return async ({
Expand Down
Loading

0 comments on commit a3b92fa

Please sign in to comment.