Fix off-by-one in PushBlock that causes nil dereference panic#2924
Merged
wen-coding merged 4 commits intomainfrom Feb 20, 2026
Merged
Fix off-by-one in PushBlock that causes nil dereference panic#2924wen-coding merged 4 commits intomainfrom
wen-coding merged 4 commits intomainfrom
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2924 +/- ##
==========================================
+ Coverage 68.42% 68.64% +0.21%
==========================================
Files 5 5
Lines 456 456
==========================================
+ Hits 312 313 +1
+ Misses 114 113 -1
Partials 30 30
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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
arajasek
approved these changes
Feb 19, 2026
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>
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>
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>
TestPushBlockAcceptsBlockWithQC exercises PushBlock outside a synctest bubble so coverage instrumentation records the changed line. Co-authored-by: Cursor <cursoragent@cursor.com>
812e0d1 to
e923016
Compare
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).