types: Remove NewExtendedCommit constructor

Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
Thane Thomson
2022-05-04 17:18:41 -04:00
parent a3b3415a3a
commit b5a94bba16
11 changed files with 46 additions and 40 deletions

View File

@@ -43,9 +43,9 @@ 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}}
var blockID types.BlockID
var extCommitSigs []types.ExtendedCommitSig
extCommit := types.NewExtendedCommit(input.request.Height, 0, blockID, extCommitSigs)
extCommit := &types.ExtendedCommit{
Height: input.request.Height,
}
_ = 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

View File

@@ -150,7 +150,7 @@ func (rts *reactorTestSuite) addNode(
var lastExtCommit *types.ExtendedCommit
// The commit we are building for the current height.
seenExtCommit := types.NewExtendedCommit(0, 0, types.BlockID{}, nil)
seenExtCommit := &types.ExtendedCommit{}
for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ {
lastExtCommit = seenExtCommit.Copy()
@@ -173,12 +173,12 @@ func (rts *reactorTestSuite) addNode(
time.Now(),
)
require.NoError(t, err)
seenExtCommit = types.NewExtendedCommit(
vote.Height,
vote.Round,
blockID,
[]types.ExtendedCommitSig{vote.ExtendedCommitSig()},
)
seenExtCommit = &types.ExtendedCommit{
Height: vote.Height,
Round: vote.Round,
BlockID: blockID,
ExtendedSignatures: []types.ExtendedCommitSig{vote.ExtendedCommitSig()},
}
state, err = blockExec.ApplyBlock(ctx, state, blockID, thisBlock)
require.NoError(t, err)

View File

@@ -183,7 +183,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
case lazyNodeState.Height == lazyNodeState.state.InitialHeight:
// We're creating a proposal for the first block.
// The commit is empty, but not nil.
commit = types.NewExtendedCommit(0, 0, types.BlockID{}, nil)
commit = &types.ExtendedCommit{}
case lazyNodeState.LastCommit.HasTwoThirdsMajority():
// Make the commit from LastCommit
commit = lazyNodeState.LastCommit.MakeExtendedCommit()

View File

@@ -1097,8 +1097,12 @@ func makeBlockchainFromWAL(t *testing.T, wal WAL) ([]*types.Block, []*types.Exte
require.NoError(t, err)
case *types.Vote:
if p.Type == tmproto.PrecommitType {
thisBlockExtCommit = types.NewExtendedCommit(p.Height, p.Round,
p.BlockID, []types.ExtendedCommitSig{p.ExtendedCommitSig()})
thisBlockExtCommit = &types.ExtendedCommit{
Height: p.Height,
Round: p.Round,
BlockID: p.BlockID,
ExtendedSignatures: []types.ExtendedCommitSig{p.ExtendedCommitSig()},
}
}
}
}

View File

@@ -1402,7 +1402,7 @@ func (cs *State) createProposalBlock(ctx context.Context) (*types.Block, error)
case cs.Height == cs.state.InitialHeight:
// We're creating a proposal for the first block.
// The commit is empty, but not nil.
extCommit = types.NewExtendedCommit(0, 0, types.BlockID{}, nil)
extCommit = &types.ExtendedCommit{}
case cs.LastCommit.HasTwoThirdsMajority():
// Make the commit from LastCommit

View File

@@ -587,12 +587,16 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) (*store.Blo
}
func makeExtCommit(height int64, valAddr []byte) *types.ExtendedCommit {
return types.NewExtendedCommit(height, 0, types.BlockID{}, []types.ExtendedCommitSig{{
BlockIDFlag: types.BlockIDFlagCommit,
ValidatorAddress: valAddr,
Timestamp: defaultEvidenceTime,
Signature: []byte("Signature"),
}})
return &types.ExtendedCommit{
Height: height,
BlockID: types.BlockID{},
ExtendedSignatures: []types.ExtendedCommitSig{{
BlockIDFlag: types.BlockIDFlagCommit,
ValidatorAddress: valAddr,
Timestamp: defaultEvidenceTime,
Signature: []byte("Signature"),
}},
}
}
func defaultTestPool(ctx context.Context, t *testing.T, height int64) (*evidence.Pool, types.MockPV, *eventbus.EventBus) {

View File

@@ -94,7 +94,11 @@ func makeValidCommit(
votes[i] = vote
}
return types.NewExtendedCommit(height, 0, blockID, sigs), votes
return &types.ExtendedCommit{
Height: height,
BlockID: blockID,
ExtendedSignatures: sigs,
}, votes
}
func makeState(t *testing.T, nVals, height int) (sm.State, dbm.DB, map[string]types.PrivValidator) {

View File

@@ -35,15 +35,14 @@ func makeTestExtCommit(height int64, timestamp time.Time) *types.ExtendedCommit
Timestamp: timestamp,
Signature: []byte("Signature"),
}}
return types.NewExtendedCommit(
height,
0,
types.BlockID{
return &types.ExtendedCommit{
Height: height,
BlockID: types.BlockID{
Hash: crypto.CRandBytes(32),
PartSetHeader: types.PartSetHeader{Hash: crypto.CRandBytes(32), Total: 2},
},
extCommitSigs,
)
ExtendedSignatures: extCommitSigs,
}
}
func makeStateAndBlockStore(dir string) (sm.State, *BlockStore, cleanupFunc, error) {

View File

@@ -339,7 +339,7 @@ func TestCreateProposalBlock(t *testing.T) {
sm.NopMetrics(),
)
extCommit := types.NewExtendedCommit(height-1, 0, types.BlockID{}, nil)
extCommit := &types.ExtendedCommit{Height: height - 1}
block, err := blockExec.CreateProposalBlock(
ctx,
height,
@@ -419,7 +419,7 @@ func TestMaxTxsProposalBlockSize(t *testing.T) {
sm.NopMetrics(),
)
extCommit := types.NewExtendedCommit(height-1, 0, types.BlockID{}, nil)
extCommit := &types.ExtendedCommit{Height: height - 1}
block, err := blockExec.CreateProposalBlock(
ctx,
height,

View File

@@ -1083,16 +1083,6 @@ type ExtendedCommit struct {
bitArray *bits.BitArray
}
// NewExtendedCommit constructs an ExtendedCommit from the given parameters.
func NewExtendedCommit(height int64, round int32, blockID BlockID, extCommitSigs []ExtendedCommitSig) *ExtendedCommit {
return &ExtendedCommit{
Height: height,
Round: round,
BlockID: blockID,
ExtendedSignatures: extCommitSigs,
}
}
// Copy creates a copy of this extended commit.
func (extCommit *ExtendedCommit) Copy() *ExtendedCommit {
ec := *extCommit

View File

@@ -635,7 +635,12 @@ func (voteSet *VoteSet) MakeExtendedCommit() *ExtendedCommit {
extCommitSigs[i] = extCommitSig
}
return NewExtendedCommit(voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, extCommitSigs)
return &ExtendedCommit{
Height: voteSet.GetHeight(),
Round: voteSet.GetRound(),
BlockID: *voteSet.maj23,
ExtendedSignatures: extCommitSigs,
}
}
//--------------------------------------------------------------------------------