Skip to content

Commit

Permalink
throwaway: Use concrete types for blocks, does not compile
Browse files Browse the repository at this point in the history
  • Loading branch information
fridrik01 committed Dec 9, 2024
1 parent 146e3b3 commit 6b239b6
Show file tree
Hide file tree
Showing 24 changed files with 277 additions and 117 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
14 changes: 8 additions & 6 deletions beacon/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ import (

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

// sendPostBlockFCU sends a forkchoice update to the execution client.
func (s *Service[
_, _, ConsensusBlockT, _, _, _, BeaconStateT, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _,
]) sendPostBlockFCU(
ctx context.Context,
st BeaconStateT,
blk ConsensusBlockT,
blk consensusTypes.ConsensusBlock[*types.BeaconBlock],
) {
lph, err := st.GetLatestExecutionPayloadHeader()
if err != nil {
Expand All @@ -57,11 +59,11 @@ func (s *Service[
// client with attributes.
func (s *Service[
_, _, ConsensusBlockT, _, _, _, BeaconStateT, _, _,
_, _, ExecutionPayloadHeaderT, _, _,
_, _, ExecutionPayloadHeaderT, _, _, _, _,
]) sendNextFCUWithAttributes(
ctx context.Context,
st BeaconStateT,
blk ConsensusBlockT,
blk consensusTypes.ConsensusBlock[*types.BeaconBlock],
lph ExecutionPayloadHeaderT,
) {
beaconBlk := blk.GetBeaconBlock()
Expand Down Expand Up @@ -115,10 +117,10 @@ func (s *Service[
// execution client without attributes.
func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _,
ExecutionPayloadHeaderT, _, PayloadAttributesT,
ExecutionPayloadHeaderT, _, _, _, PayloadAttributesT,
]) sendNextFCUWithoutAttributes(
ctx context.Context,
blk ConsensusBlockT,
blk consensusTypes.ConsensusBlock[*types.BeaconBlock],
lph ExecutionPayloadHeaderT,
) {
beaconBlk := blk.GetBeaconBlock()
Expand Down
15 changes: 8 additions & 7 deletions beacon/blockchain/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ package blockchain
import (
"context"

"github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/primitives/math"
)

// 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 +57,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 +83,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,
st BeaconStateT,
Expand Down Expand Up @@ -140,11 +141,11 @@ func (s *Service[
// handleOptimisticPayloadBuild handles optimistically
// building for the next slot.
func (s *Service[
_, _, _, BeaconBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _,
_, _, _, BeaconBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _,
]) handleOptimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
blk BeaconBlockT,
blk *types.BeaconBlock,
nextPayloadTimestamp math.U64,
) {
if err := s.optimisticPayloadBuild(
Expand All @@ -163,11 +164,11 @@ func (s *Service[

// optimisticPayloadBuild builds a payload for the next slot.
func (s *Service[
_, _, _, BeaconBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _,
_, _, _, BeaconBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _,
]) optimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
blk BeaconBlockT,
blk *types.BeaconBlock,
nextPayloadTimestamp math.U64,
) error {
// We are building for the next slot, so we increment the slot relative
Expand Down
66 changes: 60 additions & 6 deletions beacon/blockchain/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import (
"encoding/json"
"time"

"github.com/berachain/beacon-kit/consensus-types/types"
consensusTypes "github.com/berachain/beacon-kit/consensus/types"
datypes "github.com/berachain/beacon-kit/da/types"
"github.com/berachain/beacon-kit/primitives/transition"
cmtabci "github.com/cometbft/cometbft/abci/types"
)

// ProcessGenesisData processes the genesis state and initializes the beacon
// state.
func (s *Service[
_, _, _, _, _, _, _, _, _, _, _, _, GenesisT, _,
_, _, _, _, _, _, _, _, _, _, _, _, GenesisT, _, _, _,
]) ProcessGenesisData(
ctx context.Context,
bytes []byte,
Expand All @@ -49,13 +53,63 @@ func (s *Service[
)
}

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _, _, _, _, GenesisT, ConsensusSidecarsT, _, _,
]) ProcessProposal(
ctx context.Context,
blk consensusTypes.ConsensusBlock[*types.BeaconBlock],
cs *consensusTypes.ConsensusSidecars[*datypes.BlobSidecars, *types.BeaconBlockHeader],
) (*cmtabci.ProcessProposalResponse, error) {
s.logger.Info("!!!!!!!! ProcessProposal called")
s.logger.Info("blk", blk)
s.logger.Info("sidecars", cs)

// verifySidecars
//
sidecars := cs.GetSidecars()
if !sidecars.IsNil() && sidecars.Len() > 0 {
s.logger.Info("Received incoming blob sidecars")

// TODO: Remove this once we cleanup generics
var sidecarI interface{} = cs
data, ok := sidecarI.(ConsensusSidecarsT)
if !ok {
panic("could not convert sidecar to ConsensusSidecarsT")
}

// Verify the blobs and ensure they match the local state.
if err := s.blobProcessor.VerifySidecars(data); err != nil {
s.logger.Error(
"rejecting incoming blob sidecars",
"reason", err,
)
return nil, err
}

s.logger.Info(
"Blob sidecars verification succeeded - accepting incoming blob sidecars",
"num_blobs",
sidecars.Len(),
)
}

err := s.VerifyIncomingBlock(ctx, blk)
if err != nil {
s.logger.Error("failed to verify incoming block", "error", err)
return nil, err
}

return nil, nil

}

// ProcessBeaconBlock receives an incoming beacon block, it first validates
// and then processes the block.
func (s *Service[
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) ProcessBeaconBlock(
ctx context.Context,
blk ConsensusBlockT,
blk consensusTypes.ConsensusBlock[*types.BeaconBlock],
) (transition.ValidatorUpdates, error) {
beaconBlk := blk.GetBeaconBlock()

Expand Down Expand Up @@ -104,11 +158,11 @@ func (s *Service[

// executeStateTransition runs the stf.
func (s *Service[
_, _, ConsensusBlockT, _, _, _, BeaconStateT, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _,
]) executeStateTransition(
ctx context.Context,
st BeaconStateT,
blk ConsensusBlockT,
blk consensusTypes.ConsensusBlock[*types.BeaconBlock],
) (transition.ValidatorUpdates, error) {
startTime := time.Now()
defer s.metrics.measureStateTransitionDuration(startTime)
Expand Down Expand Up @@ -142,7 +196,7 @@ func (s *Service[
ConsensusTime: blk.GetConsensusTime(),
},
st,
blk.GetBeaconBlock(),
*blk.GetBeaconBlock(),
)
return valUpdates, err
}
5 changes: 3 additions & 2 deletions beacon/blockchain/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
package blockchain

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

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _, _, _, _, _, _,
]) processPruning(beaconBlk BeaconBlockT) error {
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _, _, _, _, _, _, _, _,
]) processPruning(beaconBlk *types.BeaconBlock) error {
// prune availability store
start, end := availabilityPruneRangeFn(
beaconBlk.GetSlot().Unwrap(), s.chainSpec)
Expand Down
15 changes: 9 additions & 6 deletions beacon/blockchain/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"time"

payloadtime "github.com/berachain/beacon-kit/beacon/payload-time"
"github.com/berachain/beacon-kit/consensus-types/types"
ctypes "github.com/berachain/beacon-kit/consensus/types"
engineerrors "github.com/berachain/beacon-kit/engine-primitives/errors"
"github.com/berachain/beacon-kit/errors"
"github.com/berachain/beacon-kit/primitives/transition"
Expand All @@ -34,10 +36,10 @@ import (
// and logs the process.
func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _, _, _, _,
ExecutionPayloadHeaderT, _, _,
ExecutionPayloadHeaderT, _, _, _, _,
]) VerifyIncomingBlock(
ctx context.Context,
blk ConsensusBlockT,
blk ctypes.ConsensusBlock[*types.BeaconBlock],
) error {
var (
beaconBlk = blk.GetBeaconBlock()
Expand Down Expand Up @@ -132,15 +134,16 @@ func (s *Service[

// verifyStateRoot verifies the state root of an incoming block.
func (s *Service[
_, _, ConsensusBlockT, _, _, _, BeaconStateT, _, _, _, _, _, _, _,
_, _, ConsensusBlockT, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _,
]) verifyStateRoot(
ctx context.Context,
st BeaconStateT,
blk ConsensusBlockT,
blk ctypes.ConsensusBlock[*types.BeaconBlock],
) error {
startTime := time.Now()
defer s.metrics.measureStateRootVerificationTime(startTime)
_, err := s.stateProcessor.Transition(

// We run with a non-optimistic engine here to ensure
// that the proposer does not try to push through a bad block.
&transition.Context{
Expand All @@ -152,7 +155,7 @@ func (s *Service[
ProposerAddress: blk.GetProposerAddress(),
ConsensusTime: blk.GetConsensusTime(),
},
st, blk.GetBeaconBlock(),
st, *blk.GetBeaconBlock(),
)
if errors.Is(err, engineerrors.ErrAcceptedPayloadStatus) {
// It is safe for the validator to ignore this error since
Expand All @@ -169,7 +172,7 @@ func (s *Service[
// shouldBuildOptimisticPayloads returns true if optimistic
// payload builds are enabled.
func (s *Service[
_, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) shouldBuildOptimisticPayloads() bool {
return s.optimisticPayloadBuilds && s.localBuilder.Enabled()
}
Loading

0 comments on commit 6b239b6

Please sign in to comment.