From 24c40b5b7bc681204b0c75f43d915f543d14cc7d Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Mon, 22 Nov 2021 16:22:12 -0500 Subject: [PATCH] consensus: refactor the fake validator to take a clock source (#7300) --- internal/consensus/common_test.go | 41 ++- internal/consensus/replay_test.go | 33 +- internal/consensus/state_test.go | 481 ++++++++++++++++-------------- 3 files changed, 297 insertions(+), 258 deletions(-) diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index cf0f641c2..a87e4abe2 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -19,7 +19,6 @@ import ( "github.com/tendermint/tendermint/abci/example/kvstore" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" - cfg "github.com/tendermint/tendermint/config" cstypes "github.com/tendermint/tendermint/internal/consensus/types" "github.com/tendermint/tendermint/internal/eventbus" tmsync "github.com/tendermint/tendermint/internal/libs/sync" @@ -92,6 +91,7 @@ type validatorStub struct { Index int32 // Validator index. NOTE: we don't assume validator set changes. Height int64 Round int32 + clock tmtime.Source types.PrivValidator VotingPower int64 lastVote *types.Vote @@ -104,16 +104,15 @@ func newValidatorStub(privValidator types.PrivValidator, valIndex int32) *valida Index: valIndex, PrivValidator: privValidator, VotingPower: testMinPower, + clock: tmtime.DefaultSource{}, } } func (vs *validatorStub) signVote( ctx context.Context, - cfg *config.Config, voteType tmproto.SignedMsgType, - hash []byte, - header types.PartSetHeader, -) (*types.Vote, error) { + chainID string, + blockID types.BlockID) (*types.Vote, error) { pubKey, err := vs.PrivValidator.GetPubKey(ctx) if err != nil { @@ -125,12 +124,12 @@ func (vs *validatorStub) signVote( ValidatorAddress: pubKey.Address(), Height: vs.Height, Round: vs.Round, - Timestamp: tmtime.Now(), + Timestamp: vs.clock.Now(), Type: voteType, - BlockID: types.BlockID{Hash: hash, PartSetHeader: header}, + BlockID: blockID, } v := vote.ToProto() - if err := vs.PrivValidator.SignVote(ctx, cfg.ChainID(), v); err != nil { + if err := vs.PrivValidator.SignVote(ctx, chainID, v); err != nil { return nil, fmt.Errorf("sign vote failed: %w", err) } @@ -150,13 +149,11 @@ func (vs *validatorStub) signVote( func signVote( ctx context.Context, vs *validatorStub, - cfg *config.Config, voteType tmproto.SignedMsgType, - hash []byte, - header types.PartSetHeader, -) *types.Vote { + chainID string, + blockID types.BlockID) *types.Vote { - v, err := vs.signVote(ctx, cfg, voteType, hash, header) + v, err := vs.signVote(ctx, voteType, chainID, blockID) if err != nil { panic(fmt.Errorf("failed to sign vote: %v", err)) } @@ -168,14 +165,13 @@ func signVote( func signVotes( ctx context.Context, - cfg *config.Config, voteType tmproto.SignedMsgType, - hash []byte, - header types.PartSetHeader, + chainID string, + blockID types.BlockID, vss ...*validatorStub) []*types.Vote { votes := make([]*types.Vote, len(vss)) for i, vs := range vss { - votes[i] = signVote(ctx, vs, cfg, voteType, hash, header) + votes[i] = signVote(ctx, vs, voteType, chainID, blockID) } return votes } @@ -270,14 +266,13 @@ func addVotes(to *State, votes ...*types.Vote) { func signAddVotes( ctx context.Context, - cfg *config.Config, to *State, voteType tmproto.SignedMsgType, - hash []byte, - header types.PartSetHeader, + chainID string, + blockID types.BlockID, vss ...*validatorStub, ) { - addVotes(to, signVotes(ctx, cfg, voteType, hash, header, vss...)...) + addVotes(to, signVotes(ctx, voteType, chainID, blockID, vss...)...) } func validatePrevote(ctx context.Context, t *testing.T, cs *State, round int32, privVal *validatorStub, blockHash []byte) { @@ -898,7 +893,7 @@ type genesisStateArgs struct { Time time.Time } -func makeGenesisState(config *cfg.Config, args genesisStateArgs) (sm.State, []types.PrivValidator) { +func makeGenesisState(cfg *config.Config, args genesisStateArgs) (sm.State, []types.PrivValidator) { if args.Power == 0 { args.Power = 1 } @@ -912,7 +907,7 @@ func makeGenesisState(config *cfg.Config, args genesisStateArgs) (sm.State, []ty if args.Time.IsZero() { args.Time = time.Now() } - genDoc := factory.GenesisDoc(config, args.Time, valSet.Validators, args.Params) + genDoc := factory.GenesisDoc(cfg, args.Time, valSet.Validators, args.Params) s0, _ := sm.MakeGenesisState(genDoc) return s0, privValidators } diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index 3371d3cea..517ac3626 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -364,8 +364,8 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { ensureNewProposal(t, proposalCh, height, round) rs := css[0].GetRoundState() - signAddVotes(ctx, sim.Config, css[0], tmproto.PrecommitType, - rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), + signAddVotes(ctx, css[0], tmproto.PrecommitType, sim.Config.ChainID(), + types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()}, vss[1:nVals]...) ensureNewRound(t, newRoundCh, height+1, 0) @@ -397,8 +397,8 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { } ensureNewProposal(t, proposalCh, height, round) rs = css[0].GetRoundState() - signAddVotes(ctx, sim.Config, css[0], tmproto.PrecommitType, - rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), + signAddVotes(ctx, css[0], tmproto.PrecommitType, sim.Config.ChainID(), + types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()}, vss[1:nVals]...) ensureNewRound(t, newRoundCh, height+1, 0) @@ -429,8 +429,8 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { } ensureNewProposal(t, proposalCh, height, round) rs = css[0].GetRoundState() - signAddVotes(ctx, sim.Config, css[0], tmproto.PrecommitType, - rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), + signAddVotes(ctx, css[0], tmproto.PrecommitType, sim.Config.ChainID(), + types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()}, vss[1:nVals]...) ensureNewRound(t, newRoundCh, height+1, 0) @@ -497,9 +497,10 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { if i == selfIndex { continue } - signAddVotes(ctx, sim.Config, css[0], - tmproto.PrecommitType, rs.ProposalBlock.Hash(), - rs.ProposalBlockParts.Header(), newVss[i]) + signAddVotes(ctx, css[0], + tmproto.PrecommitType, sim.Config.ChainID(), + types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()}, + newVss[i]) } ensureNewRound(t, newRoundCh, height+1, 0) @@ -518,9 +519,10 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { if i == selfIndex { continue } - signAddVotes(ctx, sim.Config, css[0], - tmproto.PrecommitType, rs.ProposalBlock.Hash(), - rs.ProposalBlockParts.Header(), newVss[i]) + signAddVotes(ctx, css[0], + tmproto.PrecommitType, sim.Config.ChainID(), + types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()}, + newVss[i]) } ensureNewRound(t, newRoundCh, height+1, 0) @@ -555,9 +557,10 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { if i == selfIndex { continue } - signAddVotes(ctx, sim.Config, css[0], - tmproto.PrecommitType, rs.ProposalBlock.Hash(), - rs.ProposalBlockParts.Header(), newVss[i]) + signAddVotes(ctx, css[0], + tmproto.PrecommitType, sim.Config.ChainID(), + types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()}, + newVss[i]) } ensureNewRound(t, newRoundCh, height+1, 0) diff --git a/internal/consensus/state_test.go b/internal/consensus/state_test.go index 407f59ac9..0f3663fd5 100644 --- a/internal/consensus/state_test.go +++ b/internal/consensus/state_test.go @@ -93,15 +93,10 @@ func TestStateProposerSelection0(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - signAddVotes( - ctx, - config, - cs1, - tmproto.PrecommitType, - rs.ProposalBlock.Hash(), - rs.ProposalBlockParts.Header(), - vss[1:]..., - ) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + }, vss[1:]...) // Wait for new round so next validator is set. ensureNewRound(t, newRoundCh, height+1, 0) @@ -150,7 +145,7 @@ func TestStateProposerSelection2(t *testing.T) { prop.Address)) } - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vss[1:]...) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vss[1:]...) ensureNewRound(t, newRoundCh, height, i+round+1) // wait for the new round event each round incrementRound(vss[1:]...) } @@ -275,13 +270,13 @@ func TestStateBadProposal(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) // add bad prevote from vs2 and wait for it - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2) ensurePrevote(t, voteCh, height, round) // wait for precommit ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2) } func TestStateOversizedBlock(t *testing.T) { @@ -341,11 +336,11 @@ func TestStateOversizedBlock(t *testing.T) { // precommit on it ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2) ensurePrevote(t, voteCh, height, round) ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2) } //---------------------------------------------------------------------------------------------------- @@ -443,20 +438,20 @@ func TestStateFullRound2(t *testing.T) { // we should be stuck in limbo waiting for more prevotes rs := cs1.GetRoundState() - propBlockHash, propPartSetHeader := rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header() + blockID := types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()} // prevote arrives from vs2: - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propPartSetHeader, vs2) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2) ensurePrevote(t, voteCh, height, round) // prevote ensurePrecommit(t, voteCh, height, round) // precommit // the proposed block should now be locked and our precommit added - validatePrecommit(ctx, t, cs1, 0, 0, vss[0], propBlockHash, propBlockHash) + validatePrecommit(ctx, t, cs1, 0, 0, vss[0], blockID.Hash, blockID.Hash) // we should be stuck in limbo waiting for more precommits // precommit arrives from vs2: - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlockHash, propPartSetHeader, vs2) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2) ensurePrecommit(t, voteCh, height, round) // wait to finish commit, propose in next height @@ -499,26 +494,32 @@ func TestStateLock_NoPOL(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) roundState := cs1.GetRoundState() - theBlockHash := roundState.ProposalBlock.Hash() - thePartSetHeader := roundState.ProposalBlockParts.Header() + initialBlockID := types.BlockID{ + Hash: roundState.ProposalBlock.Hash(), + PartSetHeader: roundState.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) // prevote // we should now be stuck in limbo forever, waiting for more prevotes // prevote arrives from vs2: - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, thePartSetHeader, vs2) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), initialBlockID, vs2) ensurePrevote(t, voteCh, height, round) // prevote + validatePrevote(ctx, t, cs1, round, vss[0], initialBlockID.Hash) // the proposed block should now be locked and our precommit added ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], initialBlockID.Hash, initialBlockID.Hash) // we should now be stuck in limbo forever, waiting for more precommits // lets add one for a different block - hash := make([]byte, len(theBlockHash)) - copy(hash, theBlockHash) + hash := make([]byte, len(initialBlockID.Hash)) + copy(hash, initialBlockID.Hash) hash[0] = (hash[0] + 1) % 255 - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, hash, thePartSetHeader, vs2) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{ + Hash: hash, + PartSetHeader: initialBlockID.PartSetHeader, + }, vs2) ensurePrecommit(t, voteCh, height, round) // precommit // (note we're entering precommit for a second time this round) @@ -550,7 +551,8 @@ func TestStateLock_NoPOL(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) // add a conflicting prevote from the other validator - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2) + conflictingBlockID := types.BlockID{Hash: hash, PartSetHeader: rs.LockedBlock.MakePartSet(partSize).Header()} + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), conflictingBlockID, vs2) ensurePrevote(t, voteCh, height, round) // now we're going to enter prevote again, but with invalid args @@ -559,10 +561,10 @@ func TestStateLock_NoPOL(t *testing.T) { // the proposed block should still be locked block. // we should precommit nil and be locked on the proposal. ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, initialBlockID.Hash) // add conflicting precommit from vs2 - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), conflictingBlockID, vs2) ensurePrecommit(t, voteCh, height, round) // (note we're entering precommit for a second time this round, but with invalid args @@ -592,21 +594,22 @@ func TestStateLock_NoPOL(t *testing.T) { ensurePrevote(t, voteCh, height, round) // prevote validatePrevote(ctx, t, cs1, round, vss[0], rs.LockedBlock.Hash()) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2) + newBlockID := types.BlockID{Hash: hash, PartSetHeader: rs.ProposalBlock.MakePartSet(partSize).Header()} + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), newBlockID, vs2) ensurePrevote(t, voteCh, height, round) ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) ensurePrecommit(t, voteCh, height, round) // precommit - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) // precommit nil but be locked on proposal + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, initialBlockID.Hash) // precommit nil but be locked on proposal signAddVotes( ctx, - config, cs1, tmproto.PrecommitType, - hash, - rs.ProposalBlock.MakePartSet(partSize).Header(), + config.ChainID(), + + newBlockID, vs2) // NOTE: conflicting precommits at same height ensurePrecommit(t, voteCh, height, round) @@ -619,6 +622,10 @@ func TestStateLock_NoPOL(t *testing.T) { if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") } + propBlockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlock.MakePartSet(partSize).Header(), + } incrementRound(vs2) @@ -642,20 +649,20 @@ func TestStateLock_NoPOL(t *testing.T) { validatePrevote(ctx, t, cs1, 3, vss[0], nil) // prevote for proposed block - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), propBlockID, vs2) ensurePrevote(t, voteCh, height, round) ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) // precommit nil but locked on proposal + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, initialBlockID.Hash) // precommit nil but locked on proposal signAddVotes( ctx, - config, cs1, tmproto.PrecommitType, - propBlock.Hash(), - propBlock.MakePartSet(partSize).Header(), + config.ChainID(), + + propBlockID, vs2) // NOTE: conflicting precommits at same height ensurePrecommit(t, voteCh, height, round) } @@ -704,22 +711,24 @@ func TestStateLock_POLUpdateLock(t *testing.T) { ensureNewRound(t, newRoundCh, height, round) ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - theBlockHash := rs.ProposalBlock.Hash() - theBlockParts := rs.ProposalBlockParts.Header() + initialBlockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), initialBlockID, vs2, vs3, vs4) // check that the validator generates a Lock event. ensureLock(t, lockCh, height, round) // the proposed block should now be locked and our precommit added. ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], initialBlockID.Hash, initialBlockID.Hash) // add precommits from the rest of the validators. - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // timeout to new round. ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -742,7 +751,11 @@ func TestStateLock_POLUpdateLock(t *testing.T) { propR1, propBlockR1 := decideProposal(ctx, t, cs2, vs2, vs2.Height, vs2.Round) propBlockR1Parts := propBlockR1.MakePartSet(partSize) propBlockR1Hash := propBlockR1.Hash() - require.NotEqual(t, propBlockR1Hash, theBlockHash) + r1BlockID := types.BlockID{ + Hash: propBlockR1Hash, + PartSetHeader: propBlockR1Parts.Header(), + } + require.NotEqual(t, propBlockR1Hash, initialBlockID.Hash) if err := cs1.SetProposalAndBlock(propR1, propBlockR1, propBlockR1Parts, "some peer"); err != nil { t.Fatal(err) } @@ -757,7 +770,7 @@ func TestStateLock_POLUpdateLock(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) // Add prevotes from the remainder of the validators for the new locked block. - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockR1Hash, propBlockR1Parts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), r1BlockID, vs2, vs3, vs4) // Check that we lock on a new block. ensureLock(t, lockCh, height, round) @@ -809,22 +822,25 @@ func TestStateLock_POLRelock(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() theBlock := rs.ProposalBlock - theBlockHash := rs.ProposalBlock.Hash() theBlockParts := rs.ProposalBlockParts + blockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) // check that the validator generates a Lock event. ensureLock(t, lockCh, height, round) // the proposed block should now be locked and our precommit added. ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash) // add precommits from the rest of the validators. - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // timeout to new round. ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -840,8 +856,7 @@ func TestStateLock_POLRelock(t *testing.T) { t.Log("### Starting Round 1") incrementRound(vs2, vs3, vs4) round++ - propBlockID := types.BlockID{Hash: theBlockHash, PartSetHeader: theBlockParts.Header()} - propR1 := types.NewProposal(height, round, cs1.ValidRound, propBlockID) + propR1 := types.NewProposal(height, round, cs1.ValidRound, blockID) p := propR1.ToProto() if err := vs2.SignProposal(ctx, cs1.state.ChainID, p); err != nil { t.Fatalf("error signing proposal: %s", err) @@ -858,10 +873,10 @@ func TestStateLock_POLRelock(t *testing.T) { // Prevote our locked block since it matches the propsal seen in this round. ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], theBlockHash) + validatePrevote(ctx, t, cs1, round, vss[0], blockID.Hash) // Add prevotes from the remainder of the validators for the locked block. - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) // Check that we relock. ensureRelock(t, relockCh, height, round) @@ -869,7 +884,7 @@ func TestStateLock_POLRelock(t *testing.T) { ensurePrecommit(t, voteCh, height, round) // We should now be locked on the same block but with an updated locked round. - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash) } // TestStateLock_PrevoteNilWhenLockedAndMissProposal tests that a validator prevotes nil @@ -909,22 +924,24 @@ func TestStateLock_PrevoteNilWhenLockedAndMissProposal(t *testing.T) { ensureNewRound(t, newRoundCh, height, round) ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - theBlockHash := rs.ProposalBlock.Hash() - theBlockParts := rs.ProposalBlockParts + blockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) // check that the validator generates a Lock event. ensureLock(t, lockCh, height, round) // the proposed block should now be locked and our precommit added. ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash) // add precommits from the rest of the validators. - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // timeout to new round. ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -948,10 +965,10 @@ func TestStateLock_PrevoteNilWhenLockedAndMissProposal(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) // Add prevotes from the remainder of the validators nil. - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // We should now be locked on the same block but with an updated locked round. - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, blockID.Hash) } // TestStateLock_PrevoteNilWhenLockedAndMissProposal tests that a validator prevotes nil @@ -996,22 +1013,24 @@ func TestStateLock_PrevoteNilWhenLockedAndDifferentProposal(t *testing.T) { ensureNewRound(t, newRoundCh, height, round) ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - theBlockHash := rs.ProposalBlock.Hash() - theBlockParts := rs.ProposalBlockParts + blockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) // check that the validator generates a Lock event. ensureLock(t, lockCh, height, round) // the proposed block should now be locked and our precommit added. ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash) // add precommits from the rest of the validators. - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // timeout to new round. ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -1033,7 +1052,7 @@ func TestStateLock_PrevoteNilWhenLockedAndDifferentProposal(t *testing.T) { propR1, propBlockR1 := decideProposal(ctx, t, cs2, vs2, vs2.Height, vs2.Round) propBlockR1Parts := propBlockR1.MakePartSet(types.BlockPartSizeBytes) propBlockR1Hash := propBlockR1.Hash() - require.NotEqual(t, propBlockR1Hash, theBlockHash) + require.NotEqual(t, propBlockR1Hash, blockID.Hash) if err := cs1.SetProposalAndBlock(propR1, propBlockR1, propBlockR1Parts, "some peer"); err != nil { t.Fatal(err) } @@ -1046,11 +1065,11 @@ func TestStateLock_PrevoteNilWhenLockedAndDifferentProposal(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) // Add prevotes from the remainder of the validators for nil. - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // We should now be locked on the same block but prevote nil. ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, blockID.Hash) } // TestStateLock_POLDoesNotUnlock tests that a validator maintains its locked block @@ -1100,13 +1119,15 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - theBlockHash := rs.ProposalBlock.Hash() - theBlockParts := rs.ProposalBlockParts.Header() + blockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], theBlockHash) + validatePrevote(ctx, t, cs1, round, vss[0], blockID.Hash) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) // the validator should have locked a block in this round. ensureLock(t, lockCh, height, round) @@ -1114,15 +1135,15 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) { ensurePrecommit(t, voteCh, height, round) // the proposed block should now be locked and our should be for this locked block. - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash) // Add precommits from the other validators. // We only issue 1/2 Precommits for the block in this round. // This ensures that the validator being tested does not commit the block. // We do not want the validator to commit the block because we want the test // test to proceeds to the next consensus round. - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs3) // timeout to new round ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -1140,7 +1161,7 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) { require.NoError(t, err) prop, propBlock := decideProposal(ctx, t, cs2, vs2, vs2.Height, vs2.Round) propBlockParts := propBlock.MakePartSet(types.BlockPartSizeBytes) - require.NotEqual(t, propBlock.Hash(), theBlockHash) + require.NotEqual(t, propBlock.Hash(), blockID.Hash) if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, ""); err != nil { t.Fatal(err) } @@ -1154,14 +1175,14 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) // add >2/3 prevotes for nil from all other validators - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // verify that we haven't update our locked block since the first round - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, blockID.Hash) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) /* @@ -1189,12 +1210,12 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) { ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // verify that we haven't update our locked block since the first round - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, blockID.Hash) } @@ -1235,19 +1256,21 @@ func TestStateLock_MissingProposalWhenPOLSeenDoesNotUpdateLock(t *testing.T) { ensureNewRound(t, newRoundCh, height, round) ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - firstBlockHash := rs.ProposalBlock.Hash() - firstBlockParts := rs.ProposalBlockParts.Header() + firstBlockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) // prevote - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, firstBlockHash, firstBlockParts, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), firstBlockID, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // our precommit // the proposed block should now be locked and our precommit added - validatePrecommit(ctx, t, cs1, round, round, vss[0], firstBlockHash, firstBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], firstBlockID.Hash, firstBlockID.Hash) // add precommits from the rest - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // timeout to new round ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -1268,9 +1291,11 @@ func TestStateLock_MissingProposalWhenPOLSeenDoesNotUpdateLock(t *testing.T) { if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") } - secondBlockParts := propBlock.MakePartSet(partSize) - secondBlockHash := propBlock.Hash() - require.NotEqual(t, secondBlockHash, firstBlockHash) + secondBlockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlock.MakePartSet(partSize).Header(), + } + require.NotEqual(t, secondBlockID.Hash, firstBlockID.Hash) ensureNewRound(t, newRoundCh, height, round) @@ -1279,10 +1304,10 @@ func TestStateLock_MissingProposalWhenPOLSeenDoesNotUpdateLock(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) // now lets add prevotes from everyone else for the new block - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, secondBlockHash, secondBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), secondBlockID, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, firstBlockHash) + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, firstBlockID.Hash) } // TestStateLock_DoesNotLockOnOldProposal tests that observing @@ -1321,18 +1346,20 @@ func TestStateLock_DoesNotLockOnOldProposal(t *testing.T) { ensureNewRound(t, newRoundCh, height, round) ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - firstBlockHash := rs.ProposalBlock.Hash() - firstBlockParts := rs.ProposalBlockParts.Header() + firstBlockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // The proposed block should not have been locked. ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) incrementRound(vs2, vs3, vs4) @@ -1356,7 +1383,7 @@ func TestStateLock_DoesNotLockOnOldProposal(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) // All validators prevote for the old block. // All validators prevote for the old block. - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, firstBlockHash, firstBlockParts, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), firstBlockID, vs2, vs3, vs4) // Make sure that cs1 did not lock on the block since it did not receive a proposal for it. ensurePrecommit(t, voteCh, height, round) @@ -1399,14 +1426,14 @@ func TestStateLock_POLSafety1(t *testing.T) { ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], propBlock.Hash()) - + blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlock.MakePartSet(partSize).Header()} // the others sign a polka but we don't see it - prevotes := signVotes(ctx, config, tmproto.PrevoteType, - propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), + prevotes := signVotes(ctx, tmproto.PrevoteType, config.ChainID(), + blockID, vs2, vs3, vs4) // we do see them precommit nil - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // cs1 precommit nil ensurePrecommit(t, voteCh, height, round) @@ -1418,8 +1445,11 @@ func TestStateLock_POLSafety1(t *testing.T) { cs2, err := newState(ctx, logger, cs1.state, vs2, kvstore.NewApplication()) require.NoError(t, err) prop, propBlock := decideProposal(ctx, t, cs2, vs2, vs2.Height, vs2.Round) - propBlockHash := propBlock.Hash() propBlockParts := propBlock.MakePartSet(partSize) + r2BlockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlockParts.Header(), + } ensureNewRound(t, newRoundCh, height, round) @@ -1442,16 +1472,16 @@ func TestStateLock_POLSafety1(t *testing.T) { // go to prevote, prevote for proposal block ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash) + validatePrevote(ctx, t, cs1, round, vss[0], r2BlockID.Hash) // now we see the others prevote for it, so we should lock on it - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), r2BlockID, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // we should have precommitted - validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockHash, propBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], r2BlockID.Hash, r2BlockID.Hash) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -1518,12 +1548,12 @@ func TestStateLock_POLSafety2(t *testing.T) { propBlockID0 := types.BlockID{Hash: propBlockHash0, PartSetHeader: propBlockParts0.Header()} // the others sign a polka but we don't see it - prevotes := signVotes(ctx, config, tmproto.PrevoteType, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4) + prevotes := signVotes(ctx, tmproto.PrevoteType, config.ChainID(), propBlockID0, vs2, vs3, vs4) // the block for round 1 prop1, propBlock1 := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round+1) - propBlockHash1 := propBlock1.Hash() propBlockParts1 := propBlock1.MakePartSet(partSize) + propBlockID1 := types.BlockID{Hash: propBlock1.Hash(), PartSetHeader: propBlockParts1.Header()} incrementRound(vs2, vs3, vs4) @@ -1539,17 +1569,17 @@ func TestStateLock_POLSafety2(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash1) + validatePrevote(ctx, t, cs1, round, vss[0], propBlockID1.Hash) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), propBlockID1, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // the proposed block should now be locked and our precommit added - validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockHash1, propBlockHash1) + validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockID1.Hash, propBlockID1.Hash) // add precommits from the rest - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlockHash1, propBlockParts1.Header(), vs3) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), propBlockID1, vs3) incrementRound(vs2, vs3, vs4) @@ -1581,7 +1611,7 @@ func TestStateLock_POLSafety2(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash1) + validatePrevote(ctx, t, cs1, round, vss[0], propBlockID1.Hash) } @@ -1625,22 +1655,24 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) { ensureNewRound(t, newRoundCh, height, round) ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - theBlockHash := rs.ProposalBlock.Hash() - theBlockParts := rs.ProposalBlockParts.Header() + r0BlockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), r0BlockID, vs2, vs3, vs4) // check that the validator generates a Lock event. ensureLock(t, lockCh, height, round) // the proposed block should now be locked and our precommit added. ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], r0BlockID.Hash, r0BlockID.Hash) // add precommits from the rest of the validators. - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // timeout to new round. ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -1664,17 +1696,20 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) { propR1, propBlockR1 := decideProposal(ctx, t, cs2, vs2, vs2.Height, round) t.Log(propR1.POLRound) propBlockR1Parts := propBlockR1.MakePartSet(partSize) - propBlockR1Hash := propBlockR1.Hash() - require.NotEqual(t, propBlockR1Hash, theBlockHash) + r1BlockID := types.BlockID{ + Hash: propBlockR1.Hash(), + PartSetHeader: propBlockR1Parts.Header(), + } + require.NotEqual(t, r1BlockID.Hash, r0BlockID.Hash) ensureNewRound(t, newRoundCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockR1Hash, propBlockR1Parts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), r1BlockID, vs2, vs3, vs4) ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) @@ -1682,7 +1717,6 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) { ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) /* - Round 2: Create a new proposal for D, the same block from Round 1. cs1 already saw greater than 2/3 of the voting power on the network vote for D in a previous round, so it should prevote D once it receives a proposal for it. @@ -1696,8 +1730,7 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) { t.Log("### Starting Round 2") incrementRound(vs2, vs3, vs4) round++ - propBlockID := types.BlockID{Hash: propBlockR1Hash, PartSetHeader: propBlockR1Parts.Header()} - propR2 := types.NewProposal(height, round, 1, propBlockID) + propR2 := types.NewProposal(height, round, 1, r1BlockID) p := propR2.ToProto() if err := vs3.SignProposal(ctx, cs1.state.ChainID, p); err != nil { t.Fatalf("error signing proposal: %s", err) @@ -1716,14 +1749,14 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) { // We should now prevote this block, despite being locked on the block from // round 0. ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], propBlockR1Hash) + validatePrevote(ctx, t, cs1, round, vss[0], r1BlockID.Hash) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) // cs1 did not receive a POL within this round, so it should remain locked // on the block from round 0. ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, theBlockHash) + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, r0BlockID.Hash) } // 4 vals. @@ -1760,22 +1793,23 @@ func TestProposeValidBlock(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() propBlock := rs.ProposalBlock - propBlockHash := propBlock.Hash() + blockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlock.MakePartSet(partSize).Header(), + } ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash) + validatePrevote(ctx, t, cs1, round, vss[0], blockID.Hash) // the others sign a polka - signAddVotes(ctx, cfg, cs1, tmproto.PrevoteType, - propBlockHash, propBlock.MakePartSet(partSize).Header(), vs2, - vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, cfg.ChainID(), blockID, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // we should have precommitted the proposed block in this round. - validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockHash, propBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash) - signAddVotes(ctx, cfg, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, cfg.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -1792,17 +1826,17 @@ func TestProposeValidBlock(t *testing.T) { ensurePrevote(t, voteCh, height, round) validatePrevote(ctx, t, cs1, round, vss[0], nil) - signAddVotes(ctx, cfg, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, cfg.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // we should have precommitted nil during this round because we received // >2/3 precommits for nil from the other validators. - validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, propBlockHash) + validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, blockID.Hash) incrementRound(vs2, vs3, vs4) incrementRound(vs2, vs3, vs4) - signAddVotes(ctx, cfg, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, cfg.ChainID(), types.BlockID{}, vs2, vs3, vs4) round += 2 // increment by multiple rounds @@ -1818,7 +1852,7 @@ func TestProposeValidBlock(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs = cs1.GetRoundState() - assert.True(t, bytes.Equal(rs.ProposalBlock.Hash(), propBlockHash)) + assert.True(t, bytes.Equal(rs.ProposalBlock.Hash(), blockID.Hash)) assert.True(t, bytes.Equal(rs.ProposalBlock.Hash(), rs.ValidBlock.Hash())) assert.True(t, rs.Proposal.POLRound == rs.ValidRound) assert.True(t, bytes.Equal(rs.Proposal.BlockID.Hash, rs.ValidBlock.Hash())) @@ -1855,17 +1889,19 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() propBlock := rs.ProposalBlock - propBlockHash := propBlock.Hash() - propBlockParts := propBlock.MakePartSet(partSize) + blockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlock.MakePartSet(partSize).Header(), + } ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], propBlockHash) + validatePrevote(ctx, t, cs1, round, vss[0], blockID.Hash) // vs2 send prevote for propBlock - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2) // vs3 send prevote nil - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs3) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs3) ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) @@ -1880,14 +1916,14 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) { assert.True(t, rs.ValidRound == -1) // vs2 send (delayed) prevote for propBlock - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs4) ensureNewValidBlock(t, validBlockCh, height, round) rs = cs1.GetRoundState() - assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), propBlockHash)) - assert.True(t, rs.ValidBlockParts.Header().Equals(propBlockParts.Header())) + assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), blockID.Hash)) + assert.True(t, rs.ValidBlockParts.Header().Equals(blockID.PartSetHeader)) assert.True(t, rs.ValidRound == round) } @@ -1929,11 +1965,13 @@ func TestSetValidBlockOnDelayedProposal(t *testing.T) { validatePrevote(ctx, t, cs1, round, vss[0], nil) prop, propBlock := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round+1) - propBlockHash := propBlock.Hash() - propBlockParts := propBlock.MakePartSet(partSize) + blockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlock.MakePartSet(partSize).Header(), + } // vs2, vs3 and vs4 send prevote for propBlock - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) ensureNewValidBlock(t, validBlockCh, height, round) ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) @@ -1941,15 +1979,15 @@ func TestSetValidBlockOnDelayedProposal(t *testing.T) { ensurePrecommit(t, voteCh, height, round) validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil) - if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil { + if err := cs1.SetProposalAndBlock(prop, propBlock, propBlock.MakePartSet(partSize), "some peer"); err != nil { t.Fatal(err) } ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), propBlockHash)) - assert.True(t, rs.ValidBlockParts.Header().Equals(propBlockParts.Header())) + assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), blockID.Hash)) + assert.True(t, rs.ValidBlockParts.Header().Equals(blockID.PartSetHeader)) assert.True(t, rs.ValidRound == round) } @@ -1974,7 +2012,7 @@ func TestWaitingTimeoutOnNilPolka(t *testing.T) { startTestRound(ctx, cs1, height, round) ensureNewRound(t, newRoundCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) ensureNewRound(t, newRoundCh, height, round+1) @@ -2008,7 +2046,7 @@ func TestWaitingTimeoutProposeOnNewRound(t *testing.T) { ensurePrevote(t, voteCh, height, round) incrementRound(vss[1:]...) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) round++ // moving to the next round ensureNewRound(t, newRoundCh, height, round) @@ -2050,7 +2088,7 @@ func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) { ensurePrevote(t, voteCh, height, round) incrementRound(vss[1:]...) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) round++ // moving to the next round ensureNewRound(t, newRoundCh, height, round) @@ -2090,7 +2128,7 @@ func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) { ensureNewRound(t, newRoundCh, height, round) incrementRound(vss[1:]...) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4) ensureNewTimeout(t, timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) @@ -2119,21 +2157,23 @@ func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) { validBlockCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryValidBlock) _, propBlock := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round) - propBlockHash := propBlock.Hash() - propBlockParts := propBlock.MakePartSet(partSize) + blockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlock.MakePartSet(partSize).Header(), + } // start round in which PO is not proposer startTestRound(ctx, cs1, height, round) ensureNewRound(t, newRoundCh, height, round) // vs2, vs3 and vs4 send precommit for propBlock - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2, vs3, vs4) ensureNewValidBlock(t, validBlockCh, height, round) rs := cs1.GetRoundState() assert.True(t, rs.Step == cstypes.RoundStepCommit) assert.True(t, rs.ProposalBlock == nil) - assert.True(t, rs.ProposalBlockParts.Header().Equals(propBlockParts.Header())) + assert.True(t, rs.ProposalBlockParts.Header().Equals(blockID.PartSetHeader)) } @@ -2158,15 +2198,17 @@ func TestCommitFromPreviousRound(t *testing.T) { proposalCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryCompleteProposal) prop, propBlock := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round) - propBlockHash := propBlock.Hash() - propBlockParts := propBlock.MakePartSet(partSize) + blockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlock.MakePartSet(partSize).Header(), + } // start round in which PO is not proposer startTestRound(ctx, cs1, height, round) ensureNewRound(t, newRoundCh, height, round) // vs2, vs3 and vs4 send precommit for propBlock for the previous round - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2, vs3, vs4) ensureNewValidBlock(t, validBlockCh, height, round) @@ -2174,9 +2216,9 @@ func TestCommitFromPreviousRound(t *testing.T) { assert.True(t, rs.Step == cstypes.RoundStepCommit) assert.True(t, rs.CommitRound == vs2.Round) assert.True(t, rs.ProposalBlock == nil) - assert.True(t, rs.ProposalBlockParts.Header().Equals(propBlockParts.Header())) + assert.True(t, rs.ProposalBlockParts.Header().Equals(blockID.PartSetHeader)) - if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil { + if err := cs1.SetProposalAndBlock(prop, propBlock, propBlock.MakePartSet(partSize), "some peer"); err != nil { t.Fatal(err) } @@ -2230,21 +2272,23 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - theBlockHash := rs.ProposalBlock.Hash() - theBlockParts := rs.ProposalBlockParts.Header() + blockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], theBlockHash) + validatePrevote(ctx, t, cs1, round, vss[0], blockID.Hash) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // the proposed block should now be locked and our precommit added - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash) // add precommits - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs3) // wait till timeout occurs ensurePrecommitTimeout(t, precommitTimeoutCh) @@ -2252,9 +2296,9 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) { ensureNewRound(t, newRoundCh, height, round+1) // majority is now reached - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs4) - ensureNewBlockHeader(t, newBlockHeader, height, theBlockHash) + ensureNewBlockHeader(t, newBlockHeader, height, blockID.Hash) cs1.txNotifier.(*fakeTxNotifier).Notify() @@ -2296,23 +2340,25 @@ func TestResetTimeoutPrecommitUponNewHeight(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() - theBlockHash := rs.ProposalBlock.Hash() - theBlockParts := rs.ProposalBlockParts.Header() + blockID := types.BlockID{ + Hash: rs.ProposalBlock.Hash(), + PartSetHeader: rs.ProposalBlockParts.Header(), + } ensurePrevote(t, voteCh, height, round) - validatePrevote(ctx, t, cs1, round, vss[0], theBlockHash) + validatePrevote(ctx, t, cs1, round, vss[0], blockID.Hash) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) - validatePrecommit(ctx, t, cs1, round, round, vss[0], theBlockHash, theBlockHash) + validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash) // add precommits - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs4) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs3) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs4) - ensureNewBlockHeader(t, newBlockHeader, height, theBlockHash) + ensureNewBlockHeader(t, newBlockHeader, height, blockID.Hash) prop, propBlock := decideProposal(ctx, t, cs1, vs2, height+1, 0) propBlockParts := propBlock.MakePartSet(partSize) @@ -2356,15 +2402,8 @@ func TestStateSlashing_Prevotes(t *testing.T) { // add one for a different block should cause us to go into prevote wait hash := rs.ProposalBlock.Hash() hash[0] = byte(hash[0]+1) % 255 - signAddVotes(cs1, tmproto.PrevoteType, hash, rs.ProposalBlockParts.Header(), vs2) - - <-timeoutWaitCh - - // NOTE: we have to send the vote for different block first so we don't just go into precommit round right - // away and ignore more prevotes (and thus fail to slash!) - - // add the conflicting vote - signAddVotes(cs1, tmproto.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) + signAddVotes(tmproto.PrevoteType, hash, config.ChainID(), blockID, + rs.ProposalBlock.Hash(), config.ChainID(), rs.ProposalBlockParts.Header(), vs2) // XXX: Check for existence of Dupeout info } @@ -2386,21 +2425,12 @@ func TestStateSlashing_Precommits(t *testing.T) { <-voteCh // prevote // add prevote from vs2 - signAddVotes(cs1, tmproto.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) - - <-voteCh // precommit - - // we should now be stuck in limbo forever, waiting for more prevotes + signAddVotes(tmproto.PrevoteType, rs.ProposalBlock.Hash(),config.ChainID(), blockID, waiting for more prevotes // add one for a different block should cause us to go into prevote wait hash := rs.ProposalBlock.Hash() hash[0] = byte(hash[0]+1) % 255 - signAddVotes(cs1, tmproto.PrecommitType, hash, rs.ProposalBlockParts.Header(), vs2) - - // NOTE: we have to send the vote for different block first so we don't just go into precommit round right - // away and ignore more prevotes (and thus fail to slash!) - - // add precommit from vs2 - signAddVotes(cs1, tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) + signAddVotes(tmproto.PrecommitType, hash, config.ChainID(), blockID, + rs.ProposalBlock.Hash(), config.ChainID(), rs.ProposalBlockParts.Header(), vs2) // XXX: Check for existence of Dupeout info } @@ -2442,21 +2472,24 @@ func TestStateHalt1(t *testing.T) { ensureNewProposal(t, proposalCh, height, round) rs := cs1.GetRoundState() propBlock := rs.ProposalBlock - propBlockParts := propBlock.MakePartSet(partSize) + blockID := types.BlockID{ + Hash: propBlock.Hash(), + PartSetHeader: propBlock.MakePartSet(partSize).Header(), + } ensurePrevote(t, voteCh, height, round) - signAddVotes(ctx, config, cs1, tmproto.PrevoteType, propBlock.Hash(), propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(ctx, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4) ensurePrecommit(t, voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlock.Hash(), propBlock.Hash()) // add precommits from the rest - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2) // didnt receive proposal - signAddVotes(ctx, config, cs1, tmproto.PrecommitType, propBlock.Hash(), propBlockParts.Header(), vs3) + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2) // didnt receive proposal + signAddVotes(ctx, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs3) // we receive this later, but vs3 might receive it earlier and with ours will go to commit! - precommit4 := signVote(ctx, vs4, config, tmproto.PrecommitType, propBlock.Hash(), propBlockParts.Header()) + precommit4 := signVote(ctx, vs4, tmproto.PrecommitType, config.ChainID(), blockID) incrementRound(vs2, vs3, vs4) @@ -2548,8 +2581,11 @@ func TestStateOutputVoteStats(t *testing.T) { require.NoError(t, err) randBytes := tmrand.Bytes(tmhash.Size) + blockID := types.BlockID{ + Hash: randBytes, + } - vote := signVote(ctx, vss[1], config, tmproto.PrecommitType, randBytes, types.PartSetHeader{}) + vote := signVote(ctx, vss[1], tmproto.PrecommitType, config.ChainID(), blockID) voteMessage := &VoteMessage{vote} cs.handleMsg(msgInfo{voteMessage, peerID}) @@ -2563,7 +2599,7 @@ func TestStateOutputVoteStats(t *testing.T) { // sending the vote for the bigger height incrementHeight(vss[1]) - vote = signVote(ctx, vss[1], config, tmproto.PrecommitType, randBytes, types.PartSetHeader{}) + vote = signVote(ctx, vss[1], tmproto.PrecommitType, config.ChainID(), blockID) cs.handleMsg(msgInfo{&VoteMessage{vote}, peerID}) @@ -2589,19 +2625,24 @@ func TestSignSameVoteTwice(t *testing.T) { vote := signVote( ctx, vss[1], - config, tmproto.PrecommitType, - randBytes, - types.PartSetHeader{Total: 10, Hash: randBytes}, - ) + config.ChainID(), + types.BlockID{ + Hash: randBytes, + PartSetHeader: types.PartSetHeader{Total: 10, Hash: randBytes}, + }, + ) vote2 := signVote( ctx, vss[1], - config, tmproto.PrecommitType, - randBytes, - types.PartSetHeader{Total: 10, Hash: randBytes}, + config.ChainID(), + + types.BlockID{ + Hash: randBytes, + PartSetHeader: types.PartSetHeader{Total: 10, Hash: randBytes}, + }, ) require.Equal(t, vote, vote2)