Skip to content

feature: Get all Invalid Fills #1085

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions src/clients/SpokePoolClient/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,21 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
);
}

/**
* Find all deposits (including duplicates) based on its deposit ID.
* @param depositId The unique ID of the deposit being queried.
* @returns Array of all deposits with the given depositId, including duplicates.
*/
public getDepositsForDepositId(depositId: BigNumber): DepositWithBlock[] {
const deposit = this.getDeposit(depositId);
if (!deposit) {
return [];
}
const depositHash = getRelayEventKey(deposit);
const duplicates = this.duplicateDepositHashes[depositHash] ?? [];
return [deposit, ...duplicates];
}

// ///////////////////////
// // ABSTRACT METHODS //
// ///////////////////////
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/SpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export interface Fill extends Omit<RelayData, "message"> {
relayExecutionInfo: RelayExecutionEventInfo;
}

export interface InvalidFill {
fill: FillWithBlock;
validationResults: Array<{
reason: string;
deposit?: DepositWithBlock;
}>;
}

export interface FillWithBlock extends Fill, SortableEvent {}
export interface FillWithTime extends Fill, SortableEvent {
fillTimestamp: number;
Expand Down
66 changes: 64 additions & 2 deletions src/utils/SpokeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { encodeAbiParameters, Hex, keccak256 } from "viem";
import { fixedPointAdjustment as fixedPoint } from "./common";
import { MAX_SAFE_DEPOSIT_ID, ZERO_ADDRESS, ZERO_BYTES } from "../constants";
import { Deposit, Fill, FillType, RelayData, SlowFillLeaf } from "../interfaces";
import { Deposit, DepositWithBlock, Fill, FillType, InvalidFill, RelayData, SlowFillLeaf } from "../interfaces";
import { toBytes32 } from "./AddressUtils";
import { BigNumber } from "./BigNumberUtils";
import { isMessageEmpty } from "./DepositUtils";
import { isMessageEmpty, validateFillForDeposit } from "./DepositUtils";
import { chainIsSvm } from "./NetworkUtils";
import { svm } from "../arch";
import { SpokePoolClient } from "../clients";

export function isSlowFill(fill: Fill): boolean {
return fill.relayExecutionInfo.fillType === FillType.SlowFill;
Expand Down Expand Up @@ -102,3 +103,64 @@ export function isZeroAddress(address: string): boolean {
export function getMessageHash(message: string): string {
return isMessageEmpty(message) ? ZERO_BYTES : keccak256(message as Hex);
}

export function findInvalidFills(spokePoolClients: { [chainId: number]: SpokePoolClient }): InvalidFill[] {
const invalidFills: InvalidFill[] = [];

// Iterate through each spoke pool client
Object.values(spokePoolClients).forEach((spokePoolClient) => {
// Get all fills for this client
const fills = spokePoolClient.getFills();

// Process each fill
fills.forEach((fill) => {
// Skip fills with unsafe deposit IDs
if (isUnsafeDepositId(fill.depositId)) {
return;
}

// Get all deposits (including duplicates) for this fill's depositId
const deposits = spokePoolClients[fill.originChainId].getDepositsForDepositId(fill.depositId);

// If no deposits found at all
if (deposits.length === 0) {
invalidFills.push({
fill,
validationResults: [
{
reason: `no deposit with depositId ${fill.depositId} found`,
},
],
});
return;
}

// Try to find a valid deposit for this fill
let foundValidDeposit = false;
const validationResults: Array<{ reason: string; deposit: DepositWithBlock }> = [];

for (const deposit of deposits) {
// Validate the fill against the deposit
const validationResult = validateFillForDeposit(fill, deposit);
if (validationResult.valid) {
foundValidDeposit = true;
break;
}
validationResults.push({
reason: validationResult.reason,
deposit,
});
}

// If no valid deposit was found, add to invalid fills with all validation results
if (!foundValidDeposit) {
invalidFills.push({
fill,
validationResults,
});
}
});
});

return invalidFills;
}