Skip to content

Commit

Permalink
Merge branch 'main' of github.com:berachain/beacon-kit into fix-deps-…
Browse files Browse the repository at this point in the history
…htr2
  • Loading branch information
calbera committed Dec 16, 2024
2 parents dd54258 + cc31590 commit ea02520
Show file tree
Hide file tree
Showing 116 changed files with 755 additions and 1,632 deletions.
6 changes: 3 additions & 3 deletions beacon/blockchain/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
const defaultRetryInterval = 20 * time.Second

func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _,
]) depositFetcher(
ctx context.Context,
blockNum math.U64,
Expand All @@ -52,7 +52,7 @@ func (s *Service[
}

func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _,
]) fetchAndStoreDeposits(
ctx context.Context,
blockNum math.U64,
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *Service[
}

func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _,
]) depositCatchupFetcher(ctx context.Context) {
ticker := time.NewTicker(defaultRetryInterval)
defer ticker.Stop()
Expand Down
91 changes: 9 additions & 82 deletions beacon/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ package blockchain

import (
"context"
"time"

payloadtime "github.com/berachain/beacon-kit/beacon/payload-time"
"github.com/berachain/beacon-kit/config/spec"
engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives"
)

// sendPostBlockFCU sends a forkchoice update to the execution client.
// sendPostBlockFCU sends a forkchoice update to the execution client after a
// block is finalized.This function should only be used to notify
// the EL client of the new head and should not request optimistic builds, as:
// Optimistic clients already request builds in handleOptimisticPayloadBuild()
// Non-optimistic clients should never request optimistic builds.
func (s *Service[
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, PayloadAttributesT,
]) sendPostBlockFCU(
ctx context.Context,
st BeaconStateT,
Expand All @@ -46,84 +47,10 @@ func (s *Service[
return
}

if !s.shouldBuildOptimisticPayloads() && s.localBuilder.Enabled() {
s.sendNextFCUWithAttributes(ctx, st, blk, lph)
} else {
s.sendNextFCUWithoutAttributes(ctx, blk, lph)
}
}

// sendNextFCUWithAttributes sends a forkchoice update to the execution
// client with attributes.
func (s *Service[
_, _, ConsensusBlockT, _, _, BeaconStateT, _,
_, _, ExecutionPayloadHeaderT, _, _, _, _,
]) sendNextFCUWithAttributes(
ctx context.Context,
st BeaconStateT,
blk ConsensusBlockT,
lph ExecutionPayloadHeaderT,
) {
// Send a forkchoice update without payload attributes to notify
// EL of the new head.
beaconBlk := blk.GetBeaconBlock()

stCopy := st.Copy()
if _, err := s.stateProcessor.ProcessSlots(
stCopy, beaconBlk.GetSlot()+1,
); err != nil {
s.logger.Error(
"failed to process slots in non-optimistic payload",
"error", err,
)
return
}

nextPayloadTime := payloadtime.Next(
blk.GetConsensusTime(),
lph.GetTimestamp(),
true, // buildOptimistically
).Unwrap()

// We set timestamp check on Bartio for backward compatibility reasons
// TODO: drop this we drop other Bartio special cases.
if s.chainSpec.DepositEth1ChainID() == spec.BartioChainID {
nextPayloadTime = max(
//#nosec:G701
uint64(time.Now().Unix()+1),
uint64((lph.GetTimestamp() + 1)),
)
}

prevBlockRoot := beaconBlk.HashTreeRoot()
if _, err := s.localBuilder.RequestPayloadAsync(
ctx,
stCopy,
beaconBlk.GetSlot()+1,
nextPayloadTime,
prevBlockRoot,
lph.GetBlockHash(),
lph.GetParentHash(),
); err != nil {
s.logger.Error(
"failed to send forkchoice update with attributes in non-optimistic payload",
"error",
err,
)
}
}

// sendNextFCUWithoutAttributes sends a forkchoice update to the
// execution client without attributes.
func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _,
ExecutionPayloadHeaderT, _, _, _, PayloadAttributesT,
]) sendNextFCUWithoutAttributes(
ctx context.Context,
blk ConsensusBlockT,
lph ExecutionPayloadHeaderT,
) {
beaconBlk := blk.GetBeaconBlock()

if _, _, err := s.executionEngine.NotifyForkchoiceUpdate(
if _, _, err = s.executionEngine.NotifyForkchoiceUpdate(
ctx,
// TODO: Switch to New().
engineprimitives.
Expand Down
6 changes: 3 additions & 3 deletions beacon/blockchain/finalize_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _,
_, _, ConsensusBlockT, BeaconBlockT, _, _,
_, _, _, GenesisT, ConsensusSidecarsT, BlobSidecarsT, _,
]) FinalizeBlock(
ctx sdk.Context,
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *Service[
// finalizeBeaconBlock receives an incoming beacon block, it first validates
// and then processes the block.
func (s *Service[
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) finalizeBeaconBlock(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -148,7 +148,7 @@ func (s *Service[

// executeStateTransition runs the stf.
func (s *Service[
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) executeStateTransition(
ctx context.Context,
st BeaconStateT,
Expand Down
2 changes: 1 addition & 1 deletion beacon/blockchain/init_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// ProcessGenesisData processes the genesis state and initializes the beacon
// state.
func (s *Service[
_, _, _, _, _, _, _, _, _, _, GenesisT, _, _, _,
_, _, _, _, _, _, _, _, _, GenesisT, _, _, _,
]) ProcessGenesisData(
ctx context.Context,
bytes []byte,
Expand Down
10 changes: 5 additions & 5 deletions beacon/blockchain/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// forceStartupHead sends a force head FCU to the execution client.
func (s *Service[
_, _, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, _, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) forceStartupHead(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -56,7 +56,7 @@ func (s *Service[
// handleRebuildPayloadForRejectedBlock handles the case where the incoming
// block was rejected and we need to rebuild the payload for the current slot.
func (s *Service[
_, _, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, _, _, _, BeaconStateT, _, _, _, _, _, _, _,
]) handleRebuildPayloadForRejectedBlock(
ctx context.Context,
st BeaconStateT,
Expand All @@ -82,7 +82,7 @@ func (s *Service[
// rejected the incoming block and it would be unsafe to use any
// information from it.
func (s *Service[
_, _, _, _, _, BeaconStateT, _, _, _, ExecutionPayloadHeaderT,
_, _, _, _, _, BeaconStateT, _, _, ExecutionPayloadHeaderT,
_, _, _, _,
]) rebuildPayloadForRejectedBlock(
ctx context.Context,
Expand Down Expand Up @@ -141,7 +141,7 @@ func (s *Service[
// handleOptimisticPayloadBuild handles optimistically
// building for the next slot.
func (s *Service[
_, _, _, BeaconBlockT, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, _, BeaconBlockT, _, BeaconStateT, _, _, _, _, _, _, _,
]) handleOptimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
Expand All @@ -164,7 +164,7 @@ func (s *Service[

// optimisticPayloadBuild builds a payload for the next slot.
func (s *Service[
_, _, _, BeaconBlockT, _, BeaconStateT, _, _, _, _, _, _, _, _,
_, _, _, BeaconBlockT, _, BeaconStateT, _, _, _, _, _, _, _,
]) optimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
Expand Down
8 changes: 4 additions & 4 deletions beacon/blockchain/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _,
_, _, ConsensusBlockT, BeaconBlockT, _, _,
_, _, _, GenesisT, ConsensusSidecarsT, BlobSidecarsT, _,
]) ProcessProposal(
ctx sdk.Context,
Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *Service[
// VerifyIncomingBlock verifies the state root of an incoming block
// and logs the process.
func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _,
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _,
ExecutionPayloadHeaderT, _, _, _, _,
]) VerifyIncomingBlock(
ctx context.Context,
Expand Down Expand Up @@ -233,7 +233,7 @@ func (s *Service[
// verifyStateRoot verifies the state root of an incoming block.
func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, BeaconStateT,
_, _, _, _, _, _, _, _,
_, _, _, _, _, _, _,
]) verifyStateRoot(
ctx context.Context,
st BeaconStateT,
Expand Down Expand Up @@ -272,7 +272,7 @@ func (s *Service[
// shouldBuildOptimisticPayloads returns true if optimistic
// payload builds are enabled.
func (s *Service[
_, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _,
]) shouldBuildOptimisticPayloads() bool {
return s.optimisticPayloadBuilds && s.localBuilder.Enabled()
}
Expand Down
8 changes: 3 additions & 5 deletions beacon/blockchain/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
package blockchain

import (
"github.com/berachain/beacon-kit/execution/deposit"
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/primitives/common"
"github.com/berachain/beacon-kit/primitives/math"
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _, _, _, _, _,
]) processPruning(beaconBlk BeaconBlockT) error {
// prune availability store
start, end := availabilityPruneRangeFn(
Expand All @@ -49,9 +49,7 @@ func (s *Service[
return nil
}

func depositPruneRangeFn[
DepositT deposit.Deposit[DepositT],
](deposits []DepositT, cs common.ChainSpec) (uint64, uint64) {
func depositPruneRangeFn(deposits []*ctypes.Deposit, cs common.ChainSpec) (uint64, uint64) {
if len(deposits) == 0 || cs.MaxDepositsPerBlock() == 0 {
return 0, 0
}
Expand Down
Loading

0 comments on commit ea02520

Please sign in to comment.