Repository navigation
use full commit verification in blocksync (CON-246) #4847
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
Open
merkroot
wants to merge
21
commits into
main
Choose a base branch
from
sanaz/blocksync-commit-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 3df5305
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot 98c9057
take the block store interface in NewReactor
merkroot 1909420
use one block fixture generator in the blocksync tests
merkroot ee979bb
rename test peers to invalidCommitPeer and correctPeer in blocksync v…
merkroot 85a5a6d
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot aa1d98d
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot cc435e6
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot 5c37d91
minor formatting fix
merkroot 6631445
save and read fixture blocks through the reactor store in the older b…
merkroot d5400e9
drop the leaktest check from the blocksync validation test
merkroot 8e02cd9
let the type assertion panic on a non-error value in waitForDisconnect
merkroot 04d96c3
wait for the peer disconnect in the main task of the blocksync valida…
merkroot d434138
assert the store content of the syncing node instead of the order of …
merkroot 39eea39
import utils/require without an alias in the blocksync validation test
merkroot e12a807
use utils/require for every assertion in the blocksync reactor test
merkroot 14096da
remove a double space in the godoc of the blocksync invalid commit test
merkroot d81bc59
name the block with the invalid commit after the invalid-commit peer …
merkroot 8d777da
name the store wrapper as the actor that publishes the saved height
merkroot 50160d7
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot 9d37be5
Merge branch 'main' into sanaz/blocksync-commit-check
merkroot 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
| 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" | ||
| ) | ||
|
|
||
|
|
@@ -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) | ||
|
|
@@ -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, | ||
|
|
@@ -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) { | ||
|
|
@@ -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(), | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, done. |
||
| lastCommit = b.commit | ||
| } | ||
| require.NoError(t, server.Start(ctx)) | ||
| t.Cleanup(server.Wait) | ||
|
|
@@ -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(), | ||
|
|
@@ -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) | ||
| } | ||
Oops, something went wrong.
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.
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.
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.
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