Skip to content

Commit

Permalink
refactor(SpokePoolClient): Drop historical depositId queries
Browse files Browse the repository at this point in the history
These queries seem to be mostly superfluous; they can be dropped to ease
non-EVM integrations.
  • Loading branch information
pxrl committed Mar 6, 2025
1 parent 29cc135 commit eccd069
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 64 deletions.
34 changes: 2 additions & 32 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import {
getRelayEventKey,
isDefined,
toBN,
bnOne,
getMessageHash,
isUnsafeDepositId,
isSlowFill,
isValidEvmAddress,
isZeroAddress,
Expand Down Expand Up @@ -56,8 +54,6 @@ import { getRepaymentChainId, forceDestinationRepayment } from "./BundleDataClie
type SpokePoolUpdateSuccess = {
success: true;
currentTime: number;
firstDepositId: BigNumber;
latestDepositId: BigNumber;
events: Log[][];
searchEndBlock: number;
};
Expand Down Expand Up @@ -85,10 +81,6 @@ export class SpokePoolClient extends BaseAbstractClient {
protected queryableEventNames: string[] = [];
protected configStoreClient: AcrossConfigStoreClient | undefined;
protected invalidFills: Set<string> = new Set();
public earliestDepositIdQueried = MAX_BIG_INT;
public latestDepositIdQueried = bnZero;
public firstDepositIdForSpokePool = MAX_BIG_INT;
public lastDepositIdForSpokePool = MAX_BIG_INT;
public fills: { [OriginChainId: number]: FillWithBlock[] } = {};

/**
Expand Down Expand Up @@ -518,16 +510,6 @@ export class SpokePoolClient extends BaseAbstractClient {
* @returns A Promise that resolves to a SpokePoolUpdate object.
*/
protected async _update(eventsToQuery: string[]): Promise<SpokePoolUpdate> {
// Find the earliest known depositId. This assumes no deposits were placed in the deployment block.
let firstDepositId = this.firstDepositIdForSpokePool;
if (firstDepositId.eq(MAX_BIG_INT)) {
firstDepositId = await this.spokePool.numberOfDeposits({ blockTag: this.deploymentBlock });
firstDepositId = BigNumber.from(firstDepositId); // Cast input to a big number.
if (!BigNumber.isBigNumber(firstDepositId) || firstDepositId.lt(bnZero)) {
throw new Error(`SpokePoolClient::update: Invalid first deposit id (${firstDepositId})`);
}
}

const searchConfig = await this.updateSearchConfig(this.spokePool.provider);
if (isUpdateFailureReason(searchConfig)) {
const reason = searchConfig;
Expand Down Expand Up @@ -562,7 +544,7 @@ export class SpokePoolClient extends BaseAbstractClient {
});

const timerStart = Date.now();
const multicallFunctions = ["getCurrentTime", "numberOfDeposits"];
const multicallFunctions = ["getCurrentTime"];
const [multicallOutput, ...events] = await Promise.all([
spokePool.callStatic.multicall(
multicallFunctions.map((f) => spokePool.interface.encodeFunctionData(f)),
Expand All @@ -572,10 +554,9 @@ export class SpokePoolClient extends BaseAbstractClient {
]);
this.log("debug", `Time to query new events from RPC for ${this.chainId}: ${Date.now() - timerStart} ms`);

const [currentTime, _numberOfDeposits] = multicallFunctions.map(
const [currentTime] = multicallFunctions.map(
(fn, idx) => spokePool.interface.decodeFunctionResult(fn, multicallOutput[idx])[0]
);
const _latestDepositId = BigNumber.from(_numberOfDeposits).sub(bnOne);

if (!BigNumber.isBigNumber(currentTime) || currentTime.lt(this.currentTime)) {
const errMsg = BigNumber.isBigNumber(currentTime)
Expand All @@ -590,8 +571,6 @@ export class SpokePoolClient extends BaseAbstractClient {
return {
success: true,
currentTime: currentTime.toNumber(), // uint32
firstDepositId,
latestDepositId: _latestDepositId.gt(bnZero) ? _latestDepositId : bnZero,
searchEndBlock: searchConfig.toBlock,
events,
};
Expand Down Expand Up @@ -673,13 +652,6 @@ export class SpokePoolClient extends BaseAbstractClient {
continue;
}
assign(this.depositHashes, [getRelayEventKey(deposit)], deposit);

if (deposit.depositId.lt(this.earliestDepositIdQueried) && !isUnsafeDepositId(deposit.depositId)) {
this.earliestDepositIdQueried = deposit.depositId;
}
if (deposit.depositId.gt(this.latestDepositIdQueried) && !isUnsafeDepositId(deposit.depositId)) {
this.latestDepositIdQueried = deposit.depositId;
}
}
};

Expand Down Expand Up @@ -831,9 +803,7 @@ export class SpokePoolClient extends BaseAbstractClient {

// Next iteration should start off from where this one ended.
this.currentTime = currentTime;
this.firstDepositIdForSpokePool = update.firstDepositId;
this.latestBlockSearched = searchEndBlock;
this.lastDepositIdForSpokePool = update.latestDepositId;
this.firstBlockToSearch = searchEndBlock + 1;
this.eventSearchConfig.toBlock = undefined; // Caller can re-set on subsequent updates if necessary
this.isUpdated = true;
Expand Down
9 changes: 0 additions & 9 deletions src/clients/mocks/MockSpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
randomAddress,
BigNumber,
bnZero,
bnMax,
bnOne,
toAddress,
toBytes32,
Expand Down Expand Up @@ -107,17 +106,9 @@ export class MockSpokePoolClient extends SpokePoolClient {
}
});

// Update latestDepositIdQueried.
const idx = eventsToQuery.indexOf("V3FundsDeposited");
const latestDepositId = (events[idx] ?? []).reduce(
(depositId, event) => bnMax(depositId, event.args["depositId"] ?? bnZero),
this.latestDepositIdQueried
);

return Promise.resolve({
success: true,
firstDepositId: bnZero,
latestDepositId,
currentTime,
oldestTime: 0,
events,
Expand Down
29 changes: 6 additions & 23 deletions src/utils/DepositUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,10 @@ export async function queryHistoricalDepositForFill(
}

const { depositId } = fill;
let { firstDepositIdForSpokePool: lowId, lastDepositIdForSpokePool: highId } = spokePoolClient;
if (depositId.lt(lowId) || depositId.gt(highId)) {
return {
found: false,
code: InvalidFill.DepositIdInvalid,
reason: `Deposit ID ${depositId.toString()} is outside of SpokePool bounds [${lowId},${highId}].`,
};
}

({ earliestDepositIdQueried: lowId, latestDepositIdQueried: highId } = spokePoolClient);
if (depositId.gte(lowId) && depositId.lte(highId)) {
const originChain = getNetworkName(fill.originChainId);
const deposit = spokePoolClient.getDeposit(depositId);
if (isDefined(deposit)) {
const match = validateFillForDeposit(fill, deposit);
const originChain = getNetworkName(fill.originChainId);
let deposit = spokePoolClient.getDeposit(depositId);
if (isDefined(deposit)) {
const match = validateFillForDeposit(fill, deposit);
if (match.valid) {

Check warning on line 67 in src/utils/DepositUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
return { found: true, deposit };

Check warning on line 68 in src/utils/DepositUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
}

Check warning on line 69 in src/utils/DepositUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `······` with `····`
Expand All @@ -86,14 +75,8 @@ export async function queryHistoricalDepositForFill(
};

Check warning on line 75 in src/utils/DepositUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
}

Check warning on line 76 in src/utils/DepositUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`

return {
found: false,
code: InvalidFill.DepositIdNotFound,
reason: `${originChain} deposit ID ${depositId.toString()} not found in SpokePoolClient event buffer.`,
};
}

let deposit: DepositWithBlock, cachedDeposit: Deposit | undefined;
// Deposit not found in SpokePoolClient buffer, search elsewhere.
let cachedDeposit: Deposit | undefined;
if (cache) {
cachedDeposit = await getDepositInCache(getDepositKey(fill), cache);
// We only want to warn and remove the cached deposit if it
Expand Down

0 comments on commit eccd069

Please sign in to comment.