Skip to content

Commit

Permalink
reverting trie.Hash func
Browse files Browse the repository at this point in the history
  • Loading branch information
kishansagathiya committed Mar 9, 2022
1 parent 38d9157 commit 32f4e17
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ChainSafe/gossamer/internal/trie/codec"
"github.com/ChainSafe/gossamer/internal/trie/node"
"github.com/ChainSafe/gossamer/internal/trie/pools"
"github.com/ChainSafe/gossamer/lib/common"
)

Expand Down Expand Up @@ -154,8 +155,16 @@ func (t *Trie) MustHash() common.Hash {

// Hash returns the hashed root of the trie.
func (t *Trie) Hash() (rootHash common.Hash, err error) {
_, hash, err := t.root.EncodeAndHash(true)
return common.BytesToHash(hash), err
buffer := pools.EncodingBuffers.Get().(*bytes.Buffer)
buffer.Reset()
defer pools.EncodingBuffers.Put(buffer)

err = encodeRoot(t.root, buffer)
if err != nil {
return [32]byte{}, err
}

return common.Blake2bHash(buffer.Bytes()) // TODO optimisation: use hashers sync pools
}

// Entries returns all the key-value pairs in the trie as a map of keys to values
Expand Down

0 comments on commit 32f4e17

Please sign in to comment.