Skip to content

Commit

Permalink
improve(HubPoolClient): Permit selectively overriding search config (#…
Browse files Browse the repository at this point in the history
…583)

This follows the pattern established in the SpokePoolClient, where
EnabledDepositRoute overriddes searchConfig.fromBlock on the first
update.

This will be used in the relayer to reduce the lookback for events
related to root bundles, since there's no need to query those all the 
way back to HubPool genesis.
  • Loading branch information
pxrl authored Mar 9, 2024
1 parent 6711a15 commit f9933ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@across-protocol/sdk-v2",
"author": "UMA Team",
"version": "0.22.10",
"version": "0.22.11",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/v/developer-docs/developers/across-sdk",
"files": [
Expand Down
26 changes: 23 additions & 3 deletions src/clients/HubPoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,17 +771,37 @@ export class HubPoolClient extends BaseAbstractClient {
return { success: false };
}

const eventSearchConfigs = eventNames.map((eventName) => {
if (!Object.keys(hubPoolEvents).includes(eventName)) {
throw new Error(`HubPoolClient: Cannot query unrecognised HubPool event name: ${eventName}`);
}

const _searchConfig = { ...searchConfig }; // shallow copy

// By default, an event's query range is controlled by the `searchConfig` passed in during
// instantiation. However, certain events generally must be queried back to HubPool genesis.
const overrideEvents = ["CrossChainContractsSet", "L1TokenEnabledForLiquidityProvision", "SetPoolRebalanceRoute"];
if (overrideEvents.includes(eventName) && !this.isUpdated) {
_searchConfig.fromBlock = this.deploymentBlock;
}

return {
eventName,
filter: hubPoolEvents[eventName],
searchConfig: _searchConfig,
};
});

this.logger.debug({
at: "HubPoolClient",
message: "Updating HubPool client",
searchConfig,
eventNames,
searchConfig: eventSearchConfigs.map(({ eventName, searchConfig }) => ({ eventName, searchConfig })),
});
const timerStart = Date.now();
const [currentTime, pendingRootBundleProposal, ...events] = await Promise.all([
this.hubPool.getCurrentTime({ blockTag: searchConfig.toBlock }),
this.hubPool.rootBundleProposal({ blockTag: searchConfig.toBlock }),
...eventNames.map((eventName) => paginatedEventQuery(this.hubPool, hubPoolEvents[eventName], searchConfig)),
...eventSearchConfigs.map((config) => paginatedEventQuery(this.hubPool, config.filter, config.searchConfig)),
]);
this.logger.debug({
at: "HubPoolClient#_update",
Expand Down

0 comments on commit f9933ba

Please sign in to comment.