Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib/blocktree): fix setting leaves after blocktree pruning #1605

Merged
merged 13 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions lib/blocktree/blocktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ func TestBlockTree_Prune(t *testing.T) {
t.Fatal("pruned an ancestor of the finalised node!!")
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also verify if the leaves count?
This test will still pass if the leaves count returned is 0.

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