trie: update merkle hash when stage is commited
This commit is contained in:
parent
d3419ea775
commit
212fd1983a
2 changed files with 4 additions and 0 deletions
|
@ -17,6 +17,7 @@ func newNode(val Value) *node {
|
||||||
// We clear the Merkle Hash for every node along the path, including the root.
|
// We clear the Merkle Hash for every node along the path, including the root.
|
||||||
// Calculation of the hash happens much less frequently then updating to the MerkleTrie.
|
// Calculation of the hash happens much less frequently then updating to the MerkleTrie.
|
||||||
func update(n *node, key Key, val Value) {
|
func update(n *node, key Key, val Value) {
|
||||||
|
n.hash = nil
|
||||||
// Follow the path to reach the node.
|
// Follow the path to reach the node.
|
||||||
for _, k := range key {
|
for _, k := range key {
|
||||||
if n.links[k] == nil {
|
if n.links[k] == nil {
|
||||||
|
|
|
@ -39,6 +39,9 @@ func (s *Stage) Update(key Key, val Value) error {
|
||||||
|
|
||||||
// Commit ...
|
// Commit ...
|
||||||
func (s *Stage) Commit(head *Commit, meta CommitMeta) (*Commit, error) {
|
func (s *Stage) Commit(head *Commit, meta CommitMeta) (*Commit, error) {
|
||||||
|
// Update Merkle Hash.
|
||||||
|
s.MerkleHash()
|
||||||
|
|
||||||
c := NewCommit(head, meta, s.MerkleTrie)
|
c := NewCommit(head, meta, s.MerkleTrie)
|
||||||
|
|
||||||
s.MerkleTrie = New()
|
s.MerkleTrie = New()
|
||||||
|
|
Loading…
Reference in a new issue