mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-03 14:47:16 +00:00
update spec for Merkle RFC 6962 (#3175)
* spec: specify when MerkleRoot is on hashes * remove unnecessary hash methods * update changelog * fix test
This commit is contained in:
+3
-8
@@ -3,25 +3,20 @@ package types
|
||||
import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// ABCIResult is the deterministic component of a ResponseDeliverTx.
|
||||
// TODO: add Tags
|
||||
// TODO: add tags and other fields
|
||||
// https://github.com/tendermint/tendermint/issues/1007
|
||||
type ABCIResult struct {
|
||||
Code uint32 `json:"code"`
|
||||
Data cmn.HexBytes `json:"data"`
|
||||
}
|
||||
|
||||
// Hash returns the canonical hash of the ABCIResult
|
||||
func (a ABCIResult) Hash() []byte {
|
||||
bz := tmhash.Sum(cdcEncode(a))
|
||||
return bz
|
||||
}
|
||||
|
||||
// Bytes returns the amino encoded ABCIResult
|
||||
func (a ABCIResult) Bytes() []byte {
|
||||
return cdcEncode(a)
|
||||
}
|
||||
|
||||
+10
-9
@@ -16,20 +16,21 @@ func TestABCIResults(t *testing.T) {
|
||||
e := ABCIResult{Code: 14, Data: []byte("foo")}
|
||||
f := ABCIResult{Code: 14, Data: []byte("bar")}
|
||||
|
||||
// Nil and []byte{} should produce the same hash.
|
||||
require.Equal(t, a.Hash(), a.Hash())
|
||||
require.Equal(t, b.Hash(), b.Hash())
|
||||
require.Equal(t, a.Hash(), b.Hash())
|
||||
// Nil and []byte{} should produce the same bytes
|
||||
require.Equal(t, a.Bytes(), a.Bytes())
|
||||
require.Equal(t, b.Bytes(), b.Bytes())
|
||||
require.Equal(t, a.Bytes(), b.Bytes())
|
||||
|
||||
// a and b should be the same, don't go in results.
|
||||
results := ABCIResults{a, c, d, e, f}
|
||||
|
||||
// Make sure each result hashes properly.
|
||||
// Make sure each result serializes differently
|
||||
var last []byte
|
||||
for i, res := range results {
|
||||
h := res.Hash()
|
||||
assert.NotEqual(t, last, h, "%d", i)
|
||||
last = h
|
||||
assert.Equal(t, last, a.Bytes()) // first one is empty
|
||||
for i, res := range results[1:] {
|
||||
bz := res.Bytes()
|
||||
assert.NotEqual(t, last, bz, "%d", i)
|
||||
last = bz
|
||||
}
|
||||
|
||||
// Make sure that we can get a root hash from results and verify proofs.
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
)
|
||||
@@ -70,12 +68,6 @@ func (v *Validator) String() string {
|
||||
v.ProposerPriority)
|
||||
}
|
||||
|
||||
// Hash computes the unique ID of a validator with a given voting power.
|
||||
// It excludes the ProposerPriority value, which changes with every round.
|
||||
func (v *Validator) Hash() []byte {
|
||||
return tmhash.Sum(v.Bytes())
|
||||
}
|
||||
|
||||
// Bytes computes the unique encoding of a validator with a given voting power.
|
||||
// These are the bytes that gets hashed in consensus. It excludes address
|
||||
// as its redundant with the pubkey. This also excludes ProposerPriority
|
||||
|
||||
Reference in New Issue
Block a user