Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add oldest time searched to SpokePoolClient #506

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type Block = providers.Block;
type _SpokePoolUpdate = {
success: boolean;
currentTime: number;
oldestTime: number;
fillDeadlineBuffer: number;
firstDepositId: number;
latestDepositId: number;
events: Event[][];
Expand All @@ -70,6 +72,8 @@ export type SpokePoolUpdate = { success: false } | _SpokePoolUpdate;
*/
export class SpokePoolClient extends BaseAbstractClient {
protected currentTime = 0;
protected oldestTime = 0;
protected fillDeadlineBuffer = Number.MAX_SAFE_INTEGER;
protected depositHashes: { [depositHash: string]: DepositWithBlock } = {};
protected depositHashesToFills: { [depositHash: string]: FillWithBlock[] } = {};
protected speedUps: { [depositorAddress: string]: { [depositId: number]: SpeedUp[] } } = {};
Expand Down Expand Up @@ -573,9 +577,13 @@ export class SpokePoolClient extends BaseAbstractClient {
});

const timerStart = Date.now();
const [numberOfDeposits, currentTime, ...events] = await Promise.all([
// TODO: Once the SpokePools are updated and have the `fillDeadlineBuffer()` method, load it dynamically here.
const fillDeadlineBuffer = 2 * 60 * 60; // 2 hours. We're assuming this is hardcoded to the same value that the
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
// V3 spoke pools will be instantiated with.
const [numberOfDeposits, currentTime, oldestTime, ...events] = await Promise.all([
this.spokePool.numberOfDeposits({ blockTag: searchConfig.toBlock }),
this.spokePool.getCurrentTime({ 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 Down Expand Up @@ -619,6 +627,8 @@ export class SpokePoolClient extends BaseAbstractClient {
return {
success: true,
currentTime: currentTime.toNumber(), // uint32
oldestTime: oldestTime.toNumber(),
fillDeadlineBuffer,
firstDepositId,
latestDepositId: Math.max(numberOfDeposits - 1, 0),
searchEndBlock: searchConfig.toBlock,
Expand Down Expand Up @@ -651,7 +661,7 @@ export class SpokePoolClient extends BaseAbstractClient {
// understand why we see this in test. @todo: Resolve.
return;
}
const { events: queryResults, blocks, currentTime, searchEndBlock } = update;
const { events: queryResults, blocks, currentTime, oldestTime, searchEndBlock, fillDeadlineBuffer } = update;

if (eventsToQuery.includes("TokensBridged")) {
for (const event of queryResults[eventsToQuery.indexOf("TokensBridged")]) {
Expand Down Expand Up @@ -828,6 +838,8 @@ 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.fillDeadlineBuffer = fillDeadlineBuffer;
this.firstDepositIdForSpokePool = update.firstDepositId;
this.latestBlockSearched = searchEndBlock;
this.lastDepositIdForSpokePool = update.latestDepositId;
Expand Down Expand Up @@ -930,12 +942,29 @@ export class SpokePoolClient extends BaseAbstractClient {

/**
* Retrieves the current time from the SpokePool contract.
* @returns The current time.
* @returns The current time, which will be 0 if there has been no update() yet.
*/
public getCurrentTime(): number {
return this.currentTime;
}

/**
* 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.
*/
public getOldestTime(): number {
return this.oldestTime;
}

/**
* Returns the latest fill deadline buffer for this SpokePool.
* @returns The latest fill deadline buffer for this SpokePool contract, which will be the max integer value
* if there has been no update() yet.
*/
public getFillDeadlineBuffer(): number {
return this.fillDeadlineBuffer;
}

/**
* Finds a deposit for a given deposit ID, destination chain ID and depositor address. This method will search for
* the deposit in the SpokePool contract and return it if found. If the deposit is not found, this method will
Expand Down
2 changes: 2 additions & 0 deletions src/clients/mocks/MockSpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class MockSpokePoolClient extends SpokePoolClient {
firstDepositId: 0,
latestDepositId,
currentTime,
oldestTime: 0,
fillDeadlineBuffer: 0,
events,
blocks,
searchEndBlock: this.eventSearchConfig.toBlock || latestBlockSearched,
Expand Down
2 changes: 1 addition & 1 deletion test/SpokePoolClient.fills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe("SpokePoolClient: Fills", function () {
await hre.network.provider.send("evm_mine");

// Now search for the fill _after_ it was filled and expect an exception.
const srcChain = getNetworkName(deposit.originChainId);
const srcChain = getNetworkName(deposit.originChainId);
await assertPromiseError(
findFillBlock(spokePool, deposit as RelayData, lateBlockNumber),
`${srcChain} deposit ${deposit.depositId} filled on `
Expand Down