Skip to content

Commit

Permalink
refactor: Remove SpokePoolClient oldestTime lookup (#886)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul <[email protected]>
  • Loading branch information
nicholaspai and pxrl authored Feb 13, 2025
1 parent b22331b commit 5d4db39
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import assert from "assert";
import { Contract, EventFilter } from "ethers";
import winston from "winston";
import {
AnyObject,
BigNumber,
bnZero,
bnUint32Max,
DefaultLogLevels,
EventSearchConfig,
MAX_BIG_INT,
Expand Down Expand Up @@ -53,7 +55,6 @@ import { getRepaymentChainId, forceDestinationRepayment } from "./BundleDataClie
type SpokePoolUpdateSuccess = {
success: true;
currentTime: number;
oldestTime: number;
firstDepositId: BigNumber;
latestDepositId: BigNumber;
events: Log[][];
Expand All @@ -71,7 +72,6 @@ export type SpokePoolUpdate = SpokePoolUpdateSuccess | SpokePoolUpdateFailure;
*/
export class SpokePoolClient extends BaseAbstractClient {
protected currentTime = 0;
protected oldestTime = 0;
protected depositHashes: { [depositHash: string]: DepositWithBlock } = {};
protected duplicateDepositHashes: { [depositHash: string]: DepositWithBlock[] } = {};
protected depositHashesToFills: { [depositHash: string]: FillWithBlock[] } = {};
Expand Down Expand Up @@ -542,12 +542,11 @@ export class SpokePoolClient extends BaseAbstractClient {

const timerStart = Date.now();
const multicallFunctions = ["getCurrentTime", "numberOfDeposits"];
const [multicallOutput, oldestTime, ...events] = await Promise.all([
const [multicallOutput, ...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`);
Expand All @@ -570,7 +569,6 @@ export class SpokePoolClient extends BaseAbstractClient {
return {
success: true,
currentTime: currentTime.toNumber(), // uint32
oldestTime: oldestTime.toNumber(),
firstDepositId,
latestDepositId: _latestDepositId.gt(bnZero) ? _latestDepositId : bnZero,
searchEndBlock: searchConfig.toBlock,
Expand All @@ -595,7 +593,7 @@ export class SpokePoolClient extends BaseAbstractClient {
if (!update.success) {
return;
}
const { events: queryResults, currentTime, oldestTime, searchEndBlock } = update;
const { events: queryResults, currentTime, searchEndBlock } = update;

if (eventsToQuery.includes("TokensBridged")) {
// Temporarily query old spoke pool events as well to ease migration:
Expand Down Expand Up @@ -797,7 +795,6 @@ export class SpokePoolClient extends BaseAbstractClient {

// Next iteration should start off from where this one ended.
this.currentTime = currentTime;
if (this.oldestTime === 0) this.oldestTime = oldestTime; // Set oldest time only after the first update.
this.firstDepositIdForSpokePool = update.firstDepositId;
this.latestBlockSearched = searchEndBlock;
this.lastDepositIdForSpokePool = update.latestDepositId;
Expand Down Expand Up @@ -887,11 +884,13 @@ export class SpokePoolClient extends BaseAbstractClient {
}

/**
* Retrieves the oldest time searched on the SpokePool contract.
* @returns The oldest time searched, which will be 0 if there has been no update() yet.
* Retrieves the time from the SpokePool contract at a particular block.
* @returns The time at the specified block tag.
*/
public getOldestTime(): number {
return this.oldestTime;
public async getTimeAt(blockNumber: number): Promise<number> {
const currentTime = await this.spokePool.getCurrentTime({ blockTag: blockNumber });
assert(BigNumber.isBigNumber(currentTime) && currentTime.lt(bnUint32Max));
return currentTime.toNumber();
}

async findDeposit(depositId: BigNumber, destinationChainId: number): Promise<DepositWithBlock> {
Expand Down

0 comments on commit 5d4db39

Please sign in to comment.