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

Minor cleanup to forkchoice pkg #12078

Merged
merged 5 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions beacon-chain/forkchoice/doubly-linked-tree/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions beacon-chain/forkchoice/doubly-linked-tree/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/forkchoice/doubly-linked-tree/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 3 additions & 4 deletions beacon-chain/forkchoice/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ type HeadRetriever interface {
Head(context.Context) ([32]byte, error)
GetProposerHead() [32]byte
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.
Expand All @@ -45,7 +43,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.
Expand All @@ -63,10 +60,11 @@ type Getter interface {
BestJustifiedCheckpoint() *forkchoicetypes.Checkpoint
NodeCount() int
HighestReceivedBlockSlot() primitives.Slot
HighestReceivedBlockRoot() [32]byte
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not used either?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed not used. I can also remove the implementation

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)
ShouldOverrideFCU() bool
}

Expand All @@ -80,4 +78,5 @@ type Setter interface {
SetOriginRoot([32]byte)
NewSlot(context.Context, primitives.Slot) error
SetBalancesByRooter(BalancesByRooter)
InsertSlashedIndex(context.Context, primitives.ValidatorIndex)
}
10 changes: 1 addition & 9 deletions beacon-chain/forkchoice/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down