types: change Commit to consist of just signatures (#4146)

* types: change `Commit` to consist of just signatures

These are final changes towards removing votes from commit and leaving
only signatures (see ADR-25)

Fixes #1648

* bring back TestCommitToVoteSetWithVotesForAnotherBlockOrNilBlock

+ add absent flag to Vote to indicate that it's for another block

* encode nil votes as CommitSig with BlockIDFlagAbsent

+ make Commit#Precommits array of non-pointers
because precommit will never be nil

* add NewCommitSigAbsent and Absent() funcs

* uncomment validation in CommitSig#ValidateBasic

* add comments to ValidatorSet funcs

* add a changelog entry

* break instead of continue

continue does not make sense in these cases

* types: rename Commit#Precommits to Signatures

* swagger: fix /commit response

* swagger: change block_id_flag type

* fix merge conflicts
This commit is contained in:
Anton Kaliaev
2019-11-26 14:10:38 +04:00
committed by GitHub
parent fb8b00f1d8
commit ad715fe966
30 changed files with 531 additions and 425 deletions
+23 -16
View File
@@ -30,14 +30,14 @@ func TestValidateBlockHeader(t *testing.T) {
mock.Mempool{},
sm.MockEvidencePool{},
)
lastCommit := types.NewCommit(types.BlockID{}, nil)
lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
// some bad values
wrongHash := tmhash.Sum([]byte("this hash is wrong"))
wrongVersion1 := state.Version.Consensus
wrongVersion1.Block += 1
wrongVersion1.Block++
wrongVersion2 := state.Version.Consensus
wrongVersion2.App += 1
wrongVersion2.App++
// Manipulation of any header field causes failure.
testCases := []struct {
@@ -100,8 +100,8 @@ func TestValidateBlockCommit(t *testing.T) {
mock.Mempool{},
sm.MockEvidencePool{},
)
lastCommit := types.NewCommit(types.BlockID{}, nil)
wrongPrecommitsCommit := types.NewCommit(types.BlockID{}, nil)
lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
wrongSigsCommit := types.NewCommit(1, 0, types.BlockID{}, nil)
badPrivVal := types.NewMockPV()
for height := int64(1); height < validationTestsStopHeight; height++ {
@@ -119,22 +119,25 @@ func TestValidateBlockCommit(t *testing.T) {
chainID,
)
require.NoError(t, err, "height %d", height)
wrongHeightCommit := types.NewCommit(state.LastBlockID, []*types.CommitSig{wrongHeightVote.CommitSig()})
wrongHeightCommit := types.NewCommit(
wrongHeightVote.Height,
wrongHeightVote.Round,
state.LastBlockID,
[]types.CommitSig{wrongHeightVote.CommitSig()},
)
block, _ := state.MakeBlock(height, makeTxs(height), wrongHeightCommit, nil, proposerAddr)
err = blockExec.ValidateBlock(state, block)
_, isErrInvalidCommitHeight := err.(types.ErrInvalidCommitHeight)
require.True(t, isErrInvalidCommitHeight, "expected ErrInvalidCommitHeight at height %d but got: %v", height, err)
/*
#2589: test len(block.LastCommit.Precommits) == state.LastValidators.Size()
#2589: test len(block.LastCommit.Signatures) == state.LastValidators.Size()
*/
block, _ = state.MakeBlock(height, makeTxs(height), wrongPrecommitsCommit, nil, proposerAddr)
block, _ = state.MakeBlock(height, makeTxs(height), wrongSigsCommit, nil, proposerAddr)
err = blockExec.ValidateBlock(state, block)
_, isErrInvalidCommitPrecommits := err.(types.ErrInvalidCommitPrecommits)
require.True(
t,
isErrInvalidCommitPrecommits,
"expected ErrInvalidCommitPrecommits at height %d but got: %v",
_, isErrInvalidCommitSignatures := err.(types.ErrInvalidCommitSignatures)
require.True(t, isErrInvalidCommitSignatures,
"expected ErrInvalidCommitSignatures at height %d, but got: %v",
height,
err,
)
@@ -157,7 +160,7 @@ func TestValidateBlockCommit(t *testing.T) {
require.NoError(t, err, "height %d", height)
/*
wrongPrecommitsCommit is fine except for the extra bad precommit
wrongSigsCommit is fine except for the extra bad precommit
*/
goodVote, err := types.MakeVote(height, blockID, state.Validators, privVals[proposerAddr.String()], chainID)
require.NoError(t, err, "height %d", height)
@@ -172,7 +175,11 @@ func TestValidateBlockCommit(t *testing.T) {
}
err = badPrivVal.SignVote(chainID, goodVote)
require.NoError(t, err, "height %d", height)
wrongPrecommitsCommit = types.NewCommit(blockID, []*types.CommitSig{goodVote.CommitSig(), badVote.CommitSig()})
err = badPrivVal.SignVote(chainID, badVote)
require.NoError(t, err, "height %d", height)
wrongSigsCommit = types.NewCommit(goodVote.Height, goodVote.Round,
blockID, []types.CommitSig{goodVote.CommitSig(), badVote.CommitSig()})
}
}
@@ -189,7 +196,7 @@ func TestValidateBlockEvidence(t *testing.T) {
mock.Mempool{},
sm.MockEvidencePool{},
)
lastCommit := types.NewCommit(types.BlockID{}, nil)
lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
for height := int64(1); height < validationTestsStopHeight; height++ {
proposerAddr := state.Validators.GetProposer().Address