crypto/merkle: remove simple prefix (#4989)

## Description

This PR removes simple prefix from all types in the crypto/merkle directory.

The two proto types `Proof` & `ProofOp` have been moved to the `proto/crypto/merkle` directory.

proto messge `Proof` was renamed to `ProofOps` and `SimpleProof` message to `Proof`. 

Closes: #2755
This commit is contained in:
Marko
2020-06-10 14:57:38 +00:00
committed by GitHub
parent d54de61bf6
commit 46f6d17601
34 changed files with 1318 additions and 1559 deletions
+2 -2
View File
@@ -449,7 +449,7 @@ func (h *Header) Hash() tmbytes.HexBytes {
if h == nil || len(h.ValidatorsHash) == 0 {
return nil
}
return merkle.SimpleHashFromByteSlices([][]byte{
return merkle.HashFromByteSlices([][]byte{
cdcEncode(h.Version),
cdcEncode(h.ChainID),
cdcEncode(h.Height),
@@ -867,7 +867,7 @@ func (commit *Commit) Hash() tmbytes.HexBytes {
for i, commitSig := range commit.Signatures {
bs[i] = cdcEncode(commitSig)
}
commit.hash = merkle.SimpleHashFromByteSlices(bs)
commit.hash = merkle.HashFromByteSlices(bs)
}
return commit.hash
}
+1 -1
View File
@@ -306,7 +306,7 @@ func TestHeaderHash(t *testing.T) {
byteSlices = append(byteSlices, cdcEncode(f.Interface()))
}
assert.Equal(t,
bytes.HexBytes(merkle.SimpleHashFromByteSlices(byteSlices)), tc.header.Hash())
bytes.HexBytes(merkle.HashFromByteSlices(byteSlices)), tc.header.Hash())
}
})
}
+1 -1
View File
@@ -520,7 +520,7 @@ func (evl EvidenceList) Hash() []byte {
for i := 0; i < len(evl); i++ {
evidenceBzs[i] = evl[i].Bytes()
}
return merkle.SimpleHashFromByteSlices(evidenceBzs)
return merkle.HashFromByteSlices(evidenceBzs)
}
func (evl EvidenceList) String() string {
+5 -5
View File
@@ -21,9 +21,9 @@ var (
)
type Part struct {
Index uint32 `json:"index"`
Bytes tmbytes.HexBytes `json:"bytes"`
Proof merkle.SimpleProof `json:"proof"`
Index uint32 `json:"index"`
Bytes tmbytes.HexBytes `json:"bytes"`
Proof merkle.Proof `json:"proof"`
}
// ValidateBasic performs basic validation.
@@ -72,7 +72,7 @@ func PartFromProto(pb *tmproto.Part) (*Part, error) {
}
part := new(Part)
proof, err := merkle.SimpleProofFromProto(&pb.Proof)
proof, err := merkle.ProofFromProto(&pb.Proof)
if err != nil {
return nil, err
}
@@ -166,7 +166,7 @@ func NewPartSetFromData(data []byte, partSize uint32) *PartSet {
partsBitArray.SetIndex(int(i), true)
}
// Compute merkle proofs
root, proofs := merkle.SimpleProofsFromByteSlices(partsBytes)
root, proofs := merkle.ProofsFromByteSlices(partsBytes)
for i := uint32(0); i < total; i++ {
parts[i].Proof = *proofs[i]
}
+2 -2
View File
@@ -115,7 +115,7 @@ func TestPartValidateBasic(t *testing.T) {
{"Good Part", func(pt *Part) {}, false},
{"Too big part", func(pt *Part) { pt.Bytes = make([]byte, BlockPartSizeBytes+1) }, true},
{"Too big proof", func(pt *Part) {
pt.Proof = merkle.SimpleProof{
pt.Proof = merkle.Proof{
Total: 1,
Index: 1,
LeafHash: make([]byte, 1024*1024),
@@ -160,7 +160,7 @@ func TestParSetHeaderProtoBuf(t *testing.T) {
func TestPartProtoBuf(t *testing.T) {
proof := merkle.SimpleProof{
proof := merkle.Proof{
Total: 1,
Index: 1,
LeafHash: tmrand.Bytes(32),
+3 -3
View File
@@ -54,12 +54,12 @@ func (a ABCIResults) Bytes() []byte {
func (a ABCIResults) Hash() []byte {
// NOTE: we copy the impl of the merkle tree for txs -
// we should be consistent and either do it for both or not.
return merkle.SimpleHashFromByteSlices(a.toByteSlices())
return merkle.HashFromByteSlices(a.toByteSlices())
}
// ProveResult returns a merkle proof of one result from the set
func (a ABCIResults) ProveResult(i int) merkle.SimpleProof {
_, proofs := merkle.SimpleProofsFromByteSlices(a.toByteSlices())
func (a ABCIResults) ProveResult(i int) merkle.Proof {
_, proofs := merkle.ProofsFromByteSlices(a.toByteSlices())
return *proofs[i]
}
+5 -5
View File
@@ -37,7 +37,7 @@ func (txs Txs) Hash() []byte {
for i := 0; i < len(txs); i++ {
txBzs[i] = txs[i].Hash()
}
return merkle.SimpleHashFromByteSlices(txBzs)
return merkle.HashFromByteSlices(txBzs)
}
// Index returns the index of this transaction in the list, or -1 if not found
@@ -69,7 +69,7 @@ func (txs Txs) Proof(i int) TxProof {
for i := 0; i < l; i++ {
bzs[i] = txs[i].Hash()
}
root, proofs := merkle.SimpleProofsFromByteSlices(bzs)
root, proofs := merkle.ProofsFromByteSlices(bzs)
return TxProof{
RootHash: root,
@@ -80,9 +80,9 @@ func (txs Txs) Proof(i int) TxProof {
// TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree.
type TxProof struct {
RootHash tmbytes.HexBytes `json:"root_hash"`
Data Tx `json:"data"`
Proof merkle.SimpleProof `json:"proof"`
RootHash tmbytes.HexBytes `json:"root_hash"`
Data Tx `json:"data"`
Proof merkle.Proof `json:"proof"`
}
// Leaf returns the hash(tx), which is the leaf in the merkle tree which this proof refers to.
+1 -1
View File
@@ -352,7 +352,7 @@ func (vals *ValidatorSet) Hash() []byte {
for i, val := range vals.Validators {
bzs[i] = val.Bytes()
}
return merkle.SimpleHashFromByteSlices(bzs)
return merkle.HashFromByteSlices(bzs)
}
// Iterate will run the given function over the set.