types: Remove NewCommit constructor

Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
Thane Thomson
2022-05-04 17:33:31 -04:00
parent b5a94bba16
commit 59434d8513
7 changed files with 59 additions and 37 deletions

View File

@@ -199,12 +199,15 @@ func TestFinalizeBlockByzantineValidators(t *testing.T) {
ConflictingBlock: &types.LightBlock{
SignedHeader: &types.SignedHeader{
Header: header,
Commit: types.NewCommit(10, 0, makeBlockID(header.Hash(), 100, []byte("partshash")), []types.CommitSig{{
BlockIDFlag: types.BlockIDFlagNil,
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
Timestamp: defaultEvidenceTime,
Signature: crypto.CRandBytes(types.MaxSignatureSize),
}}),
Commit: &types.Commit{
Height: 10,
BlockID: makeBlockID(header.Hash(), 100, []byte("partshash")),
Signatures: []types.CommitSig{{
BlockIDFlag: types.BlockIDFlagNil,
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
Timestamp: defaultEvidenceTime,
Signature: crypto.CRandBytes(types.MaxSignatureSize)}},
},
},
ValidatorSet: state.Validators,
},
@@ -325,7 +328,10 @@ func TestProcessProposal(t *testing.T) {
lastCommitSig = append(lastCommitSig, vote.CommitSig())
}
lastCommit := types.NewCommit(height-1, 0, types.BlockID{}, lastCommitSig)
lastCommit := &types.Commit{
Height: height - 1,
Signatures: lastCommitSig,
}
block1 := sf.MakeBlock(state, height, lastCommit)
block1.Txs = txs

View File

@@ -63,7 +63,7 @@ func makeBlockAndPartSet(
) (*types.Block, *types.PartSet) {
t.Helper()
lastCommit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
lastCommit := &types.Commit{Height: height - 1}
if height > 1 {
vote, err := factory.MakeVote(
ctx,
@@ -73,8 +73,12 @@ func makeBlockAndPartSet(
lastBlockMeta.BlockID,
time.Now())
require.NoError(t, err)
lastCommit = types.NewCommit(vote.Height, vote.Round,
lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()})
lastCommit = &types.Commit{
Height: vote.Height,
Round: vote.Round,
BlockID: lastBlock.LastBlockID,
Signatures: []types.CommitSig{vote.CommitSig()},
}
}
block := state.MakeBlock(height, []types.Tx{}, lastCommit, nil, state.Validators.GetProposer().Address)

View File

@@ -65,7 +65,7 @@ func TestValidateBlockHeader(t *testing.T) {
eventBus,
sm.NopMetrics(),
)
lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
lastCommit := &types.Commit{}
var lastExtCommit *types.ExtendedCommit
// some bad values
@@ -101,7 +101,7 @@ func TestValidateBlockHeader(t *testing.T) {
{"Proposer invalid", func(block *types.Block) { block.ProposerAddress = []byte("wrong size") }},
{"first LastCommit contains signatures", func(block *types.Block) {
block.LastCommit = types.NewCommit(0, 0, types.BlockID{}, []types.CommitSig{types.NewCommitSigAbsent()})
block.LastCommit = &types.Commit{Signatures: []types.CommitSig{types.NewCommitSigAbsent()}}
block.LastCommitHash = block.LastCommit.Hash()
}},
}
@@ -171,9 +171,9 @@ func TestValidateBlockCommit(t *testing.T) {
eventBus,
sm.NopMetrics(),
)
lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
lastCommit := &types.Commit{}
var lastExtCommit *types.ExtendedCommit
wrongSigsCommit := types.NewCommit(1, 0, types.BlockID{}, nil)
wrongSigsCommit := &types.Commit{Height: 1}
badPrivVal := types.NewMockPV()
for height := int64(1); height < validationTestsStopHeight; height++ {
@@ -195,12 +195,12 @@ func TestValidateBlockCommit(t *testing.T) {
time.Now(),
)
require.NoError(t, err)
wrongHeightCommit := types.NewCommit(
wrongHeightVote.Height,
wrongHeightVote.Round,
state.LastBlockID,
[]types.CommitSig{wrongHeightVote.CommitSig()},
)
wrongHeightCommit := &types.Commit{
Height: wrongHeightVote.Height,
Round: wrongHeightVote.Round,
BlockID: state.LastBlockID,
Signatures: []types.CommitSig{wrongHeightVote.CommitSig()},
}
block := statefactory.MakeBlock(state, height, wrongHeightCommit)
err = blockExec.ValidateBlock(ctx, state, block)
_, isErrInvalidCommitHeight := err.(types.ErrInvalidCommitHeight)
@@ -274,8 +274,12 @@ func TestValidateBlockCommit(t *testing.T) {
goodVote.Signature, badVote.Signature = g.Signature, b.Signature
wrongSigsCommit = types.NewCommit(goodVote.Height, goodVote.Round,
blockID, []types.CommitSig{goodVote.CommitSig(), badVote.CommitSig()})
wrongSigsCommit = &types.Commit{
Height: goodVote.Height,
Round: goodVote.Round,
BlockID: blockID,
Signatures: []types.CommitSig{goodVote.CommitSig(), badVote.CommitSig()},
}
}
}
@@ -323,7 +327,7 @@ func TestValidateBlockEvidence(t *testing.T) {
eventBus,
sm.NopMetrics(),
)
lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil)
lastCommit := &types.Commit{}
var lastExtCommit *types.ExtendedCommit
for height := int64(1); height < validationTestsStopHeight; height++ {

View File

@@ -72,7 +72,12 @@ func (pkz privKeys) signHeader(t testing.TB, header *types.Header, valSet *types
commitSigs[vote.ValidatorIndex] = vote.CommitSig()
}
return types.NewCommit(header.Height, 1, blockID, commitSigs)
return &types.Commit{
Height: header.Height,
Round: 1,
BlockID: blockID,
Signatures: commitSigs,
}
}
func makeVote(t testing.TB, header *types.Header, valset *types.ValidatorSet, key crypto.PrivKey, blockID types.BlockID) *types.Vote {

View File

@@ -896,16 +896,6 @@ type Commit struct {
hash tmbytes.HexBytes
}
// NewCommit returns a new Commit.
func NewCommit(height int64, round int32, blockID BlockID, commitSigs []CommitSig) *Commit {
return &Commit{
Height: height,
Round: round,
BlockID: blockID,
Signatures: commitSigs,
}
}
// GetVote converts the CommitSig for the given valIdx to a Vote. Commits do
// not contain vote extensions, so the vote extension and vote extension
// signature will not be present in the returned vote.
@@ -1122,7 +1112,12 @@ func (extCommit *ExtendedCommit) StripExtensions() *Commit {
Signature: extCommitSig.Signature,
}
}
return NewCommit(extCommit.Height, extCommit.Round, extCommit.BlockID, commitSigs)
return &Commit{
Height: extCommit.Height,
Round: extCommit.Round,
BlockID: extCommit.BlockID,
Signatures: commitSigs,
}
}
// GetExtendedVote converts the ExtendedCommitSig for the given valIdx to a

View File

@@ -104,7 +104,10 @@ func TestBlockValidateBasic(t *testing.T) {
blk.LastCommit = nil
}, true},
{"Invalid LastCommit", func(blk *Block) {
blk.LastCommit = NewCommit(-1, 0, *voteSet.maj23, nil)
blk.LastCommit = &Commit{
Height: -1,
BlockID: *voteSet.maj23,
}
}, true},
{"Invalid Evidence", func(blk *Block) {
emptyEv := &DuplicateVoteEvidence{}

View File

@@ -99,7 +99,12 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) {
vi++
}
commit := NewCommit(tc.height, round, tc.blockID, sigs)
commit := &Commit{
Height: tc.height,
Round: round,
BlockID: tc.blockID,
Signatures: sigs,
}
err := valSet.VerifyCommit(chainID, blockID, height, commit)
if tc.expErr {