Skip to content

Commit 58c0854

Browse files
authored
fix(lib/blocktree): fix setting leaves after blocktree pruning (ChainSafe#1605)
1 parent f195204 commit 58c0854

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/blocktree/blocktree.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ func (bt *BlockTree) Prune(finalised Hash) (pruned []Hash) {
187187

188188
pruned = bt.head.prune(n, nil)
189189
bt.head = n
190+
leaves := n.getLeaves(nil)
190191
bt.leaves = newEmptyLeafMap()
191-
bt.leaves.store(n.hash, n)
192+
for _, leaf := range leaves {
193+
bt.leaves.store(leaf.hash, leaf)
194+
}
192195
return pruned
193196
}
194197

lib/blocktree/blocktree_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ func TestBlockTree_Prune(t *testing.T) {
378378
t.Fatal("pruned an ancestor of the finalised node!!")
379379
}
380380
}
381+
382+
require.NotEqual(t, 0, len(bt.leaves.nodes()))
383+
for _, leaf := range bt.leaves.nodes() {
384+
require.NotEqual(t, leaf.hash, finalised.hash)
385+
require.True(t, leaf.isDescendantOf(finalised))
386+
}
381387
}
382388

383389
func TestBlockTree_DeepCopy(t *testing.T) {

0 commit comments

Comments
 (0)