Skip to content

Commit

Permalink
10/n Remove BeaconBlockT and BeaconStateT generic types (#2297)
Browse files Browse the repository at this point in the history
Co-authored-by: aBear <[email protected]>
  • Loading branch information
fridrik01 and abi87 authored Dec 20, 2024
1 parent f9e2640 commit 7e5f02d
Show file tree
Hide file tree
Showing 76 changed files with 604 additions and 987 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
5 changes: 3 additions & 2 deletions beacon/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

ctypes "github.com/berachain/beacon-kit/consensus-types/types"
engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives"
statedb "github.com/berachain/beacon-kit/state-transition/core/state"
)

// sendPostBlockFCU sends a forkchoice update to the execution client after a
Expand All @@ -33,10 +34,10 @@ import (
// Optimistic clients already request builds in handleOptimisticPayloadBuild()
// Non-optimistic clients should never request optimistic builds.
func (s *Service[
_, _, ConsensusBlockT, _, BeaconStateT, _, _, _,
_, _, ConsensusBlockT, _, _, _,
]) sendPostBlockFCU(
ctx context.Context,
st BeaconStateT,
st *statedb.StateDB,
blk ConsensusBlockT,
) {
lph, err := st.GetLatestExecutionPayloadHeader()
Expand Down
29 changes: 15 additions & 14 deletions beacon/blockchain/finalize_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import (
"github.com/berachain/beacon-kit/consensus/types"
"github.com/berachain/beacon-kit/primitives/math"
"github.com/berachain/beacon-kit/primitives/transition"
statedb "github.com/berachain/beacon-kit/state-transition/core/state"
cmtabci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _,
_, GenesisT, ConsensusSidecarsT,
_, _, ConsensusBlockT, _,
GenesisT, ConsensusSidecarsT,
]) FinalizeBlock(
ctx sdk.Context,
req *cmtabci.FinalizeBlockRequest,
Expand All @@ -46,13 +47,13 @@ func (s *Service[

// STEP 1: Decode blok and blobs
blk, blobs, err := encoding.
ExtractBlobsAndBlockFromRequest[BeaconBlockT](
req,
BeaconBlockTxIndex,
BlobSidecarsTxIndex,
s.chainSpec.ActiveForkVersionForSlot(
math.Slot(req.Height),
))
ExtractBlobsAndBlockFromRequest(
req,
BeaconBlockTxIndex,
BlobSidecarsTxIndex,
s.chainSpec.ActiveForkVersionForSlot(
math.Slot(req.Height),
))
if err != nil {
//nolint:nilerr // If we don't have a block, we can't do anything.
return nil, nil
Expand All @@ -69,7 +70,7 @@ func (s *Service[
}

// STEP 3: finalize the block
var consensusBlk *types.ConsensusBlock[BeaconBlockT]
var consensusBlk *types.ConsensusBlock
consensusBlk = consensusBlk.New(
blk,
req.GetProposerAddress(),
Expand Down Expand Up @@ -117,10 +118,10 @@ func (s *Service[
// finalizeBeaconBlock receives an incoming beacon block, it first validates
// and then processes the block.
func (s *Service[
_, _, ConsensusBlockT, _, BeaconStateT, _, _, _,
_, _, ConsensusBlockT, _, _, _,
]) finalizeBeaconBlock(
ctx context.Context,
st BeaconStateT,
st *statedb.StateDB,
blk ConsensusBlockT,
) (transition.ValidatorUpdates, error) {
beaconBlk := blk.GetBeaconBlock()
Expand Down Expand Up @@ -148,10 +149,10 @@ func (s *Service[

// executeStateTransition runs the stf.
func (s *Service[
_, _, ConsensusBlockT, _, BeaconStateT, _, _, _,
_, _, ConsensusBlockT, _, _, _,
]) executeStateTransition(
ctx context.Context,
st BeaconStateT,
st *statedb.StateDB,
blk ConsensusBlockT,
) (transition.ValidatorUpdates, error) {
startTime := time.Now()
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
26 changes: 14 additions & 12 deletions beacon/blockchain/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ package blockchain
import (
"context"

ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/primitives/math"
statedb "github.com/berachain/beacon-kit/state-transition/core/state"
)

// forceStartupHead sends a force head FCU to the execution client.
func (s *Service[
_, _, _, _, BeaconStateT, _, _, _,
_, _, _, _, _, _,
]) forceStartupHead(
ctx context.Context,
st BeaconStateT,
st *statedb.StateDB,
) {
slot, err := st.GetSlot()
if err != nil {
Expand All @@ -56,10 +58,10 @@ 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, _, _, _,
_, _, _, _, _, _,
]) handleRebuildPayloadForRejectedBlock(
ctx context.Context,
st BeaconStateT,
st *statedb.StateDB,
nextPayloadTimestamp math.U64,
) {
if err := s.rebuildPayloadForRejectedBlock(
Expand All @@ -82,11 +84,11 @@ func (s *Service[
// rejected the incoming block and it would be unsafe to use any
// information from it.
func (s *Service[
_, _, _, _, BeaconStateT, _,
_, _, _, _,
_, _,
]) rebuildPayloadForRejectedBlock(
ctx context.Context,
st BeaconStateT,
st *statedb.StateDB,
nextPayloadTimestamp math.U64,
) error {
s.logger.Info("Rebuilding payload for rejected block ⏳ ")
Expand Down Expand Up @@ -141,11 +143,11 @@ func (s *Service[
// handleOptimisticPayloadBuild handles optimistically
// building for the next slot.
func (s *Service[
_, _, _, BeaconBlockT, BeaconStateT, _, _, _,
_, _, _, _, _, _,
]) handleOptimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
blk BeaconBlockT,
st *statedb.StateDB,
blk *ctypes.BeaconBlock,
nextPayloadTimestamp math.U64,
) {
if err := s.optimisticPayloadBuild(
Expand All @@ -164,11 +166,11 @@ func (s *Service[

// optimisticPayloadBuild builds a payload for the next slot.
func (s *Service[
_, _, _, BeaconBlockT, BeaconStateT, _, _, _,
_, _, _, _, _, _,
]) optimisticPayloadBuild(
ctx context.Context,
st BeaconStateT,
blk BeaconBlockT,
st *statedb.StateDB,
blk *ctypes.BeaconBlock,
nextPayloadTimestamp math.U64,
) error {
// We are building for the next slot, so we increment the slot relative
Expand Down
30 changes: 16 additions & 14 deletions beacon/blockchain/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/berachain/beacon-kit/errors"
"github.com/berachain/beacon-kit/primitives/math"
"github.com/berachain/beacon-kit/primitives/transition"
statedb "github.com/berachain/beacon-kit/state-transition/core/state"
cmtabci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -46,19 +47,19 @@ const (
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _,
_, GenesisT, ConsensusSidecarsT,
_, _, ConsensusBlockT, _,
GenesisT, ConsensusSidecarsT,
]) ProcessProposal(
ctx sdk.Context,
req *cmtabci.ProcessProposalRequest,
) (*cmtabci.ProcessProposalResponse, error) {
// Decode the beacon block.
blk, err := encoding.
UnmarshalBeaconBlockFromABCIRequest[BeaconBlockT](
req,
BeaconBlockTxIndex,
s.chainSpec.ActiveForkVersionForSlot(math.U64(req.Height)),
)
UnmarshalBeaconBlockFromABCIRequest(
req,
BeaconBlockTxIndex,
s.chainSpec.ActiveForkVersionForSlot(math.U64(req.Height)),
)
if err != nil {
return createProcessProposalResponse(errors.WrapNonFatal(err))
}
Expand Down Expand Up @@ -124,7 +125,7 @@ func (s *Service[
}

// Process the block
var consensusBlk *types.ConsensusBlock[BeaconBlockT]
var consensusBlk *types.ConsensusBlock
consensusBlk = consensusBlk.New(
blk,
req.GetProposerAddress(),
Expand All @@ -147,11 +148,11 @@ func (s *Service[
// VerifyIncomingBlock verifies the state root of an incoming block
// and logs the process.
func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _,
_, _, ConsensusBlockT, _,
_, _,
]) VerifyIncomingBlock(
ctx context.Context,
beaconBlk BeaconBlockT,
beaconBlk *ctypes.BeaconBlock,
consensusTime math.U64,
proposerAddress []byte,
) error {
Expand Down Expand Up @@ -181,6 +182,7 @@ func (s *Service[
// to avoid modifying the underlying state, for the event in which
// we have to rebuild a payload for this slot again, if we do not agree
// with the incoming block.
//nolint:contextcheck // TODO: We should look at using the passed context
postState := preState.Copy()

// Verify the state root of the incoming block.
Expand Down Expand Up @@ -250,12 +252,12 @@ func (s *Service[

// verifyStateRoot verifies the state root of an incoming block.
func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, BeaconStateT,
_, _, ConsensusBlockT,
_, _, _,
]) verifyStateRoot(
ctx context.Context,
st BeaconStateT,
blk BeaconBlockT,
st *statedb.StateDB,
blk *ctypes.BeaconBlock,
consensusTime math.U64,
proposerAddress []byte,
) error {
Expand Down Expand Up @@ -290,7 +292,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
4 changes: 2 additions & 2 deletions beacon/blockchain/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
)

func (s *Service[
_, _, ConsensusBlockT, BeaconBlockT, _, _, _, _,
]) processPruning(beaconBlk BeaconBlockT) error {
_, _, ConsensusBlockT, _, _, _,
]) processPruning(beaconBlk *ctypes.BeaconBlock) error {
// prune availability store
start, end := availabilityPruneRangeFn(
beaconBlk.GetSlot().Unwrap(), s.chainSpec)
Expand Down
Loading

0 comments on commit 7e5f02d

Please sign in to comment.