-
Notifications
You must be signed in to change notification settings - Fork 28
reorg handles transaction/logs count #310
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2a808a8
reorg handles transaction/logs count
nischitpra 5a75c64
minor change
nischitpra a8a23b7
Np/debug reorg (#311)
nischitpra 6a68b0f
log kafka message
nischitpra e1104ac
Merge branch 'np/reorg_fix' of https://github.com/thirdweb-dev/insigh…
nischitpra 9309415
remove get block from clickhouse verificatino
nischitpra 8ab3050
undo test codes
nischitpra cc81319
log updates
nischitpra ee8e4b5
last block check
nischitpra ebf1254
minor change
nischitpra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Harden header handling against nils and decouple header-based reorgs from ClickHouse verification failures
Overall structure of the new multi-source reorg detection looks solid, and handling the error from
SetReorgLastValidBlockis a good improvement. There are, however, a couple of important robustness gaps in this function:GetBlockHeadersForReorgCheckPer the provided context,
GetBlockHeadersForReorgCheckcan return a[]*common.Block"with nils for missing entries if any". The continuity loop andlastHeaderBlockassignment assume that every element is non-nil:blockHeaders[i].Number.Int64()andblockHeaders[i-1].Number.Int64()(Lines 112–115, 121, 127)lastHeaderBlock := blockHeaders[len(blockHeaders)-1].Number.Int64()(Line 134)If any entry is nil, this will panic and take down the validator. At minimum, you should defensively guard against nil entries before dereferencing:
blockHeaders, err := libs.GetBlockHeadersForReorgCheck(libs.ChainId.Uint64(), uint64(startBlock), uint64(endBlock)) if err != nil { return 0, fmt.Errorf("detectAndHandleReorgs: failed to get block headers: %w", err) } if len(blockHeaders) == 0 { log.Debug().Msg("detectAndHandleReorgs: No block headers found in range") return 0, nil } + + // Fail fast if any header in the range is unexpectedly nil to avoid panics. + for i, h := range blockHeaders { + if h == nil { + return 0, fmt.Errorf("detectAndHandleReorgs: nil header at index %d (start=%d end=%d)", i, startBlock, endBlock) + } + } @@ - // set end to the last block if not set - lastHeaderBlock := blockHeaders[len(blockHeaders)-1].Number.Int64() + // set end to the last block if not set + lastHeaderBlock := blockHeaders[len(blockHeaders)-1].Number.Int64()If nils are actually expected in normal operation, you may instead want to skip those entries or treat them as mismatches rather than returning an error, but you should still avoid dereferencing them.
Right now any failure from
GetTransactionMismatchRangeFromClickHouseV2orGetLogsMismatchRangeFromClickHouseV2aborts the whole function:This couples correctness to ClickHouse health even when header continuity has already detected a clear reorg range (
reorgStartBlock > -1). A transient failure in either mismatch query will prevent you from handling a header-based reorg at all.Consider treating these mismatch checks as best-effort signals and falling back to header-only behavior when they fail, for example:
txStart, txEnd, err := libs.GetTransactionMismatchRangeFromClickHouseV2(libs.ChainId.Uint64(), uint64(startBlock), uint64(endBlock)) if err != nil { - return 0, fmt.Errorf("detectAndHandleReorgs: transaction verification failed: %w", err) + log.Error().Err(err). + Int64("start_block", startBlock). + Int64("end_block", endBlock). + Msg("detectAndHandleReorgs: transaction verification failed; continuing with other signals") + txStart, txEnd = -1, -1 } @@ logsStart, logsEnd, err := libs.GetLogsMismatchRangeFromClickHouseV2(libs.ChainId.Uint64(), uint64(startBlock), uint64(endBlock)) if err != nil { - return 0, fmt.Errorf("detectAndHandleReorgs: logs verification failed: %w", err) + log.Error().Err(err). + Int64("start_block", startBlock). + Int64("end_block", endBlock). + Msg("detectAndHandleReorgs: logs verification failed; continuing with other signals") + logsStart, logsEnd = -1, -1 }This way:
len(blockHeaders) == 0Currently the "no headers found" path returns
(0, nil)and never updates Redis:Given the caller only uses the returned
lastValidBlockfor logging, this is not a correctness bug, but it does mean:last_block_checkwill be logged as0for that iteration.getLastValidBlockwill continue to drive the window based on the previous Redis value or the "1 day ago" fallback.If this "no headers in range" case is expected to happen in practice (e.g., sparse data or lag), you might want to either:
startBlock-1) and handle that in the caller instead of overloading0.Also applies to: 108-138, 140-152, 153-183, 185-198