Skip to content

use full commit verification in blocksync (CON-246) - #4847

Open
merkroot wants to merge 21 commits into
mainfrom
sanaz/blocksync-commit-check
Open

merkroot wants to merge 21 commits into
mainfrom
sanaz/blocksync-commit-check

Conversation

@merkroot

Copy link
Copy Markdown

Blocksync now verifies every signature of a commit before it saves the commit with a block, the same check that block validation already applies. The new test TestReactor_RejectsInvalidCommitFromPeer covers this.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedNov 17, 2026, 1:18 AM

@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.62%. Comparing base (c7d841c) to head (9d37be5).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4847      +/-   ##
==========================================
- Coverage   61.62%   61.62%   -0.01%     
==========================================
  Files        2080     2080              
  Lines      162041   162041              
==========================================
- Hits        99865    99860       -5     
- Misses      62171    62176       +5     
  Partials        5        5              
Flag Coverage Δ
sei-chain 59.82% <100.00%> (-0.01%) ⬇️
sei-db 75.17% <ø> (ø)
sei-db-state-db 81.61% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-tendermint/internal/blocksync/reactor.go 69.67% <100.00%> (ø)

... and 26 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@merkroot merkroot changed the title use full commit verification in blocksync use full commit verification in blocksync (CON 246) Nov 13, 2026
@merkroot merkroot changed the title use full commit verification in blocksync (CON 246) use full commit verification in blocksync (CON-246) Nov 13, 2026
@merkroot

Copy link
Copy Markdown
Author

@seidroid review

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Blocksync now runs the full VerifyCommit on second.LastCommit before saving it as the seen commit of first, so nil votes and the signatures beyond the 2/3 mark are checked too, which matches the check ValidateBlock already applies to LastCommit; the new test catches both cases the light check let through, and NewReactor now accepts the sm.BlockStore interface, which *store.BlockStore still satisfies. I found nothing that blocks after reviewing against the merge tree at 0660c94 (not built or run, because the sandbox has no Go toolchain); I dropped codex's one finding because ed25519.Signature.Bytes() has a value receiver and returns a copy, so flipping a byte in withBadLastSignature cannot change correct[2].commit.

seidroid review · decision approve · session 9ba7e82a3cf54db8aaa6ed953ee78289 · turn resp_claude_3770df9649c63430cfdfa9cc940d8519 · item 97c9d415fda55c7d884681a0b9062e29

Findings: 0 blocking | 0 non-blocking | 0 posted inline

@merkroot
merkroot marked this pull request as ready for review November 13, 2026 17:24
@merkroot
merkroot requested a review from wen-coding November 13, 2026 17:24
@cursor

cursor Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches consensus-critical blocksync validation and what commits get persisted, though behavior aligns with full block validation and is covered by new integration tests.

Overview
Block sync now runs full commit verification (VerifyCommit) instead of the light path when checking the next block’s LastCommit before persisting the prior block’s seen commit, so invalid signatures are never written to the block store.

NewReactor and tests depend on the sm.BlockStore interface rather than the concrete internal/store type. Test helpers were refactored (makeCommittedBlock, injectable mem block stores), and TestReactor_RejectsInvalidCommitFromPeer was added to assert that a syncing node stops at a bad commit, evicts the peer, and continues from a honest peer (commit and nil vote cases).

Reviewed by Cursor Bugbot for commit 9d37be5. Bugbot is set up for automated code reviews on this repo. Configure here.

sm "github.com/sei-protocol/sei-chain/sei-tendermint/internal/state"
"github.com/sei-protocol/sei-chain/sei-tendermint/internal/test/factory"
"github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils"
utilsrequire "github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils/require"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: alias is not needed, now that you replaced testify/require

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Dropped the alias, the file imports utils/require as require now.
39eea39

require.NoError(t, err)
server.store.SaveBlock(block, partSet, seenCommit)
lastCommit = seenCommit
blockStore.SaveBlock(b.block, b.parts, b.commit)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: is there any particular reason why server.store.SaveBlock won't do?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, done.
6631445

@@ -28,6 +28,7 @@ import (
"github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils"
utilsrequire "github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils/require"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: while you are at it, can you migrate all assertions in this file to utils/require? It is kind of annoying to have both testify/require and utils/require in the same file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. Every assertion in the file goes through utils/require, and the testify require and assert imports are gone. testify/mock stays for MockBlockStore.
e12a807

// WaitForDisconnect panics with the context error.
defer func() {
if r := recover(); r != nil {
ctxErr, ok := r.(error)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: err = r.(error) would also panic on bad cast

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, simplified to err = r.(error). The helper later went away entirely with the change for the disconnect comment below.
8e02cd9

} {
t.Run(tc.name, func(t *testing.T) {
// After every other cleanup, no goroutine of the nodes is left running.
t.Cleanup(leaktest.Check(t))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fyi: we do not consider leaktest very useful in our codebase, and other occurrences that you see are mostly leftovers from the original fork.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, removed the leaktest check and its import from the new test.
d5400e9

err = scope.Run(ctx, func(ctx context.Context, s scope.Scope) error {
// Report the end of the first connection to the invalid-commit node.
s.SpawnBgNamed("wait for disconnection", func() error {
if err := waitForDisconnect(ctx, syncNode, invalidCommitConn); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: imo you can just wait for disconnect directly in the main task, rather than going though the syncEvent channel.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. The main task calls WaitForDisconnect directly, so the background task, the scope.Run block, the disconnect event and the waitForDisconnect wrapper are gone.
04d96c3

})

// Block 1 is saved with its correct seen commit.
if err := observer.expectSaved(ctx, correct[0].block, correct[0].commit); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: these assertions are rather strong and require a very specific order of events. How about just waiting for disconnect and then assert the db content afterwards (i.e. blocks 0,1 and missing block 2)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. After the disconnect the test checks the syncing node's store: height 2, block 2, and the seen commit of block 2. For block 3 from the correct node, the store wrapper publishes the saved height on an AtomicSend and the test waits on that, then checks block 3 and its seen commit.
d434138

@pompon0 pompon0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm, please consider "nit" comments as non-blocking

@merkroot
merkroot requested a review from sei-will November 16, 2026 15:36
@merkroot

Copy link
Copy Markdown
Author

@seidroid review

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The fix is unchanged: blocksync still runs the full VerifyCommit before saving a commit as the seen commit. Since my last review only the tests moved: TestReactor_RejectsInvalidCommitFromPeer now uses a store that records the height of each saved block, instead of the event channel and the panic-recovering helper, and the files switched to the libs/utils/require wrappers. I checked this against the merge tree at 7071aec and found nothing new and nothing left open from before, so I approve; codex also found nothing, so it added no findings. Nothing was built or run, because the sandbox has no Go toolchain.

seidroid review · decision approve · session 9ba7e82a3cf54db8aaa6ed953ee78289 · turn resp_claude_dbef8dfa2ce8adf08861616983210d1f · item 2624295bf1a857a286edcb80f3b9d7cd

Findings: 0 blocking | 0 non-blocking | 0 posted inline

@merkroot

Copy link
Copy Markdown
Author

@seidroid review

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Only the tests moved since my last review: the new test now also checks that the syncing node stored the correct block 2 before it dropped the peer, and the status test reads its block store through server.store; the fix itself, the full VerifyCommit before saving the seen commit, is unchanged. I checked this against the merge tree at 952ad9d, found no new issue and had none open from before, so I approve; codex also found nothing, so it added no findings, and nothing was built or run.

seidroid review · decision approve · session 9ba7e82a3cf54db8aaa6ed953ee78289 · turn resp_claude_04d16c33a1058f4e5342f596f484530f · item 195d6e09210955beb1159b9a04ab9f78

Findings: 0 blocking | 0 non-blocking | 0 posted inline

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants