Skip to content

Commit

Permalink
improve(SpokePoolClient): Multicall latestBlock updates (#750)
Browse files Browse the repository at this point in the history
The SpokePoolClient is currently throwing semi-regular errors on update.
This seems to be particularly occurring against Polygon. The underlying
reason for this is that the RPC quroum system is performing an eth_call
against multiple providers, tagged at the latest block number as
resolved by only one of them. Some providers may not have resolved that
block number yet, in which case the query fails.

The instance of this can presumably be reduced by bundling the two calls
where this occurs into a single SpokePool multicall. As a side-benefit,
it will reduce RPC consumption.
  • Loading branch information
pxrl authored Oct 15, 2024
1 parent 85755b1 commit f62a410
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 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",
"author": "UMA Team",
"version": "3.2.6",
"version": "3.2.7",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/reference/sdk",
"files": [
Expand Down
16 changes: 12 additions & 4 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,21 +499,29 @@ export class SpokePoolClient extends BaseAbstractClient {
};
});

const { spokePool } = this;
this.log("debug", `Updating SpokePool client for chain ${this.chainId}`, {
eventsToQuery,
searchConfig,
spokePool: this.spokePool.address,
spokePool: spokePool.address,
});

const timerStart = Date.now();
const [numberOfDeposits, currentTime, oldestTime, ...events] = await Promise.all([
this.spokePool.numberOfDeposits({ blockTag: searchConfig.toBlock }),
this.spokePool.getCurrentTime({ blockTag: searchConfig.toBlock }),
const multicallFunctions = ["getCurrentTime", "numberOfDeposits"];
const [multicallOutput, oldestTime, ...events] = await Promise.all([
spokePool.callStatic.multicall(
multicallFunctions.map((f) => spokePool.interface.encodeFunctionData(f)),
{ blockTag: searchConfig.toBlock }
),
this.spokePool.getCurrentTime({ blockTag: Math.max(searchConfig.fromBlock, this.deploymentBlock) }),
...eventSearchConfigs.map((config) => paginatedEventQuery(this.spokePool, config.filter, config.searchConfig)),
]);
this.log("debug", `Time to query new events from RPC for ${this.chainId}: ${Date.now() - timerStart} ms`);

const [currentTime, numberOfDeposits] = multicallFunctions.map(
(fn, idx) => spokePool.interface.decodeFunctionResult(fn, multicallOutput[idx])[0]
);

if (!BigNumber.isBigNumber(currentTime) || currentTime.lt(this.currentTime)) {
const errMsg = BigNumber.isBigNumber(currentTime)
? `currentTime: ${currentTime} < ${toBN(this.currentTime)}`
Expand Down

0 comments on commit f62a410

Please sign in to comment.