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

Validate RPC log/callTrace response #1152

Merged
7 changes: 7 additions & 0 deletions packages/core/src/sync-realtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,13 @@ export const createRealtimeSync = (
requiredTransactions.has(hash),
);

// Validate that filtered logs/callTraces point to valid transaction in the block
if (transactions.length !== requiredTransactions.size) {
throw new Error(
`Received callTrace/log in the block referencing transaction that is not in current head block '${block.hash}'`,
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but I'd advocate for a more specific error message which includes the suspicious transaction hashes. That would make it much easier for us to submit bug reports to chains / RPC providers.

Also, what if the lengths are different because we have an extra required transaction? That scenario would suggest a Ponder bug rather than a faulty RPC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. With regards to error message, do you think it would be better to include the list of suspicious tx hashes in the message?
  2. We would expect requiredTransactions size to be larger than transactions length only in the case if some logs or callTraces that is matched with filter are pointing to more transactions, than there are transactions filtered by those logs/traces.
    const transactions = block.transactions.filter(({ hash }) => requiredTransactions.has(hash), );

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yes
  2. I think the transaction validation should be more precise. Something like:
const blockTransactionsHashes = new Set(
  block.transactions.map((t) => t.hash),
);
for (const hash of Array.from(requiredTransactions)) {
  if (blockTransactionsHashes.has(hash) === false) {
    // throw error, include `hash`
  }
}

I also think it would be nice to have something that compares blockHash in logs and callTraces to block.hash

}

////////
// Transaction Receipts
////////
Expand Down
Loading