Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
db17019
use full commit verification in blocksync
merkroot Nov 13, 2026
3df5305
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot Nov 13, 2026
98c9057
take the block store interface in NewReactor
merkroot Nov 13, 2026
1909420
use one block fixture generator in the blocksync tests
merkroot Nov 13, 2026
ee979bb
rename test peers to invalidCommitPeer and correctPeer in blocksync v…
merkroot Nov 13, 2026
85a5a6d
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot Nov 13, 2026
aa1d98d
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot Nov 13, 2026
cc435e6
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot Nov 13, 2026
5c37d91
minor formatting fix
merkroot Nov 16, 2026
6631445
save and read fixture blocks through the reactor store in the older b…
merkroot Nov 16, 2026
d5400e9
drop the leaktest check from the blocksync validation test
merkroot Nov 16, 2026
8e02cd9
let the type assertion panic on a non-error value in waitForDisconnect
merkroot Nov 16, 2026
04d96c3
wait for the peer disconnect in the main task of the blocksync valida…
merkroot Nov 16, 2026
d434138
assert the store content of the syncing node instead of the order of …
merkroot Nov 17, 2026
39eea39
import utils/require without an alias in the blocksync validation test
merkroot Nov 17, 2026
e12a807
use utils/require for every assertion in the blocksync reactor test
merkroot Nov 17, 2026
14096da
remove a double space in the godoc of the blocksync invalid commit test
merkroot Nov 17, 2026
d81bc59
name the block with the invalid commit after the invalid-commit peer …
merkroot Nov 17, 2026
8d777da
name the store wrapper as the actor that publishes the saved height
merkroot Nov 17, 2026
50160d7
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot Nov 17, 2026
9d37be5
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions sei-tendermint/internal/blocksync/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/sei-protocol/sei-chain/sei-tendermint/internal/eventbus"
"github.com/sei-protocol/sei-chain/sei-tendermint/internal/p2p"
sm "github.com/sei-protocol/sei-chain/sei-tendermint/internal/state"
"github.com/sei-protocol/sei-chain/sei-tendermint/internal/store"
"github.com/sei-protocol/sei-chain/sei-tendermint/libs/service"
"github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils"
"github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils/scope"
Expand Down Expand Up @@ -165,7 +164,7 @@ type syncController struct {
// NewReactor returns new reactor instance.
func NewReactor(
stateStore sm.Store,
store *store.BlockStore,
store sm.BlockStore,
router *p2p.Router,
syncerConfig utils.Option[SyncerConfig],
) (*Reactor, error) {
Expand Down Expand Up @@ -552,7 +551,10 @@ func (s *syncController) poolRoutine(ctx context.Context, pool *BlockPool, initi

firstID := types.BlockID{Hash: first.Hash(), PartSetHeader: firstParts.Header()}

err = state.Validators.VerifyCommitLight(chainID, firstID, first.Height, second.LastCommit)
// Use the full check, not the light one, because second.LastCommit is
// saved as the seen commit of first. A seen commit with an invalid
// signature must never be saved.
err = state.Validators.VerifyCommit(chainID, firstID, first.Height, second.LastCommit)
if err != nil {
err = types.DefaultConsensusPolicy().HandleError(fmt.Errorf("%w: %w", types.ErrLastCommitVerify, err))
}
Expand Down
88 changes: 48 additions & 40 deletions sei-tendermint/internal/blocksync/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

pb "github.com/sei-protocol/sei-chain/sei-tendermint/proto/tendermint/blocksync"
tmproto "github.com/sei-protocol/sei-chain/sei-tendermint/proto/tendermint/types"
"github.com/sei-protocol/sei-chain/sei-tendermint/types"
)

Expand Down Expand Up @@ -79,22 +80,27 @@ func setup(
return rts
}

// newMemBlockStore returns a block store backed by a fresh in-memory database.
func newMemBlockStore() sm.BlockStore {
return store.NewBlockStore(dbm.NewMemDB())
}

// makeReactor returns a reactor serving genDoc on router, backed by blockStore.
func makeReactor(
ctx context.Context,
t *testing.T,
genDoc *types.GenesisDoc,
router *p2p.Router,
blockStore sm.BlockStore,
blockSync bool,
restartEvent func(),
selfRemediationConfig *config.SelfRemediationConfig,
) *Reactor {

app := abci.BaseApplication{}

blockDB := dbm.NewMemDB()
stateDB := dbm.NewMemDB()
stateStore := sm.NewStore(stateDB)
blockStore := store.NewBlockStore(blockDB)
proxyApp := proxy.New(app)

state, err := sm.MakeGenesisState(genDoc)
Expand Down Expand Up @@ -148,11 +154,13 @@ func (rts *reactorTestSuite) addNode(
remediationConfig := config.DefaultSelfRemediationConfig()
remediationConfig.BlocksBehindThreshold = 1000

blockStore := newMemBlockStore()
reactor := makeReactor(
ctx,
t,
genDoc,
rts.network.Node(nodeID).Router,
blockStore,
true,
func() {},
remediationConfig,
Expand All @@ -162,52 +170,48 @@ func (rts *reactorTestSuite) addNode(
state, err := reactor.stateStore.Load()
require.NoError(t, err)
for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ {
block, blockID, partSet, seenCommit := makeNextBlock(ctx, t, state, privVal, blockHeight, lastCommit)
b := makeCommittedBlock(ctx, t, state, utils.Slice(privVal), blockHeight, lastCommit)

syncer := reactor.syncer.OrPanic("syncer should be configured in tests")
state, err = syncer.blockExec.ApplyBlock(ctx, state, blockID, block, nil)
state, err = syncer.blockExec.ApplyBlock(ctx, state, b.id, b.block, nil)
require.NoError(t, err)

reactor.store.SaveBlock(block, partSet, seenCommit)
lastCommit = seenCommit
blockStore.SaveBlock(b.block, b.parts, b.commit)
lastCommit = b.commit
}

rts.reactors[nodeID] = reactor
require.NoError(t, reactor.Start(ctx))
require.True(t, reactor.IsRunning())
}

func makeNextBlock(ctx context.Context,
// committedBlock is a block with its ID, its part set, and a commit for it.
type committedBlock struct {
block *types.Block
id types.BlockID
parts *types.PartSet
commit *types.Commit
}

// makeCommittedBlock returns the block at height on top of state, with lastCommit as its last
// commit, and a commit for it signed by every validator in privVals.
func makeCommittedBlock(
ctx context.Context,
t *testing.T,
state sm.State,
signer types.PrivValidator,
privVals []types.PrivValidator,
height int64,
lc *types.Commit) (*types.Block, types.BlockID, *types.PartSet, *types.Commit) {
block := sf.MakeBlock(state, height, lc)
partSet, err := block.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: partSet.Header()}

// Simulate a commit for the current height
vote, err := factory.MakeVote(
ctx,
signer,
block.Header.ChainID,
0,
block.Header.Height,
0,
2,
blockID,
time.Now(),
)
require.NoError(t, err)
seenCommit := &types.Commit{
Height: vote.Height,
Round: vote.Round,
BlockID: blockID,
Signatures: []types.CommitSig{vote.CommitSig()},
}
return block, blockID, partSet, seenCommit
lastCommit *types.Commit,
) committedBlock {
t.Helper()
block := sf.MakeBlock(state, height, lastCommit)
parts, err := block.MakePartSet(types.BlockPartSizeBytes)
utilsrequire.NoError(t, err)
id := types.BlockID{Hash: block.Hash(), PartSetHeader: parts.Header()}
voteSet := types.NewVoteSet(state.ChainID, height, 0, tmproto.PrecommitType, state.Validators)
commit, err := factory.MakeCommit(ctx, id, height, 0, voteSet, privVals, time.Now())
utilsrequire.NoError(t, err)
return committedBlock{block: block, id: id, parts: parts, commit: commit}
}

func (rts *reactorTestSuite) start(t *testing.T) {
Expand Down Expand Up @@ -493,11 +497,13 @@ func TestQueryResponder_ServesBlockRequestsWhenBlockSyncDisabled(t *testing.T) {
network := p2p.MakeTestNetwork(t, p2p.TestNetworkOptions{NumNodes: 2})
nodeIDs := network.NodeIDs()

blockStore := newMemBlockStore()
server := makeReactor(
ctx,
t,
genDoc,
network.Node(nodeIDs[0]).Router,
blockStore,
false,
func() {},
config.DefaultSelfRemediationConfig(),
Expand All @@ -506,11 +512,11 @@ func TestQueryResponder_ServesBlockRequestsWhenBlockSyncDisabled(t *testing.T) {
state, err := server.stateStore.Load()
require.NoError(t, err)
for height := int64(1); height <= 3; height++ {
block, blockID, partSet, seenCommit := makeNextBlock(ctx, t, state, privVals[0], height, lastCommit)
state, err = server.syncer.OrPanic("syncer should be configured in tests").blockExec.ApplyBlock(ctx, state, blockID, block, nil)
b := makeCommittedBlock(ctx, t, state, privVals, height, lastCommit)
state, err = server.syncer.OrPanic("syncer should be configured in tests").blockExec.ApplyBlock(ctx, state, b.id, b.block, nil)
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

lastCommit = b.commit
}
require.NoError(t, server.Start(ctx))
t.Cleanup(server.Wait)
Expand Down Expand Up @@ -563,11 +569,13 @@ func TestQueryResponder_ServesStatusRequestsWhenBlockSyncDisabled(t *testing.T)
network := p2p.MakeTestNetwork(t, p2p.TestNetworkOptions{NumNodes: 2})
nodeIDs := network.NodeIDs()

blockStore := newMemBlockStore()
server := makeReactor(
ctx,
t,
genDoc,
network.Node(nodeIDs[0]).Router,
blockStore,
false,
func() {},
config.DefaultSelfRemediationConfig(),
Expand All @@ -584,7 +592,7 @@ func TestQueryResponder_ServesStatusRequestsWhenBlockSyncDisabled(t *testing.T)

statusResponse, ok := msg.Message.Sum.(*pb.Message_StatusResponse)
require.True(t, ok)
require.Equal(t, server.store.Base(), statusResponse.StatusResponse.GetBase())
require.Equal(t, server.store.Height(), statusResponse.StatusResponse.GetHeight())
require.Equal(t, blockStore.Base(), statusResponse.StatusResponse.GetBase())
require.Equal(t, blockStore.Height(), statusResponse.StatusResponse.GetHeight())
require.Equal(t, nodeIDs[0], msg.From)
}
Loading
Loading