Skip to content

Commit

Permalink
Update DepositUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Mar 6, 2025
1 parent e898483 commit 4cc1f17
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MakeOptional,
assign,
getRelayEventKey,
InvalidFill,
isDefined,
toBN,
getMessageHash,
Expand Down Expand Up @@ -899,7 +900,7 @@ export class SpokePoolClient extends BaseAbstractClient {
return currentTime.toNumber();
}

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

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Builds

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Test

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Test

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Test

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Test

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Test

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Test

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Lint

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Lint

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Lint

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Lint

Return type of public method from exported class has or is using private name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Lint

Cannot find name 'DepositSearchResult'.

Check failure on line 903 in src/clients/SpokePoolClient.ts

View workflow job for this annotation

GitHub Actions / Lint

Return type of public method from exported class has or is using private name 'DepositSearchResult'.
// Binary search for event search bounds. This way we can get the blocks before and after the deposit with
// deposit ID = fill.depositId and use those blocks to optimize the search for that deposit.
// Stop searches after a maximum # of searches to limit number of eth_call requests. Make an
Expand All @@ -908,7 +909,7 @@ export class SpokePoolClient extends BaseAbstractClient {
//
// @dev Limiting between 5-10 searches empirically performs best when there are ~300,000 deposits
// for a spoke pool and we're looking for a deposit <5 days older than HEAD.
const searchBounds = await getBlockRangeForDepositId(
const { low: fromBlock, high: toBlock } = await getBlockRangeForDepositId(
depositId,
this.deploymentBlock,
this.latestBlockSearched,
Expand All @@ -918,7 +919,6 @@ export class SpokePoolClient extends BaseAbstractClient {

const tStart = Date.now();
// Check both V3FundsDeposited and FundsDeposited events to look for a specified depositId.
const [fromBlock, toBlock] = [searchBounds.low, searchBounds.high];
const { maxBlockLookBack } = this.eventSearchConfig;
const query = (
await Promise.all([
Expand All @@ -939,11 +939,11 @@ export class SpokePoolClient extends BaseAbstractClient {
const event = query.find(({ args }) => args["depositId"].eq(depositId));
if (event === undefined) {
const srcChain = getNetworkName(this.chainId);
const dstChain = getNetworkName(destinationChainId);
throw new Error(
`Could not find deposit ${depositId.toString()} for ${dstChain} fill` +
` between ${srcChain} blocks [${searchBounds.low}, ${searchBounds.high}]`
);
return {
found: false,
code: InvalidFill.DepositIdNotFound,
reason: `${srcChain} depositId ${depositId} not found between blocks [${fromBlock}, ${toBlock}].`,
};
}

const deposit = {
Expand All @@ -967,7 +967,7 @@ export class SpokePoolClient extends BaseAbstractClient {
elapsedMs: tStop - tStart,
});

return deposit;
return { found: true, deposit };
}

/**
Expand Down
15 changes: 11 additions & 4 deletions src/utils/DepositUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,24 @@ export async function queryHistoricalDepositForFill(
if (isDefined(cachedDeposit)) {
deposit = cachedDeposit as DepositWithBlock;
} else {
deposit = await spokePoolClient.findDeposit(fill.depositId, fill.destinationChainId);
const result = await spokePoolClient.findDeposit(fill.depositId);
if (!result.found) {
return result;
}

({ deposit } = result);
if (cache) {
await setDepositInCache(deposit, getCurrentTime(), cache, DEFAULT_CACHING_TTL);
await setDepositInCache(deposit!, getCurrentTime(), cache, DEFAULT_CACHING_TTL);
}
}

deposit.messageHash ??= getMessageHash(deposit.message);
if (isDefined(deposit)) {
deposit.messageHash ??= getMessageHash(deposit.message);
}

const match = validateFillForDeposit(fill, deposit);
if (match.valid) {
return { found: true, deposit };
return { found: true, deposit: deposit! };
}

return {
Expand Down

0 comments on commit 4cc1f17

Please sign in to comment.