mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Minor cleanup to forkchoice pkg (#12078)
* Minor cleanup to forkchoice pkg * Rm implementation --------- Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -63,10 +60,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)
|
||||
ShouldOverrideFCU() bool
|
||||
}
|
||||
|
||||
@@ -80,4 +78,5 @@ type Setter interface {
|
||||
SetOriginRoot([32]byte)
|
||||
NewSlot(context.Context, primitives.Slot) error
|
||||
SetBalancesByRooter(BalancesByRooter)
|
||||
InsertSlashedIndex(context.Context, primitives.ValidatorIndex)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user