Skip to content

Commit

Permalink
fixup! feat: chainHub retries
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 8, 2024
1 parent 39f1897 commit a267ba2
Showing 1 changed file with 63 additions and 48 deletions.
111 changes: 63 additions & 48 deletions packages/orchestration/src/exos/chain-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ export const makeChainHub = (agoricNames, vowTools) => {
valueShape: IBCConnectionInfoShape,
});

// eslint-disable-next-line no-restricted-syntax -- TODO more exact rules for vow best practices
const lookupChainInfo = async chainName => {
await null;
try {
const chainInfo = await E(agoricNames).lookup(CHAIN_KEY, chainName);
chainInfos.init(chainName, chainInfo);
return chainInfo;
} catch (_) {
throw makeError(`chain not found:${chainName}`);
}
};

// eslint-disable-next-line no-restricted-syntax -- TODO more exact rules for vow best practices
const lookupConnectionInfo = async (chainId1, chainId2) => {
await null;
const key = connectionKey(chainId1, chainId2);
try {
const connectionInfo = await E(agoricNames).lookup(CONNECTIONS_KEY, key);
connectionInfos.init(key, connectionInfo);
return connectionInfo;
} catch (_) {
throw makeError(`connection not found: ${chainId1}<->${chainId2}`);
}
};

const chainHub = zone.exo('ChainHub', ChainHubI, {
/**
* Register a new chain. The name will override a name in well known chain
Expand Down Expand Up @@ -134,20 +159,10 @@ export const makeChainHub = (agoricNames, vowTools) => {

const lookup = vowTools.retriable(
zone,
'getConnectionInfo',
// eslint-disable-next-line no-restricted-syntax -- TODO more exact rules for vow best practices
async () => {
await null;
try {
const chainInfo = await E(agoricNames).lookup(CHAIN_KEY, chainName);
chainInfos.init(chainName, chainInfo);
return chainInfo;
} catch (_) {
throw makeError(`chain not found:${chainName}`);
}
},
'lookupChainInfo',
lookupChainInfo,
);
return lookup();
return lookup(chainName);
},
/**
* @param {string} chainId1
Expand All @@ -174,23 +189,10 @@ export const makeChainHub = (agoricNames, vowTools) => {

const lookup = vowTools.retriable(
zone,
'getConnectionInfo',
// eslint-disable-next-line no-restricted-syntax -- TODO more exact rules for vow best practices
async () => {
await null;
try {
const connectionInfo = await E(agoricNames).lookup(
CONNECTIONS_KEY,
key,
);
connectionInfos.init(key, connectionInfo);
return connectionInfo;
} catch (_) {
throw makeError(`connection not found: ${chainId1}<->${chainId2}`);
}
},
'lookupConnectionInfo',
lookupConnectionInfo,
);
return lookup();
return lookup(chainId1, chainId2);
},

/**
Expand All @@ -205,29 +207,42 @@ export const makeChainHub = (agoricNames, vowTools) => {
getChainsAndConnection(chainName1, chainName2) {
const lookup = vowTools.retriable(
zone,
'getChainsAndConnection',
// eslint-disable-next-line no-restricted-syntax -- TODO more exact rules for vow best practices
async () => {
const [chain1, chain2] = await vowTools.asPromise(
vowTools.allVows([
chainHub.getChainInfo(chainName1),
chainHub.getChainInfo(chainName2),
]),
);
const connectionInfo = await vowTools.asPromise(
chainHub.getConnectionInfo(chain2, chain1),
);
return /** @type {[ActualChainInfo<C1>, ActualChainInfo<C2>, IBCConnectionInfo]} */ ([
chain1,
chain2,
connectionInfo,
]);
},
'lookupChainsAndConnection',
// eslint-disable-next-line no-use-before-define -- needs to reference this exo
lookupChainsAndConnection,
);
return lookup();
// @ts-expect-error XXX generic parameter propagation
return lookup(chainName1, chainName2);
},
});

/**
* @template {string} C1
* @template {string} C2
* @param {C1} chainName1
* @param {C2} chainName2
* @returns {Promise<
* [ActualChainInfo<C1>, ActualChainInfo<C2>, IBCConnectionInfo]
* >}
*/
// eslint-disable-next-line no-restricted-syntax -- TODO more exact rules for vow best practices
const lookupChainsAndConnection = async (chainName1, chainName2) => {
const [chain1, chain2] = await vowTools.asPromise(
vowTools.allVows([
chainHub.getChainInfo(chainName1),
chainHub.getChainInfo(chainName2),
]),
);
const connectionInfo = await vowTools.asPromise(
chainHub.getConnectionInfo(chain2, chain1),
);
return /** @type {[ActualChainInfo<C1>, ActualChainInfo<C2>, IBCConnectionInfo]} */ ([
chain1,
chain2,
connectionInfo,
]);
};

return chainHub;
};
/** @typedef {ReturnType<typeof makeChainHub>} ChainHub */

0 comments on commit a267ba2

Please sign in to comment.