mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 14:34:17 +00:00
types: rename partsheader to partsetheader (#5029)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
dc87c09d93
commit
51da4fe356
+14
-14
@@ -1242,19 +1242,19 @@ func (data *EvidenceData) FromProto(eviData *tmproto.EvidenceData) error {
|
||||
|
||||
// BlockID
|
||||
type BlockID struct {
|
||||
Hash tmbytes.HexBytes `json:"hash"`
|
||||
PartsHeader PartSetHeader `json:"parts"`
|
||||
Hash tmbytes.HexBytes `json:"hash"`
|
||||
PartSetHeader PartSetHeader `json:"parts"`
|
||||
}
|
||||
|
||||
// Equals returns true if the BlockID matches the given BlockID
|
||||
func (blockID BlockID) Equals(other BlockID) bool {
|
||||
return bytes.Equal(blockID.Hash, other.Hash) &&
|
||||
blockID.PartsHeader.Equals(other.PartsHeader)
|
||||
blockID.PartSetHeader.Equals(other.PartSetHeader)
|
||||
}
|
||||
|
||||
// Key returns a machine-readable string representation of the BlockID
|
||||
func (blockID BlockID) Key() string {
|
||||
pbph := blockID.PartsHeader.ToProto()
|
||||
pbph := blockID.PartSetHeader.ToProto()
|
||||
bz, err := pbph.Marshal()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -1269,8 +1269,8 @@ func (blockID BlockID) ValidateBasic() error {
|
||||
if err := ValidateHash(blockID.Hash); err != nil {
|
||||
return fmt.Errorf("wrong Hash")
|
||||
}
|
||||
if err := blockID.PartsHeader.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("wrong PartsHeader: %v", err)
|
||||
if err := blockID.PartSetHeader.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("wrong PartSetHeader: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1278,19 +1278,19 @@ func (blockID BlockID) ValidateBasic() error {
|
||||
// IsZero returns true if this is the BlockID of a nil block.
|
||||
func (blockID BlockID) IsZero() bool {
|
||||
return len(blockID.Hash) == 0 &&
|
||||
blockID.PartsHeader.IsZero()
|
||||
blockID.PartSetHeader.IsZero()
|
||||
}
|
||||
|
||||
// IsComplete returns true if this is a valid BlockID of a non-nil block.
|
||||
func (blockID BlockID) IsComplete() bool {
|
||||
return len(blockID.Hash) == tmhash.Size &&
|
||||
blockID.PartsHeader.Total > 0 &&
|
||||
len(blockID.PartsHeader.Hash) == tmhash.Size
|
||||
blockID.PartSetHeader.Total > 0 &&
|
||||
len(blockID.PartSetHeader.Hash) == tmhash.Size
|
||||
}
|
||||
|
||||
// String returns a human readable string representation of the BlockID
|
||||
func (blockID BlockID) String() string {
|
||||
return fmt.Sprintf(`%v:%v`, blockID.Hash, blockID.PartsHeader)
|
||||
return fmt.Sprintf(`%v:%v`, blockID.Hash, blockID.PartSetHeader)
|
||||
}
|
||||
|
||||
// ToProto converts BlockID to protobuf
|
||||
@@ -1300,8 +1300,8 @@ func (blockID *BlockID) ToProto() tmproto.BlockID {
|
||||
}
|
||||
|
||||
return tmproto.BlockID{
|
||||
Hash: blockID.Hash,
|
||||
PartsHeader: blockID.PartsHeader.ToProto(),
|
||||
Hash: blockID.Hash,
|
||||
PartSetHeader: blockID.PartSetHeader.ToProto(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1313,12 +1313,12 @@ func BlockIDFromProto(bID *tmproto.BlockID) (*BlockID, error) {
|
||||
}
|
||||
|
||||
blockID := new(BlockID)
|
||||
ph, err := PartSetHeaderFromProto(&bID.PartsHeader)
|
||||
ph, err := PartSetHeaderFromProto(&bID.PartSetHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blockID.PartsHeader = *ph
|
||||
blockID.PartSetHeader = *ph
|
||||
blockID.Hash = bID.Hash
|
||||
|
||||
return blockID, blockID.ValidateBasic()
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestBlockMeta_ToProto(t *testing.T) {
|
||||
h := makeRandHeader()
|
||||
bi := BlockID{Hash: h.Hash(), PartsHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
|
||||
bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
|
||||
|
||||
bm := &BlockMeta{
|
||||
BlockID: bi,
|
||||
@@ -47,11 +47,11 @@ func TestBlockMeta_ToProto(t *testing.T) {
|
||||
|
||||
func TestBlockMeta_ValidateBasic(t *testing.T) {
|
||||
h := makeRandHeader()
|
||||
bi := BlockID{Hash: h.Hash(), PartsHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
|
||||
bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
|
||||
bi2 := BlockID{Hash: tmrand.Bytes(tmhash.Size),
|
||||
PartsHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
|
||||
PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
|
||||
bi3 := BlockID{Hash: []byte("incorrect hash"),
|
||||
PartsHeader: PartSetHeader{Total: 123, Hash: []byte("incorrect hash")}}
|
||||
PartSetHeader: PartSetHeader{Total: 123, Hash: []byte("incorrect hash")}}
|
||||
|
||||
bm := &BlockMeta{
|
||||
BlockID: bi,
|
||||
|
||||
+12
-12
@@ -187,7 +187,7 @@ func makeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) BlockID {
|
||||
copy(psH, partSetHash)
|
||||
return BlockID{
|
||||
Hash: h,
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: partSetSize,
|
||||
Hash: psH,
|
||||
},
|
||||
@@ -588,7 +588,7 @@ func TestSignedHeaderValidateBasic(t *testing.T) {
|
||||
func TestBlockIDValidateBasic(t *testing.T) {
|
||||
validBlockID := BlockID{
|
||||
Hash: bytes.HexBytes{},
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: 1,
|
||||
Hash: bytes.HexBytes{},
|
||||
},
|
||||
@@ -596,29 +596,29 @@ func TestBlockIDValidateBasic(t *testing.T) {
|
||||
|
||||
invalidBlockID := BlockID{
|
||||
Hash: []byte{0},
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: 1,
|
||||
Hash: []byte{0},
|
||||
},
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
testName string
|
||||
blockIDHash bytes.HexBytes
|
||||
blockIDPartsHeader PartSetHeader
|
||||
expectErr bool
|
||||
testName string
|
||||
blockIDHash bytes.HexBytes
|
||||
blockIDPartSetHeader PartSetHeader
|
||||
expectErr bool
|
||||
}{
|
||||
{"Valid BlockID", validBlockID.Hash, validBlockID.PartsHeader, false},
|
||||
{"Invalid BlockID", invalidBlockID.Hash, validBlockID.PartsHeader, true},
|
||||
{"Invalid BlockID", validBlockID.Hash, invalidBlockID.PartsHeader, true},
|
||||
{"Valid BlockID", validBlockID.Hash, validBlockID.PartSetHeader, false},
|
||||
{"Invalid BlockID", invalidBlockID.Hash, validBlockID.PartSetHeader, true},
|
||||
{"Invalid BlockID", validBlockID.Hash, invalidBlockID.PartSetHeader, true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
blockID := BlockID{
|
||||
Hash: tc.blockIDHash,
|
||||
PartsHeader: tc.blockIDPartsHeader,
|
||||
Hash: tc.blockIDHash,
|
||||
PartSetHeader: tc.blockIDPartSetHeader,
|
||||
}
|
||||
assert.Equal(t, tc.expectErr, blockID.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ func CanonicalizeBlockID(bid tmproto.BlockID) *tmproto.CanonicalBlockID {
|
||||
cbid = nil
|
||||
} else {
|
||||
cbid = &tmproto.CanonicalBlockID{
|
||||
Hash: bid.Hash,
|
||||
PartsHeader: CanonicalizePartSetHeader(bid.PartsHeader),
|
||||
Hash: bid.Hash,
|
||||
PartSetHeader: CanonicalizePartSetHeader(bid.PartSetHeader),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ import (
|
||||
func TestCanonicalizeBlockID(t *testing.T) {
|
||||
randhash := tmrand.Bytes(tmhash.Size)
|
||||
block1 := tmproto.BlockID{Hash: randhash,
|
||||
PartsHeader: tmproto.PartSetHeader{Total: 5, Hash: randhash}}
|
||||
PartSetHeader: tmproto.PartSetHeader{Total: 5, Hash: randhash}}
|
||||
block2 := tmproto.BlockID{Hash: randhash,
|
||||
PartsHeader: tmproto.PartSetHeader{Total: 10, Hash: randhash}}
|
||||
PartSetHeader: tmproto.PartSetHeader{Total: 10, Hash: randhash}}
|
||||
cblock1 := tmproto.CanonicalBlockID{Hash: randhash,
|
||||
PartsHeader: tmproto.CanonicalPartSetHeader{Total: 5, Hash: randhash}}
|
||||
PartSetHeader: tmproto.CanonicalPartSetHeader{Total: 5, Hash: randhash}}
|
||||
cblock2 := tmproto.CanonicalBlockID{Hash: randhash,
|
||||
PartsHeader: tmproto.CanonicalPartSetHeader{Total: 10, Hash: randhash}}
|
||||
PartSetHeader: tmproto.CanonicalPartSetHeader{Total: 10, Hash: randhash}}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -294,7 +294,7 @@ func TestConflictingHeadersEvidence(t *testing.T) {
|
||||
|
||||
commit1, err := MakeCommit(BlockID{
|
||||
Hash: header1.Hash(),
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: 100,
|
||||
Hash: crypto.CRandBytes(tmhash.Size),
|
||||
},
|
||||
@@ -302,7 +302,7 @@ func TestConflictingHeadersEvidence(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
commit2, err := MakeCommit(BlockID{
|
||||
Hash: header2.Hash(),
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: 100,
|
||||
Hash: crypto.CRandBytes(tmhash.Size),
|
||||
},
|
||||
@@ -607,7 +607,7 @@ func TestEvidenceProto(t *testing.T) {
|
||||
|
||||
commit1, err := MakeCommit(BlockID{
|
||||
Hash: header1.Hash(),
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: 100,
|
||||
Hash: crypto.CRandBytes(tmhash.Size),
|
||||
},
|
||||
@@ -615,7 +615,7 @@ func TestEvidenceProto(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
commit2, err := MakeCommit(BlockID{
|
||||
Hash: header2.Hash(),
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: 100,
|
||||
Hash: crypto.CRandBytes(tmhash.Size),
|
||||
},
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
|
||||
|
||||
// ValidateBasic performs basic validation.
|
||||
func (psh PartSetHeader) ValidateBasic() error {
|
||||
// Hash can be empty in case of POLBlockID.PartsHeader in Proposal.
|
||||
// Hash can be empty in case of POLBlockID.PartSetHeader in Proposal.
|
||||
if err := ValidateHash(psh.Hash); err != nil {
|
||||
return fmt.Errorf("wrong Hash: %w", err)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func init() {
|
||||
Height: 12345,
|
||||
Round: 23456,
|
||||
BlockID: BlockID{Hash: []byte("--June_15_2020_amino_was_removed"),
|
||||
PartsHeader: PartSetHeader{Total: 111, Hash: []byte("--June_15_2020_amino_was_removed")}},
|
||||
PartSetHeader: PartSetHeader{Total: 111, Hash: []byte("--June_15_2020_amino_was_removed")}},
|
||||
POLRound: -1,
|
||||
Timestamp: stamp,
|
||||
}
|
||||
|
||||
+7
-7
@@ -71,16 +71,16 @@ func (tm2pb) Validator(val *Validator) abci.Validator {
|
||||
}
|
||||
}
|
||||
|
||||
func (tm2pb) BlockID(blockID BlockID) abci.BlockID {
|
||||
return abci.BlockID{
|
||||
Hash: blockID.Hash,
|
||||
PartsHeader: TM2PB.PartSetHeader(blockID.PartsHeader),
|
||||
func (tm2pb) BlockID(blockID BlockID) tmproto.BlockID {
|
||||
return tmproto.BlockID{
|
||||
Hash: blockID.Hash,
|
||||
PartSetHeader: TM2PB.PartSetHeader(blockID.PartSetHeader),
|
||||
}
|
||||
}
|
||||
|
||||
func (tm2pb) PartSetHeader(header PartSetHeader) abci.PartSetHeader {
|
||||
return abci.PartSetHeader{
|
||||
Total: int32(header.Total),
|
||||
func (tm2pb) PartSetHeader(header PartSetHeader) tmproto.PartSetHeader {
|
||||
return tmproto.PartSetHeader{
|
||||
Total: header.Total,
|
||||
Hash: header.Hash,
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -176,7 +176,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
|
||||
|
||||
blockHash := crypto.CRandBytes(32)
|
||||
blockPartsTotal := uint32(123)
|
||||
blockPartsHeader := PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
|
||||
blockPartSetHeader := PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
|
||||
|
||||
voteProto := &Vote{
|
||||
ValidatorAddress: nil, // NOTE: must fill in
|
||||
@@ -185,7 +185,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
|
||||
Round: round,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: tmproto.PrevoteType,
|
||||
BlockID: BlockID{blockHash, blockPartsHeader},
|
||||
BlockID: BlockID{blockHash, blockPartSetHeader},
|
||||
}
|
||||
|
||||
// 66 out of 100 voted for nil.
|
||||
@@ -221,7 +221,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
|
||||
addr := pubKey.Address()
|
||||
vote := withValidator(voteProto, addr, 67)
|
||||
blockPartsHeader := PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
|
||||
_, err = signAddVote(privValidators[67], withBlockPartsHeader(vote, blockPartsHeader), voteSet)
|
||||
_, err = signAddVote(privValidators[67], withBlockPartSetHeader(vote, blockPartsHeader), voteSet)
|
||||
require.NoError(t, err)
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
assert.False(t, ok || !blockID.IsZero(),
|
||||
@@ -234,8 +234,8 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
addr := pubKey.Address()
|
||||
vote := withValidator(voteProto, addr, 68)
|
||||
blockPartsHeader := PartSetHeader{blockPartsTotal + 1, blockPartsHeader.Hash}
|
||||
_, err = signAddVote(privValidators[68], withBlockPartsHeader(vote, blockPartsHeader), voteSet)
|
||||
blockPartsHeader := PartSetHeader{blockPartsTotal + 1, blockPartSetHeader.Hash}
|
||||
_, err = signAddVote(privValidators[68], withBlockPartSetHeader(vote, blockPartsHeader), voteSet)
|
||||
require.NoError(t, err)
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
assert.False(t, ok || !blockID.IsZero(),
|
||||
@@ -255,7 +255,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
|
||||
"there should be no 2/3 majority: last vote added had different BlockHash")
|
||||
}
|
||||
|
||||
// 71st validator voted for the right BlockHash & BlockPartsHeader
|
||||
// 71st validator voted for the right BlockHash & BlockPartSetHeader
|
||||
{
|
||||
pubKey, err := privValidators[70].GetPubKey()
|
||||
require.NoError(t, err)
|
||||
@@ -264,7 +264,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) {
|
||||
_, err = signAddVote(privValidators[70], vote, voteSet)
|
||||
require.NoError(t, err)
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
assert.True(t, ok && blockID.Equals(BlockID{blockHash, blockPartsHeader}),
|
||||
assert.True(t, ok && blockID.Equals(BlockID{blockHash, blockPartSetHeader}),
|
||||
"there should be 2/3 majority")
|
||||
}
|
||||
}
|
||||
@@ -398,7 +398,7 @@ func TestVoteSet_Conflicts(t *testing.T) {
|
||||
func TestVoteSet_MakeCommit(t *testing.T) {
|
||||
height, round := int64(1), int32(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrecommitType, 10, 1)
|
||||
blockHash, blockPartsHeader := crypto.CRandBytes(32), PartSetHeader{123, crypto.CRandBytes(32)}
|
||||
blockHash, blockPartSetHeader := crypto.CRandBytes(32), PartSetHeader{123, crypto.CRandBytes(32)}
|
||||
|
||||
voteProto := &Vote{
|
||||
ValidatorAddress: nil,
|
||||
@@ -407,7 +407,7 @@ func TestVoteSet_MakeCommit(t *testing.T) {
|
||||
Round: round,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: BlockID{blockHash, blockPartsHeader},
|
||||
BlockID: BlockID{blockHash, blockPartSetHeader},
|
||||
}
|
||||
|
||||
// 6 out of 10 voted for some block.
|
||||
@@ -432,7 +432,7 @@ func TestVoteSet_MakeCommit(t *testing.T) {
|
||||
addr := pv.Address()
|
||||
vote := withValidator(voteProto, addr, 6)
|
||||
vote = withBlockHash(vote, tmrand.Bytes(32))
|
||||
vote = withBlockPartsHeader(vote, PartSetHeader{123, tmrand.Bytes(32)})
|
||||
vote = withBlockPartSetHeader(vote, PartSetHeader{123, tmrand.Bytes(32)})
|
||||
|
||||
_, err = signAddVote(privValidators[6], vote, voteSet)
|
||||
require.NoError(t, err)
|
||||
@@ -560,8 +560,8 @@ func withBlockHash(vote *Vote, blockHash []byte) *Vote {
|
||||
}
|
||||
|
||||
// Convenience: Return new vote with different blockParts
|
||||
func withBlockPartsHeader(vote *Vote, blockPartsHeader PartSetHeader) *Vote {
|
||||
func withBlockPartSetHeader(vote *Vote, blockPartsHeader PartSetHeader) *Vote {
|
||||
vote = vote.Copy()
|
||||
vote.BlockID.PartsHeader = blockPartsHeader
|
||||
vote.BlockID.PartSetHeader = blockPartsHeader
|
||||
return vote
|
||||
}
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ func exampleVote(t byte) *Vote {
|
||||
Timestamp: stamp,
|
||||
BlockID: BlockID{
|
||||
Hash: tmhash.Sum([]byte("blockID_hash")),
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: 1000000,
|
||||
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
|
||||
},
|
||||
@@ -232,7 +232,7 @@ func TestMaxVoteBytes(t *testing.T) {
|
||||
Type: tmproto.PrevoteType,
|
||||
BlockID: BlockID{
|
||||
Hash: tmhash.Sum([]byte("blockID_hash")),
|
||||
PartsHeader: PartSetHeader{
|
||||
PartSetHeader: PartSetHeader{
|
||||
Total: math.MaxInt32,
|
||||
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user