From c3a592a985da2ef15c2b30689eddfcc319d90c1c Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sun, 5 Mar 2023 10:45:24 -0700 Subject: [PATCH 1/2] Minor cleanup to forkchoice pkg --- .../forkchoice/doubly-linked-tree/forkchoice.go | 2 +- .../forkchoice/doubly-linked-tree/vote_test.go | 2 +- beacon-chain/forkchoice/interfaces.go | 7 +++---- beacon-chain/forkchoice/types/types.go | 10 +--------- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go index e893ee852c7b..2d63d07e37d6 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go @@ -495,7 +495,7 @@ func (f *ForkChoice) CommonAncestor(ctx context.Context, r1 [32]byte, r2 [32]byt } } -// InsertOptimisticChain inserts all nodes corresponding to blocks in the slice +// InsertChain inserts all nodes corresponding to blocks in the slice // `blocks`. This slice must be ordered from child to parent. It includes all // blocks **except** the first one (that is the one with the highest slot // number). All blocks are assumed to be a strict chain diff --git a/beacon-chain/forkchoice/doubly-linked-tree/vote_test.go b/beacon-chain/forkchoice/doubly-linked-tree/vote_test.go index 47ad0edac5ca..8a4a68553a68 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/vote_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/vote_test.go @@ -124,7 +124,7 @@ func TestVotes_CanFindHead(t *testing.T) { // / // 5 <- head, justified epoch = 2 // - // We set this node's slot to be 64 so that when prunning below we do not prune its child + // We set this node's slot to be 64 so that when pruning below we do not prune its child state, blkRoot, err = prepareForkchoiceState(context.Background(), 2*params.BeaconConfig().SlotsPerEpoch, indexToHash(5), indexToHash(4), params.BeaconConfig().ZeroHash, 2, 2) require.NoError(t, err) require.NoError(t, f.InsertNode(ctx, state, blkRoot)) diff --git a/beacon-chain/forkchoice/interfaces.go b/beacon-chain/forkchoice/interfaces.go index 51cbe90f5e08..626817edc1b2 100644 --- a/beacon-chain/forkchoice/interfaces.go +++ b/beacon-chain/forkchoice/interfaces.go @@ -31,8 +31,6 @@ type ForkChoicer interface { type HeadRetriever interface { Head(context.Context) ([32]byte, error) CachedHeadRoot() [32]byte - Tips() ([][32]byte, []primitives.Slot) - IsOptimistic(root [32]byte) (bool, error) } // BlockProcessor processes the block that's used for accounting fork choice. @@ -44,7 +42,6 @@ type BlockProcessor interface { // AttestationProcessor processes the attestation that's used for accounting fork choice. type AttestationProcessor interface { ProcessAttestation(context.Context, []uint64, [32]byte, primitives.Epoch) - InsertSlashedIndex(context.Context, primitives.ValidatorIndex) } // Getter returns fork choice related information. @@ -62,10 +59,11 @@ type Getter interface { BestJustifiedCheckpoint() *forkchoicetypes.Checkpoint NodeCount() int HighestReceivedBlockSlot() primitives.Slot - HighestReceivedBlockRoot() [32]byte ReceivedBlocksLastEpoch() (uint64, error) ForkChoiceDump(context.Context) (*v1.ForkChoiceDump, error) Weight(root [32]byte) (uint64, error) + Tips() ([][32]byte, []primitives.Slot) + IsOptimistic(root [32]byte) (bool, error) } // Setter allows to set forkchoice information @@ -78,4 +76,5 @@ type Setter interface { SetOriginRoot([32]byte) NewSlot(context.Context, primitives.Slot) error SetBalancesByRooter(BalancesByRooter) + InsertSlashedIndex(context.Context, primitives.ValidatorIndex) } diff --git a/beacon-chain/forkchoice/types/types.go b/beacon-chain/forkchoice/types/types.go index e7d3bbd2b412..46e41b1dd9d3 100644 --- a/beacon-chain/forkchoice/types/types.go +++ b/beacon-chain/forkchoice/types/types.go @@ -7,16 +7,8 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" ) -// ProposerBoostRootArgs to call the BoostProposerRoot function. -type ProposerBoostRootArgs struct { - BlockRoot [32]byte - BlockSlot primitives.Slot - CurrentSlot primitives.Slot - SecondsIntoSlot uint64 -} - // Checkpoint is an array version of ethpb.Checkpoint. It is used internally in -// forkchoice, while the slice version is used in the interface to legagy code +// forkchoice, while the slice version is used in the interface to legacy code // in other packages type Checkpoint struct { Epoch primitives.Epoch From 1161c4bdfd42c283d87684dee158ebeb795d52a7 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sun, 5 Mar 2023 15:55:27 -0800 Subject: [PATCH 2/2] Rm implementation --- .../forkchoice/doubly-linked-tree/store.go | 8 -------- .../doubly-linked-tree/store_test.go | 20 ------------------- 2 files changed, 28 deletions(-) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/store.go b/beacon-chain/forkchoice/doubly-linked-tree/store.go index efcd9c35d2a4..0211657b0755 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/store.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/store.go @@ -226,14 +226,6 @@ func (f *ForkChoice) HighestReceivedBlockSlot() primitives.Slot { return f.store.highestReceivedNode.slot } -// HighestReceivedBlockRoot returns the highest slot root received by the forkchoice -func (f *ForkChoice) HighestReceivedBlockRoot() [32]byte { - if f.store.highestReceivedNode == nil { - return [32]byte{} - } - return f.store.highestReceivedNode.root -} - // ReceivedBlocksLastEpoch returns the number of blocks received in the last epoch func (f *ForkChoice) ReceivedBlocksLastEpoch() (uint64, error) { count := uint64(0) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/store_test.go b/beacon-chain/forkchoice/doubly-linked-tree/store_test.go index 630653390624..0b5c21bb4f55 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/store_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/store_test.go @@ -320,26 +320,6 @@ func TestStore_PruneMapsNodes(t *testing.T) { } -func TestForkChoice_HighestReceivedBlockSlotRoot(t *testing.T) { - f := setup(1, 1) - s := f.store - _, err := s.insert(context.Background(), 100, [32]byte{'A'}, [32]byte{}, params.BeaconConfig().ZeroHash, 1, 1) - require.NoError(t, err) - require.Equal(t, primitives.Slot(100), s.highestReceivedNode.slot) - require.Equal(t, primitives.Slot(100), f.HighestReceivedBlockSlot()) - require.Equal(t, [32]byte{'A'}, f.HighestReceivedBlockRoot()) - _, err = s.insert(context.Background(), 1000, [32]byte{'B'}, [32]byte{}, params.BeaconConfig().ZeroHash, 1, 1) - require.NoError(t, err) - require.Equal(t, primitives.Slot(1000), s.highestReceivedNode.slot) - require.Equal(t, primitives.Slot(1000), f.HighestReceivedBlockSlot()) - require.Equal(t, [32]byte{'B'}, f.HighestReceivedBlockRoot()) - _, err = s.insert(context.Background(), 500, [32]byte{'C'}, [32]byte{}, params.BeaconConfig().ZeroHash, 1, 1) - require.NoError(t, err) - require.Equal(t, primitives.Slot(1000), s.highestReceivedNode.slot) - require.Equal(t, primitives.Slot(1000), f.HighestReceivedBlockSlot()) - require.Equal(t, [32]byte{'B'}, f.HighestReceivedBlockRoot()) -} - func TestForkChoice_ReceivedBlocksLastEpoch(t *testing.T) { f := setup(1, 1) s := f.store