trie: update merkle hash when stage is commited

This commit is contained in:
Tzu-Jung Lee 2018-07-11 09:54:41 -07:00
parent d3419ea775
commit 212fd1983a
2 changed files with 4 additions and 0 deletions

View file

@ -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 {

View file

@ -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()