From bd83018e768b2cd043d81f8aa341e225768bf60b Mon Sep 17 00:00:00 2001 From: int88 <106391185+int88@users.noreply.github.com> Date: Tue, 31 Jan 2023 18:53:29 +0800 Subject: [PATCH] delete from s.nodeByPayload as well when pruneFinalizedNodeByRootMap (#11813) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * delete from s.nodeByPayload as well when pruneFinalizedNodeByRootMap * regresstion test * add different payload node --------- Co-authored-by: Raul Jordan Co-authored-by: Radosław Kapka --- beacon-chain/forkchoice/doubly-linked-tree/store.go | 1 + .../forkchoice/doubly-linked-tree/store_test.go | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/store.go b/beacon-chain/forkchoice/doubly-linked-tree/store.go index f89a1673ef..0e498357c0 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/store.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/store.go @@ -204,6 +204,7 @@ func (s *Store) pruneFinalizedNodeByRootMap(ctx context.Context, node, finalized node.children = nil delete(s.nodeByRoot, node.root) + delete(s.nodeByPayload, node.payloadHash) return nil } diff --git a/beacon-chain/forkchoice/doubly-linked-tree/store_test.go b/beacon-chain/forkchoice/doubly-linked-tree/store_test.go index 1e6914f2d9..5211df84f3 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/store_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/store_test.go @@ -224,10 +224,10 @@ func TestStore_Prune_ReturnEarly(t *testing.T) { func TestStore_Prune_NoDanglingBranch(t *testing.T) { f := setup(0, 0) ctx := context.Background() - state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0) + state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, [32]byte{'1'}, 0, 0) require.NoError(t, err) require.NoError(t, f.InsertNode(ctx, state, blkRoot)) - state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0) + state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), params.BeaconConfig().ZeroHash, [32]byte{'2'}, 0, 0) require.NoError(t, err) require.NoError(t, f.InsertNode(ctx, state, blkRoot)) @@ -235,6 +235,7 @@ func TestStore_Prune_NoDanglingBranch(t *testing.T) { s.finalizedCheckpoint.Root = indexToHash(1) require.NoError(t, s.prune(context.Background())) require.Equal(t, len(s.nodeByRoot), 1) + require.Equal(t, len(s.nodeByPayload), 1) } // This test starts with the following branching diagram @@ -304,10 +305,10 @@ func TestStore_tips(t *testing.T) { func TestStore_PruneMapsNodes(t *testing.T) { f := setup(0, 0) ctx := context.Background() - state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0) + state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, [32]byte{'1'}, 0, 0) require.NoError(t, err) require.NoError(t, f.InsertNode(ctx, state, blkRoot)) - state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0) + state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), params.BeaconConfig().ZeroHash, [32]byte{'2'}, 0, 0) require.NoError(t, err) require.NoError(t, f.InsertNode(ctx, state, blkRoot)) @@ -315,6 +316,7 @@ func TestStore_PruneMapsNodes(t *testing.T) { s.finalizedCheckpoint.Root = indexToHash(1) require.NoError(t, s.prune(context.Background())) require.Equal(t, len(s.nodeByRoot), 1) + require.Equal(t, len(s.nodeByPayload), 1) }