Skip to content

Commit

Permalink
fix(lib/blocktree): fix setting leaves after blocktree pruning (Chain…
Browse files Browse the repository at this point in the history
  • Loading branch information
noot authored and timwu20 committed Dec 6, 2021
1 parent ee5a5b6 commit a00f881
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/blocktree/blocktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,11 @@ func (bt *BlockTree) Prune(finalised Hash) (pruned []Hash) {

pruned = bt.head.prune(n, nil)
bt.head = n
leaves := n.getLeaves(nil)
bt.leaves = newEmptyLeafMap()
bt.leaves.store(n.hash, n)
for _, leaf := range leaves {
bt.leaves.store(leaf.hash, leaf)
}
return pruned
}

Expand Down
6 changes: 6 additions & 0 deletions lib/blocktree/blocktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ func TestBlockTree_Prune(t *testing.T) {
t.Fatal("pruned an ancestor of the finalised node!!")
}
}

require.NotEqual(t, 0, len(bt.leaves.nodes()))
for _, leaf := range bt.leaves.nodes() {
require.NotEqual(t, leaf.hash, finalised.hash)
require.True(t, leaf.isDescendantOf(finalised))
}
}

func TestBlockTree_DeepCopy(t *testing.T) {
Expand Down

0 comments on commit a00f881

Please sign in to comment.