Skip to content

Commit

Permalink
fix: zkSync system logs (#1411)
Browse files Browse the repository at this point in the history
* fix: zkSync system logs

* chore: changeset and logs

---------

Co-authored-by: typedarray <[email protected]>
  • Loading branch information
kyscott18 and typedarray authored Jan 6, 2025
1 parent 82612fb commit 60704d3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-pigs-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ponder": patch
---

Fixed an issue where ZKsync system logs failed with the error `Detected inconsistent RPC responses. 'log.transactionHash' 0x0000000000000000000000000000000000000000000000000000000000000000 not found in 'block.transactions' (...)`.
14 changes: 11 additions & 3 deletions packages/core/src/sync-historical/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
hexToBigInt,
hexToNumber,
toHex,
zeroHash,
} from "viem";

export type HistoricalSync = {
Expand Down Expand Up @@ -493,9 +494,16 @@ export const createHistoricalSync = async (
block.transactions.find((t) => t.hash === log.transactionHash) ===
undefined
) {
throw new Error(
`Detected inconsistent RPC responses. 'log.transactionHash' ${log.transactionHash} not found in 'block.transactions' ${block.hash}`,
);
if (log.transactionHash === zeroHash) {
args.common.logger.warn({
service: "sync",
msg: `Detected log with empty transaction hash in block ${block.hash} at log index ${hexToNumber(log.logIndex)}. This is expected for some networks like ZKsync.`,
});
} else {
throw new Error(
`Detected inconsistent RPC responses. 'log.transactionHash' ${log.transactionHash} not found in 'block.transactions' ${block.hash}`,
);
}
}
}

Expand Down
19 changes: 17 additions & 2 deletions packages/core/src/sync-realtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from "@/utils/rpc.js";
import { wait } from "@/utils/wait.js";
import { type Queue, createQueue } from "@ponder/common";
import { type Address, type Hash, hexToNumber } from "viem";
import { type Address, type Hash, hexToNumber, zeroHash } from "viem";
import { isFilterInBloom, zeroLogsBloom } from "./bloom.js";
import {
isBlockFilterMatched,
Expand Down Expand Up @@ -658,13 +658,28 @@ export const createRealtimeSync = (
);
}

// Check that logs refer to the correct block
for (const log of logs) {
if (log.blockHash !== block.hash) {
throw new Error(
`Detected invalid eth_getLogs response. 'log.blockHash' ${log.blockHash} does not match requested block hash ${block.hash}`,
);
}

if (
block.transactions.find((t) => t.hash === log.transactionHash) ===
undefined
) {
if (log.transactionHash === zeroHash) {
args.common.logger.warn({
service: "sync",
msg: `Detected log with empty transaction hash in block ${block.hash} at log index ${hexToNumber(log.logIndex)}. This is expected for some networks like ZKsync.`,
});
} else {
throw new Error(
`Detected inconsistent RPC responses. 'log.transactionHash' ${log.transactionHash} not found in 'block.transactions' ${block.hash}`,
);
}
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/sync/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ export const buildEvents = ({
}),
log: convertLog(log),
block: convertBlock(block),
transaction: convertTransaction(
transactionCache.get(log.transactionHash)!,
),
transaction: transactionCache.has(log.transactionHash)
? convertTransaction(
transactionCache.get(log.transactionHash)!,
)
: undefined,
transactionReceipt: shouldGetTransactionReceipt(filter)
? convertTransactionReceipt(
transactionReceiptCache.get(log.transactionHash)!,
Expand Down

0 comments on commit 60704d3

Please sign in to comment.