Merge branch 'master' into thane/8272-propagate-vote-extensions

This commit is contained in:
Thane Thomson
2022-04-29 08:08:14 -04:00
committed by GitHub
46 changed files with 371 additions and 342 deletions
+2 -3
View File
@@ -13,7 +13,6 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/bits"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmmath "github.com/tendermint/tendermint/libs/math"
@@ -1502,9 +1501,9 @@ func (blockID BlockID) IsNil() bool {
// 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 &&
return len(blockID.Hash) == crypto.HashSize &&
blockID.PartSetHeader.Total > 0 &&
len(blockID.PartSetHeader.Hash) == tmhash.Size
len(blockID.PartSetHeader.Hash) == crypto.HashSize
}
// String returns a human readable string representation of the BlockID.
+5 -5
View File
@@ -5,13 +5,13 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/crypto"
tmrand "github.com/tendermint/tendermint/libs/rand"
)
func TestBlockMeta_ToProto(t *testing.T) {
h := MakeRandHeader()
bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(crypto.HashSize)}}
bm := &BlockMeta{
BlockID: bi,
@@ -48,9 +48,9 @@ func TestBlockMeta_ToProto(t *testing.T) {
func TestBlockMeta_ValidateBasic(t *testing.T) {
h := MakeRandHeader()
bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bi2 := BlockID{Hash: tmrand.Bytes(tmhash.Size),
PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}}
bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(crypto.HashSize)}}
bi2 := BlockID{Hash: tmrand.Bytes(crypto.HashSize),
PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(crypto.HashSize)}}
bi3 := BlockID{Hash: []byte("incorrect hash"),
PartSetHeader: PartSetHeader{Total: 123, Hash: []byte("incorrect hash")}}
+98 -99
View File
@@ -19,7 +19,6 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/bits"
"github.com/tendermint/tendermint/libs/bytes"
tmrand "github.com/tendermint/tendermint/libs/rand"
@@ -213,8 +212,8 @@ func TestBlockString(t *testing.T) {
func makeBlockIDRandom() BlockID {
var (
blockHash = make([]byte, tmhash.Size)
partSetHash = make([]byte, tmhash.Size)
blockHash = make([]byte, crypto.HashSize)
partSetHash = make([]byte, crypto.HashSize)
)
rand.Read(blockHash) //nolint: errcheck // ignore errcheck for read
rand.Read(partSetHash) //nolint: errcheck // ignore errcheck for read
@@ -223,8 +222,8 @@ func makeBlockIDRandom() BlockID {
func makeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) BlockID {
var (
h = make([]byte, tmhash.Size)
psH = make([]byte, tmhash.Size)
h = make([]byte, crypto.HashSize)
psH = make([]byte, crypto.HashSize)
)
copy(h, hash)
copy(psH, partSetHash)
@@ -324,10 +323,10 @@ func TestMaxCommitBytes(t *testing.T) {
Height: math.MaxInt64,
Round: math.MaxInt32,
BlockID: BlockID{
Hash: tmhash.Sum([]byte("blockID_hash")),
Hash: crypto.Checksum([]byte("blockID_hash")),
PartSetHeader: PartSetHeader{
Total: math.MaxInt32,
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
Hash: crypto.Checksum([]byte("blockID_part_set_header_hash")),
},
},
Signatures: []CommitSig{cs},
@@ -359,15 +358,15 @@ func TestHeaderHash(t *testing.T) {
ChainID: "chainId",
Height: 3,
Time: time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC),
LastBlockID: makeBlockID(make([]byte, tmhash.Size), 6, make([]byte, tmhash.Size)),
LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
DataHash: tmhash.Sum([]byte("data_hash")),
ValidatorsHash: tmhash.Sum([]byte("validators_hash")),
NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")),
ConsensusHash: tmhash.Sum([]byte("consensus_hash")),
AppHash: tmhash.Sum([]byte("app_hash")),
LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
LastBlockID: makeBlockID(make([]byte, crypto.HashSize), 6, make([]byte, crypto.HashSize)),
LastCommitHash: crypto.Checksum([]byte("last_commit_hash")),
DataHash: crypto.Checksum([]byte("data_hash")),
ValidatorsHash: crypto.Checksum([]byte("validators_hash")),
NextValidatorsHash: crypto.Checksum([]byte("next_validators_hash")),
ConsensusHash: crypto.Checksum([]byte("consensus_hash")),
AppHash: crypto.Checksum([]byte("app_hash")),
LastResultsHash: crypto.Checksum([]byte("last_results_hash")),
EvidenceHash: crypto.Checksum([]byte("evidence_hash")),
ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
}, hexBytesFromString(t, "F740121F553B5418C3EFBD343C2DBFE9E007BB67B0D020A0741374BAB65242A4")},
{"nil header yields nil", nil, nil},
@@ -376,15 +375,15 @@ func TestHeaderHash(t *testing.T) {
ChainID: "chainId",
Height: 3,
Time: time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC),
LastBlockID: makeBlockID(make([]byte, tmhash.Size), 6, make([]byte, tmhash.Size)),
LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
DataHash: tmhash.Sum([]byte("data_hash")),
LastBlockID: makeBlockID(make([]byte, crypto.HashSize), 6, make([]byte, crypto.HashSize)),
LastCommitHash: crypto.Checksum([]byte("last_commit_hash")),
DataHash: crypto.Checksum([]byte("data_hash")),
ValidatorsHash: nil,
NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")),
ConsensusHash: tmhash.Sum([]byte("consensus_hash")),
AppHash: tmhash.Sum([]byte("app_hash")),
LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
NextValidatorsHash: crypto.Checksum([]byte("next_validators_hash")),
ConsensusHash: crypto.Checksum([]byte("consensus_hash")),
AppHash: crypto.Checksum([]byte("app_hash")),
LastResultsHash: crypto.Checksum([]byte("last_results_hash")),
EvidenceHash: crypto.Checksum([]byte("evidence_hash")),
ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
}, nil},
}
@@ -455,15 +454,15 @@ func TestMaxHeaderBytes(t *testing.T) {
ChainID: maxChainID,
Height: math.MaxInt64,
Time: timestamp,
LastBlockID: makeBlockID(make([]byte, tmhash.Size), math.MaxInt32, make([]byte, tmhash.Size)),
LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
DataHash: tmhash.Sum([]byte("data_hash")),
ValidatorsHash: tmhash.Sum([]byte("validators_hash")),
NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")),
ConsensusHash: tmhash.Sum([]byte("consensus_hash")),
AppHash: tmhash.Sum([]byte("app_hash")),
LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
LastBlockID: makeBlockID(make([]byte, crypto.HashSize), math.MaxInt32, make([]byte, crypto.HashSize)),
LastCommitHash: crypto.Checksum([]byte("last_commit_hash")),
DataHash: crypto.Checksum([]byte("data_hash")),
ValidatorsHash: crypto.Checksum([]byte("validators_hash")),
NextValidatorsHash: crypto.Checksum([]byte("next_validators_hash")),
ConsensusHash: crypto.Checksum([]byte("consensus_hash")),
AppHash: crypto.Checksum([]byte("app_hash")),
LastResultsHash: crypto.Checksum([]byte("last_results_hash")),
EvidenceHash: crypto.Checksum([]byte("evidence_hash")),
ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
}
@@ -765,7 +764,7 @@ func MakeRandHeader() Header {
chainID := "test"
t := time.Now()
height := mrand.Int63()
randBytes := tmrand.Bytes(tmhash.Size)
randBytes := tmrand.Bytes(crypto.HashSize)
randAddress := tmrand.Bytes(crypto.AddressSize)
h := Header{
Version: version.Consensus{Block: version.BlockProtocol, App: 1},
@@ -1014,7 +1013,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size+1),
Hash: make([]byte, crypto.HashSize+1),
},
},
true, "wrong Hash",
@@ -1026,9 +1025,9 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size+1),
Hash: make([]byte, crypto.HashSize+1),
},
},
},
@@ -1041,12 +1040,12 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size+1),
LastCommitHash: make([]byte, crypto.HashSize+1),
},
true, "wrong LastCommitHash",
},
@@ -1057,13 +1056,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size),
DataHash: make([]byte, tmhash.Size+1),
LastCommitHash: make([]byte, crypto.HashSize),
DataHash: make([]byte, crypto.HashSize+1),
},
true, "wrong DataHash",
},
@@ -1074,14 +1073,14 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size),
DataHash: make([]byte, tmhash.Size),
EvidenceHash: make([]byte, tmhash.Size+1),
LastCommitHash: make([]byte, crypto.HashSize),
DataHash: make([]byte, crypto.HashSize),
EvidenceHash: make([]byte, crypto.HashSize+1),
},
true, "wrong EvidenceHash",
},
@@ -1092,14 +1091,14 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size),
DataHash: make([]byte, tmhash.Size),
EvidenceHash: make([]byte, tmhash.Size),
LastCommitHash: make([]byte, crypto.HashSize),
DataHash: make([]byte, crypto.HashSize),
EvidenceHash: make([]byte, crypto.HashSize),
ProposerAddress: make([]byte, crypto.AddressSize+1),
},
true, "invalid ProposerAddress length",
@@ -1111,16 +1110,16 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size),
DataHash: make([]byte, tmhash.Size),
EvidenceHash: make([]byte, tmhash.Size),
LastCommitHash: make([]byte, crypto.HashSize),
DataHash: make([]byte, crypto.HashSize),
EvidenceHash: make([]byte, crypto.HashSize),
ProposerAddress: make([]byte, crypto.AddressSize),
ValidatorsHash: make([]byte, tmhash.Size+1),
ValidatorsHash: make([]byte, crypto.HashSize+1),
},
true, "wrong ValidatorsHash",
},
@@ -1131,17 +1130,17 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size),
DataHash: make([]byte, tmhash.Size),
EvidenceHash: make([]byte, tmhash.Size),
LastCommitHash: make([]byte, crypto.HashSize),
DataHash: make([]byte, crypto.HashSize),
EvidenceHash: make([]byte, crypto.HashSize),
ProposerAddress: make([]byte, crypto.AddressSize),
ValidatorsHash: make([]byte, tmhash.Size),
NextValidatorsHash: make([]byte, tmhash.Size+1),
ValidatorsHash: make([]byte, crypto.HashSize),
NextValidatorsHash: make([]byte, crypto.HashSize+1),
},
true, "wrong NextValidatorsHash",
},
@@ -1152,18 +1151,18 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size),
DataHash: make([]byte, tmhash.Size),
EvidenceHash: make([]byte, tmhash.Size),
LastCommitHash: make([]byte, crypto.HashSize),
DataHash: make([]byte, crypto.HashSize),
EvidenceHash: make([]byte, crypto.HashSize),
ProposerAddress: make([]byte, crypto.AddressSize),
ValidatorsHash: make([]byte, tmhash.Size),
NextValidatorsHash: make([]byte, tmhash.Size),
ConsensusHash: make([]byte, tmhash.Size+1),
ValidatorsHash: make([]byte, crypto.HashSize),
NextValidatorsHash: make([]byte, crypto.HashSize),
ConsensusHash: make([]byte, crypto.HashSize+1),
},
true, "wrong ConsensusHash",
},
@@ -1174,19 +1173,19 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size),
DataHash: make([]byte, tmhash.Size),
EvidenceHash: make([]byte, tmhash.Size),
LastCommitHash: make([]byte, crypto.HashSize),
DataHash: make([]byte, crypto.HashSize),
EvidenceHash: make([]byte, crypto.HashSize),
ProposerAddress: make([]byte, crypto.AddressSize),
ValidatorsHash: make([]byte, tmhash.Size),
NextValidatorsHash: make([]byte, tmhash.Size),
ConsensusHash: make([]byte, tmhash.Size),
LastResultsHash: make([]byte, tmhash.Size+1),
ValidatorsHash: make([]byte, crypto.HashSize),
NextValidatorsHash: make([]byte, crypto.HashSize),
ConsensusHash: make([]byte, crypto.HashSize),
LastResultsHash: make([]byte, crypto.HashSize+1),
},
true, "wrong LastResultsHash",
},
@@ -1197,19 +1196,19 @@ func TestHeader_ValidateBasic(t *testing.T) {
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
LastCommitHash: make([]byte, tmhash.Size),
DataHash: make([]byte, tmhash.Size),
EvidenceHash: make([]byte, tmhash.Size),
LastCommitHash: make([]byte, crypto.HashSize),
DataHash: make([]byte, crypto.HashSize),
EvidenceHash: make([]byte, crypto.HashSize),
ProposerAddress: make([]byte, crypto.AddressSize),
ValidatorsHash: make([]byte, tmhash.Size),
NextValidatorsHash: make([]byte, tmhash.Size),
ConsensusHash: make([]byte, tmhash.Size),
LastResultsHash: make([]byte, tmhash.Size),
ValidatorsHash: make([]byte, crypto.HashSize),
NextValidatorsHash: make([]byte, crypto.HashSize),
ConsensusHash: make([]byte, crypto.HashSize),
LastResultsHash: make([]byte, crypto.HashSize),
},
false, "",
},
@@ -1262,9 +1261,9 @@ func TestCommit_ValidateBasic(t *testing.T) {
Height: 1,
Round: 1,
BlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
},
@@ -1276,9 +1275,9 @@ func TestCommit_ValidateBasic(t *testing.T) {
Height: 1,
Round: 1,
BlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
Signatures: []CommitSig{
@@ -1297,9 +1296,9 @@ func TestCommit_ValidateBasic(t *testing.T) {
Height: 1,
Round: 1,
BlockID: BlockID{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
PartSetHeader: PartSetHeader{
Hash: make([]byte, tmhash.Size),
Hash: make([]byte, crypto.HashSize),
},
},
Signatures: []CommitSig{
+2 -2
View File
@@ -4,13 +4,13 @@ import (
"reflect"
"testing"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/crypto"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
func TestCanonicalizeBlockID(t *testing.T) {
randhash := tmrand.Bytes(tmhash.Size)
randhash := tmrand.Bytes(crypto.HashSize)
block1 := tmproto.BlockID{Hash: randhash,
PartSetHeader: tmproto.PartSetHeader{Total: 5, Hash: randhash}}
block2 := tmproto.BlockID{Hash: randhash,
+8 -8
View File
@@ -12,8 +12,8 @@ import (
"time"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/internal/jsontypes"
tmmath "github.com/tendermint/tendermint/libs/math"
tmrand "github.com/tendermint/tendermint/libs/rand"
@@ -113,7 +113,7 @@ func (dve *DuplicateVoteEvidence) Bytes() []byte {
// Hash returns the hash of the evidence.
func (dve *DuplicateVoteEvidence) Hash() []byte {
return tmhash.Sum(dve.Bytes())
return crypto.Checksum(dve.Bytes())
}
// Height returns the height of the infraction
@@ -374,10 +374,10 @@ func (l *LightClientAttackEvidence) ConflictingHeaderIsInvalid(trustedHeader *He
func (l *LightClientAttackEvidence) Hash() []byte {
buf := make([]byte, binary.MaxVarintLen64)
n := binary.PutVarint(buf, l.CommonHeight)
bz := make([]byte, tmhash.Size+n)
copy(bz[:tmhash.Size-1], l.ConflictingBlock.Hash().Bytes())
copy(bz[tmhash.Size:], buf)
return tmhash.Sum(bz)
bz := make([]byte, crypto.HashSize+n)
copy(bz[:crypto.HashSize-1], l.ConflictingBlock.Hash().Bytes())
copy(bz[crypto.HashSize:], buf)
return crypto.Checksum(bz)
}
// Height returns the last height at which the primary provider and witness provider had the same header.
@@ -843,10 +843,10 @@ func makeMockVote(height int64, round, index int32, addr Address,
func randBlockID() BlockID {
return BlockID{
Hash: tmrand.Bytes(tmhash.Size),
Hash: tmrand.Bytes(crypto.HashSize),
PartSetHeader: PartSetHeader{
Total: 1,
Hash: tmrand.Bytes(tmhash.Size),
Hash: tmrand.Bytes(crypto.HashSize),
},
}
}
+18 -19
View File
@@ -13,7 +13,6 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/version"
@@ -93,15 +92,15 @@ func TestDuplicateVoteEvidence(t *testing.T) {
ev, err := NewMockDuplicateVoteEvidence(ctx, height, time.Now(), "mock-chain-id")
require.NoError(t, err)
assert.Equal(t, ev.Hash(), tmhash.Sum(ev.Bytes()))
assert.Equal(t, ev.Hash(), crypto.Checksum(ev.Bytes()))
assert.NotNil(t, ev.String())
assert.Equal(t, ev.Height(), height)
}
func TestDuplicateVoteEvidenceValidation(t *testing.T) {
val := NewMockPV()
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID := makeBlockID(crypto.Checksum([]byte("blockhash")), math.MaxInt32, crypto.Checksum([]byte("partshash")))
blockID2 := makeBlockID(crypto.Checksum([]byte("blockhash2")), math.MaxInt32, crypto.Checksum([]byte("partshash")))
const chainID = "mychain"
ctx, cancel := context.WithCancel(context.Background())
@@ -153,7 +152,7 @@ func TestLightClientAttackEvidenceBasic(t *testing.T) {
header := makeHeaderRandom()
header.Height = height
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID := makeBlockID(crypto.Checksum([]byte("blockhash")), math.MaxInt32, crypto.Checksum([]byte("partshash")))
commit, err := makeCommit(ctx, blockID, height, 1, voteSet, privVals, defaultVoteTime)
require.NoError(t, err)
lcae := &LightClientAttackEvidence{
@@ -217,7 +216,7 @@ func TestLightClientAttackEvidenceValidation(t *testing.T) {
header := makeHeaderRandom()
header.Height = height
header.ValidatorsHash = valSet.Hash()
blockID := makeBlockID(header.Hash(), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID := makeBlockID(header.Hash(), math.MaxInt32, crypto.Checksum([]byte("partshash")))
commit, err := makeCommit(ctx, blockID, height, 1, voteSet, privVals, time.Now())
require.NoError(t, err)
lcae := &LightClientAttackEvidence{
@@ -332,14 +331,14 @@ func makeHeaderRandom() *Header {
Height: int64(mrand.Uint32() + 1),
Time: time.Now(),
LastBlockID: makeBlockIDRandom(),
LastCommitHash: crypto.CRandBytes(tmhash.Size),
DataHash: crypto.CRandBytes(tmhash.Size),
ValidatorsHash: crypto.CRandBytes(tmhash.Size),
NextValidatorsHash: crypto.CRandBytes(tmhash.Size),
ConsensusHash: crypto.CRandBytes(tmhash.Size),
AppHash: crypto.CRandBytes(tmhash.Size),
LastResultsHash: crypto.CRandBytes(tmhash.Size),
EvidenceHash: crypto.CRandBytes(tmhash.Size),
LastCommitHash: crypto.CRandBytes(crypto.HashSize),
DataHash: crypto.CRandBytes(crypto.HashSize),
ValidatorsHash: crypto.CRandBytes(crypto.HashSize),
NextValidatorsHash: crypto.CRandBytes(crypto.HashSize),
ConsensusHash: crypto.CRandBytes(crypto.HashSize),
AppHash: crypto.CRandBytes(crypto.HashSize),
LastResultsHash: crypto.CRandBytes(crypto.HashSize),
EvidenceHash: crypto.CRandBytes(crypto.HashSize),
ProposerAddress: crypto.CRandBytes(crypto.AddressSize),
}
}
@@ -350,8 +349,8 @@ func TestEvidenceProto(t *testing.T) {
// -------- Votes --------
val := NewMockPV()
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID := makeBlockID(crypto.Checksum([]byte("blockhash")), math.MaxInt32, crypto.Checksum([]byte("partshash")))
blockID2 := makeBlockID(crypto.Checksum([]byte("blockhash2")), math.MaxInt32, crypto.Checksum([]byte("partshash")))
const chainID = "mychain"
v := makeVote(ctx, t, val, chainID, math.MaxInt32, math.MaxInt64, 1, 0x01, blockID, defaultVoteTime)
v2 := makeVote(ctx, t, val, chainID, math.MaxInt32, math.MaxInt64, 2, 0x01, blockID2, defaultVoteTime)
@@ -395,8 +394,8 @@ func TestEvidenceVectors(t *testing.T) {
// Votes for duplicateEvidence
val := NewMockPV()
val.PrivKey = ed25519.GenPrivKeyFromSecret([]byte("it's a secret")) // deterministic key
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID := makeBlockID(crypto.Checksum([]byte("blockhash")), math.MaxInt32, crypto.Checksum([]byte("partshash")))
blockID2 := makeBlockID(crypto.Checksum([]byte("blockhash2")), math.MaxInt32, crypto.Checksum([]byte("partshash")))
const chainID = "mychain"
v := makeVote(ctx, t, val, chainID, math.MaxInt32, math.MaxInt64, 1, 0x01, blockID, defaultVoteTime)
v2 := makeVote(ctx, t, val, chainID, math.MaxInt32, math.MaxInt64, 2, 0x01, blockID2, defaultVoteTime)
@@ -424,7 +423,7 @@ func TestEvidenceVectors(t *testing.T) {
EvidenceHash: []byte("f2564c78071e26643ae9b3e2a19fa0dc10d4d9e873aa0be808660123f11a1e78"),
ProposerAddress: []byte("2915b7b15f979e48ebc61774bb1d86ba3136b7eb"),
}
blockID3 := makeBlockID(header.Hash(), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID3 := makeBlockID(header.Hash(), math.MaxInt32, crypto.Checksum([]byte("partshash")))
commit, err := makeCommit(ctx, blockID3, height, 1, voteSet, privVals, defaultVoteTime)
require.NoError(t, err)
lcae := &LightClientAttackEvidence{
+3 -3
View File
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/internal/libs/protoio"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmtime "github.com/tendermint/tendermint/libs/time"
@@ -61,7 +61,7 @@ func TestProposalVerifySignature(t *testing.T) {
prop := NewProposal(
4, 2, 2,
BlockID{tmrand.Bytes(tmhash.Size), PartSetHeader{777, tmrand.Bytes(tmhash.Size)}}, tmtime.Now())
BlockID{tmrand.Bytes(crypto.HashSize), PartSetHeader{777, tmrand.Bytes(crypto.HashSize)}}, tmtime.Now())
p := prop.ToProto()
signBytes := ProposalSignBytes("test_chain_id", p)
@@ -163,7 +163,7 @@ func TestProposalValidateBasic(t *testing.T) {
p.Signature = make([]byte, MaxSignatureSize+1)
}, true},
}
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
blockID := makeBlockID(crypto.Checksum([]byte("blockhash")), math.MaxInt32, crypto.Checksum([]byte("partshash")))
for _, tc := range testCases {
tc := tc
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"sort"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
@@ -23,7 +23,7 @@ type Tx []byte
func (tx Tx) Key() TxKey { return sha256.Sum256(tx) }
// Hash computes the TMHASH hash of the wire encoded transaction.
func (tx Tx) Hash() []byte { return tmhash.Sum(tx) }
func (tx Tx) Hash() []byte { return crypto.Checksum(tx) }
// String returns the hex-encoded transaction as a string.
func (tx Tx) String() string { return fmt.Sprintf("Tx{%X}", []byte(tx)) }
+4 -4
View File
@@ -4,8 +4,8 @@ import (
"errors"
"fmt"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/batch"
"github.com/tendermint/tendermint/crypto/tmhash"
tmmath "github.com/tendermint/tendermint/libs/math"
)
@@ -132,11 +132,11 @@ func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *Commi
}
// ValidateHash returns an error if the hash is not empty, but its
// size != tmhash.Size.
// size != crypto.HashSize.
func ValidateHash(h []byte) error {
if len(h) > 0 && len(h) != tmhash.Size {
if len(h) > 0 && len(h) != crypto.HashSize {
return fmt.Errorf("expected size to be %d bytes, got %d bytes",
tmhash.Size,
crypto.HashSize,
len(h),
)
}
+2 -3
View File
@@ -11,7 +11,6 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/internal/libs/protoio"
tmtime "github.com/tendermint/tendermint/libs/time"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -40,10 +39,10 @@ func exampleVote(tb testing.TB, t byte) *Vote {
Round: 2,
Timestamp: stamp,
BlockID: BlockID{
Hash: tmhash.Sum([]byte("blockID_hash")),
Hash: crypto.Checksum([]byte("blockID_hash")),
PartSetHeader: PartSetHeader{
Total: 1000000,
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
Hash: crypto.Checksum([]byte("blockID_part_set_header_hash")),
},
},
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),