Fix off-by-one in PushBlock that causes nil dereference panic#2924
Open
wen-coding wants to merge 7 commits intomainfrom
Open
Fix off-by-one in PushBlock that causes nil dereference panic#2924wen-coding wants to merge 7 commits intomainfrom
wen-coding wants to merge 7 commits intomainfrom
Conversation
PushBlock's WaitUntil used n <= inner.nextQC, allowing it to proceed when n == nextQC. Since inner.qcs stores [first, nextQC), the lookup returns nil, causing a panic on qc.Headers(). Changed to n < nextQC to match every other waiter in the file. Added defense-in-depth nil check with a descriptive error message. Co-authored-by: Cursor <cursoragent@cursor.com>
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2924 +/- ##
==========================================
- Coverage 57.35% 57.33% -0.02%
==========================================
Files 2095 2095
Lines 172870 172870
==========================================
- Hits 99142 99110 -32
- Misses 64842 64869 +27
- Partials 8886 8891 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
WaitUntil(n < nextQC) guarantees inner.qcs[n] is non-nil, making the defense-in-depth nil check dead code that triggers coverage complaints. Co-authored-by: Cursor <cursoragent@cursor.com>
pompon0
reviewed
Feb 19, 2026
| "github.com/sei-protocol/sei-chain/sei-tendermint/internal/autobahn/types" | ||
| "github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils" | ||
| "github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils/scope" | ||
| "github.com/stretchr/testify/require" |
Contributor
There was a problem hiding this comment.
libs/utils/require. It contains a strongly typed wrappers of testify/require. If you are missing any wrappers, you can add them there.
pompon0
reviewed
Feb 19, 2026
| _, err := state.TryBlock(gr2.First) | ||
| require.ErrorIs(t, err, ErrNotFound) | ||
|
|
||
| // PushBlock for a block in qc2's range. With the off-by-one bug |
pompon0
reviewed
Feb 19, 2026
| // (n <= inner.nextQC), this would immediately dereference a nil QC | ||
| // pointer and panic. With the fix, it waits for the QC. | ||
| errc := make(chan error, 1) | ||
| go func() { |
Contributor
There was a problem hiding this comment.
this looks like a great use case for https://go.dev/blog/synctest . Do you want to give it a try?
pompon0
approved these changes
Feb 19, 2026
Replace manual goroutine + channel pattern with synctest.Test/Wait, enabling a stronger intermediate assertion that the block is absent while PushBlock is blocked. Also switch to libs/utils/require. Co-authored-by: Cursor <cursoragent@cursor.com>
arajasek
approved these changes
Feb 19, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
PushBlock: TheWaitUntilcondition usedn <= inner.nextQC, which allowsPushBlockto proceed whenn == nextQC. Sinceinner.qcsstores entries for the half-open range[first, nextQC), the map lookup returnsnil, and the subsequentqc.Headers()call panics with a nil pointer dereference. Changed ton < inner.nextQCto match every other waiter in the file (QC,Block,GlobalBlock,AppProposal).