diff --git a/internal/blocksync/pool_test.go b/internal/blocksync/pool_test.go index 1cb8cca40..0b4598df6 100644 --- a/internal/blocksync/pool_test.go +++ b/internal/blocksync/pool_test.go @@ -43,7 +43,13 @@ func (p testPeer) runInputRoutine() { // Request desired, pretend like we got the block immediately. func (p testPeer) simulateInput(input inputData) { block := &types.Block{Header: types.Header{Height: input.request.Height}} - input.pool.AddBlock(input.request.PeerID, block, 123) + blockID := types.BlockID{ + Hash: []byte{}, + PartSetHeader: types.PartSetHeader{}, + } + extCommitSigs := make([]types.ExtendedCommitSig, 0) + extCommit := types.NewExtendedCommit(input.request.Height, 0, blockID, extCommitSigs) + input.pool.AddBlock(input.request.PeerID, block, extCommit, 123) // TODO: uncommenting this creates a race which is detected by: // https://github.com/golang/go/blob/2bd767b1022dd3254bcec469f0ee164024726486/src/testing/testing.go#L854-L856 // see: https://github.com/tendermint/tendermint/issues/3390#issue-418379890 @@ -110,7 +116,7 @@ func TestBlockPoolBasic(t *testing.T) { if !pool.IsRunning() { return } - first, second := pool.PeekTwoBlocks() + first, second, _ := pool.PeekTwoBlocks() if first != nil && second != nil { pool.PopRequest() } else { @@ -164,7 +170,7 @@ func TestBlockPoolTimeout(t *testing.T) { if !pool.IsRunning() { return } - first, second := pool.PeekTwoBlocks() + first, second, _ := pool.PeekTwoBlocks() if first != nil && second != nil { pool.PopRequest() } else { diff --git a/internal/blocksync/reactor_test.go b/internal/blocksync/reactor_test.go index 857b0a519..c22558096 100644 --- a/internal/blocksync/reactor_test.go +++ b/internal/blocksync/reactor_test.go @@ -147,39 +147,43 @@ func (rts *reactorTestSuite) addNode( sm.NopMetrics(), ) + var lastExtCommit *types.ExtendedCommit + + // The commit we are building for the current height. + seenExtCommit := types.NewExtendedCommit(0, 0, types.BlockID{}, nil) + for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ { - lastCommit := types.NewCommit(blockHeight-1, 0, types.BlockID{}, nil) + lastExtCommit = seenExtCommit.Copy() - if blockHeight > 1 { - lastBlockMeta := blockStore.LoadBlockMeta(blockHeight - 1) - lastBlock := blockStore.LoadBlock(blockHeight - 1) - - vote, err := factory.MakeVote( - ctx, - privVal, - lastBlock.Header.ChainID, 0, - lastBlock.Header.Height, 0, 2, - lastBlockMeta.BlockID, - time.Now(), - ) - require.NoError(t, err) - lastCommit = types.NewCommit( - vote.Height, - vote.Round, - lastBlockMeta.BlockID, - []types.CommitSig{vote.CommitSig()}, - ) - } - - thisBlock := sf.MakeBlock(state, blockHeight, lastCommit) + thisBlock := sf.MakeBlock(state, blockHeight, lastExtCommit.StripExtensions()) thisParts, err := thisBlock.MakePartSet(types.BlockPartSizeBytes) require.NoError(t, err) blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()} + // Simulate a commit for the current height + vote, err := factory.MakeVote( + ctx, + privVal, + thisBlock.Header.ChainID, + 0, + thisBlock.Header.Height, + 0, + 2, + blockID, + time.Now(), + ) + require.NoError(t, err) + seenExtCommit = types.NewExtendedCommit( + vote.Height, + vote.Round, + blockID, + []types.ExtendedCommitSig{vote.ExtendedCommitSig()}, + ) + state, err = blockExec.ApplyBlock(ctx, state, blockID, thisBlock) require.NoError(t, err) - blockStore.SaveBlock(thisBlock, thisParts, lastCommit) + blockStore.SaveBlock(thisBlock, thisParts, seenExtCommit) } rts.peerChans[nodeID] = make(chan p2p.PeerUpdate) diff --git a/internal/consensus/byzantine_test.go b/internal/consensus/byzantine_test.go index 804ebdb18..5a75d3fb2 100644 --- a/internal/consensus/byzantine_test.go +++ b/internal/consensus/byzantine_test.go @@ -178,22 +178,22 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { lazyNodeState.decideProposal = func(ctx context.Context, height int64, round int32) { require.NotNil(t, lazyNodeState.privValidator) - var commit *types.Commit + var commit *types.ExtendedCommit switch { case lazyNodeState.Height == lazyNodeState.state.InitialHeight: // We're creating a proposal for the first block. // The commit is empty, but not nil. - commit = types.NewCommit(0, 0, types.BlockID{}, nil) + commit = types.NewExtendedCommit(0, 0, types.BlockID{}, nil) case lazyNodeState.LastCommit.HasTwoThirdsMajority(): // Make the commit from LastCommit - commit = lazyNodeState.LastCommit.MakeCommit() + commit = lazyNodeState.LastCommit.MakeExtendedCommit() default: // This shouldn't happen. lazyNodeState.logger.Error("enterPropose: Cannot propose anything: No commit for the previous block") return } // omit the last signature in the commit - commit.Signatures[len(commit.Signatures)-1] = types.NewCommitSigAbsent() + commit.ExtendedSignatures[len(commit.ExtendedSignatures)-1] = types.NewExtendedCommitSigAbsent() if lazyNodeState.privValidatorPubKey == nil { // If this node is a validator & proposer in the current round, it will @@ -204,7 +204,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { proposerAddr := lazyNodeState.privValidatorPubKey.Address() block, err := lazyNodeState.blockExec.CreateProposalBlock( - ctx, lazyNodeState.Height, lazyNodeState.state, commit, proposerAddr, lazyNodeState.LastCommit.GetVotes()) + ctx, lazyNodeState.Height, lazyNodeState.state, commit, proposerAddr) require.NoError(t, err) blockParts, err := block.MakePartSet(types.BlockPartSizeBytes) require.NoError(t, err) diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index f112f23e8..aa8e74a48 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -297,7 +297,7 @@ type simulatorTestSuite struct { GenesisState sm.State Config *config.Config Chain []*types.Block - Commits []*types.Commit + ExtCommits []*types.ExtendedCommit CleanupFunc cleanupFunc Mempool mempool.Mempool @@ -579,10 +579,10 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { ensureNewRound(t, newRoundCh, height+1, 0) sim.Chain = make([]*types.Block, 0) - sim.Commits = make([]*types.Commit, 0) + sim.ExtCommits = make([]*types.ExtendedCommit, 0) for i := 1; i <= numBlocks; i++ { sim.Chain = append(sim.Chain, css[0].blockStore.LoadBlock(int64(i))) - sim.Commits = append(sim.Commits, css[0].blockStore.LoadBlockCommit(int64(i))) + sim.ExtCommits = append(sim.ExtCommits, css[0].blockStore.LoadBlockExtCommit(int64(i))) } return sim @@ -679,7 +679,7 @@ func testHandshakeReplay( testValidatorsChange bool, ) { var chain []*types.Block - var commits []*types.Commit + var extCommits []*types.ExtendedCommit var store *mockBlockStore var stateDB dbm.DB var genesisState sm.State @@ -699,7 +699,7 @@ func testHandshakeReplay( genesisState = sim.GenesisState cfg = sim.Config chain = append([]*types.Block{}, sim.Chain...) // copy chain - commits = sim.Commits + extCommits = sim.ExtCommits store = newMockBlockStore(t, cfg, genesisState.ConsensusParams) } else { // test single node testConfig, err := ResetConfig(t.TempDir(), fmt.Sprintf("%s_%v_s", t.Name(), mode)) @@ -718,7 +718,7 @@ func testHandshakeReplay( err = wal.Start(ctx) require.NoError(t, err) t.Cleanup(func() { cancel(); wal.Wait() }) - chain, commits = makeBlockchainFromWAL(t, wal) + chain, extCommits = makeBlockchainFromWAL(t, wal) pubKey, err := privVal.GetPubKey(ctx) require.NoError(t, err) stateDB, genesisState, store = stateAndStore(t, cfg, pubKey, kvstore.ProtocolVersion) @@ -726,7 +726,7 @@ func testHandshakeReplay( } stateStore := sm.NewStore(stateDB) store.chain = chain - store.commits = commits + store.extCommits = extCommits state := genesisState.Copy() // run the chain through state.ApplyBlock to build up the tendermint state @@ -1034,7 +1034,7 @@ func (app *badApp) Commit(context.Context) (*abci.ResponseCommit, error) { //-------------------------- // utils for making blocks -func makeBlockchainFromWAL(t *testing.T, wal WAL) ([]*types.Block, []*types.Commit) { +func makeBlockchainFromWAL(t *testing.T, wal WAL) ([]*types.Block, []*types.ExtendedCommit) { t.Helper() var height int64 @@ -1047,10 +1047,10 @@ func makeBlockchainFromWAL(t *testing.T, wal WAL) ([]*types.Block, []*types.Comm // log.Notice("Build a blockchain by reading from the WAL") var ( - blocks []*types.Block - commits []*types.Commit - thisBlockParts *types.PartSet - thisBlockCommit *types.Commit + blocks []*types.Block + extCommits []*types.ExtendedCommit + thisBlockParts *types.PartSet + thisBlockExtCommit *types.ExtendedCommit ) dec := NewWALDecoder(gr) @@ -1082,12 +1082,12 @@ func makeBlockchainFromWAL(t *testing.T, wal WAL) ([]*types.Block, []*types.Comm require.Equal(t, block.Height, height+1, "read bad block from wal. got height %d, expected %d", block.Height, height+1) - commitHeight := thisBlockCommit.Height + commitHeight := thisBlockExtCommit.Height require.Equal(t, commitHeight, height+1, "commit doesnt match. got height %d, expected %d", commitHeight, height+1) blocks = append(blocks, block) - commits = append(commits, thisBlockCommit) + extCommits = append(extCommits, thisBlockExtCommit) height++ } case *types.PartSetHeader: @@ -1097,8 +1097,8 @@ func makeBlockchainFromWAL(t *testing.T, wal WAL) ([]*types.Block, []*types.Comm require.NoError(t, err) case *types.Vote: if p.Type == tmproto.PrecommitType { - thisBlockCommit = types.NewCommit(p.Height, p.Round, - p.BlockID, []types.CommitSig{p.CommitSig()}) + thisBlockExtCommit = types.NewExtendedCommit(p.Height, p.Round, + p.BlockID, []types.ExtendedCommitSig{p.ExtendedCommitSig()}) } } } @@ -1113,12 +1113,12 @@ func makeBlockchainFromWAL(t *testing.T, wal WAL) ([]*types.Block, []*types.Comm require.NoError(t, err) require.Equal(t, block.Height, height+1, "read bad block from wal. got height %d, expected %d", block.Height, height+1) - commitHeight := thisBlockCommit.Height + commitHeight := thisBlockExtCommit.Height require.Equal(t, commitHeight, height+1, "commit does not match. got height %d, expected %d", commitHeight, height+1) blocks = append(blocks, block) - commits = append(commits, thisBlockCommit) - return blocks, commits + extCommits = append(extCommits, thisBlockExtCommit) + return blocks, extCommits } func readPieceFromWAL(msg *TimedWALMessage) interface{} { @@ -1162,14 +1162,16 @@ func stateAndStore( // mock block store type mockBlockStore struct { - cfg *config.Config - params types.ConsensusParams - chain []*types.Block - commits []*types.Commit - base int64 - t *testing.T + cfg *config.Config + params types.ConsensusParams + chain []*types.Block + extCommits []*types.ExtendedCommit + base int64 + t *testing.T } +var _ sm.BlockStore = &mockBlockStore{} + // TODO: NewBlockStore(db.NewMemDB) ... func newMockBlockStore(t *testing.T, cfg *config.Config, params types.ConsensusParams) *mockBlockStore { return &mockBlockStore{ @@ -1198,20 +1200,24 @@ func (bs *mockBlockStore) LoadBlockMeta(height int64) *types.BlockMeta { } } func (bs *mockBlockStore) LoadBlockPart(height int64, index int) *types.Part { return nil } -func (bs *mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) { +func (bs *mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.ExtendedCommit) { } + func (bs *mockBlockStore) LoadBlockCommit(height int64) *types.Commit { - return bs.commits[height-1] + return bs.extCommits[height-1].StripExtensions() } func (bs *mockBlockStore) LoadSeenCommit() *types.Commit { - return bs.commits[len(bs.commits)-1] + return bs.extCommits[len(bs.extCommits)-1].StripExtensions() +} +func (bs *mockBlockStore) LoadBlockExtCommit(height int64) *types.ExtendedCommit { + return bs.extCommits[height-1] } func (bs *mockBlockStore) PruneBlocks(height int64) (uint64, error) { pruned := uint64(0) for i := int64(0); i < height-1; i++ { bs.chain[i] = nil - bs.commits[i] = nil + bs.extCommits[i] = nil pruned++ } bs.base = height diff --git a/internal/evidence/pool_test.go b/internal/evidence/pool_test.go index dcf44a5df..162e507cb 100644 --- a/internal/evidence/pool_test.go +++ b/internal/evidence/pool_test.go @@ -249,8 +249,8 @@ func TestEvidencePoolUpdate(t *testing.T) { evidenceChainID, ) require.NoError(t, err) - lastCommit := makeCommit(height, val.PrivKey.PubKey().Address()) - block := types.MakeBlock(height+1, []types.Tx{}, lastCommit, []types.Evidence{ev}) + lastExtCommit := makeExtCommit(height, val.PrivKey.PubKey().Address()) + block := types.MakeBlock(height+1, []types.Tx{}, lastExtCommit.StripExtensions(), []types.Evidence{ev}) // update state (partially) state.LastBlockHeight = height + 1 @@ -568,8 +568,8 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) (*store.Blo blockStore := store.NewBlockStore(db) for i := int64(1); i <= state.LastBlockHeight; i++ { - lastCommit := makeCommit(i-1, valAddr) - block := sf.MakeBlock(state, i, lastCommit) + lastCommit := makeExtCommit(i-1, valAddr) + block := sf.MakeBlock(state, i, lastCommit.StripExtensions()) block.Header.Time = defaultEvidenceTime.Add(time.Duration(i) * time.Minute) block.Header.Version = version.Consensus{Block: version.BlockProtocol, App: 1} @@ -579,22 +579,22 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) (*store.Blo return nil, err } - seenCommit := makeCommit(i, valAddr) + seenCommit := makeExtCommit(i, valAddr) blockStore.SaveBlock(block, partSet, seenCommit) } return blockStore, nil } -func makeCommit(height int64, valAddr []byte) *types.Commit { - commitSigs := []types.CommitSig{{ +func makeExtCommit(height int64, valAddr []byte) *types.ExtendedCommit { + extCommitSigs := []types.ExtendedCommitSig{{ BlockIDFlag: types.BlockIDFlagCommit, ValidatorAddress: valAddr, Timestamp: defaultEvidenceTime, Signature: []byte("Signature"), }} - return types.NewCommit(height, 0, types.BlockID{}, commitSigs) + return types.NewExtendedCommit(height, 0, types.BlockID{}, extCommitSigs) } func defaultTestPool(ctx context.Context, t *testing.T, height int64) (*evidence.Pool, types.MockPV, *eventbus.EventBus) { diff --git a/internal/evidence/verify_test.go b/internal/evidence/verify_test.go index b2056186f..2ed84fa69 100644 --- a/internal/evidence/verify_test.go +++ b/internal/evidence/verify_test.go @@ -234,8 +234,9 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) { // except the last validator vote twice blockID := factory.MakeBlockIDWithHash(conflictingHeader.Hash()) voteSet := types.NewVoteSet(evidenceChainID, 10, 1, tmproto.SignedMsgType(2), conflictingVals) - commit, err := factory.MakeCommit(ctx, blockID, 10, 1, voteSet, conflictingPrivVals[:4], defaultEvidenceTime) + extCommit, err := factory.MakeExtendedCommit(ctx, blockID, 10, 1, voteSet, conflictingPrivVals[:4], defaultEvidenceTime) require.NoError(t, err) + commit := extCommit.StripExtensions() ev := &types.LightClientAttackEvidence{ ConflictingBlock: &types.LightBlock{ @@ -253,9 +254,10 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) { trustedBlockID := makeBlockID(trustedHeader.Hash(), 1000, []byte("partshash")) trustedVoteSet := types.NewVoteSet(evidenceChainID, 10, 1, tmproto.SignedMsgType(2), conflictingVals) - trustedCommit, err := factory.MakeCommit(ctx, trustedBlockID, 10, 1, + trustedExtCommit, err := factory.MakeExtendedCommit(ctx, trustedBlockID, 10, 1, trustedVoteSet, conflictingPrivVals, defaultEvidenceTime) require.NoError(t, err) + trustedCommit := trustedExtCommit.StripExtensions() trustedSignedHeader := &types.SignedHeader{ Header: trustedHeader, @@ -335,8 +337,9 @@ func TestVerifyLightClientAttack_Amnesia(t *testing.T) { // except the last validator vote twice. However this time the commits are of different rounds. blockID := makeBlockID(conflictingHeader.Hash(), 1000, []byte("partshash")) voteSet := types.NewVoteSet(evidenceChainID, height, 0, tmproto.SignedMsgType(2), conflictingVals) - commit, err := factory.MakeCommit(ctx, blockID, height, 0, voteSet, conflictingPrivVals, defaultEvidenceTime) + extCommit, err := factory.MakeExtendedCommit(ctx, blockID, height, 0, voteSet, conflictingPrivVals, defaultEvidenceTime) require.NoError(t, err) + commit := extCommit.StripExtensions() ev := &types.LightClientAttackEvidence{ ConflictingBlock: &types.LightBlock{ @@ -354,9 +357,10 @@ func TestVerifyLightClientAttack_Amnesia(t *testing.T) { trustedBlockID := makeBlockID(trustedHeader.Hash(), 1000, []byte("partshash")) trustedVoteSet := types.NewVoteSet(evidenceChainID, height, 1, tmproto.SignedMsgType(2), conflictingVals) - trustedCommit, err := factory.MakeCommit(ctx, trustedBlockID, height, 1, + trustedExtCommit, err := factory.MakeExtendedCommit(ctx, trustedBlockID, height, 1, trustedVoteSet, conflictingPrivVals, defaultEvidenceTime) require.NoError(t, err) + trustedCommit := trustedExtCommit.StripExtensions() trustedSignedHeader := &types.SignedHeader{ Header: trustedHeader, @@ -550,8 +554,9 @@ func makeLunaticEvidence( blockID := factory.MakeBlockIDWithHash(conflictingHeader.Hash()) voteSet := types.NewVoteSet(evidenceChainID, height, 1, tmproto.SignedMsgType(2), conflictingVals) - commit, err := factory.MakeCommit(ctx, blockID, height, 1, voteSet, conflictingPrivVals, defaultEvidenceTime) + extCommit, err := factory.MakeExtendedCommit(ctx, blockID, height, 1, voteSet, conflictingPrivVals, defaultEvidenceTime) require.NoError(t, err) + commit := extCommit.StripExtensions() ev = &types.LightClientAttackEvidence{ ConflictingBlock: &types.LightBlock{ @@ -578,8 +583,9 @@ func makeLunaticEvidence( trustedBlockID := factory.MakeBlockIDWithHash(trustedHeader.Hash()) trustedVals, privVals := factory.ValidatorSet(ctx, t, totalVals, defaultVotingPower) trustedVoteSet := types.NewVoteSet(evidenceChainID, height, 1, tmproto.SignedMsgType(2), trustedVals) - trustedCommit, err := factory.MakeCommit(ctx, trustedBlockID, height, 1, trustedVoteSet, privVals, defaultEvidenceTime) + trustedExtCommit, err := factory.MakeExtendedCommit(ctx, trustedBlockID, height, 1, trustedVoteSet, privVals, defaultEvidenceTime) require.NoError(t, err) + trustedCommit := trustedExtCommit.StripExtensions() trusted = &types.LightBlock{ SignedHeader: &types.SignedHeader{ diff --git a/internal/state/execution_test.go b/internal/state/execution_test.go index 0937b9990..410177064 100644 --- a/internal/state/execution_test.go +++ b/internal/state/execution_test.go @@ -79,9 +79,10 @@ func TestApplyBlock(t *testing.T) { assert.EqualValues(t, 1, state.Version.Consensus.App, "App version wasn't updated") } -// TestFinalizeBlockDecidedLastCommit ensures we correctly send the DecidedLastCommit to the -// application. The test ensures that the DecidedLastCommit properly reflects -// which validators signed the preceding block. +// TestFinalizeBlockDecidedLastCommit ensures we correctly send the +// DecidedLastCommit to the application. The test ensures that the +// DecidedLastCommit properly reflects which validators signed the preceding +// block. func TestFinalizeBlockDecidedLastCommit(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -96,7 +97,7 @@ func TestFinalizeBlockDecidedLastCommit(t *testing.T) { state, stateDB, privVals := makeState(t, 7, 1) stateStore := sm.NewStore(stateDB) - absentSig := types.NewCommitSigAbsent() + absentSig := types.NewExtendedCommitSigAbsent() testCases := []struct { name string @@ -134,12 +135,12 @@ func TestFinalizeBlockDecidedLastCommit(t *testing.T) { for idx, isAbsent := range tc.absentCommitSigs { if isAbsent { - lastCommit.Signatures[idx] = absentSig + lastCommit.ExtendedSignatures[idx] = absentSig } } // block for height 2 - block := sf.MakeBlock(state, 2, lastCommit) + block := sf.MakeBlock(state, 2, lastCommit.StripExtensions()) bps, err := block.MakePartSet(testPartSize) require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} @@ -653,8 +654,8 @@ func TestEmptyPrepareProposal(t *testing.T) { sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) - commit, votes := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) - _, err = blockExec.CreateProposalBlock(ctx, height, state, commit, pa, votes) + commit, _ := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) + _, err = blockExec.CreateProposalBlock(ctx, height, state, commit, pa) require.NoError(t, err) } @@ -708,8 +709,8 @@ func TestPrepareProposalErrorOnNonExistingRemoved(t *testing.T) { sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) - commit, votes := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) - block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa, votes) + commit, _ := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) + block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa) require.ErrorContains(t, err, "new transaction incorrectly marked as removed") require.Nil(t, block) @@ -764,8 +765,8 @@ func TestPrepareProposalRemoveTxs(t *testing.T) { sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) - commit, votes := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) - block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa, votes) + commit, _ := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) + block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa) require.NoError(t, err) require.Len(t, block.Data.Txs.ToSliceOfBytes(), len(trs)-2) @@ -823,8 +824,8 @@ func TestPrepareProposalAddedTxsIncluded(t *testing.T) { sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) - commit, votes := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) - block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa, votes) + commit, _ := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) + block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa) require.NoError(t, err) require.Equal(t, txs[0], block.Data.Txs[0]) @@ -879,8 +880,8 @@ func TestPrepareProposalReorderTxs(t *testing.T) { sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) - commit, votes := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) - block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa, votes) + commit, _ := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) + block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa) require.NoError(t, err) for i, tx := range block.Data.Txs { require.Equal(t, types.Tx(trs[i].Tx), tx) @@ -939,9 +940,8 @@ func TestPrepareProposalErrorOnTooManyTxs(t *testing.T) { sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) - commit, votes := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) - - block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa, votes) + commit, _ := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) + block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa) require.ErrorContains(t, err, "transaction data size exceeds maximum") require.Nil(t, block, "") @@ -991,9 +991,8 @@ func TestPrepareProposalErrorOnPrepareProposalError(t *testing.T) { sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) - commit, votes := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) - - block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa, votes) + commit, _ := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) + block, err := blockExec.CreateProposalBlock(ctx, height, state, commit, pa) require.Nil(t, block) require.ErrorContains(t, err, "an injected error") diff --git a/internal/state/helpers_test.go b/internal/state/helpers_test.go index 07dd0d865..464df86d4 100644 --- a/internal/state/helpers_test.go +++ b/internal/state/helpers_test.go @@ -39,7 +39,7 @@ func makeAndCommitGoodBlock( blockExec *sm.BlockExecutor, privVals map[string]types.PrivValidator, evidence []types.Evidence, -) (sm.State, types.BlockID, *types.Commit) { +) (sm.State, types.BlockID, *types.ExtendedCommit) { t.Helper() // A good block passes @@ -82,19 +82,19 @@ func makeValidCommit( blockID types.BlockID, vals *types.ValidatorSet, privVals map[string]types.PrivValidator, -) (*types.Commit, []*types.Vote) { +) (*types.ExtendedCommit, []*types.Vote) { t.Helper() - sigs := make([]types.CommitSig, vals.Size()) + sigs := make([]types.ExtendedCommitSig, vals.Size()) votes := make([]*types.Vote, vals.Size()) for i := 0; i < vals.Size(); i++ { _, val := vals.GetByIndex(int32(i)) vote, err := factory.MakeVote(ctx, privVals[val.Address.String()], chainID, int32(i), height, 0, 2, blockID, time.Now()) require.NoError(t, err) - sigs[i] = vote.CommitSig() + sigs[i] = vote.ExtendedCommitSig() votes[i] = vote } - return types.NewCommit(height, 0, blockID, sigs), votes + return types.NewExtendedCommit(height, 0, blockID, sigs), votes } func makeState(t *testing.T, nVals, height int) (sm.State, dbm.DB, map[string]types.PrivValidator) { diff --git a/internal/state/validation_test.go b/internal/state/validation_test.go index 376ce61bc..407eca23c 100644 --- a/internal/state/validation_test.go +++ b/internal/state/validation_test.go @@ -66,6 +66,7 @@ func TestValidateBlockHeader(t *testing.T) { sm.NopMetrics(), ) lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil) + var lastExtCommit *types.ExtendedCommit // some bad values wrongHash := crypto.Checksum([]byte("this hash is wrong")) @@ -121,8 +122,9 @@ func TestValidateBlockHeader(t *testing.T) { /* A good block passes */ - state, _, lastCommit = makeAndCommitGoodBlock(ctx, t, + state, _, lastExtCommit = makeAndCommitGoodBlock(ctx, t, state, height, lastCommit, state.Validators.GetProposer().Address, blockExec, privVals, nil) + lastCommit = lastExtCommit.StripExtensions() } nextHeight := validationTestsStopHeight @@ -170,6 +172,7 @@ func TestValidateBlockCommit(t *testing.T) { sm.NopMetrics(), ) lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil) + var lastExtCommit *types.ExtendedCommit wrongSigsCommit := types.NewCommit(1, 0, types.BlockID{}, nil) badPrivVal := types.NewMockPV() @@ -220,7 +223,7 @@ func TestValidateBlockCommit(t *testing.T) { A good block passes */ var blockID types.BlockID - state, blockID, lastCommit = makeAndCommitGoodBlock( + state, blockID, lastExtCommit = makeAndCommitGoodBlock( ctx, t, state, @@ -231,6 +234,7 @@ func TestValidateBlockCommit(t *testing.T) { privVals, nil, ) + lastCommit = lastExtCommit.StripExtensions() /* wrongSigsCommit is fine except for the extra bad precommit @@ -320,6 +324,7 @@ func TestValidateBlockEvidence(t *testing.T) { sm.NopMetrics(), ) lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil) + var lastExtCommit *types.ExtendedCommit for height := int64(1); height < validationTestsStopHeight; height++ { proposerAddr := state.Validators.GetProposer().Address @@ -364,7 +369,7 @@ func TestValidateBlockEvidence(t *testing.T) { evidence = append(evidence, newEv) } - state, _, lastCommit = makeAndCommitGoodBlock( + state, _, lastExtCommit = makeAndCommitGoodBlock( ctx, t, state, @@ -375,6 +380,7 @@ func TestValidateBlockEvidence(t *testing.T) { privVals, evidence, ) + lastCommit = lastExtCommit.StripExtensions() } } diff --git a/internal/statesync/reactor_test.go b/internal/statesync/reactor_test.go index 55a9fcf8c..904fb2b74 100644 --- a/internal/statesync/reactor_test.go +++ b/internal/statesync/reactor_test.go @@ -856,12 +856,12 @@ func mockLB(ctx context.Context, t *testing.T, height int64, time time.Time, las header.ConsensusHash = types.DefaultConsensusParams().HashConsensusParams() lastBlockID = factory.MakeBlockIDWithHash(header.Hash()) voteSet := types.NewVoteSet(factory.DefaultTestChainID, height, 0, tmproto.PrecommitType, currentVals) - commit, err := factory.MakeCommit(ctx, lastBlockID, height, 0, voteSet, currentPrivVals, time) + extCommit, err := factory.MakeExtendedCommit(ctx, lastBlockID, height, 0, voteSet, currentPrivVals, time) require.NoError(t, err) return nextVals, nextPrivVals, &types.LightBlock{ SignedHeader: &types.SignedHeader{ Header: header, - Commit: commit, + Commit: extCommit.StripExtensions(), }, ValidatorSet: currentVals, } diff --git a/internal/store/store_test.go b/internal/store/store_test.go index 4fa577cc4..136180991 100644 --- a/internal/store/store_test.go +++ b/internal/store/store_test.go @@ -27,22 +27,24 @@ import ( // test. type cleanupFunc func() -// make a Commit with a single vote containing just the height and a timestamp -func makeTestCommit(height int64, timestamp time.Time) *types.Commit { - commitSigs := []types.CommitSig{{ +// make an extended commit with a single vote containing just the height and a +// timestamp +func makeTestExtCommit(height int64, timestamp time.Time) *types.ExtendedCommit { + extCommitSigs := []types.ExtendedCommitSig{{ BlockIDFlag: types.BlockIDFlagCommit, ValidatorAddress: tmrand.Bytes(crypto.AddressSize), Timestamp: timestamp, Signature: []byte("Signature"), }} - return types.NewCommit( + return types.NewExtendedCommit( height, 0, types.BlockID{ Hash: crypto.CRandBytes(32), PartSetHeader: types.PartSetHeader{Hash: crypto.CRandBytes(32), Total: 2}, }, - commitSigs) + extCommitSigs, + ) } func makeStateAndBlockStore(dir string) (sm.State, *BlockStore, cleanupFunc, error) { @@ -70,7 +72,7 @@ var ( partSet *types.PartSet part1 *types.Part part2 *types.Part - seenCommit1 *types.Commit + seenCommit1 *types.ExtendedCommit ) func TestMain(m *testing.M) { @@ -93,7 +95,7 @@ func TestMain(m *testing.M) { } part1 = partSet.GetPart(0) part2 = partSet.GetPart(1) - seenCommit1 = makeTestCommit(10, tmtime.Now()) + seenCommit1 = makeTestExtCommit(10, tmtime.Now()) code := m.Run() cleanup() os.RemoveAll(dir) // best-effort @@ -120,7 +122,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { block := factory.MakeBlock(state, bs.Height()+1, new(types.Commit)) validPartSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(10, tmtime.Now()) + seenCommit := makeTestExtCommit(bs.Height()+1, tmtime.Now()) bs.SaveBlock(block, partSet, seenCommit) require.EqualValues(t, 1, bs.Base(), "expecting the new height to be changed") require.EqualValues(t, block.Header.Height, bs.Height(), "expecting the new height to be changed") @@ -139,11 +141,11 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { } // End of setup, test data - commitAtH10 := makeTestCommit(10, tmtime.Now()) + commitAtH10 := makeTestExtCommit(10, tmtime.Now()).StripExtensions() tuples := []struct { block *types.Block parts *types.PartSet - seenCommit *types.Commit + seenCommit *types.ExtendedCommit wantPanic string wantErr bool @@ -172,10 +174,10 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { ChainID: "block_test", Time: tmtime.Now(), ProposerAddress: tmrand.Bytes(crypto.AddressSize)}, - makeTestCommit(5, tmtime.Now()), + makeTestExtCommit(5, tmtime.Now()).StripExtensions(), ), parts: validPartSet, - seenCommit: makeTestCommit(5, tmtime.Now()), + seenCommit: makeTestExtCommit(5, tmtime.Now()), }, { @@ -324,7 +326,7 @@ func TestLoadBaseMeta(t *testing.T) { block := factory.MakeBlock(state, h, new(types.Commit)) partSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(h, tmtime.Now()) + seenCommit := makeTestExtCommit(h, tmtime.Now()) bs.SaveBlock(block, partSet, seenCommit) } @@ -391,7 +393,7 @@ func TestPruneBlocks(t *testing.T) { block := factory.MakeBlock(state, h, new(types.Commit)) partSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(h, tmtime.Now()) + seenCommit := makeTestExtCommit(h, tmtime.Now()) bs.SaveBlock(block, partSet, seenCommit) } @@ -499,7 +501,7 @@ func TestBlockFetchAtHeight(t *testing.T) { partSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(10, tmtime.Now()) + seenCommit := makeTestExtCommit(10, tmtime.Now()) bs.SaveBlock(block, partSet, seenCommit) require.Equal(t, bs.Height(), block.Header.Height, "expecting the new height to be changed") @@ -536,16 +538,16 @@ func TestSeenAndCanonicalCommit(t *testing.T) { // produce a few blocks and check that the correct seen and cannoncial commits // are persisted. for h := int64(3); h <= 5; h++ { - blockCommit := makeTestCommit(h-1, tmtime.Now()) + blockCommit := makeTestExtCommit(h-1, tmtime.Now()).StripExtensions() block := factory.MakeBlock(state, h, blockCommit) partSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(h, tmtime.Now()) + seenCommit := makeTestExtCommit(h, tmtime.Now()) bs.SaveBlock(block, partSet, seenCommit) c3 := bs.LoadSeenCommit() require.NotNil(t, c3) require.Equal(t, h, c3.Height) - require.Equal(t, seenCommit.Hash(), c3.Hash()) + require.Equal(t, seenCommit.StripExtensions().Hash(), c3.Hash()) c5 := bs.LoadBlockCommit(h) require.Nil(t, c5) c6 := bs.LoadBlockCommit(h - 1) diff --git a/internal/test/factory/commit.go b/internal/test/factory/commit.go index d2be469f3..1bd1c7ae6 100644 --- a/internal/test/factory/commit.go +++ b/internal/test/factory/commit.go @@ -8,7 +8,7 @@ import ( "github.com/tendermint/tendermint/types" ) -func MakeCommit(ctx context.Context, blockID types.BlockID, height int64, round int32, voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time) (*types.ExtendedCommit, error) { +func MakeExtendedCommit(ctx context.Context, blockID types.BlockID, height int64, round int32, voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time) (*types.ExtendedCommit, error) { // all sign for i := 0; i < len(validators); i++ { pubKey, err := validators[i].GetPubKey(ctx) diff --git a/node/node_test.go b/node/node_test.go index c5ff1f014..b563331b6 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -339,13 +339,13 @@ func TestCreateProposalBlock(t *testing.T) { sm.NopMetrics(), ) - commit := types.NewCommit(height-1, 0, types.BlockID{}, nil) + extCommit := types.NewExtendedCommit(height-1, 0, types.BlockID{}, nil) block, err := blockExec.CreateProposalBlock( ctx, height, - state, commit, + state, + extCommit, proposerAddr, - nil, ) require.NoError(t, err) @@ -419,13 +419,13 @@ func TestMaxTxsProposalBlockSize(t *testing.T) { sm.NopMetrics(), ) - commit := types.NewCommit(height-1, 0, types.BlockID{}, nil) + extCommit := types.NewExtendedCommit(height-1, 0, types.BlockID{}, nil) block, err := blockExec.CreateProposalBlock( ctx, height, - state, commit, + state, + extCommit, proposerAddr, - nil, ) require.NoError(t, err) @@ -525,14 +525,14 @@ func TestMaxProposalBlockSize(t *testing.T) { } state.ChainID = maxChainID - cs := types.CommitSig{ + ecs := types.ExtendedCommitSig{ BlockIDFlag: types.BlockIDFlagNil, ValidatorAddress: crypto.AddressHash([]byte("validator_address")), Timestamp: timestamp, Signature: crypto.CRandBytes(types.MaxSignatureSize), } - commit := &types.Commit{ + extCommit := &types.ExtendedCommit{ Height: math.MaxInt64, Round: math.MaxInt32, BlockID: blockID, @@ -547,16 +547,15 @@ func TestMaxProposalBlockSize(t *testing.T) { votes[i] = &types.Vote{ ValidatorAddress: pubKey.Address(), } - commit.Signatures = append(commit.Signatures, cs) + extCommit.ExtendedSignatures = append(extCommit.ExtendedSignatures, ecs) } block, err := blockExec.CreateProposalBlock( ctx, math.MaxInt64, state, - commit, + extCommit, proposerAddr, - votes, ) require.NoError(t, err) partSet, err := block.MakePartSet(types.BlockPartSizeBytes) diff --git a/test/e2e/runner/evidence.go b/test/e2e/runner/evidence.go index f131438cf..a71ea14fb 100644 --- a/test/e2e/runner/evidence.go +++ b/test/e2e/runner/evidence.go @@ -167,7 +167,7 @@ func generateLightClientAttackEvidence( blockID := makeBlockID(header.Hash(), 1000, []byte("partshash")) voteSet := types.NewVoteSet(chainID, forgedHeight, 0, tmproto.SignedMsgType(2), conflictingVals) - commit, err := factory.MakeCommit(ctx, blockID, forgedHeight, 0, voteSet, pv, forgedTime) + commit, err := factory.MakeExtendedCommit(ctx, blockID, forgedHeight, 0, voteSet, pv, forgedTime) if err != nil { return nil, err } diff --git a/types/block_test.go b/types/block_test.go index 7f2378505..5dd0d71b8 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -42,14 +42,14 @@ func TestBlockAddEvidence(t *testing.T) { h := int64(3) voteSet, _, vals := randVoteSet(ctx, t, h-1, 1, tmproto.PrecommitType, 10, 1) - commit, err := makeCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) + extCommit, err := makeExtCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) ev, err := NewMockDuplicateVoteEvidenceWithValidator(ctx, h, time.Now(), vals[0], "block-test-chain") require.NoError(t, err) evList := []Evidence{ev} - block := MakeBlock(h, txs, commit, evList) + block := MakeBlock(h, txs, extCommit.StripExtensions(), evList) require.NotNil(t, block) require.Equal(t, 1, len(block.Evidence)) require.NotNil(t, block.EvidenceHash) @@ -66,9 +66,9 @@ func TestBlockValidateBasic(t *testing.T) { h := int64(3) voteSet, valSet, vals := randVoteSet(ctx, t, h-1, 1, tmproto.PrecommitType, 10, 1) - commit, err := makeCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) - + extCommit, err := makeExtCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) + commit := extCommit.StripExtensions() ev, err := NewMockDuplicateVoteEvidenceWithValidator(ctx, h, time.Now(), vals[0], "block-test-chain") require.NoError(t, err) @@ -153,15 +153,14 @@ func TestBlockMakePartSetWithEvidence(t *testing.T) { h := int64(3) voteSet, _, vals := randVoteSet(ctx, t, h-1, 1, tmproto.PrecommitType, 10, 1) - commit, err := makeCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) - + extCommit, err := makeExtCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) ev, err := NewMockDuplicateVoteEvidenceWithValidator(ctx, h, time.Now(), vals[0], "block-test-chain") require.NoError(t, err) evList := []Evidence{ev} - partSet, err := MakeBlock(h, []Tx{Tx("Hello World")}, commit, evList).MakePartSet(512) + partSet, err := MakeBlock(h, []Tx{Tx("Hello World")}, extCommit.StripExtensions(), evList).MakePartSet(512) require.NoError(t, err) assert.NotNil(t, partSet) @@ -178,14 +177,14 @@ func TestBlockHashesTo(t *testing.T) { h := int64(3) voteSet, valSet, vals := randVoteSet(ctx, t, h-1, 1, tmproto.PrecommitType, 10, 1) - commit, err := makeCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) + extCommit, err := makeExtCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) ev, err := NewMockDuplicateVoteEvidenceWithValidator(ctx, h, time.Now(), vals[0], "block-test-chain") require.NoError(t, err) evList := []Evidence{ev} - block := MakeBlock(h, []Tx{Tx("Hello World")}, commit, evList) + block := MakeBlock(h, []Tx{Tx("Hello World")}, extCommit.StripExtensions(), evList) block.ValidatorsHash = valSet.Hash() assert.False(t, block.HashesTo([]byte{})) assert.False(t, block.HashesTo([]byte("something else"))) @@ -260,7 +259,7 @@ func TestCommit(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) voteSet, _, vals := randVoteSet(ctx, t, h-1, 1, tmproto.PrecommitType, 10, 1) - commit, err := makeCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) + commit, err := makeExtCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) assert.Equal(t, h-1, commit.Height) @@ -273,7 +272,7 @@ func TestCommit(t *testing.T) { require.NotNil(t, commit.BitArray()) assert.Equal(t, bits.NewBitArray(10).Size(), commit.BitArray().Size()) - assert.Equal(t, voteWithoutExtension(voteSet.GetByIndex(0)), commit.GetByIndex(0)) + assert.Equal(t, voteSet.GetByIndex(0), commit.GetByIndex(0)) assert.True(t, commit.IsCommit()) } @@ -477,11 +476,11 @@ func randCommit(ctx context.Context, t *testing.T, now time.Time) *Commit { lastID := makeBlockIDRandom() h := int64(3) voteSet, _, vals := randVoteSet(ctx, t, h-1, 1, tmproto.PrecommitType, 10, 1) - commit, err := makeCommit(ctx, lastID, h-1, 1, voteSet, vals, now) + commit, err := makeExtCommit(ctx, lastID, h-1, 1, voteSet, vals, now) require.NoError(t, err) - return commit + return commit.StripExtensions() } func hexBytesFromString(t *testing.T, s string) bytes.HexBytes { @@ -554,7 +553,7 @@ func TestBlockMaxDataBytesNoEvidence(t *testing.T) { } } -func TestCommitToVoteSet(t *testing.T) { +func TestExtendedCommitToVoteSet(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) @@ -562,17 +561,16 @@ func TestCommitToVoteSet(t *testing.T) { defer cancel() voteSet, valSet, vals := randVoteSet(ctx, t, h-1, 1, tmproto.PrecommitType, 10, 1) - commit, err := makeCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) - + extCommit, err := makeExtCommit(ctx, lastID, h-1, 1, voteSet, vals, time.Now()) assert.NoError(t, err) chainID := voteSet.ChainID() - voteSet2 := CommitToVoteSet(chainID, commit, valSet) + voteSet2 := extCommit.ToVoteSet(chainID, valSet) for i := int32(0); int(i) < len(vals); i++ { - vote1 := voteWithoutExtension(voteSet.GetByIndex(i)) + vote1 := voteSet.GetByIndex(i) vote2 := voteSet2.GetByIndex(i) - vote3 := commit.GetVote(i) + vote3 := extCommit.GetExtendedVote(i) vote1bz, err := vote1.ToProto().Marshal() require.NoError(t, err) @@ -634,12 +632,12 @@ func TestCommitToVoteSetWithVotesForNilBlock(t *testing.T) { } if tc.valid { - commit := voteSet.MakeCommit() // panics without > 2/3 valid votes - assert.NotNil(t, commit) - err := valSet.VerifyCommit(voteSet.ChainID(), blockID, height-1, commit) + extCommit := voteSet.MakeExtendedCommit() // panics without > 2/3 valid votes + assert.NotNil(t, extCommit) + err := valSet.VerifyCommit(voteSet.ChainID(), blockID, height-1, extCommit.StripExtensions()) assert.NoError(t, err) } else { - assert.Panics(t, func() { voteSet.MakeCommit() }) + assert.Panics(t, func() { voteSet.MakeExtendedCommit() }) } } } diff --git a/types/evidence_test.go b/types/evidence_test.go index 27e346343..8b06a6218 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -153,8 +153,10 @@ func TestLightClientAttackEvidenceBasic(t *testing.T) { header := makeHeaderRandom() header.Height = height blockID := makeBlockID(crypto.Checksum([]byte("blockhash")), math.MaxInt32, crypto.Checksum([]byte("partshash"))) - commit, err := makeCommit(ctx, blockID, height, 1, voteSet, privVals, defaultVoteTime) + extCommit, err := makeExtCommit(ctx, blockID, height, 1, voteSet, privVals, defaultVoteTime) require.NoError(t, err) + commit := extCommit.StripExtensions() + lcae := &LightClientAttackEvidence{ ConflictingBlock: &LightBlock{ SignedHeader: &SignedHeader{ @@ -217,8 +219,10 @@ func TestLightClientAttackEvidenceValidation(t *testing.T) { header.Height = height header.ValidatorsHash = valSet.Hash() blockID := makeBlockID(header.Hash(), math.MaxInt32, crypto.Checksum([]byte("partshash"))) - commit, err := makeCommit(ctx, blockID, height, 1, voteSet, privVals, time.Now()) + extCommit, err := makeExtCommit(ctx, blockID, height, 1, voteSet, privVals, time.Now()) require.NoError(t, err) + commit := extCommit.StripExtensions() + lcae := &LightClientAttackEvidence{ ConflictingBlock: &LightBlock{ SignedHeader: &SignedHeader{ @@ -424,13 +428,13 @@ func TestEvidenceVectors(t *testing.T) { ProposerAddress: []byte("2915b7b15f979e48ebc61774bb1d86ba3136b7eb"), } blockID3 := makeBlockID(header.Hash(), math.MaxInt32, crypto.Checksum([]byte("partshash"))) - commit, err := makeCommit(ctx, blockID3, height, 1, voteSet, privVals, defaultVoteTime) + extCommit, err := makeExtCommit(ctx, blockID3, height, 1, voteSet, privVals, defaultVoteTime) require.NoError(t, err) lcae := &LightClientAttackEvidence{ ConflictingBlock: &LightBlock{ SignedHeader: &SignedHeader{ Header: header, - Commit: commit, + Commit: extCommit.StripExtensions(), }, ValidatorSet: valSet, }, diff --git a/types/test_util.go b/types/test_util.go index 916a158e2..11daa69b9 100644 --- a/types/test_util.go +++ b/types/test_util.go @@ -8,8 +8,8 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) -func makeCommit(ctx context.Context, blockID BlockID, height int64, round int32, - voteSet *VoteSet, validators []PrivValidator, now time.Time) (*Commit, error) { +func makeExtCommit(ctx context.Context, blockID BlockID, height int64, round int32, + voteSet *VoteSet, validators []PrivValidator, now time.Time) (*ExtendedCommit, error) { // all sign for i := 0; i < len(validators); i++ { @@ -33,7 +33,7 @@ func makeCommit(ctx context.Context, blockID BlockID, height int64, round int32, } } - return voteSet.MakeExtendedCommit().StripExtensions(), nil + return voteSet.MakeExtendedCommit(), nil } func signAddVote(ctx context.Context, privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bool, err error) { @@ -46,13 +46,3 @@ func signAddVote(ctx context.Context, privVal PrivValidator, vote *Vote, voteSet vote.ExtensionSignature = v.ExtensionSignature return voteSet.AddVote(vote) } - -// Votes constructed from commits don't have extensions, because we don't store -// the extensions themselves in the commit. This method is used to construct a -// copy of a vote, but nil its extension and signature. -func voteWithoutExtension(v *Vote) *Vote { - vc := v.Copy() - vc.Extension = nil - vc.ExtensionSignature = nil - return vc -} diff --git a/types/validation_test.go b/types/validation_test.go index 7900ee5ce..6f3704bda 100644 --- a/types/validation_test.go +++ b/types/validation_test.go @@ -146,9 +146,10 @@ func TestValidatorSet_VerifyCommit_CheckAllSignatures(t *testing.T) { defer cancel() voteSet, valSet, vals := randVoteSet(ctx, t, h, 0, tmproto.PrecommitType, 4, 10) - commit, err := makeCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) - + extCommit, err := makeExtCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) require.NoError(t, err) + commit := extCommit.StripExtensions() + require.NoError(t, valSet.VerifyCommit(chainID, blockID, h, commit)) // malleate 4th signature @@ -176,9 +177,10 @@ func TestValidatorSet_VerifyCommitLight_ReturnsAsSoonAsMajorityOfVotingPowerSign defer cancel() voteSet, valSet, vals := randVoteSet(ctx, t, h, 0, tmproto.PrecommitType, 4, 10) - commit, err := makeCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) - + extCommit, err := makeExtCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) require.NoError(t, err) + commit := extCommit.StripExtensions() + require.NoError(t, valSet.VerifyCommit(chainID, blockID, h, commit)) // malleate 4th signature (3 signatures are enough for 2/3+) @@ -203,9 +205,10 @@ func TestValidatorSet_VerifyCommitLightTrusting_ReturnsAsSoonAsTrustLevelOfVotin defer cancel() voteSet, valSet, vals := randVoteSet(ctx, t, h, 0, tmproto.PrecommitType, 4, 10) - commit, err := makeCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) - + extCommit, err := makeExtCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) require.NoError(t, err) + commit := extCommit.StripExtensions() + require.NoError(t, valSet.VerifyCommit(chainID, blockID, h, commit)) // malleate 3rd signature (2 signatures are enough for 1/3+ trust level) @@ -227,10 +230,11 @@ func TestValidatorSet_VerifyCommitLightTrusting(t *testing.T) { var ( blockID = makeBlockIDRandom() voteSet, originalValset, vals = randVoteSet(ctx, t, 1, 1, tmproto.PrecommitType, 6, 1) - commit, err = makeCommit(ctx, blockID, 1, 1, voteSet, vals, time.Now()) + extCommit, err = makeExtCommit(ctx, blockID, 1, 1, voteSet, vals, time.Now()) newValSet, _ = randValidatorPrivValSet(ctx, t, 2, 1) ) require.NoError(t, err) + commit := extCommit.StripExtensions() testCases := []struct { valSet *ValidatorSet @@ -271,11 +275,11 @@ func TestValidatorSet_VerifyCommitLightTrustingErrorsOnOverflow(t *testing.T) { var ( blockID = makeBlockIDRandom() voteSet, valSet, vals = randVoteSet(ctx, t, 1, 1, tmproto.PrecommitType, 1, MaxTotalVotingPower) - commit, err = makeCommit(ctx, blockID, 1, 1, voteSet, vals, time.Now()) + extCommit, err = makeExtCommit(ctx, blockID, 1, 1, voteSet, vals, time.Now()) ) require.NoError(t, err) - err = valSet.VerifyCommitLightTrusting("test_chain_id", commit, + err = valSet.VerifyCommitLightTrusting("test_chain_id", extCommit.StripExtensions(), tmmath.Fraction{Numerator: 25, Denominator: 55}) if assert.Error(t, err) { assert.Contains(t, err.Error(), "int64 overflow") diff --git a/types/validator_set_test.go b/types/validator_set_test.go index 096327626..8b5846da9 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -1539,8 +1539,9 @@ func BenchmarkValidatorSet_VerifyCommit_Ed25519(b *testing.B) { // nolint // generate n validators voteSet, valSet, vals := randVoteSet(ctx, b, h, 0, tmproto.PrecommitType, n, int64(n*5)) // create a commit with n validators - commit, err := makeCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) + extCommit, err := makeExtCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) require.NoError(b, err) + commit := extCommit.StripExtensions() for i := 0; i < b.N/n; i++ { err = valSet.VerifyCommit(chainID, blockID, h, commit) @@ -1567,8 +1568,9 @@ func BenchmarkValidatorSet_VerifyCommitLight_Ed25519(b *testing.B) { // nolint voteSet, valSet, vals := randVoteSet(ctx, b, h, 0, tmproto.PrecommitType, n, int64(n*5)) // create a commit with n validators - commit, err := makeCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) + extCommit, err := makeExtCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) require.NoError(b, err) + commit := extCommit.StripExtensions() for i := 0; i < b.N/n; i++ { err = valSet.VerifyCommitLight(chainID, blockID, h, commit) @@ -1594,8 +1596,9 @@ func BenchmarkValidatorSet_VerifyCommitLightTrusting_Ed25519(b *testing.B) { // generate n validators voteSet, valSet, vals := randVoteSet(ctx, b, h, 0, tmproto.PrecommitType, n, int64(n*5)) // create a commit with n validators - commit, err := makeCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) + extCommit, err := makeExtCommit(ctx, blockID, h, 0, voteSet, vals, time.Now()) require.NoError(b, err) + commit := extCommit.StripExtensions() for i := 0; i < b.N/n; i++ { err = valSet.VerifyCommitLightTrusting(chainID, commit, tmmath.Fraction{Numerator: 1, Denominator: 3}) diff --git a/types/vote_set_test.go b/types/vote_set_test.go index 1805b4c3e..8d166d508 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -450,7 +450,7 @@ func TestVoteSet_MakeCommit(t *testing.T) { } // MakeCommit should fail. - assert.Panics(t, func() { voteSet.MakeCommit() }, "Doesn't have +2/3 majority") + assert.Panics(t, func() { voteSet.MakeExtendedCommit() }, "Doesn't have +2/3 majority") // 7th voted for some other block. { @@ -487,13 +487,13 @@ func TestVoteSet_MakeCommit(t *testing.T) { require.NoError(t, err) } - commit := voteSet.MakeCommit() + extCommit := voteSet.MakeExtendedCommit() // Commit should have 10 elements - assert.Equal(t, 10, len(commit.Signatures)) + assert.Equal(t, 10, len(extCommit.ExtendedSignatures)) // Ensure that Commit is good. - if err := commit.ValidateBasic(); err != nil { + if err := extCommit.ValidateBasic(); err != nil { t.Errorf("error in Commit.ValidateBasic(): %v", err) } } diff --git a/types/vote_test.go b/types/vote_test.go index f2de70087..70cd91381 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -493,11 +493,11 @@ func getSampleCommit(ctx context.Context, t testing.TB) *Commit { lastID := makeBlockIDRandom() voteSet, _, vals := randVoteSet(ctx, t, 2, 1, tmproto.PrecommitType, 10, 1) - commit, err := makeCommit(ctx, lastID, 2, 1, voteSet, vals, time.Now()) + commit, err := makeExtCommit(ctx, lastID, 2, 1, voteSet, vals, time.Now()) require.NoError(t, err) - return commit + return commit.StripExtensions() } func BenchmarkVoteSignBytes(b *testing.B) {