From cd0f814f2e4414878e783df996605c458ecf0f5e Mon Sep 17 00:00:00 2001 From: Potuz Date: Tue, 23 May 2023 08:12:31 -0300 Subject: [PATCH] fixed erroneous panic (#12450) --- .../doubly-linked-tree/reorg_late_blocks.go | 2 +- .../doubly-linked-tree/reorg_late_blocks_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/reorg_late_blocks.go b/beacon-chain/forkchoice/doubly-linked-tree/reorg_late_blocks.go index 0c0db069dd..b1cff49de7 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/reorg_late_blocks.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/reorg_late_blocks.go @@ -85,7 +85,7 @@ func (f *ForkChoice) ShouldOverrideFCU() (override bool) { // Only orphan a block if the parent LMD vote is strong if parent.weight*100 < f.store.committeeWeight*params.BeaconConfig().ReorgParentWeightThreshold { - panic(f.store.committeeWeight) + return } return true } diff --git a/beacon-chain/forkchoice/doubly-linked-tree/reorg_late_blocks_test.go b/beacon-chain/forkchoice/doubly-linked-tree/reorg_late_blocks_test.go index 61780e4cb5..8485021a18 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/reorg_late_blocks_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/reorg_late_blocks_test.go @@ -84,6 +84,12 @@ func TestForkChoice_ShouldOverrideFCU(t *testing.T) { require.Equal(t, false, f.ShouldOverrideFCU()) f.store.headNode.parent = saved }) + t.Run("parent is weak", func(t *testing.T) { + saved := f.store.headNode.parent.weight + f.store.headNode.parent.weight = 0 + require.Equal(t, false, f.ShouldOverrideFCU()) + f.store.headNode.parent.weight = saved + }) t.Run("Head is strong", func(t *testing.T) { f.store.headNode.weight = f.store.committeeWeight require.Equal(t, false, f.ShouldOverrideFCU()) @@ -169,6 +175,12 @@ func TestForkChoice_GetProposerHead(t *testing.T) { require.Equal(t, childRoot, f.GetProposerHead()) f.store.headNode.parent = saved }) + t.Run("parent is weak", func(t *testing.T) { + saved := f.store.headNode.parent.weight + f.store.headNode.parent.weight = 0 + require.Equal(t, false, f.ShouldOverrideFCU()) + f.store.headNode.parent.weight = saved + }) t.Run("Head is strong", func(t *testing.T) { f.store.headNode.weight = f.store.committeeWeight require.Equal(t, childRoot, f.GetProposerHead())