diff --git a/beacon/blockchain/deposit.go b/beacon/blockchain/deposit.go index 7c0a899f09..914be8be1c 100644 --- a/beacon/blockchain/deposit.go +++ b/beacon/blockchain/deposit.go @@ -34,7 +34,7 @@ import ( const defaultRetryInterval = 20 * time.Second func (s *Service[ - _, _, ConsensusBlockT, _, _, _, _, _, + _, _, ConsensusBlockT, _, _, _, ]) depositFetcher( ctx context.Context, blockNum math.U64, @@ -52,7 +52,7 @@ func (s *Service[ } func (s *Service[ - _, _, ConsensusBlockT, _, _, _, _, _, + _, _, ConsensusBlockT, _, _, _, ]) fetchAndStoreDeposits( ctx context.Context, blockNum math.U64, @@ -92,7 +92,7 @@ func (s *Service[ } func (s *Service[ - _, _, ConsensusBlockT, _, _, _, _, _, + _, _, ConsensusBlockT, _, _, _, ]) depositCatchupFetcher(ctx context.Context) { ticker := time.NewTicker(defaultRetryInterval) defer ticker.Stop() diff --git a/beacon/blockchain/execution_engine.go b/beacon/blockchain/execution_engine.go index 71705f2fd3..0431e2f4c1 100644 --- a/beacon/blockchain/execution_engine.go +++ b/beacon/blockchain/execution_engine.go @@ -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 @@ -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() diff --git a/beacon/blockchain/finalize_block.go b/beacon/blockchain/finalize_block.go index bc8af76283..4d5e930456 100644 --- a/beacon/blockchain/finalize_block.go +++ b/beacon/blockchain/finalize_block.go @@ -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, @@ -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 @@ -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(), @@ -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() @@ -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() diff --git a/beacon/blockchain/init_chain.go b/beacon/blockchain/init_chain.go index a9b7714b19..3ba429dec1 100644 --- a/beacon/blockchain/init_chain.go +++ b/beacon/blockchain/init_chain.go @@ -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, diff --git a/beacon/blockchain/payload.go b/beacon/blockchain/payload.go index 3948a84e46..98864a82e3 100644 --- a/beacon/blockchain/payload.go +++ b/beacon/blockchain/payload.go @@ -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 { @@ -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( @@ -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 ⏳ ") @@ -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( @@ -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 diff --git a/beacon/blockchain/process_proposal.go b/beacon/blockchain/process_proposal.go index 98e5c0bef6..5fed102423 100644 --- a/beacon/blockchain/process_proposal.go +++ b/beacon/blockchain/process_proposal.go @@ -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" ) @@ -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)) } @@ -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(), @@ -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 { @@ -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. @@ -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 { @@ -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() } diff --git a/beacon/blockchain/pruning.go b/beacon/blockchain/pruning.go index 46b53db302..4e14ade220 100644 --- a/beacon/blockchain/pruning.go +++ b/beacon/blockchain/pruning.go @@ -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) diff --git a/beacon/blockchain/service.go b/beacon/blockchain/service.go index f4a50fb66b..9032ea111c 100644 --- a/beacon/blockchain/service.go +++ b/beacon/blockchain/service.go @@ -38,17 +38,15 @@ import ( type Service[ AvailabilityStoreT AvailabilityStore, DepositStoreT backend.DepositStore, - ConsensusBlockT ConsensusBlock[BeaconBlockT], - BeaconBlockT BeaconBlock[BeaconBlockT], - BeaconStateT ReadOnlyBeaconState[BeaconStateT], - BlockStoreT blockstore.BlockStore[BeaconBlockT], + ConsensusBlockT ConsensusBlock, + BlockStoreT blockstore.BlockStore, GenesisT Genesis, ConsensusSidecarsT da.ConsensusSidecars, ] struct { // homeDir is the directory for config and data" homeDir string // storageBackend represents the backend storage for not state-enforced data. - storageBackend StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] + storageBackend StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT] // blobProcessor is used for processing sidecars. blobProcessor da.BlobProcessor[AvailabilityStoreT, ConsensusSidecarsT] // depositContract is the contract interface for interacting with the @@ -70,9 +68,9 @@ type Service[ // execution payloads. executionEngine ExecutionEngine // localBuilder is a local builder for constructing new beacon states. - localBuilder LocalBuilder[BeaconStateT] + localBuilder LocalBuilder // stateProcessor is the state processor for beacon blocks and states. - stateProcessor StateProcessor[BeaconBlockT, BeaconStateT, *transition.Context] + stateProcessor StateProcessor[*transition.Context] // metrics is the metrics for the service. metrics *chainMetrics // optimisticPayloadBuilds is a flag used when the optimistic payload @@ -86,36 +84,41 @@ type Service[ func NewService[ AvailabilityStoreT AvailabilityStore, DepositStoreT backend.DepositStore, - ConsensusBlockT ConsensusBlock[BeaconBlockT], - BeaconBlockT BeaconBlock[BeaconBlockT], - BeaconStateT ReadOnlyBeaconState[BeaconStateT], - BlockStoreT blockstore.BlockStore[BeaconBlockT], + ConsensusBlockT ConsensusBlock, + BlockStoreT blockstore.BlockStore, GenesisT Genesis, ConsensusSidecarsT da.ConsensusSidecars, ]( homeDir string, - storageBackend StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT], - blobProcessor da.BlobProcessor[AvailabilityStoreT, ConsensusSidecarsT], + storageBackend StorageBackend[ + AvailabilityStoreT, + BlockStoreT, + DepositStoreT, + ], + blobProcessor da.BlobProcessor[ + AvailabilityStoreT, + ConsensusSidecarsT, + ], depositContract deposit.Contract, eth1FollowDistance math.U64, logger log.Logger, chainSpec chain.ChainSpec, executionEngine ExecutionEngine, - localBuilder LocalBuilder[BeaconStateT], - stateProcessor StateProcessor[BeaconBlockT, BeaconStateT, *transition.Context], + localBuilder LocalBuilder, + stateProcessor StateProcessor[*transition.Context], telemetrySink TelemetrySink, optimisticPayloadBuilds bool, ) *Service[ AvailabilityStoreT, DepositStoreT, - ConsensusBlockT, BeaconBlockT, - BeaconStateT, BlockStoreT, + ConsensusBlockT, + BlockStoreT, GenesisT, ConsensusSidecarsT, ] { return &Service[ AvailabilityStoreT, DepositStoreT, - ConsensusBlockT, BeaconBlockT, - BeaconStateT, BlockStoreT, + ConsensusBlockT, + BlockStoreT, GenesisT, ConsensusSidecarsT, ]{ homeDir: homeDir, @@ -137,13 +140,13 @@ func NewService[ // Name returns the name of the service. func (s *Service[ - _, _, _, _, _, _, _, _, + _, _, _, _, _, _, ]) Name() string { return "blockchain" } func (s *Service[ - _, _, _, _, _, _, _, _, + _, _, _, _, _, _, ]) Start(ctx context.Context) error { // Catchup deposits for failed blocks. go s.depositCatchupFetcher(ctx) @@ -152,7 +155,7 @@ func (s *Service[ } func (s *Service[ - _, _, _, _, _, _, _, _, + _, _, _, _, _, _, ]) Stop() error { return nil } diff --git a/beacon/blockchain/types.go b/beacon/blockchain/types.go index daf5e16177..418a7c6965 100644 --- a/beacon/blockchain/types.go +++ b/beacon/blockchain/types.go @@ -31,6 +31,7 @@ import ( "github.com/berachain/beacon-kit/primitives/crypto" "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" ) @@ -48,8 +49,8 @@ type AvailabilityStore interface { Prune(start, end uint64) error } -type ConsensusBlock[BeaconBlockT any] interface { - GetBeaconBlock() BeaconBlockT +type ConsensusBlock interface { + GetBeaconBlock() *ctypes.BeaconBlock // GetProposerAddress returns the address of the validator // selected by consensus to propose the block @@ -60,22 +61,6 @@ type ConsensusBlock[BeaconBlockT any] interface { GetConsensusTime() math.U64 } -// BeaconBlock represents a beacon block interface. -type BeaconBlock[ - BeaconBlockT any, -] interface { - constraints.SSZMarshallableRootable - constraints.Nillable - // GetSlot returns the slot of the beacon block. - GetSlot() math.Slot - // GetStateRoot returns the state root of the beacon block. - GetStateRoot() common.Root - // GetBody returns the body of the beacon block. - GetBody() *ctypes.BeaconBlockBody - NewFromSSZ([]byte, uint32) (BeaconBlockT, error) - GetHeader() *ctypes.BeaconBlockHeader -} - type BlobSidecars[T any] interface { constraints.SSZMarshallable constraints.Empty[T] @@ -121,13 +106,13 @@ type Genesis interface { } // LocalBuilder is the interface for the builder service. -type LocalBuilder[BeaconStateT any] interface { +type LocalBuilder interface { // Enabled returns true if the local builder is enabled. Enabled() bool // RequestPayloadAsync requests a new payload for the given slot. RequestPayloadAsync( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, timestamp uint64, parentBlockRoot common.Root, @@ -137,7 +122,7 @@ type LocalBuilder[BeaconStateT any] interface { // SendForceHeadFCU sends a force head FCU request. SendForceHeadFCU( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, ) error } @@ -166,30 +151,28 @@ type ReadOnlyBeaconState[ // StateProcessor defines the interface for processing various state transitions // in the beacon chain. type StateProcessor[ - BeaconBlockT, - BeaconStateT, ContextT any, ] interface { // InitializePreminedBeaconStateFromEth1 initializes the premined beacon // state // from the eth1 deposits. InitializePreminedBeaconStateFromEth1( - BeaconStateT, + *statedb.StateDB, ctypes.Deposits, *ctypes.ExecutionPayloadHeader, common.Version, ) (transition.ValidatorUpdates, error) // ProcessSlots processes the state transition for a range of slots. ProcessSlots( - BeaconStateT, math.Slot, + *statedb.StateDB, math.Slot, ) (transition.ValidatorUpdates, error) // Transition processes the state transition for a given block. Transition( ContextT, - BeaconStateT, - BeaconBlockT, + *statedb.StateDB, + *ctypes.BeaconBlock, ) (transition.ValidatorUpdates, error) - GetSidecarVerifierFn(BeaconStateT) ( + GetSidecarVerifierFn(*statedb.StateDB) ( func( blkHeader *ctypes.BeaconBlockHeader, signature crypto.BLSSignature) error, @@ -201,14 +184,13 @@ type StateProcessor[ // required by the beacon node. type StorageBackend[ AvailabilityStoreT any, - BeaconStateT any, BlockStoreT any, DepositStoreT any, ] interface { // AvailabilityStore returns the availability store for the given context. AvailabilityStore() AvailabilityStoreT // StateFromContext retrieves the beacon state from the given context. - StateFromContext(context.Context) BeaconStateT + StateFromContext(context.Context) *statedb.StateDB // DepositStore retrieves the deposit store. DepositStore() DepositStoreT // BlockStore retrieves the block store. diff --git a/beacon/validator/block_builder.go b/beacon/validator/block_builder.go index 2d08a2795d..6d2060d57a 100644 --- a/beacon/validator/block_builder.go +++ b/beacon/validator/block_builder.go @@ -36,18 +36,16 @@ import ( "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" "github.com/berachain/beacon-kit/primitives/version" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // BuildBlockAndSidecars builds a new beacon block. -func (s *Service[ - BeaconBlockT, _, - _, -]) BuildBlockAndSidecars( +func (s *Service[_]) BuildBlockAndSidecars( ctx context.Context, slotData types.SlotData, ) ([]byte, []byte, error) { var ( - blk BeaconBlockT + blk *ctypes.BeaconBlock sidecars datypes.BlobSidecars forkData *ctypes.ForkData ) @@ -149,12 +147,10 @@ func (s *Service[ } // getEmptyBeaconBlockForSlot creates a new empty block. -func (s *Service[ - BeaconBlockT, BeaconStateT, _, -]) getEmptyBeaconBlockForSlot( - st BeaconStateT, requestedSlot math.Slot, -) (BeaconBlockT, error) { - var blk BeaconBlockT +func (s *Service[_]) getEmptyBeaconBlockForSlot( + st *statedb.StateDB, requestedSlot math.Slot, +) (*ctypes.BeaconBlock, error) { + var blk *ctypes.BeaconBlock // Create a new block. parentBlockRoot, err := st.GetBlockRootAtIndex( (requestedSlot.Unwrap() - 1) % s.chainSpec.SlotsPerHistoricalRoot(), @@ -180,10 +176,8 @@ func (s *Service[ ) } -func (s *Service[ - _, BeaconStateT, _, -]) buildForkData( - st BeaconStateT, +func (s *Service[_]) buildForkData( + st *statedb.StateDB, slot math.Slot, ) (*ctypes.ForkData, error) { var ( @@ -204,9 +198,7 @@ func (s *Service[ } // buildRandaoReveal builds a randao reveal for the given slot. -func (s *Service[ - _, BeaconStateT, _, -]) buildRandaoReveal( +func (s *Service[_]) buildRandaoReveal( forkData *ctypes.ForkData, slot math.Slot, ) (crypto.BLSSignature, error) { @@ -219,12 +211,10 @@ func (s *Service[ } // retrieveExecutionPayload retrieves the execution payload for the block. -func (s *Service[ - BeaconBlockT, BeaconStateT, _, -]) retrieveExecutionPayload( +func (s *Service[_]) retrieveExecutionPayload( ctx context.Context, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, slotData types.SlotData, ) (ctypes.BuiltExecutionPayloadEnv, error) { // @@ -279,12 +269,10 @@ func (s *Service[ } // BuildBlockBody assembles the block body with necessary components. -func (s *Service[ - BeaconBlockT, BeaconStateT, _, -]) buildBlockBody( +func (s *Service[_]) buildBlockBody( _ context.Context, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, reveal crypto.BLSSignature, envelope ctypes.BuiltExecutionPayloadEnv, slotData types.SlotData, @@ -363,14 +351,12 @@ func (s *Service[ // computeAndSetStateRoot computes the state root of an outgoing block // and sets it in the block. -func (s *Service[ - BeaconBlockT, BeaconStateT, _, -]) computeAndSetStateRoot( +func (s *Service[_]) computeAndSetStateRoot( ctx context.Context, proposerAddress []byte, consensusTime math.U64, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, ) error { stateRoot, err := s.computeStateRoot( ctx, @@ -392,14 +378,12 @@ func (s *Service[ } // computeStateRoot computes the state root of an outgoing block. -func (s *Service[ - BeaconBlockT, BeaconStateT, _, -]) computeStateRoot( +func (s *Service[_]) computeStateRoot( ctx context.Context, proposerAddress []byte, consensusTime math.U64, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, ) (common.Root, error) { startTime := time.Now() defer s.metrics.measureStateRootComputationTime(startTime) diff --git a/beacon/validator/service.go b/beacon/validator/service.go index 058dc82366..d709ee7ecf 100644 --- a/beacon/validator/service.go +++ b/beacon/validator/service.go @@ -31,8 +31,6 @@ import ( // Service is responsible for building beacon blocks and sidecars. type Service[ - BeaconBlockT BeaconBlock[BeaconBlockT], - BeaconStateT BeaconState, DepositStoreT DepositStore, ] struct { // cfg is the validator config. @@ -44,55 +42,39 @@ type Service[ // signer is used to retrieve the public key of this node. signer crypto.BLSSigner // blobFactory is used to create blob sidecars for blocks. - blobFactory BlobFactory[BeaconBlockT] + blobFactory BlobFactory // sb is the beacon state backend. - sb StorageBackend[BeaconStateT, DepositStoreT] + sb StorageBackend[DepositStoreT] // stateProcessor is responsible for processing the state. - stateProcessor StateProcessor[ - BeaconBlockT, - BeaconStateT, - *transition.Context, - ] + stateProcessor StateProcessor[*transition.Context] // localPayloadBuilder represents the local block builder, this builder // is connected to this nodes execution client via the EngineAPI. // Building blocks are done by submitting forkchoice updates through. // The local Builder. - localPayloadBuilder PayloadBuilder[BeaconStateT] + localPayloadBuilder PayloadBuilder // remotePayloadBuilders represents a list of remote block builders, these // builders are connected to other execution clients via the EngineAPI. - remotePayloadBuilders []PayloadBuilder[BeaconStateT] + remotePayloadBuilders []PayloadBuilder // metrics is a metrics collector. metrics *validatorMetrics } // NewService creates a new validator service. func NewService[ - BeaconBlockT BeaconBlock[BeaconBlockT], - BeaconStateT BeaconState, DepositStoreT DepositStore, ]( cfg *Config, logger log.Logger, chainSpec chain.ChainSpec, - sb StorageBackend[BeaconStateT, DepositStoreT], - stateProcessor StateProcessor[ - BeaconBlockT, - BeaconStateT, - *transition.Context, - ], + sb StorageBackend[DepositStoreT], + stateProcessor StateProcessor[*transition.Context], signer crypto.BLSSigner, - blobFactory BlobFactory[BeaconBlockT], - localPayloadBuilder PayloadBuilder[BeaconStateT], - remotePayloadBuilders []PayloadBuilder[BeaconStateT], + blobFactory BlobFactory, + localPayloadBuilder PayloadBuilder, + remotePayloadBuilders []PayloadBuilder, ts TelemetrySink, -) *Service[ - BeaconBlockT, BeaconStateT, - DepositStoreT, -] { - return &Service[ - BeaconBlockT, - BeaconStateT, DepositStoreT, - ]{ +) *Service[DepositStoreT] { + return &Service[DepositStoreT]{ cfg: cfg, logger: logger, sb: sb, @@ -107,20 +89,16 @@ func NewService[ } // Name returns the name of the service. -func (s *Service[ - _, _, _, -]) Name() string { +func (s *Service[_]) Name() string { return "validator" } -func (s *Service[ - _, _, _, -]) Start( +func (s *Service[_]) Start( _ context.Context, ) error { return nil } -func (s *Service[_, _, _]) Stop() error { +func (s *Service[_]) Stop() error { return nil } diff --git a/beacon/validator/types.go b/beacon/validator/types.go index 73dd14e261..e11212eeb2 100644 --- a/beacon/validator/types.go +++ b/beacon/validator/types.go @@ -33,6 +33,7 @@ import ( "github.com/berachain/beacon-kit/primitives/eip4844" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // BeaconBlock represents a beacon block interface. @@ -103,12 +104,10 @@ type BeaconState interface { } // BlobFactory represents a blob factory interface. -type BlobFactory[ - BeaconBlockT any, -] interface { +type BlobFactory interface { // BuildSidecars builds sidecars for a given block and blobs bundle. BuildSidecars( - blk BeaconBlockT, + blk *ctypes.BeaconBlock, blobs ctypes.BlobsBundle, signer crypto.BLSSigner, forkData *ctypes.ForkData, @@ -142,7 +141,7 @@ type ForkData[T any] interface { // PayloadBuilder represents a service that is responsible for // building eth1 blocks. -type PayloadBuilder[BeaconStateT any] interface { +type PayloadBuilder interface { // RetrievePayload retrieves the payload for the given slot. RetrievePayload( ctx context.Context, @@ -153,7 +152,7 @@ type PayloadBuilder[BeaconStateT any] interface { // blocks until the payload is delivered. RequestPayloadSync( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, timestamp uint64, parentBlockRoot common.Root, @@ -180,31 +179,28 @@ type SlotData interface { // StateProcessor defines the interface for processing the state. type StateProcessor[ - BeaconBlockT any, - BeaconStateT any, ContextT any, ] interface { // ProcessSlot processes the slot. ProcessSlots( - st BeaconStateT, slot math.Slot, + st *statedb.StateDB, slot math.Slot, ) (transition.ValidatorUpdates, error) // Transition performs the core state transition. Transition( ctx ContextT, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, ) (transition.ValidatorUpdates, error) } // StorageBackend is the interface for the storage backend. type StorageBackend[ - BeaconStateT any, DepositStoreT any, ] interface { // DepositStore retrieves the deposit store. DepositStore() DepositStoreT // StateFromContext retrieves the beacon state from the context. - StateFromContext(context.Context) BeaconStateT + StateFromContext(context.Context) *statedb.StateDB } // TelemetrySink is an interface for sending metrics to a telemetry backend. diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index f86ee44892..2fed9e59f1 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -24,16 +24,12 @@ import ( "github.com/berachain/beacon-kit/node-core/components" ) -//nolint:funlen func DefaultComponents() []any { c := []any{ - components.ProvideAttributesFactory[ - *BeaconState, *BeaconStateMarshallable, - *KVStore, *Logger, - ], + components.ProvideAttributesFactory[*Logger], components.ProvideAvailibilityStore[*Logger], components.ProvideDepositContract, - components.ProvideBlockStore[*BeaconBlock, *Logger], + components.ProvideBlockStore[*Logger], components.ProvideBlsSigner, components.ProvideBlobProcessor[ *AvailabilityStore, *ConsensusSidecars, *Logger, @@ -41,8 +37,7 @@ func DefaultComponents() []any { components.ProvideBlobProofVerifier, components.ProvideChainService[ *AvailabilityStore, - *ConsensusBlock, *BeaconBlock, - *BeaconState, *BeaconStateMarshallable, + *ConsensusBlock, *ConsensusSidecars, *DepositStore, *DepositContract, *Genesis, @@ -61,38 +56,35 @@ func DefaultComponents() []any { components.ProvideExecutionEngine[*Logger], components.ProvideJWTSecret, components.ProvideLocalBuilder[ - *BeaconState, *BeaconStateMarshallable, *KVStore, *Logger, ], components.ProvideReportingService[*Logger], components.ProvideCometBFTService[*Logger], components.ProvideServiceRegistry[ *AvailabilityStore, - *ConsensusBlock, *BeaconBlock, - *BlockStore, *BeaconState, - *BeaconStateMarshallable, + *ConsensusBlock, + *BlockStore, *ConsensusSidecars, *DepositStore, *Genesis, *KVStore, *Logger, NodeAPIContext, ], - components.ProvideSidecarFactory[*BeaconBlock], + components.ProvideSidecarFactory, components.ProvideStateProcessor[ - *Logger, *BeaconBlock, - *BeaconState, *BeaconStateMarshallable, *DepositStore, + *Logger, + *DepositStore, *KVStore, ], components.ProvideKVStore, components.ProvideStorageBackend[ - *AvailabilityStore, *BlockStore, *BeaconState, + *AvailabilityStore, *BlockStore, *KVStore, *DepositStore, ], components.ProvideTelemetrySink, components.ProvideTelemetryService, components.ProvideTrustedSetup, components.ProvideValidatorService[ - *AvailabilityStore, *BeaconBlock, - *BeaconState, *BeaconStateMarshallable, + *AvailabilityStore, *BlockStore, *DepositStore, *KVStore, *Logger, *StorageBackend, @@ -105,20 +97,18 @@ func DefaultComponents() []any { components.ProvideNodeAPIServer[*Logger, NodeAPIContext], components.ProvideNodeAPIEngine, components.ProvideNodeAPIBackend[ - *AvailabilityStore, *BeaconBlock, - *BlockStore, *BeaconState, - *BeaconStateMarshallable, *DepositStore, + *AvailabilityStore, + *BlockStore, *DepositStore, *KVStore, *CometBFTService, *StorageBackend, ], ) c = append(c, components.ProvideNodeAPIHandlers[ - *BeaconState, *BeaconStateMarshallable, *KVStore, NodeAPIContext, ], components.ProvideNodeAPIBeaconHandler[ - *BeaconState, *CometBFTService, NodeAPIContext, + *CometBFTService, NodeAPIContext, ], components.ProvideNodeAPIBuilderHandler[NodeAPIContext], components.ProvideNodeAPIConfigHandler[NodeAPIContext], @@ -126,7 +116,6 @@ func DefaultComponents() []any { components.ProvideNodeAPIEventsHandler[NodeAPIContext], components.ProvideNodeAPINodeHandler[NodeAPIContext], components.ProvideNodeAPIProofHandler[ - *BeaconState, *BeaconStateMarshallable, *KVStore, *CometBFTService, NodeAPIContext, ], ) diff --git a/cmd/beacond/types.go b/cmd/beacond/types.go index 3780eb2922..04d63d71db 100644 --- a/cmd/beacond/types.go +++ b/cmd/beacond/types.go @@ -43,7 +43,6 @@ import ( payloadbuilder "github.com/berachain/beacon-kit/payload/builder" "github.com/berachain/beacon-kit/primitives/transition" "github.com/berachain/beacon-kit/state-transition/core" - statedb "github.com/berachain/beacon-kit/state-transition/core/state" "github.com/berachain/beacon-kit/storage/beacondb" "github.com/berachain/beacon-kit/storage/block" depositdb "github.com/berachain/beacon-kit/storage/deposit" @@ -57,7 +56,7 @@ import ( type ( // AttributesFactory is a type alias for the attributes factory. - AttributesFactory = attributes.Factory[*BeaconState] + AttributesFactory = attributes.Factory // BlobProcessor is a type alias for the blob processor. BlobProcessor = dablob.Processor[ @@ -70,8 +69,6 @@ type ( *AvailabilityStore, *DepositStore, *ConsensusBlock, - *BeaconBlock, - *BeaconState, *BlockStore, *Genesis, *ConsensusSidecars, @@ -93,7 +90,7 @@ type ( KVStore = beacondb.KVStore // LocalBuilder is a type alias for the local builder. - LocalBuilder = payloadbuilder.PayloadBuilder[*BeaconState] + LocalBuilder = payloadbuilder.PayloadBuilder // NodeAPIEngine is a type alias for the node API engine. NodeAPIEngine = echo.Engine @@ -105,12 +102,10 @@ type ( ReportingService = version.ReportingService // SidecarFactory is a type alias for the sidecar factory. - SidecarFactory = dablob.SidecarFactory[*BeaconBlock] + SidecarFactory = dablob.SidecarFactory // StateProcessor is the type alias for the state processor interface. StateProcessor = core.StateProcessor[ - *BeaconBlock, - *BeaconState, *Context, *KVStore, ] @@ -118,18 +113,13 @@ type ( // StorageBackend is the type alias for the storage backend interface. StorageBackend = storage.Backend[ *AvailabilityStore, - *BeaconState, *BlockStore, *DepositStore, *KVStore, ] // ValidatorService is a type alias for the validator service. - ValidatorService = validator.Service[ - *BeaconBlock, - *BeaconState, - *DepositStore, - ] + ValidatorService = validator.Service[*DepositStore] ) /* -------------------------------------------------------------------------- */ @@ -141,17 +131,7 @@ type ( AvailabilityStore = dastore.Store // BeaconBlock type aliases. - ConsensusBlock = consruntimetypes.ConsensusBlock[*BeaconBlock] - BeaconBlock = types.BeaconBlock - - // BeaconState is a type alias for the BeaconState. - BeaconState = statedb.StateDB[ - *BeaconStateMarshallable, - *KVStore, - ] - - // BeaconStateMarshallable is a type alias for the BeaconState. - BeaconStateMarshallable = types.BeaconState + ConsensusBlock = consruntimetypes.ConsensusBlock // BlobSidecars type aliases. ConsensusSidecars = consruntimetypes.ConsensusSidecars @@ -159,7 +139,7 @@ type ( BlobSidecars = datypes.BlobSidecars // BlockStore is a type alias for the block store. - BlockStore = block.KVStore[*BeaconBlock] + BlockStore = block.KVStore[*types.BeaconBlock] // Context is a type alias for the transition context. Context = transition.Context @@ -197,9 +177,6 @@ type ( // NodeAPIBackend is a type alias for the node API backend. NodeAPIBackend = backend.Backend[ *AvailabilityStore, - *BeaconBlock, - *BeaconState, - *BeaconStateMarshallable, *BlockStore, sdk.Context, *DepositStore, diff --git a/consensus-types/types/block.go b/consensus-types/types/block.go index 02bcd44de2..aee046fea4 100644 --- a/consensus-types/types/block.go +++ b/consensus-types/types/block.go @@ -85,10 +85,10 @@ func (b *BeaconBlock) NewFromSSZ( return block, block.UnmarshalSSZ(bz) } - return nil, errors.Wrap( - ErrForkVersionNotSupported, - fmt.Sprintf("fork %d", forkVersion), - ) + // assign err here to appease nilaway + err := errors.Wrap(ErrForkVersionNotSupported, fmt.Sprintf("fork %d", forkVersion)) + + return nil, err } /* -------------------------------------------------------------------------- */ diff --git a/consensus/cometbft/service/encoding/encoding.go b/consensus/cometbft/service/encoding/encoding.go index e6162d5ede..f3a5d7e84f 100644 --- a/consensus/cometbft/service/encoding/encoding.go +++ b/consensus/cometbft/service/encoding/encoding.go @@ -21,29 +21,28 @@ package encoding import ( + ctypes "github.com/berachain/beacon-kit/consensus-types/types" datypes "github.com/berachain/beacon-kit/da/types" ) // ExtractBlobsAndBlockFromRequest extracts the blobs and block from an ABCI // request. -func ExtractBlobsAndBlockFromRequest[ - BeaconBlockT BeaconBlock[BeaconBlockT], -]( +func ExtractBlobsAndBlockFromRequest( req ABCIRequest, beaconBlkIndex uint, blobSidecarsIndex uint, forkVersion uint32, -) (BeaconBlockT, datypes.BlobSidecars, error) { +) (*ctypes.BeaconBlock, datypes.BlobSidecars, error) { var ( blobs datypes.BlobSidecars - blk BeaconBlockT + blk *ctypes.BeaconBlock ) if req == nil { return blk, blobs, ErrNilABCIRequest } - blk, err := UnmarshalBeaconBlockFromABCIRequest[BeaconBlockT]( + blk, err := UnmarshalBeaconBlockFromABCIRequest( req, beaconBlkIndex, forkVersion, @@ -65,14 +64,12 @@ func ExtractBlobsAndBlockFromRequest[ // UnmarshalBeaconBlockFromABCIRequest extracts a beacon block from an ABCI // request. -func UnmarshalBeaconBlockFromABCIRequest[ - BeaconBlockT BeaconBlock[BeaconBlockT], -]( +func UnmarshalBeaconBlockFromABCIRequest( req ABCIRequest, bzIndex uint, forkVersion uint32, -) (BeaconBlockT, error) { - var blk BeaconBlockT +) (*ctypes.BeaconBlock, error) { + var blk *ctypes.BeaconBlock if req == nil { return blk, ErrNilABCIRequest } diff --git a/consensus/cometbft/service/encoding/types.go b/consensus/cometbft/service/encoding/types.go index e5781be2ab..820769c77e 100644 --- a/consensus/cometbft/service/encoding/types.go +++ b/consensus/cometbft/service/encoding/types.go @@ -22,8 +22,6 @@ package encoding import ( "time" - - "github.com/berachain/beacon-kit/primitives/constraints" ) // ABCIRequest represents the interface for an ABCI request. @@ -35,8 +33,3 @@ type ABCIRequest interface { // GetTxs returns the transactions included in the request. GetTxs() [][]byte } - -type BeaconBlock[T any] interface { - constraints.SSZMarshallable - NewFromSSZ([]byte, uint32) (T, error) -} diff --git a/consensus/types/consensus_block.go b/consensus/types/consensus_block.go index 300bfca4a5..c0e06b834b 100644 --- a/consensus/types/consensus_block.go +++ b/consensus/types/consensus_block.go @@ -23,23 +23,24 @@ package types import ( "time" + "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/primitives/math" ) -type ConsensusBlock[BeaconBlockT any] struct { - blk BeaconBlockT +type ConsensusBlock struct { + blk *types.BeaconBlock // some consensus data useful to build and verify the block *commonConsensusData } // New creates a new ConsensusBlock instance. -func (b *ConsensusBlock[BeaconBlockT]) New( - beaconBlock BeaconBlockT, +func (b *ConsensusBlock) New( + beaconBlock *types.BeaconBlock, proposerAddress []byte, consensusTime time.Time, -) *ConsensusBlock[BeaconBlockT] { - b = &ConsensusBlock[BeaconBlockT]{ +) *ConsensusBlock { + b = &ConsensusBlock{ blk: beaconBlock, commonConsensusData: &commonConsensusData{ proposerAddress: proposerAddress, @@ -49,6 +50,6 @@ func (b *ConsensusBlock[BeaconBlockT]) New( return b } -func (b *ConsensusBlock[BeaconBlockT]) GetBeaconBlock() BeaconBlockT { +func (b *ConsensusBlock) GetBeaconBlock() *types.BeaconBlock { return b.blk } diff --git a/da/blob/factory.go b/da/blob/factory.go index 96ad0dc883..26c578a8e1 100644 --- a/da/blob/factory.go +++ b/da/blob/factory.go @@ -33,9 +33,7 @@ import ( ) // SidecarFactory is a factory for sidecars. -type SidecarFactory[ - BeaconBlockT BeaconBlock, -] struct { +type SidecarFactory struct { // chainSpec defines the specifications of the blockchain. chainSpec ChainSpec // metrics is used to collect and report factory metrics. @@ -43,21 +41,19 @@ type SidecarFactory[ } // NewSidecarFactory creates a new sidecar factory. -func NewSidecarFactory[ - BeaconBlockT BeaconBlock, -]( +func NewSidecarFactory( chainSpec ChainSpec, telemetrySink TelemetrySink, -) *SidecarFactory[BeaconBlockT] { - return &SidecarFactory[BeaconBlockT]{ +) *SidecarFactory { + return &SidecarFactory{ chainSpec: chainSpec, metrics: newFactoryMetrics(telemetrySink), } } // BuildSidecars builds a sidecar. -func (f *SidecarFactory[BeaconBlockT]) BuildSidecars( - blk BeaconBlockT, +func (f *SidecarFactory) BuildSidecars( + blk *ctypes.BeaconBlock, bundle ctypes.BlobsBundle, signer crypto.BLSSigner, forkData *ctypes.ForkData, @@ -131,7 +127,7 @@ func (f *SidecarFactory[BeaconBlockT]) BuildSidecars( } // BuildKZGInclusionProof builds a KZG inclusion proof. -func (f *SidecarFactory[_]) BuildKZGInclusionProof( +func (f *SidecarFactory) BuildKZGInclusionProof( body *ctypes.BeaconBlockBody, index math.U64, kzgPosition uint64, @@ -158,7 +154,7 @@ func (f *SidecarFactory[_]) BuildKZGInclusionProof( } // BuildBlockBodyProof builds a block body proof. -func (f *SidecarFactory[_]) BuildBlockBodyProof( +func (f *SidecarFactory) BuildBlockBodyProof( body *ctypes.BeaconBlockBody, kzgPosition uint64, ) ([]common.Root, error) { @@ -176,7 +172,7 @@ func (f *SidecarFactory[_]) BuildBlockBodyProof( } // BuildCommitmentProof builds a commitment proof. -func (f *SidecarFactory[_]) BuildCommitmentProof( +func (f *SidecarFactory) BuildCommitmentProof( body *ctypes.BeaconBlockBody, index math.U64, ) ([]common.Root, error) { diff --git a/da/blob/types.go b/da/blob/types.go index 96521c5efb..b7cb254c13 100644 --- a/da/blob/types.go +++ b/da/blob/types.go @@ -43,11 +43,6 @@ type AvailabilityStore interface { Persist(math.Slot, datypes.BlobSidecars) error } -type BeaconBlock interface { - GetBody() *ctypes.BeaconBlockBody - GetHeader() *ctypes.BeaconBlockHeader -} - type ConsensusSidecars interface { GetSidecars() datypes.BlobSidecars GetHeader() *ctypes.BeaconBlockHeader diff --git a/da/store/types.go b/da/store/types.go index 6a84d65833..7b64704fa3 100644 --- a/da/store/types.go +++ b/da/store/types.go @@ -20,20 +20,6 @@ package store -import ( - "github.com/berachain/beacon-kit/primitives/math" -) - -// BeaconBlock is an interface for beacon blocks. -type BeaconBlock interface { - GetSlot() math.U64 -} - -// BlockEvent is an interface for block events. -type BlockEvent[BeaconBlockT BeaconBlock] interface { - Data() BeaconBlockT -} - // IndexDB is a database that allows prefixing by index. type IndexDB interface { Has(index uint64, key []byte) (bool, error) diff --git a/node-api/backend/backend.go b/node-api/backend/backend.go index ded4623f7b..24c9b895ef 100644 --- a/node-api/backend/backend.go +++ b/node-api/backend/backend.go @@ -26,6 +26,7 @@ import ( "github.com/berachain/beacon-kit/chain-spec/chain" "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // Backend is the db access layer for the beacon node-api. @@ -33,52 +34,46 @@ import ( // over building the query context for a given state. type Backend[ AvailabilityStoreT AvailabilityStore, - BeaconBlockT any, - BeaconStateT BeaconState, - BeaconStateMarshallableT any, - BlockStoreT BlockStore[BeaconBlockT], + BlockStoreT BlockStore, ContextT context.Context, DepositStoreT DepositStore, NodeT Node[ContextT], StateStoreT any, StorageBackendT StorageBackend[ - AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT, + AvailabilityStoreT, BlockStoreT, DepositStoreT, ], ] struct { sb StorageBackendT cs chain.ChainSpec node NodeT - sp StateProcessor[BeaconStateT] + sp StateProcessor } // New creates and returns a new Backend instance. func New[ AvailabilityStoreT AvailabilityStore, - BeaconBlockT any, - BeaconStateT BeaconState, - BeaconStateMarshallableT any, - BlockStoreT BlockStore[BeaconBlockT], + BlockStoreT BlockStore, ContextT context.Context, DepositStoreT DepositStore, NodeT Node[ContextT], StateStoreT any, StorageBackendT StorageBackend[ - AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT, + AvailabilityStoreT, BlockStoreT, DepositStoreT, ], ]( storageBackend StorageBackendT, cs chain.ChainSpec, - sp StateProcessor[BeaconStateT], + sp StateProcessor, ) *Backend[ - AvailabilityStoreT, BeaconBlockT, - BeaconStateT, BeaconStateMarshallableT, BlockStoreT, + AvailabilityStoreT, + BlockStoreT, ContextT, DepositStoreT, NodeT, StateStoreT, StorageBackendT, ] { return &Backend[ - AvailabilityStoreT, BeaconBlockT, - BeaconStateT, BeaconStateMarshallableT, BlockStoreT, + AvailabilityStoreT, + BlockStoreT, ContextT, DepositStoreT, NodeT, StateStoreT, StorageBackendT, ]{ @@ -91,28 +86,28 @@ func New[ // AttachQueryBackend sets the node on the backend for // querying historical heights. func (b *Backend[ - _, _, _, _, _, _, _, NodeT, _, _, + _, _, _, _, NodeT, _, _, ]) AttachQueryBackend(node NodeT) { b.node = node } // ChainSpec returns the chain spec from the backend. func (b *Backend[ - _, _, _, _, _, _, _, NodeT, _, _, + _, _, _, _, NodeT, _, _, ]) ChainSpec() chain.ChainSpec { return b.cs } // GetSlotByBlockRoot retrieves the slot by a block root from the block store. func (b *Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) GetSlotByBlockRoot(root common.Root) (math.Slot, error) { return b.sb.BlockStore().GetSlotByBlockRoot(root) } // GetSlotByStateRoot retrieves the slot by a state root from the block store. func (b *Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) GetSlotByStateRoot(root common.Root) (math.Slot, error) { return b.sb.BlockStore().GetSlotByStateRoot(root) } @@ -120,7 +115,7 @@ func (b *Backend[ // GetParentSlotByTimestamp retrieves the parent slot by a given timestamp from // the block store. func (b *Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) GetParentSlotByTimestamp(timestamp math.U64) (math.Slot, error) { return b.sb.BlockStore().GetParentSlotByTimestamp(timestamp) } @@ -128,10 +123,10 @@ func (b *Backend[ // stateFromSlot returns the state at the given slot, after also processing the // next slot to ensure the returned beacon state is up to date. func (b *Backend[ - _, _, BeaconStateT, _, _, _, _, _, _, _, -]) stateFromSlot(slot math.Slot) (BeaconStateT, math.Slot, error) { + _, _, _, _, _, _, _, +]) stateFromSlot(slot math.Slot) (*statedb.StateDB, math.Slot, error) { var ( - st BeaconStateT + st *statedb.StateDB err error ) if st, slot, err = b.stateFromSlotRaw(slot); err != nil { @@ -153,9 +148,9 @@ func (b *Backend[ // resolving an input slot of 0 to the latest slot. It does not process the // next slot on the beacon state. func (b *Backend[ - _, _, BeaconStateT, _, _, _, _, _, _, _, -]) stateFromSlotRaw(slot math.Slot) (BeaconStateT, math.Slot, error) { - var st BeaconStateT + _, _, _, _, _, _, _, +]) stateFromSlotRaw(slot math.Slot) (*statedb.StateDB, math.Slot, error) { + var st *statedb.StateDB //#nosec:G701 // not an issue in practice. queryCtx, err := b.node.CreateQueryContext(int64(slot), false) if err != nil { diff --git a/node-api/backend/block.go b/node-api/backend/block.go index 607b3ec390..a1f19a6e0b 100644 --- a/node-api/backend/block.go +++ b/node-api/backend/block.go @@ -29,7 +29,7 @@ import ( // BlockHeader returns the block header at the given slot. func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) BlockHeaderAtSlot(slot math.Slot) (*ctypes.BeaconBlockHeader, error) { var blockHeader *ctypes.BeaconBlockHeader @@ -44,7 +44,7 @@ func (b Backend[ // GetBlockRoot returns the root of the block at the given stateID. func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) BlockRootAtSlot(slot math.Slot) (common.Root, error) { st, slot, err := b.stateFromSlot(slot) if err != nil { @@ -58,7 +58,7 @@ func (b Backend[ // TODO: Implement this. func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) BlockRewardsAtSlot(math.Slot) (*types.BlockRewardsData, error) { return &types.BlockRewardsData{ ProposerIndex: 1, diff --git a/node-api/backend/genesis.go b/node-api/backend/genesis.go index 9fb6c1c013..b4c86527aa 100644 --- a/node-api/backend/genesis.go +++ b/node-api/backend/genesis.go @@ -27,7 +27,7 @@ import ( // GetGenesis returns the genesis state of the beacon chain. func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) GenesisValidatorsRoot(slot math.Slot) (common.Root, error) { // needs genesis_time and gensis_fork_version st, _, err := b.stateFromSlot(slot) diff --git a/node-api/backend/mocks/block_store.mock.go b/node-api/backend/mocks/block_store.mock.go index cba25b2384..c7bf467930 100644 --- a/node-api/backend/mocks/block_store.mock.go +++ b/node-api/backend/mocks/block_store.mock.go @@ -10,20 +10,20 @@ import ( ) // BlockStore is an autogenerated mock type for the BlockStore type -type BlockStore[BeaconBlockT any] struct { +type BlockStore struct { mock.Mock } -type BlockStore_Expecter[BeaconBlockT any] struct { +type BlockStore_Expecter struct { mock *mock.Mock } -func (_m *BlockStore[BeaconBlockT]) EXPECT() *BlockStore_Expecter[BeaconBlockT] { - return &BlockStore_Expecter[BeaconBlockT]{mock: &_m.Mock} +func (_m *BlockStore) EXPECT() *BlockStore_Expecter { + return &BlockStore_Expecter{mock: &_m.Mock} } // GetParentSlotByTimestamp provides a mock function with given fields: timestamp -func (_m *BlockStore[BeaconBlockT]) GetParentSlotByTimestamp(timestamp math.U64) (math.U64, error) { +func (_m *BlockStore) GetParentSlotByTimestamp(timestamp math.U64) (math.U64, error) { ret := _m.Called(timestamp) if len(ret) == 0 { @@ -51,35 +51,35 @@ func (_m *BlockStore[BeaconBlockT]) GetParentSlotByTimestamp(timestamp math.U64) } // BlockStore_GetParentSlotByTimestamp_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetParentSlotByTimestamp' -type BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT any] struct { +type BlockStore_GetParentSlotByTimestamp_Call struct { *mock.Call } // GetParentSlotByTimestamp is a helper method to define mock.On call // - timestamp math.U64 -func (_e *BlockStore_Expecter[BeaconBlockT]) GetParentSlotByTimestamp(timestamp interface{}) *BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT] { - return &BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT]{Call: _e.mock.On("GetParentSlotByTimestamp", timestamp)} +func (_e *BlockStore_Expecter) GetParentSlotByTimestamp(timestamp interface{}) *BlockStore_GetParentSlotByTimestamp_Call { + return &BlockStore_GetParentSlotByTimestamp_Call{Call: _e.mock.On("GetParentSlotByTimestamp", timestamp)} } -func (_c *BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT]) Run(run func(timestamp math.U64)) *BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT] { +func (_c *BlockStore_GetParentSlotByTimestamp_Call) Run(run func(timestamp math.U64)) *BlockStore_GetParentSlotByTimestamp_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(math.U64)) }) return _c } -func (_c *BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT]) Return(_a0 math.U64, _a1 error) *BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT] { +func (_c *BlockStore_GetParentSlotByTimestamp_Call) Return(_a0 math.U64, _a1 error) *BlockStore_GetParentSlotByTimestamp_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT]) RunAndReturn(run func(math.U64) (math.U64, error)) *BlockStore_GetParentSlotByTimestamp_Call[BeaconBlockT] { +func (_c *BlockStore_GetParentSlotByTimestamp_Call) RunAndReturn(run func(math.U64) (math.U64, error)) *BlockStore_GetParentSlotByTimestamp_Call { _c.Call.Return(run) return _c } // GetSlotByBlockRoot provides a mock function with given fields: root -func (_m *BlockStore[BeaconBlockT]) GetSlotByBlockRoot(root common.Root) (math.U64, error) { +func (_m *BlockStore) GetSlotByBlockRoot(root common.Root) (math.U64, error) { ret := _m.Called(root) if len(ret) == 0 { @@ -107,35 +107,35 @@ func (_m *BlockStore[BeaconBlockT]) GetSlotByBlockRoot(root common.Root) (math.U } // BlockStore_GetSlotByBlockRoot_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSlotByBlockRoot' -type BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT any] struct { +type BlockStore_GetSlotByBlockRoot_Call struct { *mock.Call } // GetSlotByBlockRoot is a helper method to define mock.On call // - root common.Root -func (_e *BlockStore_Expecter[BeaconBlockT]) GetSlotByBlockRoot(root interface{}) *BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT] { - return &BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT]{Call: _e.mock.On("GetSlotByBlockRoot", root)} +func (_e *BlockStore_Expecter) GetSlotByBlockRoot(root interface{}) *BlockStore_GetSlotByBlockRoot_Call { + return &BlockStore_GetSlotByBlockRoot_Call{Call: _e.mock.On("GetSlotByBlockRoot", root)} } -func (_c *BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT]) Run(run func(root common.Root)) *BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT] { +func (_c *BlockStore_GetSlotByBlockRoot_Call) Run(run func(root common.Root)) *BlockStore_GetSlotByBlockRoot_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(common.Root)) }) return _c } -func (_c *BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT]) Return(_a0 math.U64, _a1 error) *BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT] { +func (_c *BlockStore_GetSlotByBlockRoot_Call) Return(_a0 math.U64, _a1 error) *BlockStore_GetSlotByBlockRoot_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT]) RunAndReturn(run func(common.Root) (math.U64, error)) *BlockStore_GetSlotByBlockRoot_Call[BeaconBlockT] { +func (_c *BlockStore_GetSlotByBlockRoot_Call) RunAndReturn(run func(common.Root) (math.U64, error)) *BlockStore_GetSlotByBlockRoot_Call { _c.Call.Return(run) return _c } // GetSlotByStateRoot provides a mock function with given fields: root -func (_m *BlockStore[BeaconBlockT]) GetSlotByStateRoot(root common.Root) (math.U64, error) { +func (_m *BlockStore) GetSlotByStateRoot(root common.Root) (math.U64, error) { ret := _m.Called(root) if len(ret) == 0 { @@ -163,40 +163,40 @@ func (_m *BlockStore[BeaconBlockT]) GetSlotByStateRoot(root common.Root) (math.U } // BlockStore_GetSlotByStateRoot_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSlotByStateRoot' -type BlockStore_GetSlotByStateRoot_Call[BeaconBlockT any] struct { +type BlockStore_GetSlotByStateRoot_Call struct { *mock.Call } // GetSlotByStateRoot is a helper method to define mock.On call // - root common.Root -func (_e *BlockStore_Expecter[BeaconBlockT]) GetSlotByStateRoot(root interface{}) *BlockStore_GetSlotByStateRoot_Call[BeaconBlockT] { - return &BlockStore_GetSlotByStateRoot_Call[BeaconBlockT]{Call: _e.mock.On("GetSlotByStateRoot", root)} +func (_e *BlockStore_Expecter) GetSlotByStateRoot(root interface{}) *BlockStore_GetSlotByStateRoot_Call { + return &BlockStore_GetSlotByStateRoot_Call{Call: _e.mock.On("GetSlotByStateRoot", root)} } -func (_c *BlockStore_GetSlotByStateRoot_Call[BeaconBlockT]) Run(run func(root common.Root)) *BlockStore_GetSlotByStateRoot_Call[BeaconBlockT] { +func (_c *BlockStore_GetSlotByStateRoot_Call) Run(run func(root common.Root)) *BlockStore_GetSlotByStateRoot_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(common.Root)) }) return _c } -func (_c *BlockStore_GetSlotByStateRoot_Call[BeaconBlockT]) Return(_a0 math.U64, _a1 error) *BlockStore_GetSlotByStateRoot_Call[BeaconBlockT] { +func (_c *BlockStore_GetSlotByStateRoot_Call) Return(_a0 math.U64, _a1 error) *BlockStore_GetSlotByStateRoot_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *BlockStore_GetSlotByStateRoot_Call[BeaconBlockT]) RunAndReturn(run func(common.Root) (math.U64, error)) *BlockStore_GetSlotByStateRoot_Call[BeaconBlockT] { +func (_c *BlockStore_GetSlotByStateRoot_Call) RunAndReturn(run func(common.Root) (math.U64, error)) *BlockStore_GetSlotByStateRoot_Call { _c.Call.Return(run) return _c } // NewBlockStore creates a new instance of BlockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. -func NewBlockStore[BeaconBlockT any](t interface { +func NewBlockStore(t interface { mock.TestingT Cleanup(func()) -}) *BlockStore[BeaconBlockT] { - mock := &BlockStore[BeaconBlockT]{} +}) *BlockStore { + mock := &BlockStore{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/node-api/backend/mocks/state_processor.mock.go b/node-api/backend/mocks/state_processor.mock.go index ae41842911..988a1309fa 100644 --- a/node-api/backend/mocks/state_processor.mock.go +++ b/node-api/backend/mocks/state_processor.mock.go @@ -6,24 +6,25 @@ import ( math "github.com/berachain/beacon-kit/primitives/math" mock "github.com/stretchr/testify/mock" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" transition "github.com/berachain/beacon-kit/primitives/transition" ) // StateProcessor is an autogenerated mock type for the StateProcessor type -type StateProcessor[BeaconStateT any] struct { +type StateProcessor struct { mock.Mock } -type StateProcessor_Expecter[BeaconStateT any] struct { +type StateProcessor_Expecter struct { mock *mock.Mock } -func (_m *StateProcessor[BeaconStateT]) EXPECT() *StateProcessor_Expecter[BeaconStateT] { - return &StateProcessor_Expecter[BeaconStateT]{mock: &_m.Mock} +func (_m *StateProcessor) EXPECT() *StateProcessor_Expecter { + return &StateProcessor_Expecter{mock: &_m.Mock} } // ProcessSlots provides a mock function with given fields: _a0, _a1 -func (_m *StateProcessor[BeaconStateT]) ProcessSlots(_a0 BeaconStateT, _a1 math.U64) (transition.ValidatorUpdates, error) { +func (_m *StateProcessor) ProcessSlots(_a0 *statedb.StateDB, _a1 math.U64) (transition.ValidatorUpdates, error) { ret := _m.Called(_a0, _a1) if len(ret) == 0 { @@ -32,10 +33,10 @@ func (_m *StateProcessor[BeaconStateT]) ProcessSlots(_a0 BeaconStateT, _a1 math. var r0 transition.ValidatorUpdates var r1 error - if rf, ok := ret.Get(0).(func(BeaconStateT, math.U64) (transition.ValidatorUpdates, error)); ok { + if rf, ok := ret.Get(0).(func(*statedb.StateDB, math.U64) (transition.ValidatorUpdates, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(BeaconStateT, math.U64) transition.ValidatorUpdates); ok { + if rf, ok := ret.Get(0).(func(*statedb.StateDB, math.U64) transition.ValidatorUpdates); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { @@ -43,7 +44,7 @@ func (_m *StateProcessor[BeaconStateT]) ProcessSlots(_a0 BeaconStateT, _a1 math. } } - if rf, ok := ret.Get(1).(func(BeaconStateT, math.U64) error); ok { + if rf, ok := ret.Get(1).(func(*statedb.StateDB, math.U64) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -53,41 +54,41 @@ func (_m *StateProcessor[BeaconStateT]) ProcessSlots(_a0 BeaconStateT, _a1 math. } // StateProcessor_ProcessSlots_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ProcessSlots' -type StateProcessor_ProcessSlots_Call[BeaconStateT any] struct { +type StateProcessor_ProcessSlots_Call struct { *mock.Call } // ProcessSlots is a helper method to define mock.On call -// - _a0 BeaconStateT +// - _a0 *statedb.StateDB // - _a1 math.U64 -func (_e *StateProcessor_Expecter[BeaconStateT]) ProcessSlots(_a0 interface{}, _a1 interface{}) *StateProcessor_ProcessSlots_Call[BeaconStateT] { - return &StateProcessor_ProcessSlots_Call[BeaconStateT]{Call: _e.mock.On("ProcessSlots", _a0, _a1)} +func (_e *StateProcessor_Expecter) ProcessSlots(_a0 interface{}, _a1 interface{}) *StateProcessor_ProcessSlots_Call { + return &StateProcessor_ProcessSlots_Call{Call: _e.mock.On("ProcessSlots", _a0, _a1)} } -func (_c *StateProcessor_ProcessSlots_Call[BeaconStateT]) Run(run func(_a0 BeaconStateT, _a1 math.U64)) *StateProcessor_ProcessSlots_Call[BeaconStateT] { +func (_c *StateProcessor_ProcessSlots_Call) Run(run func(_a0 *statedb.StateDB, _a1 math.U64)) *StateProcessor_ProcessSlots_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(BeaconStateT), args[1].(math.U64)) + run(args[0].(*statedb.StateDB), args[1].(math.U64)) }) return _c } -func (_c *StateProcessor_ProcessSlots_Call[BeaconStateT]) Return(_a0 transition.ValidatorUpdates, _a1 error) *StateProcessor_ProcessSlots_Call[BeaconStateT] { +func (_c *StateProcessor_ProcessSlots_Call) Return(_a0 transition.ValidatorUpdates, _a1 error) *StateProcessor_ProcessSlots_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *StateProcessor_ProcessSlots_Call[BeaconStateT]) RunAndReturn(run func(BeaconStateT, math.U64) (transition.ValidatorUpdates, error)) *StateProcessor_ProcessSlots_Call[BeaconStateT] { +func (_c *StateProcessor_ProcessSlots_Call) RunAndReturn(run func(*statedb.StateDB, math.U64) (transition.ValidatorUpdates, error)) *StateProcessor_ProcessSlots_Call { _c.Call.Return(run) return _c } // NewStateProcessor creates a new instance of StateProcessor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. -func NewStateProcessor[BeaconStateT any](t interface { +func NewStateProcessor(t interface { mock.TestingT Cleanup(func()) -}) *StateProcessor[BeaconStateT] { - mock := &StateProcessor[BeaconStateT]{} +}) *StateProcessor { + mock := &StateProcessor{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/node-api/backend/mocks/storage_backend.mock.go b/node-api/backend/mocks/storage_backend.mock.go index 2992bb6e90..472656ead1 100644 --- a/node-api/backend/mocks/storage_backend.mock.go +++ b/node-api/backend/mocks/storage_backend.mock.go @@ -5,24 +5,25 @@ package mocks import ( context "context" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" mock "github.com/stretchr/testify/mock" ) // StorageBackend is an autogenerated mock type for the StorageBackend type -type StorageBackend[AvailabilityStoreT any, BeaconStateT any, BlockStoreT any, DepositStoreT any] struct { +type StorageBackend[AvailabilityStoreT any, BlockStoreT any, DepositStoreT any] struct { mock.Mock } -type StorageBackend_Expecter[AvailabilityStoreT any, BeaconStateT any, BlockStoreT any, DepositStoreT any] struct { +type StorageBackend_Expecter[AvailabilityStoreT any, BlockStoreT any, DepositStoreT any] struct { mock *mock.Mock } -func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) EXPECT() *StorageBackend_Expecter[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { - return &StorageBackend_Expecter[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]{mock: &_m.Mock} +func (_m *StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT]) EXPECT() *StorageBackend_Expecter[AvailabilityStoreT, BlockStoreT, DepositStoreT] { + return &StorageBackend_Expecter[AvailabilityStoreT, BlockStoreT, DepositStoreT]{mock: &_m.Mock} } // AvailabilityStore provides a mock function with given fields: -func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) AvailabilityStore() AvailabilityStoreT { +func (_m *StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT]) AvailabilityStore() AvailabilityStoreT { ret := _m.Called() if len(ret) == 0 { @@ -42,34 +43,34 @@ func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositS } // StorageBackend_AvailabilityStore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AvailabilityStore' -type StorageBackend_AvailabilityStore_Call[AvailabilityStoreT any, BeaconStateT any, BlockStoreT any, DepositStoreT any] struct { +type StorageBackend_AvailabilityStore_Call[AvailabilityStoreT any, BlockStoreT any, DepositStoreT any] struct { *mock.Call } // AvailabilityStore is a helper method to define mock.On call -func (_e *StorageBackend_Expecter[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) AvailabilityStore() *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { - return &StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]{Call: _e.mock.On("AvailabilityStore")} +func (_e *StorageBackend_Expecter[AvailabilityStoreT, BlockStoreT, DepositStoreT]) AvailabilityStore() *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { + return &StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]{Call: _e.mock.On("AvailabilityStore")} } -func (_c *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) Run(run func()) *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) Run(run func()) *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Run(func(args mock.Arguments) { run() }) return _c } -func (_c *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) Return(_a0 AvailabilityStoreT) *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) Return(_a0 AvailabilityStoreT) *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Return(_a0) return _c } -func (_c *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) RunAndReturn(run func() AvailabilityStoreT) *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) RunAndReturn(run func() AvailabilityStoreT) *StorageBackend_AvailabilityStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Return(run) return _c } // BlockStore provides a mock function with given fields: -func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) BlockStore() BlockStoreT { +func (_m *StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT]) BlockStore() BlockStoreT { ret := _m.Called() if len(ret) == 0 { @@ -89,34 +90,34 @@ func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositS } // StorageBackend_BlockStore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BlockStore' -type StorageBackend_BlockStore_Call[AvailabilityStoreT any, BeaconStateT any, BlockStoreT any, DepositStoreT any] struct { +type StorageBackend_BlockStore_Call[AvailabilityStoreT any, BlockStoreT any, DepositStoreT any] struct { *mock.Call } // BlockStore is a helper method to define mock.On call -func (_e *StorageBackend_Expecter[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) BlockStore() *StorageBackend_BlockStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { - return &StorageBackend_BlockStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]{Call: _e.mock.On("BlockStore")} +func (_e *StorageBackend_Expecter[AvailabilityStoreT, BlockStoreT, DepositStoreT]) BlockStore() *StorageBackend_BlockStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { + return &StorageBackend_BlockStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]{Call: _e.mock.On("BlockStore")} } -func (_c *StorageBackend_BlockStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) Run(run func()) *StorageBackend_BlockStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_BlockStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) Run(run func()) *StorageBackend_BlockStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Run(func(args mock.Arguments) { run() }) return _c } -func (_c *StorageBackend_BlockStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) Return(_a0 BlockStoreT) *StorageBackend_BlockStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_BlockStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) Return(_a0 BlockStoreT) *StorageBackend_BlockStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Return(_a0) return _c } -func (_c *StorageBackend_BlockStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) RunAndReturn(run func() BlockStoreT) *StorageBackend_BlockStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_BlockStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) RunAndReturn(run func() BlockStoreT) *StorageBackend_BlockStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Return(run) return _c } // DepositStore provides a mock function with given fields: -func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) DepositStore() DepositStoreT { +func (_m *StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT]) DepositStore() DepositStoreT { ret := _m.Called() if len(ret) == 0 { @@ -136,46 +137,46 @@ func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositS } // StorageBackend_DepositStore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DepositStore' -type StorageBackend_DepositStore_Call[AvailabilityStoreT any, BeaconStateT any, BlockStoreT any, DepositStoreT any] struct { +type StorageBackend_DepositStore_Call[AvailabilityStoreT any, BlockStoreT any, DepositStoreT any] struct { *mock.Call } // DepositStore is a helper method to define mock.On call -func (_e *StorageBackend_Expecter[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) DepositStore() *StorageBackend_DepositStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { - return &StorageBackend_DepositStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]{Call: _e.mock.On("DepositStore")} +func (_e *StorageBackend_Expecter[AvailabilityStoreT, BlockStoreT, DepositStoreT]) DepositStore() *StorageBackend_DepositStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { + return &StorageBackend_DepositStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]{Call: _e.mock.On("DepositStore")} } -func (_c *StorageBackend_DepositStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) Run(run func()) *StorageBackend_DepositStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_DepositStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) Run(run func()) *StorageBackend_DepositStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Run(func(args mock.Arguments) { run() }) return _c } -func (_c *StorageBackend_DepositStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) Return(_a0 DepositStoreT) *StorageBackend_DepositStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_DepositStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) Return(_a0 DepositStoreT) *StorageBackend_DepositStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Return(_a0) return _c } -func (_c *StorageBackend_DepositStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) RunAndReturn(run func() DepositStoreT) *StorageBackend_DepositStore_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_DepositStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) RunAndReturn(run func() DepositStoreT) *StorageBackend_DepositStore_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Return(run) return _c } // StateFromContext provides a mock function with given fields: _a0 -func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) StateFromContext(_a0 context.Context) BeaconStateT { +func (_m *StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT]) StateFromContext(_a0 context.Context) *statedb.StateDB { ret := _m.Called(_a0) if len(ret) == 0 { panic("no return value specified for StateFromContext") } - var r0 BeaconStateT - if rf, ok := ret.Get(0).(func(context.Context) BeaconStateT); ok { + var r0 *statedb.StateDB + if rf, ok := ret.Get(0).(func(context.Context) *statedb.StateDB); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(BeaconStateT) + r0 = ret.Get(0).(*statedb.StateDB) } } @@ -183,40 +184,40 @@ func (_m *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositS } // StorageBackend_StateFromContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'StateFromContext' -type StorageBackend_StateFromContext_Call[AvailabilityStoreT any, BeaconStateT any, BlockStoreT any, DepositStoreT any] struct { +type StorageBackend_StateFromContext_Call[AvailabilityStoreT any, BlockStoreT any, DepositStoreT any] struct { *mock.Call } // StateFromContext is a helper method to define mock.On call // - _a0 context.Context -func (_e *StorageBackend_Expecter[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) StateFromContext(_a0 interface{}) *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { - return &StorageBackend_StateFromContext_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]{Call: _e.mock.On("StateFromContext", _a0)} +func (_e *StorageBackend_Expecter[AvailabilityStoreT, BlockStoreT, DepositStoreT]) StateFromContext(_a0 interface{}) *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { + return &StorageBackend_StateFromContext_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]{Call: _e.mock.On("StateFromContext", _a0)} } -func (_c *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) Run(run func(_a0 context.Context)) *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) Run(run func(_a0 context.Context)) *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context)) }) return _c } -func (_c *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) Return(_a0 BeaconStateT) *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) Return(_a0 *statedb.StateDB) *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Return(_a0) return _c } -func (_c *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]) RunAndReturn(run func(context.Context) BeaconStateT) *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { +func (_c *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT]) RunAndReturn(run func(context.Context) *statedb.StateDB) *StorageBackend_StateFromContext_Call[AvailabilityStoreT, BlockStoreT, DepositStoreT] { _c.Call.Return(run) return _c } // NewStorageBackend creates a new instance of StorageBackend. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. -func NewStorageBackend[AvailabilityStoreT any, BeaconStateT any, BlockStoreT any, DepositStoreT any](t interface { +func NewStorageBackend[AvailabilityStoreT any, BlockStoreT any, DepositStoreT any](t interface { mock.TestingT Cleanup(func()) -}) *StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT] { - mock := &StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]{} +}) *StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT] { + mock := &StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT]{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/node-api/backend/randao.go b/node-api/backend/randao.go index 973c7df589..e5754593d6 100644 --- a/node-api/backend/randao.go +++ b/node-api/backend/randao.go @@ -26,7 +26,7 @@ import ( ) func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) RandaoAtEpoch(slot math.Slot, epoch math.Epoch) (common.Bytes32, error) { st, slot, err := b.stateFromSlot(slot) if err != nil { diff --git a/node-api/backend/state.go b/node-api/backend/state.go index 1c7ef39c00..d9dee188f1 100644 --- a/node-api/backend/state.go +++ b/node-api/backend/state.go @@ -24,20 +24,21 @@ import ( ctypes "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // StateFromSlotForProof returns the beacon state of the version that was used // to calculate the parent beacon block root, which has the empty state root in // the latest block header. Hence we do not process the next slot. func (b *Backend[ - _, _, BeaconStateT, _, _, _, _, _, _, _, -]) StateFromSlotForProof(slot math.Slot) (BeaconStateT, math.Slot, error) { + _, _, _, _, _, _, _, +]) StateFromSlotForProof(slot math.Slot) (*statedb.StateDB, math.Slot, error) { return b.stateFromSlotRaw(slot) } // GetStateRoot returns the root of the state at the given slot. func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) StateRootAtSlot(slot math.Slot) (common.Root, error) { st, slot, err := b.stateFromSlot(slot) if err != nil { @@ -51,7 +52,7 @@ func (b Backend[ // GetStateFork returns the fork of the state at the given stateID. func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) StateForkAtSlot(slot math.Slot) (*ctypes.Fork, error) { var fork *ctypes.Fork st, _, err := b.stateFromSlot(slot) diff --git a/node-api/backend/types.go b/node-api/backend/types.go index 773e4f845f..474319715f 100644 --- a/node-api/backend/types.go +++ b/node-api/backend/types.go @@ -28,7 +28,7 @@ import ( "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" - "github.com/berachain/beacon-kit/state-transition/core" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // The AvailabilityStore interface is responsible for validating and storing @@ -43,16 +43,8 @@ type AvailabilityStore interface { Persist(math.Slot, datypes.BlobSidecars) error } -// BeaconState is the interface for the beacon state. -type BeaconState interface { - // SetSlot sets the slot on the beacon state. - SetSlot(math.Slot) error - - core.ReadOnlyBeaconState -} - // BlockStore is the interface for block storage. -type BlockStore[BeaconBlockT any] interface { +type BlockStore interface { // GetSlotByBlockRoot retrieves the slot by a given block root. GetSlotByBlockRoot(root common.Root) (math.Slot, error) // GetSlotByStateRoot retrieves the slot by a given state root. @@ -78,18 +70,18 @@ type Node[ContextT any] interface { CreateQueryContext(height int64, prove bool) (ContextT, error) } -type StateProcessor[BeaconStateT any] interface { - ProcessSlots(BeaconStateT, math.Slot) (transition.ValidatorUpdates, error) +type StateProcessor interface { + ProcessSlots(*statedb.StateDB, math.Slot) (transition.ValidatorUpdates, error) } // StorageBackend is the interface for the storage backend. type StorageBackend[ - AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT any, + AvailabilityStoreT, BlockStoreT, DepositStoreT any, ] interface { AvailabilityStore() AvailabilityStoreT BlockStore() BlockStoreT DepositStore() DepositStoreT - StateFromContext(context.Context) BeaconStateT + StateFromContext(context.Context) *statedb.StateDB } // Validator represents an interface for a validator with generic withdrawal diff --git a/node-api/backend/utils/validator.go b/node-api/backend/utils/validator.go index 6eba6b9983..39f5f875a6 100644 --- a/node-api/backend/utils/validator.go +++ b/node-api/backend/utils/validator.go @@ -25,15 +25,12 @@ import ( "github.com/berachain/beacon-kit/primitives/crypto" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // ValidatorIndexByID parses a validator index from a string. // The string can be either a validator index or a validator pubkey. -func ValidatorIndexByID[ - BeaconStateT interface { - ValidatorIndexByPubkey(key crypto.BLSPubkey) (math.U64, error) - }, -](st BeaconStateT, keyOrIndex string) (math.U64, error) { +func ValidatorIndexByID(st *statedb.StateDB, keyOrIndex string) (math.U64, error) { index, err := strconv.ParseUint(keyOrIndex, 10, 64) if err == nil { return math.U64(index), nil diff --git a/node-api/backend/validator.go b/node-api/backend/validator.go index 9d202bcd94..962d09716f 100644 --- a/node-api/backend/validator.go +++ b/node-api/backend/validator.go @@ -27,7 +27,7 @@ import ( ) func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) ValidatorByID( slot math.Slot, id string, ) (*beacontypes.ValidatorData, error) { @@ -62,7 +62,7 @@ func (b Backend[ // TODO: filter by status func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) ValidatorsByIDs( slot math.Slot, ids []string, _ []string, ) ([]*beacontypes.ValidatorData, error) { @@ -81,7 +81,7 @@ func (b Backend[ } func (b Backend[ - _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, ]) ValidatorBalancesByIDs( slot math.Slot, ids []string, ) ([]*beacontypes.ValidatorBalanceData, error) { diff --git a/node-api/block_store/types.go b/node-api/block_store/types.go index cf36af7d62..fd6b2e28a2 100644 --- a/node-api/block_store/types.go +++ b/node-api/block_store/types.go @@ -21,19 +21,11 @@ package blockstore import ( - "github.com/berachain/beacon-kit/primitives/constraints" - "github.com/berachain/beacon-kit/primitives/math" + ctypes "github.com/berachain/beacon-kit/consensus-types/types" ) -// BeaconBlock is a generic interface for a beacon block. -type BeaconBlock interface { - constraints.SSZMarshaler - // GetSlot returns the slot of the block. - GetSlot() math.U64 -} - // BlockStore is a generic interface for a block store. -type BlockStore[BeaconBlockT BeaconBlock] interface { +type BlockStore interface { // Set sets a block at a given index. - Set(blk BeaconBlockT) error + Set(blk *ctypes.BeaconBlock) error } diff --git a/node-api/handlers/beacon/types/request.go b/node-api/handlers/beacon/types/request.go index 765cd2a3a8..7d373a985c 100644 --- a/node-api/handlers/beacon/types/request.go +++ b/node-api/handlers/beacon/types/request.go @@ -20,7 +20,10 @@ package types -import "github.com/berachain/beacon-kit/node-api/handlers/types" +import ( + ctypes "github.com/berachain/beacon-kit/consensus-types/types" + "github.com/berachain/beacon-kit/node-api/handlers/types" +) type GetGenesisRequest struct{} @@ -98,13 +101,13 @@ type PostBlindedBlocksV2Request struct { BroadcastValidation string `json:"broadcast_validation" validate:"required,broadcast_validation"` } -type PostBlocksV1Request[BeaconBlockT any] struct { - EthConsensusVersion string `json:"eth_consensus_version" validate:"required,eth_consensus_version"` - BeaconBlock BeaconBlockT `json:"beacon_block"` +type PostBlocksV1Request struct { + EthConsensusVersion string `json:"eth_consensus_version" validate:"required,eth_consensus_version"` + BeaconBlock ctypes.BeaconBlock `json:"beacon_block"` } -type PostBlocksV2Request[BeaconBlockT any] struct { - PostBlocksV1Request[BeaconBlockT] +type PostBlocksV2Request struct { + PostBlocksV1Request BroadcastValidation string `json:"broadcast_validation" validate:"required,broadcast_validation"` } diff --git a/node-api/handlers/proof/backend.go b/node-api/handlers/proof/backend.go index 65b3bf5598..856752f31f 100644 --- a/node-api/handlers/proof/backend.go +++ b/node-api/handlers/proof/backend.go @@ -23,12 +23,13 @@ package proof import ( 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" ) // Backend is the interface for backend of the proof API. -type Backend[BeaconStateT any] interface { +type Backend interface { BlockBackend - StateBackend[BeaconStateT] + StateBackend GetParentSlotByTimestamp(timestamp math.U64) (math.Slot, error) } @@ -36,6 +37,6 @@ type BlockBackend interface { BlockHeaderAtSlot(slot math.Slot) (*ctypes.BeaconBlockHeader, error) } -type StateBackend[BeaconStateT any] interface { - StateFromSlotForProof(slot math.Slot) (BeaconStateT, math.Slot, error) +type StateBackend interface { + StateFromSlotForProof(slot math.Slot) (*statedb.StateDB, math.Slot, error) } diff --git a/node-api/handlers/proof/block_proposer.go b/node-api/handlers/proof/block_proposer.go index 9198ae683f..45db8753c4 100644 --- a/node-api/handlers/proof/block_proposer.go +++ b/node-api/handlers/proof/block_proposer.go @@ -29,7 +29,7 @@ import ( // GetBlockProposer returns the block proposer pubkey for the given timestamp // id along with a merkle proof that can be verified against the beacon block // root. It also returns the merkle proof of the proposer index. -func (h *Handler[_, _, ContextT]) GetBlockProposer(c ContextT) (any, error) { +func (h *Handler[ContextT]) GetBlockProposer(c ContextT) (any, error) { params, err := utils.BindAndValidate[types.BlockProposerRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/proof/execution_fee_recipient.go b/node-api/handlers/proof/execution_fee_recipient.go index a19555d03b..0f4bfb2a59 100644 --- a/node-api/handlers/proof/execution_fee_recipient.go +++ b/node-api/handlers/proof/execution_fee_recipient.go @@ -29,7 +29,7 @@ import ( // GetExecutionFeeRecipient returns the fee recipient from the latest execution // payload header for the given timestamp id, along with the proof that can be // verified against the beacon block root. -func (h *Handler[_, _, ContextT]) GetExecutionFeeRecipient(c ContextT) (any, error) { +func (h *Handler[ContextT]) GetExecutionFeeRecipient(c ContextT) (any, error) { params, err := utils.BindAndValidate[types.ExecutionFeeRecipientRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/proof/execution_number.go b/node-api/handlers/proof/execution_number.go index c646df9646..0fd698ad0f 100644 --- a/node-api/handlers/proof/execution_number.go +++ b/node-api/handlers/proof/execution_number.go @@ -29,7 +29,7 @@ import ( // GetExecutionNumber returns the block number from the latest execution // payload header for the given timestamp id, along with the proof that can be // verified against the beacon block root. -func (h *Handler[_, _, ContextT]) GetExecutionNumber(c ContextT) (any, error) { +func (h *Handler[ContextT]) GetExecutionNumber(c ContextT) (any, error) { params, err := utils.BindAndValidate[types.ExecutionNumberRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/proof/handler.go b/node-api/handlers/proof/handler.go index acaad80dad..080a529345 100644 --- a/node-api/handlers/proof/handler.go +++ b/node-api/handlers/proof/handler.go @@ -23,33 +23,27 @@ package proof import ( ctypes "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/node-api/handlers" - "github.com/berachain/beacon-kit/node-api/handlers/proof/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" "github.com/berachain/beacon-kit/node-api/server/context" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // Handler is the handler for the proof API. type Handler[ - BeaconStateT types.BeaconState[BeaconStateMarshallableT], - BeaconStateMarshallableT types.BeaconStateMarshallable, ContextT context.Context, ] struct { *handlers.BaseHandler[ContextT] - backend Backend[BeaconStateT] + backend Backend } // NewHandler creates a new handler for the proof API. func NewHandler[ - BeaconStateT types.BeaconState[BeaconStateMarshallableT], - BeaconStateMarshallableT types.BeaconStateMarshallable, ContextT context.Context, ]( - backend Backend[BeaconStateT], -) *Handler[ - BeaconStateT, BeaconStateMarshallableT, ContextT, -] { - h := &Handler[BeaconStateT, BeaconStateMarshallableT, ContextT]{ + backend Backend, +) *Handler[ContextT] { + h := &Handler[ContextT]{ BaseHandler: handlers.NewBaseHandler( handlers.NewRouteSet[ContextT](""), ), @@ -60,13 +54,11 @@ func NewHandler[ // Get the slot from the given input of timestamp id, beacon state, and beacon // block header for the resolved slot. -func (h *Handler[ - BeaconStateT, _, _, -]) resolveTimestampID(timestampID string) ( - math.Slot, BeaconStateT, *ctypes.BeaconBlockHeader, error, +func (h *Handler[_]) resolveTimestampID(timestampID string) ( + math.Slot, *statedb.StateDB, *ctypes.BeaconBlockHeader, error, ) { var ( - beaconState BeaconStateT + beaconState *statedb.StateDB blockHeader *ctypes.BeaconBlockHeader ) diff --git a/node-api/handlers/proof/routes.go b/node-api/handlers/proof/routes.go index 8a1b9b38eb..227ddc008f 100644 --- a/node-api/handlers/proof/routes.go +++ b/node-api/handlers/proof/routes.go @@ -27,7 +27,7 @@ import ( "github.com/berachain/beacon-kit/node-api/handlers" ) -func (h *Handler[_, _, ContextT]) RegisterRoutes(logger log.Logger) { +func (h *Handler[ContextT]) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{ { diff --git a/node-core/components/api.go b/node-core/components/api.go index 7cc9af20f5..16c6dedae4 100644 --- a/node-core/components/api.go +++ b/node-core/components/api.go @@ -38,44 +38,36 @@ func ProvideNodeAPIEngine() *echo.Engine { } type NodeAPIBackendInput[ - BeaconBlockT any, - BeaconStateT any, StorageBackendT any, ] struct { depinject.In ChainSpec chain.ChainSpec - StateProcessor StateProcessor[BeaconBlockT, BeaconStateT, *Context] + StateProcessor StateProcessor[*Context] StorageBackend StorageBackendT } func ProvideNodeAPIBackend[ AvailabilityStoreT AvailabilityStore, - BeaconBlockT any, - BeaconBlockStoreT BlockStore[BeaconBlockT], - BeaconStateT BeaconState[BeaconStateT, BeaconStateMarshallableT, KVStoreT], - BeaconStateMarshallableT any, + BeaconBlockStoreT BlockStore, DepositStoreT DepositStore, KVStoreT any, NodeT interface { CreateQueryContext(height int64, prove bool) (sdk.Context, error) }, StorageBackendT StorageBackend[ - AvailabilityStoreT, BeaconStateT, BeaconBlockStoreT, DepositStoreT, + AvailabilityStoreT, BeaconBlockStoreT, DepositStoreT, ], ]( - in NodeAPIBackendInput[BeaconBlockT, BeaconStateT, StorageBackendT], + in NodeAPIBackendInput[StorageBackendT], ) *backend.Backend[ - AvailabilityStoreT, BeaconBlockT, - BeaconStateT, BeaconStateMarshallableT, BeaconBlockStoreT, + AvailabilityStoreT, + BeaconBlockStoreT, sdk.Context, DepositStoreT, NodeT, KVStoreT, StorageBackendT, ] { return backend.New[ AvailabilityStoreT, - BeaconBlockT, - BeaconStateT, - BeaconStateMarshallableT, BeaconBlockStoreT, sdk.Context, DepositStoreT, diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 6c51d2cbfc..99cebe5744 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -33,8 +33,6 @@ import ( ) type NodeAPIHandlersInput[ - BeaconStateT BeaconState[BeaconStateT, BeaconStateMarshallableT, KVStoreT], - BeaconStateMarshallableT BeaconStateMarshallable[BeaconStateMarshallableT], KVStoreT any, NodeAPIContextT NodeAPIContext, ] struct { @@ -45,18 +43,15 @@ type NodeAPIHandlersInput[ DebugAPIHandler *debugapi.Handler[NodeAPIContextT] EventsAPIHandler *eventsapi.Handler[NodeAPIContextT] NodeAPIHandler *nodeapi.Handler[NodeAPIContextT] - ProofAPIHandler *proofapi.Handler[BeaconStateT, BeaconStateMarshallableT, NodeAPIContextT] + ProofAPIHandler *proofapi.Handler[NodeAPIContextT] } func ProvideNodeAPIHandlers[ - BeaconStateT BeaconState[BeaconStateT, BeaconStateMarshallableT, KVStoreT], - BeaconStateMarshallableT BeaconStateMarshallable[BeaconStateMarshallableT], KVStoreT any, NodeAPIContextT NodeAPIContext, ]( in NodeAPIHandlersInput[ - BeaconStateT, - BeaconStateMarshallableT, KVStoreT, + KVStoreT, NodeAPIContextT, ], ) []handlers.Handlers[NodeAPIContextT] { @@ -72,13 +67,9 @@ func ProvideNodeAPIHandlers[ } func ProvideNodeAPIBeaconHandler[ - BeaconStateT any, NodeT any, NodeAPIContextT NodeAPIContext, -](b NodeAPIBackend[ - BeaconStateT, - NodeT, -]) *beaconapi.Handler[NodeAPIContextT] { +](b NodeAPIBackend[NodeT]) *beaconapi.Handler[NodeAPIContextT] { return beaconapi.NewHandler[NodeAPIContextT](b) } @@ -113,22 +104,9 @@ func ProvideNodeAPINodeHandler[ } func ProvideNodeAPIProofHandler[ - BeaconStateT BeaconState[BeaconStateT, BeaconStateMarshallableT, KVStoreT], - BeaconStateMarshallableT BeaconStateMarshallable[BeaconStateMarshallableT], KVStoreT any, NodeT any, NodeAPIContextT NodeAPIContext, -](b NodeAPIBackend[ - BeaconStateT, - NodeT, -]) *proofapi.Handler[ - BeaconStateT, - BeaconStateMarshallableT, - NodeAPIContextT, -] { - return proofapi.NewHandler[ - BeaconStateT, - BeaconStateMarshallableT, - NodeAPIContextT, - ](b) +](b NodeAPIBackend[NodeT]) *proofapi.Handler[NodeAPIContextT] { + return proofapi.NewHandler[NodeAPIContextT](b) } diff --git a/node-core/components/attributes_factory.go b/node-core/components/attributes_factory.go index 84d9c46512..dad676d06b 100644 --- a/node-core/components/attributes_factory.go +++ b/node-core/components/attributes_factory.go @@ -38,17 +38,11 @@ type AttributesFactoryInput[LoggerT any] struct { // ProvideAttributesFactory provides an AttributesFactory for the client. func ProvideAttributesFactory[ - BeaconStateT BeaconState[ - BeaconStateT, BeaconStateMarshallableT, - KVStoreT, - ], - BeaconStateMarshallableT any, - KVStoreT any, LoggerT log.Logger, ]( in AttributesFactoryInput[LoggerT], -) (*attributes.Factory[BeaconStateT], error) { - return attributes.NewAttributesFactory[BeaconStateT]( +) (*attributes.Factory, error) { + return attributes.NewAttributesFactory( in.ChainSpec, in.Logger, in.Config.PayloadBuilder.SuggestedFeeRecipient, diff --git a/node-core/components/backend.go b/node-core/components/backend.go index 8626895415..6d1807da7f 100644 --- a/node-core/components/backend.go +++ b/node-core/components/backend.go @@ -48,9 +48,6 @@ type StorageBackendInput[ func ProvideStorageBackend[ AvailabilityStoreT any, BeaconBlockStoreT any, - BeaconStateT interface { - NewFromDB(BeaconStoreT, chain.ChainSpec) BeaconStateT - }, BeaconStoreT interface { WithContext(context.Context) BeaconStoreT }, @@ -61,12 +58,11 @@ func ProvideStorageBackend[ DepositStoreT, ], ) *storage.Backend[ - AvailabilityStoreT, BeaconStateT, BeaconBlockStoreT, + AvailabilityStoreT, BeaconBlockStoreT, DepositStoreT, BeaconStoreT, ] { return storage.NewBackend[ AvailabilityStoreT, - BeaconStateT, BeaconBlockStoreT, DepositStoreT, BeaconStoreT, diff --git a/node-core/components/block_store.go b/node-core/components/block_store.go index 4fff151283..0e330e7b96 100644 --- a/node-core/components/block_store.go +++ b/node-core/components/block_store.go @@ -23,13 +23,13 @@ package components import ( "cosmossdk.io/depinject" "github.com/berachain/beacon-kit/config" + ctypes "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/storage/block" ) // BlockStoreInput is the input for the dep inject framework. type BlockStoreInput[ - BeaconBlockT BeaconBlock[BeaconBlockT], LoggerT log.AdvancedLogger[LoggerT], ] struct { depinject.In @@ -41,12 +41,11 @@ type BlockStoreInput[ // ProvideBlockStore is a function that provides the module to the // application. func ProvideBlockStore[ - BeaconBlockT BeaconBlock[BeaconBlockT], LoggerT log.AdvancedLogger[LoggerT], ]( - in BlockStoreInput[BeaconBlockT, LoggerT], -) (*block.KVStore[BeaconBlockT], error) { - return block.NewStore[BeaconBlockT]( + in BlockStoreInput[LoggerT], +) (*block.KVStore[*ctypes.BeaconBlock], error) { + return block.NewStore[*ctypes.BeaconBlock]( in.Logger.With("service", "block-store"), in.Config.BlockStoreService.AvailabilityWindow, ), nil diff --git a/node-core/components/chain_service.go b/node-core/components/chain_service.go index 4ec665730a..62b243c108 100644 --- a/node-core/components/chain_service.go +++ b/node-core/components/chain_service.go @@ -39,11 +39,9 @@ import ( // ChainServiceInput is the input for the chain service provider. type ChainServiceInput[ - BeaconBlockT any, - BeaconStateT any, StorageBackendT any, LoggerT any, - BlockStoreT BlockStore[BeaconBlockT], + BlockStoreT BlockStore, DepositStoreT any, DepositContractT any, AvailabilityStoreT any, @@ -56,14 +54,12 @@ type ChainServiceInput[ Cfg *config.Config EngineClient *client.EngineClient ExecutionEngine *engine.Engine - LocalBuilder LocalBuilder[BeaconStateT] + LocalBuilder LocalBuilder Logger LoggerT Signer crypto.BLSSigner - StateProcessor StateProcessor[ - BeaconBlockT, BeaconStateT, *Context, - ] - StorageBackend StorageBackendT - BlobProcessor BlobProcessor[ + StateProcessor StateProcessor[*Context] + StorageBackend StorageBackendT + BlobProcessor BlobProcessor[ AvailabilityStoreT, ConsensusSidecarsT, ] TelemetrySink *metrics.TelemetrySink @@ -73,35 +69,31 @@ type ChainServiceInput[ // ProvideChainService is a depinject provider for the blockchain service. func ProvideChainService[ AvailabilityStoreT AvailabilityStore, - ConsensusBlockT ConsensusBlock[BeaconBlockT], - BeaconBlockT BeaconBlock[BeaconBlockT], - BeaconStateT BeaconState[BeaconStateT, BeaconStateMarshallableT, KVStoreT], - BeaconStateMarshallableT any, + ConsensusBlockT ConsensusBlock, ConsensusSidecarsT da.ConsensusSidecars, DepositStoreT DepositStore, DepositContractT deposit.Contract, GenesisT Genesis, KVStoreT any, LoggerT log.AdvancedLogger[LoggerT], - StorageBackendT StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT], - BlockStoreT BlockStore[BeaconBlockT], + StorageBackendT StorageBackend[AvailabilityStoreT, BlockStoreT, DepositStoreT], + BlockStoreT BlockStore, ]( in ChainServiceInput[ - BeaconBlockT, BeaconStateT, StorageBackendT, LoggerT, BlockStoreT, DepositStoreT, + StorageBackendT, LoggerT, BlockStoreT, DepositStoreT, DepositContractT, AvailabilityStoreT, ConsensusSidecarsT, ], ) *blockchain.Service[ - AvailabilityStoreT, DepositStoreT, ConsensusBlockT, BeaconBlockT, BeaconStateT, + AvailabilityStoreT, DepositStoreT, ConsensusBlockT, BlockStoreT, GenesisT, ConsensusSidecarsT, ] { return blockchain.NewService[ AvailabilityStoreT, DepositStoreT, ConsensusBlockT, - BeaconBlockT, - BeaconStateT, BlockStoreT, GenesisT, + ConsensusSidecarsT, ]( cast.ToString(in.AppOpts.Get(flags.FlagHome)), in.StorageBackend, diff --git a/node-core/components/interfaces.go b/node-core/components/interfaces.go index 93fe13db37..df1e091039 100644 --- a/node-core/components/interfaces.go +++ b/node-core/components/interfaces.go @@ -37,6 +37,7 @@ import ( "github.com/berachain/beacon-kit/primitives/eip4844" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" v1 "github.com/cometbft/cometbft/api/cometbft/abci/v1" sdk "github.com/cosmos/cosmos-sdk/types" fastssz "github.com/ferranbt/fastssz" @@ -44,11 +45,9 @@ import ( type ( // AttributesFactory is the interface for the attributes factory. - AttributesFactory[ - BeaconStateT any, - ] interface { + AttributesFactory interface { BuildPayloadAttributes( - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, timestamp uint64, prevHeadRoot [32]byte, @@ -66,8 +65,8 @@ type ( Persist(math.Slot, datypes.BlobSidecars) error } - ConsensusBlock[BeaconBlockT any] interface { - GetBeaconBlock() BeaconBlockT + ConsensusBlock interface { + GetBeaconBlock() *ctypes.BeaconBlock // GetProposerAddress returns the address of the validator // selected by consensus to propose the block @@ -206,40 +205,9 @@ type ( GetHeader() *ctypes.BeaconBlockHeader } - // // BlockchainService defines the interface for interacting with the - // // blockchain - // // state and processing blocks. - // BlockchainService[ - // BeaconBlockT any, - // DepositT any, - // GenesisT any, - // ] interface { - // service.Basic - // // ProcessGenesisData processes the genesis data and initializes the - // // beacon - // // state. - // ProcessGenesisData( - // context.Context, - // GenesisT, - // ) (transition.ValidatorUpdates, error) - // // ProcessBeaconBlock processes the given beacon block and associated - // // blobs sidecars. - // ProcessBeaconBlock( - // context.Context, - // BeaconBlockT, - // ) (transition.ValidatorUpdates, error) - // // ReceiveBlock receives a beacon block and - // // associated blobs sidecars for processing. - // ReceiveBlock( - // ctx context.Context, - // blk BeaconBlockT, - // ) error - // VerifyIncomingBlock(ctx context.Context, blk BeaconBlockT) error - // } - // BlockStore is the interface for block storage. - BlockStore[BeaconBlockT any] interface { - Set(blk BeaconBlockT) error + BlockStore interface { + Set(blk *ctypes.BeaconBlock) error // GetSlotByBlockRoot retrieves the slot by a given root from the store. GetSlotByBlockRoot(root common.Root) (math.Slot, error) // GetSlotByStateRoot retrieves the slot by a given root from the store. @@ -360,15 +328,13 @@ type ( } // LocalBuilder is the interface for the builder service. - LocalBuilder[ - BeaconStateT any, - ] interface { + LocalBuilder interface { // Enabled returns true if the local builder is enabled. Enabled() bool // RequestPayloadAsync requests a new payload for the given slot. RequestPayloadAsync( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, timestamp uint64, parentBlockRoot common.Root, @@ -378,7 +344,7 @@ type ( // SendForceHeadFCU sends a force head FCU request. SendForceHeadFCU( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, ) error // RetrievePayload retrieves the payload for the given slot. @@ -391,7 +357,7 @@ type ( // blocks until the payload is delivered. RequestPayloadSync( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, timestamp uint64, parentBlockRoot common.Root, @@ -416,39 +382,37 @@ type ( // StateProcessor defines the interface for processing the state. StateProcessor[ - BeaconBlockT any, - BeaconStateT any, ContextT any, ] interface { // InitializePreminedBeaconStateFromEth1 initializes the premined beacon // state // from the eth1 deposits. InitializePreminedBeaconStateFromEth1( - BeaconStateT, + *statedb.StateDB, ctypes.Deposits, *ctypes.ExecutionPayloadHeader, common.Version, ) (transition.ValidatorUpdates, error) // ProcessSlot processes the slot. ProcessSlots( - st BeaconStateT, slot math.Slot, + st *statedb.StateDB, slot math.Slot, ) (transition.ValidatorUpdates, error) // Transition performs the core state transition. Transition( ctx ContextT, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, ) (transition.ValidatorUpdates, error) - GetSidecarVerifierFn(st BeaconStateT) ( + GetSidecarVerifierFn(st *statedb.StateDB) ( func(blkHeader *ctypes.BeaconBlockHeader, signature crypto.BLSSignature) error, error, ) } - SidecarFactory[BeaconBlockT any] interface { + SidecarFactory interface { // BuildSidecars builds sidecars for a given block and blobs bundle. BuildSidecars( - blk BeaconBlockT, + blk *ctypes.BeaconBlock, blobs ctypes.BlobsBundle, signer crypto.BLSSigner, forkData *ctypes.ForkData, @@ -459,7 +423,6 @@ type ( // components required by the beacon node. StorageBackend[ AvailabilityStoreT any, - BeaconStateT any, BlockStoreT any, DepositStoreT any, ] interface { @@ -467,7 +430,7 @@ type ( BlockStore() BlockStoreT DepositStore() DepositStoreT // StateFromContext retrieves the beacon state from the given context. - StateFromContext(context.Context) BeaconStateT + StateFromContext(context.Context) *statedb.StateDB } // // TelemetrySink is an interface for sending metrics to a telemetry @@ -837,7 +800,6 @@ type ( } NodeAPIBackend[ - BeaconStateT any, NodeT any, ] interface { AttachQueryBackend(node NodeT) @@ -846,18 +808,16 @@ type ( GetSlotByStateRoot(root common.Root) (math.Slot, error) GetParentSlotByTimestamp(timestamp math.U64) (math.Slot, error) - NodeAPIBeaconBackend[BeaconStateT] - NodeAPIProofBackend[BeaconStateT] + NodeAPIBeaconBackend + NodeAPIProofBackend } // NodeAPIBackend is the interface for backend of the beacon API. - NodeAPIBeaconBackend[ - BeaconStateT any, - ] interface { + NodeAPIBeaconBackend interface { GenesisBackend BlockBackend RandaoBackend - StateBackend[BeaconStateT] + StateBackend ValidatorBackend HistoricalBackend // GetSlotByBlockRoot retrieves the slot by a given root from the store. @@ -867,11 +827,9 @@ type ( } // NodeAPIProofBackend is the interface for backend of the proof API. - NodeAPIProofBackend[ - BeaconStateT any, - ] interface { + NodeAPIProofBackend interface { BlockBackend - StateBackend[BeaconStateT] + StateBackend GetParentSlotByTimestamp(timestamp math.U64) (math.Slot, error) } @@ -894,10 +852,10 @@ type ( BlockHeaderAtSlot(slot math.Slot) (*ctypes.BeaconBlockHeader, error) } - StateBackend[BeaconStateT any] interface { + StateBackend interface { StateRootAtSlot(slot math.Slot) (common.Root, error) StateForkAtSlot(slot math.Slot) (*ctypes.Fork, error) - StateFromSlotForProof(slot math.Slot) (BeaconStateT, math.Slot, error) + StateFromSlotForProof(slot math.Slot) (*statedb.StateDB, math.Slot, error) } ValidatorBackend interface { diff --git a/node-core/components/payload_builder.go b/node-core/components/payload_builder.go index 585d4a3671..1171e30e98 100644 --- a/node-core/components/payload_builder.go +++ b/node-core/components/payload_builder.go @@ -33,11 +33,10 @@ import ( // LocalBuilderInput is an input for the dep inject framework. type LocalBuilderInput[ - BeaconStateT any, LoggerT log.AdvancedLogger[LoggerT], ] struct { depinject.In - AttributesFactory AttributesFactory[BeaconStateT] + AttributesFactory AttributesFactory Cfg *config.Config ChainSpec chain.ChainSpec ExecutionEngine *engine.Engine @@ -47,19 +46,12 @@ type LocalBuilderInput[ // ProvideLocalBuilder provides a local payload builder for the // depinject framework. func ProvideLocalBuilder[ - BeaconStateT BeaconState[ - BeaconStateT, BeaconStateMarshallableT, - KVStoreT, - ], - BeaconStateMarshallableT any, KVStoreT any, LoggerT log.AdvancedLogger[LoggerT], ]( - in LocalBuilderInput[ - BeaconStateT, LoggerT, - ], -) *payloadbuilder.PayloadBuilder[BeaconStateT] { - return payloadbuilder.New[BeaconStateT]( + in LocalBuilderInput[LoggerT], +) *payloadbuilder.PayloadBuilder { + return payloadbuilder.New( &in.Cfg.PayloadBuilder, in.ChainSpec, in.Logger.With("service", "payload-builder"), diff --git a/node-core/components/service_registry.go b/node-core/components/service_registry.go index 953b270bbf..a8636d2b36 100644 --- a/node-core/components/service_registry.go +++ b/node-core/components/service_registry.go @@ -37,11 +37,8 @@ import ( // ServiceRegistryInput is the input for the service registry provider. type ServiceRegistryInput[ AvailabilityStoreT AvailabilityStore, - ConsensusBlockT ConsensusBlock[BeaconBlockT], - BeaconBlockT BeaconBlock[BeaconBlockT], - BeaconBlockStoreT BlockStore[BeaconBlockT], - BeaconStateT BeaconState[BeaconStateT, BeaconStateMarshallableT, KVStoreT], - BeaconStateMarshallableT any, + ConsensusBlockT ConsensusBlock, + BeaconBlockStoreT BlockStore, ConsensusSidecarsT ConsensusSidecars, DepositStoreT DepositStore, GenesisT Genesis, @@ -52,8 +49,8 @@ type ServiceRegistryInput[ depinject.In ChainService *blockchain.Service[ AvailabilityStoreT, DepositStoreT, - ConsensusBlockT, BeaconBlockT, - BeaconStateT, BeaconBlockStoreT, + ConsensusBlockT, + BeaconBlockStoreT, GenesisT, ConsensusSidecarsT, ] @@ -63,25 +60,15 @@ type ServiceRegistryInput[ ReportingService *version.ReportingService TelemetrySink *metrics.TelemetrySink TelemetryService *telemetry.Service - ValidatorService *validator.Service[ - BeaconBlockT, - BeaconStateT, DepositStoreT, - ] - CometBFTService *cometbft.Service[LoggerT] + ValidatorService *validator.Service[DepositStoreT] + CometBFTService *cometbft.Service[LoggerT] } // ProvideServiceRegistry is the depinject provider for the service registry. func ProvideServiceRegistry[ AvailabilityStoreT AvailabilityStore, - ConsensusBlockT ConsensusBlock[BeaconBlockT], - BeaconBlockT BeaconBlock[BeaconBlockT], - - BeaconBlockStoreT BlockStore[BeaconBlockT], - BeaconStateT BeaconState[ - BeaconStateT, BeaconStateMarshallableT, - KVStoreT, - ], - BeaconStateMarshallableT any, + ConsensusBlockT ConsensusBlock, + BeaconBlockStoreT BlockStore, ConsensusSidecarsT ConsensusSidecars, DepositStoreT DepositStore, GenesisT Genesis, @@ -91,9 +78,8 @@ func ProvideServiceRegistry[ ]( in ServiceRegistryInput[ AvailabilityStoreT, - ConsensusBlockT, BeaconBlockT, - BeaconBlockStoreT, BeaconStateT, - BeaconStateMarshallableT, + ConsensusBlockT, + BeaconBlockStoreT, ConsensusSidecarsT, DepositStoreT, GenesisT, KVStoreT, LoggerT, NodeAPIContextT, diff --git a/node-core/components/sidecars.go b/node-core/components/sidecars.go index d4d98bf5ea..3640ed6342 100644 --- a/node-core/components/sidecars.go +++ b/node-core/components/sidecars.go @@ -33,10 +33,8 @@ type SidecarFactoryInput struct { TelemetrySink *metrics.TelemetrySink } -func ProvideSidecarFactory[ - BeaconBlockT BeaconBlock[BeaconBlockT], -](in SidecarFactoryInput) *dablob.SidecarFactory[BeaconBlockT] { - return dablob.NewSidecarFactory[BeaconBlockT]( +func ProvideSidecarFactory(in SidecarFactoryInput) *dablob.SidecarFactory { + return dablob.NewSidecarFactory( in.ChainSpec, in.TelemetrySink, ) diff --git a/node-core/components/state_processor.go b/node-core/components/state_processor.go index 255da6ed92..eacf6086e7 100644 --- a/node-core/components/state_processor.go +++ b/node-core/components/state_processor.go @@ -48,21 +48,15 @@ type StateProcessorInput[ // framework. func ProvideStateProcessor[ LoggerT log.AdvancedLogger[LoggerT], - BeaconBlockT BeaconBlock[BeaconBlockT], - BeaconStateT BeaconState[BeaconStateT, BeaconStateMarshallableT, KVStoreT], - BeaconStateMarshallableT any, DepositStoreT DepositStore, KVStoreT BeaconStore[KVStoreT], ]( in StateProcessorInput[LoggerT], ) *core.StateProcessor[ - BeaconBlockT, - BeaconStateT, *Context, + *Context, KVStoreT, ] { return core.NewStateProcessor[ - BeaconBlockT, - BeaconStateT, *Context, KVStoreT, ]( diff --git a/node-core/components/storage/storage.go b/node-core/components/storage/storage.go index eb44b4f526..dd35c13544 100644 --- a/node-core/components/storage/storage.go +++ b/node-core/components/storage/storage.go @@ -24,13 +24,14 @@ import ( "context" "github.com/berachain/beacon-kit/chain-spec/chain" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" + "github.com/berachain/beacon-kit/storage/beacondb" ) // Backend is a struct that holds the storage backend. It provides a simple // interface to access all types of storage required by the runtime. type Backend[ AvailabilityStoreT any, - BeaconStateT BeaconState[BeaconStateT, KVStoreT], BlockStoreT any, DepositStoreT any, KVStoreT KVStore[KVStoreT], @@ -44,7 +45,6 @@ type Backend[ func NewBackend[ AvailabilityStoreT any, - BeaconStateT BeaconState[BeaconStateT, KVStoreT], BlockStoreT any, DepositStoreT any, KVStoreT KVStore[KVStoreT], @@ -55,10 +55,10 @@ func NewBackend[ depositStore DepositStoreT, blockStore BlockStoreT, ) *Backend[ - AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT, KVStoreT, + AvailabilityStoreT, BlockStoreT, DepositStoreT, KVStoreT, ] { return &Backend[ - AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT, KVStoreT, + AvailabilityStoreT, BlockStoreT, DepositStoreT, KVStoreT, ]{ chainSpec: chainSpec, availabilityStore: availabilityStore, @@ -71,7 +71,7 @@ func NewBackend[ // AvailabilityStore returns the availability store struct initialized with a // given context. func (k Backend[ - AvailabilityStoreT, _, _, _, _, + AvailabilityStoreT, _, _, _, ]) AvailabilityStore() AvailabilityStoreT { return k.availabilityStore } @@ -79,30 +79,35 @@ func (k Backend[ // BeaconState returns the beacon state struct initialized with a given // context and the store key. func (k Backend[ - _, BeaconStateT, _, _, _, + _, _, _, KVStoreT, ]) StateFromContext( ctx context.Context, -) BeaconStateT { - var st BeaconStateT - return st.NewFromDB(k.kvStore.WithContext(ctx), k.chainSpec) +) *statedb.StateDB { + kvstore, ok := any(k.kvStore.WithContext(ctx)).(*beacondb.KVStore) + if !ok { + panic("failed to cast KVStoreT to beacondb.KVStore") + } + + var st *statedb.StateDB + return st.NewFromDB(kvstore, k.chainSpec) } // BeaconStore returns the beacon store struct. func (k Backend[ - _, _, _, _, KVStoreT, + _, _, _, KVStoreT, ]) BeaconStore() KVStoreT { return k.kvStore } func (k Backend[ - _, _, BlockStoreT, _, _, + _, BlockStoreT, _, _, ]) BlockStore() BlockStoreT { return k.blockStore } // DepositStore returns the deposit store struct initialized with a. func (k Backend[ - _, _, _, DepositStoreT, _, + _, _, DepositStoreT, _, ]) DepositStore() DepositStoreT { return k.depositStore } diff --git a/node-core/components/storage/types.go b/node-core/components/storage/types.go index d013717a34..e232a67e99 100644 --- a/node-core/components/storage/types.go +++ b/node-core/components/storage/types.go @@ -22,14 +22,8 @@ package storage import ( "context" - - "github.com/berachain/beacon-kit/chain-spec/chain" ) -type BeaconState[T, KVStoreT any] interface { - NewFromDB(KVStoreT, chain.ChainSpec) T -} - // KVStore is the interface for the key-value store holding the beacon state. type KVStore[T any] interface { // WithContext returns a new key-value store with the given context. diff --git a/node-core/components/validator_service.go b/node-core/components/validator_service.go index bf7f7df95b..633c40322b 100644 --- a/node-core/components/validator_service.go +++ b/node-core/components/validator_service.go @@ -33,53 +33,39 @@ import ( // ValidatorServiceInput is the input for the validator service provider. type ValidatorServiceInput[ AvailabilityStoreT any, - BeaconBlockT any, - BeaconStateT any, LoggerT any, StorageBackendT any, ] struct { depinject.In Cfg *config.Config ChainSpec chain.ChainSpec - LocalBuilder LocalBuilder[BeaconStateT] + LocalBuilder LocalBuilder Logger LoggerT - StateProcessor StateProcessor[ - BeaconBlockT, BeaconStateT, *Context, - ] + StateProcessor StateProcessor[*Context] StorageBackend StorageBackendT Signer crypto.BLSSigner - SidecarFactory SidecarFactory[BeaconBlockT] + SidecarFactory SidecarFactory TelemetrySink *metrics.TelemetrySink } // ProvideValidatorService is a depinject provider for the validator service. func ProvideValidatorService[ AvailabilityStoreT any, - BeaconBlockT BeaconBlock[BeaconBlockT], - BeaconStateT BeaconState[BeaconStateT, BeaconStateMarshallableT, KVStoreT], - BeaconStateMarshallableT any, BeaconBlockStoreT any, DepositStoreT DepositStore, KVStoreT any, LoggerT log.AdvancedLogger[LoggerT], StorageBackendT StorageBackend[ - AvailabilityStoreT, BeaconStateT, BeaconBlockStoreT, DepositStoreT, + AvailabilityStoreT, BeaconBlockStoreT, DepositStoreT, ], ]( in ValidatorServiceInput[ - AvailabilityStoreT, BeaconBlockT, BeaconStateT, + AvailabilityStoreT, LoggerT, StorageBackendT, ], -) (*validator.Service[ - BeaconBlockT, - BeaconStateT, DepositStoreT, -], error) { +) (*validator.Service[DepositStoreT], error) { // Build the builder service. - return validator.NewService[ - BeaconBlockT, - BeaconStateT, - DepositStoreT, - ]( + return validator.NewService[DepositStoreT]( &in.Cfg.Validator, in.Logger.With("service", "validator"), in.ChainSpec, @@ -88,7 +74,7 @@ func ProvideValidatorService[ in.Signer, in.SidecarFactory, in.LocalBuilder, - []validator.PayloadBuilder[BeaconStateT]{ + []validator.PayloadBuilder{ in.LocalBuilder, }, in.TelemetrySink, diff --git a/payload/attributes/factory.go b/payload/attributes/factory.go index e3d20483b3..23eddba663 100644 --- a/payload/attributes/factory.go +++ b/payload/attributes/factory.go @@ -26,12 +26,11 @@ import ( "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // Factory is a factory for creating payload attributes. -type Factory[ - BeaconStateT BeaconState, -] struct { +type Factory struct { // chainSpec is the chain spec for the attributes factory. chainSpec chain.ChainSpec // logger is the logger for the attributes factory. @@ -42,14 +41,12 @@ type Factory[ } // NewAttributesFactory creates a new instance of AttributesFactory. -func NewAttributesFactory[ - BeaconStateT BeaconState, -]( +func NewAttributesFactory( chainSpec chain.ChainSpec, logger log.Logger, suggestedFeeRecipient common.ExecutionAddress, -) *Factory[BeaconStateT] { - return &Factory[BeaconStateT]{ +) *Factory { + return &Factory{ chainSpec: chainSpec, logger: logger, suggestedFeeRecipient: suggestedFeeRecipient, @@ -57,8 +54,8 @@ func NewAttributesFactory[ } // BuildPayloadAttributes creates a new instance of PayloadAttributes. -func (f *Factory[BeaconStateT]) BuildPayloadAttributes( - st BeaconStateT, +func (f *Factory) BuildPayloadAttributes( + st *statedb.StateDB, slot math.Slot, timestamp uint64, prevHeadRoot [32]byte, diff --git a/payload/attributes/types.go b/payload/attributes/types.go index d0a770c5c0..b0ab112b33 100644 --- a/payload/attributes/types.go +++ b/payload/attributes/types.go @@ -25,14 +25,6 @@ import ( "github.com/berachain/beacon-kit/primitives/common" ) -// BeaconState is an interface for accessing the beacon state. -type BeaconState interface { - // ExpectedWithdrawals returns the expected withdrawals. - ExpectedWithdrawals() (engineprimitives.Withdrawals, error) - // GetRandaoMixAtIndex returns the randao mix at the given index. - GetRandaoMixAtIndex(index uint64) (common.Bytes32, error) -} - // PayloadAttributes is the interface for the payload attributes. type PayloadAttributes[SelfT any] interface { engineprimitives.PayloadAttributer diff --git a/payload/builder/builder.go b/payload/builder/builder.go index 2fec40e98b..3766568a0d 100644 --- a/payload/builder/builder.go +++ b/payload/builder/builder.go @@ -28,9 +28,7 @@ import ( // PayloadBuilder is used to build payloads on the // execution client. -type PayloadBuilder[ - BeaconStateT BeaconState, -] struct { +type PayloadBuilder struct { // cfg holds the configuration settings for the PayloadBuilder. cfg *Config // chainSpec holds the chain specifications for the PayloadBuilder. @@ -44,21 +42,19 @@ type PayloadBuilder[ // the execution client. pc PayloadCache[[32]byte, math.Slot] // attributesFactory is used to create attributes for the - attributesFactory AttributesFactory[BeaconStateT] + attributesFactory AttributesFactory } // New creates a new service. -func New[ - BeaconStateT BeaconState, -]( +func New( cfg *Config, chainSpec chain.ChainSpec, logger log.Logger, ee ExecutionEngine, pc PayloadCache[[32]byte, math.Slot], - af AttributesFactory[BeaconStateT], -) *PayloadBuilder[BeaconStateT] { - return &PayloadBuilder[BeaconStateT]{ + af AttributesFactory, +) *PayloadBuilder { + return &PayloadBuilder{ cfg: cfg, chainSpec: chainSpec, logger: logger, @@ -69,6 +65,6 @@ func New[ } // Enabled returns true if the payload builder is enabled. -func (pb *PayloadBuilder[BeaconStateT]) Enabled() bool { +func (pb *PayloadBuilder) Enabled() bool { return pb.cfg.Enabled } diff --git a/payload/builder/payload.go b/payload/builder/payload.go index d2d8dba23a..03e77737cc 100644 --- a/payload/builder/payload.go +++ b/payload/builder/payload.go @@ -28,13 +28,14 @@ import ( engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // RequestPayloadAsync builds a payload for the given slot and // returns the payload ID. -func (pb *PayloadBuilder[BeaconStateT]) RequestPayloadAsync( +func (pb *PayloadBuilder) RequestPayloadAsync( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, timestamp uint64, parentBlockRoot common.Root, @@ -90,9 +91,9 @@ func (pb *PayloadBuilder[BeaconStateT]) RequestPayloadAsync( // RequestPayloadSync request a payload for the given slot and // blocks until the payload is delivered. -func (pb *PayloadBuilder[BeaconStateT]) RequestPayloadSync( +func (pb *PayloadBuilder) RequestPayloadSync( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, timestamp uint64, parentBlockRoot common.Root, @@ -143,7 +144,7 @@ func (pb *PayloadBuilder[BeaconStateT]) RequestPayloadSync( // by reading a payloadID from the builder's cache. If it fails to // retrieve a payload, it will build a new payload and wait for the // execution client to return the payload. -func (pb *PayloadBuilder[BeaconStateT]) RetrievePayload( +func (pb *PayloadBuilder) RetrievePayload( ctx context.Context, slot math.Slot, parentBlockRoot common.Root, @@ -204,9 +205,9 @@ func (pb *PayloadBuilder[BeaconStateT]) RetrievePayload( // // TODO: This should be moved onto a "sync service" // of some kind. -func (pb *PayloadBuilder[BeaconStateT]) SendForceHeadFCU( +func (pb *PayloadBuilder) SendForceHeadFCU( ctx context.Context, - st BeaconStateT, + st *statedb.StateDB, slot math.Slot, ) error { if !pb.Enabled() { @@ -242,7 +243,7 @@ func (pb *PayloadBuilder[BeaconStateT]) SendForceHeadFCU( return err } -func (pb *PayloadBuilder[_]) getPayload( +func (pb *PayloadBuilder) getPayload( ctx context.Context, payloadID engineprimitives.PayloadID, slot math.U64, diff --git a/payload/builder/types.go b/payload/builder/types.go index 60336f5b97..7cb118044b 100644 --- a/payload/builder/types.go +++ b/payload/builder/types.go @@ -27,27 +27,10 @@ import ( engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/constraints" - "github.com/berachain/beacon-kit/primitives/crypto" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) -// BeaconState defines the interface for accessing various state-related data -// required for block processing. -type BeaconState interface { - // GetRandaoMixAtIndex retrieves the RANDAO mix at a specified index. - GetRandaoMixAtIndex(uint64) (common.Bytes32, error) - // ExpectedWithdrawals lists the expected withdrawals in the current state. - ExpectedWithdrawals() (engineprimitives.Withdrawals, error) - // GetLatestExecutionPayloadHeader fetches the most recent execution payload - // header. - GetLatestExecutionPayloadHeader() (*ctypes.ExecutionPayloadHeader, error) - // ValidatorIndexByPubkey finds the validator index associated with a given - // BLS public key. - ValidatorIndexByPubkey(crypto.BLSPubkey) (math.ValidatorIndex, error) - // GetBlockRootAtIndex retrieves the block root at a specified index. - GetBlockRootAtIndex(uint64) (common.Root, error) -} - type PayloadCache[RootT, SlotT any] interface { Get(slot SlotT, stateRoot RootT) (engineprimitives.PayloadID, bool) Has(slot SlotT, stateRoot RootT) bool @@ -67,11 +50,9 @@ type ExecutionPayload[T any] interface { } // AttributesFactory is the interface for the attributes factory. -type AttributesFactory[ - BeaconStateT any, -] interface { +type AttributesFactory interface { BuildPayloadAttributes( - st BeaconStateT, + st *statedb.StateDB, slot math.U64, timestamp uint64, prevHeadRoot [32]byte, diff --git a/state-transition/core/core_test.go b/state-transition/core/core_test.go index e87bf45855..7419cd9ba2 100644 --- a/state-transition/core/core_test.go +++ b/state-transition/core/core_test.go @@ -60,14 +60,9 @@ type ( TestKVStoreT = beacondb.KVStore - TestBeaconStateT = statedb.StateDB[ - *TestBeaconStateMarshallableT, - *TestKVStoreT, - ] + TestBeaconStateT = statedb.StateDB TestStateProcessorT = core.StateProcessor[ - *types.BeaconBlock, - *TestBeaconStateT, *transition.Context, *TestKVStoreT, ] @@ -159,8 +154,6 @@ func setupState( beaconState := new(TestBeaconStateT).NewFromDB(kvStore, cs) sp := core.NewStateProcessor[ - *types.BeaconBlock, - *TestBeaconStateT, *transition.Context, *TestKVStoreT, ]( diff --git a/state-transition/core/interfaces.go b/state-transition/core/interfaces.go index 82068b3bf6..80bebf427d 100644 --- a/state-transition/core/interfaces.go +++ b/state-transition/core/interfaces.go @@ -21,9 +21,6 @@ package core import ( - "context" - - "github.com/berachain/beacon-kit/chain-spec/chain" ctypes "github.com/berachain/beacon-kit/consensus-types/types" engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" "github.com/berachain/beacon-kit/primitives/common" @@ -31,23 +28,6 @@ import ( "github.com/berachain/beacon-kit/primitives/math" ) -// BeaconState is the interface for the beacon state. It -// is a combination of the read-only and write-only beacon state types. -type BeaconState[ - T any, - KVStoreT any, -] interface { - NewFromDB( - bdb KVStoreT, - cs chain.ChainSpec, - ) T - Copy() T - Context() context.Context - HashTreeRoot() common.Root - ReadOnlyBeaconState - WriteOnlyBeaconState -} - // ReadOnlyBeaconState is the interface for a read-only beacon state. type ReadOnlyBeaconState interface { ReadOnlyEth1Data diff --git a/state-transition/core/state/statedb.go b/state-transition/core/state/statedb.go index defa78a5ce..0d65534aff 100644 --- a/state-transition/core/state/statedb.go +++ b/state-transition/core/state/statedb.go @@ -28,48 +28,36 @@ import ( "github.com/berachain/beacon-kit/errors" "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/math" + "github.com/berachain/beacon-kit/storage/beacondb" ) // StateDB is the underlying struct behind the BeaconState interface. // //nolint:revive // todo fix somehow -type StateDB[ - BeaconStateMarshallableT BeaconStateMarshallable[BeaconStateMarshallableT], - KVStoreT KVStore[KVStoreT], -] struct { - KVStore[KVStoreT] +type StateDB struct { + beacondb.KVStore + cs chain.ChainSpec } // NewBeaconStateFromDB creates a new beacon state from an underlying state db. -func (s *StateDB[BeaconStateMarshallableT, KVStoreT]) NewFromDB( - bdb KVStoreT, +func (s *StateDB) NewFromDB( + bdb *beacondb.KVStore, cs chain.ChainSpec, -) *StateDB[ - BeaconStateMarshallableT, - KVStoreT, -] { - return &StateDB[ - BeaconStateMarshallableT, - KVStoreT, - ]{ - KVStore: bdb, +) *StateDB { + return &StateDB{ + KVStore: *bdb, cs: cs, } } // Copy returns a copy of the beacon state. -func (s *StateDB[BeaconStateMarshallableT, KVStoreT]) Copy() *StateDB[ - BeaconStateMarshallableT, - KVStoreT, -] { +func (s *StateDB) Copy() *StateDB { return s.NewFromDB(s.KVStore.Copy(), s.cs) } // IncreaseBalance increases the balance of a validator. -func (s *StateDB[ - _, _, -]) IncreaseBalance( +func (s *StateDB) IncreaseBalance( idx math.ValidatorIndex, delta math.Gwei, ) error { @@ -81,9 +69,7 @@ func (s *StateDB[ } // DecreaseBalance decreases the balance of a validator. -func (s *StateDB[ - _, _, -]) DecreaseBalance( +func (s *StateDB) DecreaseBalance( idx math.ValidatorIndex, delta math.Gwei, ) error { @@ -95,7 +81,7 @@ func (s *StateDB[ } // UpdateSlashingAtIndex sets the slashing amount in the store. -func (s *StateDB[_, _]) UpdateSlashingAtIndex( +func (s *StateDB) UpdateSlashingAtIndex( index uint64, amount math.Gwei, ) error { @@ -129,7 +115,7 @@ func (s *StateDB[_, _]) UpdateSlashingAtIndex( // (as the first withdrawal) used for EVM inflation. // //nolint:funlen,gocognit // TODO: Simplify when dropping special cases. -func (s *StateDB[_, _]) ExpectedWithdrawals() (engineprimitives.Withdrawals, error) { +func (s *StateDB) ExpectedWithdrawals() (engineprimitives.Withdrawals, error) { var ( validator *ctypes.Validator balance math.Gwei @@ -284,7 +270,7 @@ func (s *StateDB[_, _]) ExpectedWithdrawals() (engineprimitives.Withdrawals, err // // NOTE: The withdrawal index and validator index are both set to 0 as they are // not used during processing. -func (s *StateDB[_, _]) EVMInflationWithdrawal() *engineprimitives.Withdrawal { +func (s *StateDB) EVMInflationWithdrawal() *engineprimitives.Withdrawal { var withdrawal *engineprimitives.Withdrawal return withdrawal.New( EVMInflationWithdrawalIndex, @@ -297,8 +283,8 @@ func (s *StateDB[_, _]) EVMInflationWithdrawal() *engineprimitives.Withdrawal { // GetMarshallable is the interface for the beacon store. // //nolint:funlen,gocognit // todo fix somehow -func (s *StateDB[BeaconStateMarshallableT, _]) GetMarshallable() (BeaconStateMarshallableT, error) { - var empty BeaconStateMarshallableT +func (s *StateDB) GetMarshallable() (*ctypes.BeaconState, error) { + var empty *ctypes.BeaconState slot, err := s.GetSlot() if err != nil { @@ -389,8 +375,8 @@ func (s *StateDB[BeaconStateMarshallableT, _]) GetMarshallable() (BeaconStateMar return empty, err } - // TODO: Properly move BeaconState into full generics. - return (*new(BeaconStateMarshallableT)).New( + var bs *ctypes.BeaconState + return bs.New( s.cs.ActiveForkVersionForSlot(slot), genesisValidatorsRoot, slot, @@ -412,7 +398,7 @@ func (s *StateDB[BeaconStateMarshallableT, _]) GetMarshallable() (BeaconStateMar } // HashTreeRoot is the interface for the beacon store. -func (s *StateDB[_, _]) HashTreeRoot() common.Root { +func (s *StateDB) HashTreeRoot() common.Root { st, err := s.GetMarshallable() if err != nil { panic(err) diff --git a/state-transition/core/state/types.go b/state-transition/core/state/types.go index 27750dde06..a37204c408 100644 --- a/state-transition/core/state/types.go +++ b/state-transition/core/state/types.go @@ -23,37 +23,9 @@ package state import ( ctypes "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/primitives/common" - "github.com/berachain/beacon-kit/primitives/constraints" "github.com/berachain/beacon-kit/primitives/math" ) -// BeaconStateMarshallable represents an interface for a beacon state -// with generic types. -type BeaconStateMarshallable[ - T any, -] interface { - constraints.SSZMarshallableRootable - // New returns a new instance of the BeaconStateMarshallable. - New( - forkVersion uint32, - genesisValidatorsRoot common.Root, - slot math.U64, - fork *ctypes.Fork, - latestBlockHeader *ctypes.BeaconBlockHeader, - blockRoots []common.Root, - stateRoots []common.Root, - eth1Data *ctypes.Eth1Data, - eth1DepositIndex uint64, - latestExecutionPayloadHeader *ctypes.ExecutionPayloadHeader, - validators []*ctypes.Validator, - balances []uint64, - randaoMixes []common.Bytes32, - nextWithdrawalIndex uint64, - nextWithdrawalValidatorIndex math.U64, - slashings []math.U64, totalSlashing math.U64, - ) (T, error) -} - // Validator represents an interface for a validator with generic withdrawal // credentials. type Validator interface { diff --git a/state-transition/core/state_processor.go b/state-transition/core/state_processor.go index f50939baea..350233a265 100644 --- a/state-transition/core/state_processor.go +++ b/state-transition/core/state_processor.go @@ -37,8 +37,6 @@ import ( // StateProcessor is a basic Processor, which takes care of the // main state transition for the beacon chain. type StateProcessor[ - BeaconBlockT BeaconBlock, - BeaconStateT BeaconState[BeaconStateT, KVStoreT], ContextT Context, KVStoreT any, ] struct { @@ -62,8 +60,6 @@ type StateProcessor[ // NewStateProcessor creates a new state processor. func NewStateProcessor[ - BeaconBlockT BeaconBlock, - BeaconStateT BeaconState[BeaconStateT, KVStoreT], ContextT Context, KVStoreT any, ]( @@ -75,13 +71,11 @@ func NewStateProcessor[ fGetAddressFromPubKey func(crypto.BLSPubkey) ([]byte, error), telemetrySink TelemetrySink, ) *StateProcessor[ - BeaconBlockT, - BeaconStateT, ContextT, + ContextT, KVStoreT, ] { return &StateProcessor[ - BeaconBlockT, - BeaconStateT, ContextT, + ContextT, KVStoreT, ]{ logger: logger, @@ -96,11 +90,11 @@ func NewStateProcessor[ // Transition is the main function for processing a state transition. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, ContextT, _, + ContextT, _, ]) Transition( ctx ContextT, - st BeaconStateT, - blk BeaconBlockT, + st *state.StateDB, + blk *ctypes.BeaconBlock, ) (transition.ValidatorUpdates, error) { if blk.IsNil() { return nil, nil @@ -121,9 +115,9 @@ func (sp *StateProcessor[ } func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) ProcessSlots( - st BeaconStateT, slot math.Slot, + st *state.StateDB, slot math.Slot, ) (transition.ValidatorUpdates, error) { var res transition.ValidatorUpdates @@ -160,9 +154,9 @@ func (sp *StateProcessor[ // processSlot is run when a slot is missed. func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processSlot( - st BeaconStateT, + st *state.StateDB, ) error { stateSlot, err := st.GetSlot() if err != nil { @@ -203,11 +197,11 @@ func (sp *StateProcessor[ // ProcessBlock processes the block, it optionally verifies the // state root. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, ContextT, _, + ContextT, _, ]) ProcessBlock( ctx ContextT, - st BeaconStateT, - blk BeaconBlockT, + st *state.StateDB, + blk *ctypes.BeaconBlock, ) error { if err := sp.processBlockHeader(ctx, st, blk); err != nil { return err @@ -250,9 +244,9 @@ func (sp *StateProcessor[ // processEpoch processes the epoch and ensures it matches the local state. func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processEpoch( - st BeaconStateT, + st *state.StateDB, ) (transition.ValidatorUpdates, error) { slot, err := st.GetSlot() if err != nil { @@ -262,7 +256,7 @@ func (sp *StateProcessor[ // track validators set before updating it, to be able to // inform consensus of the validators set changes currentEpoch := sp.cs.SlotToEpoch(slot) - currentActiveVals, err := sp.getActiveVals(st, currentEpoch) + currentActiveVals, err := getActiveVals(sp.cs, st, currentEpoch) if err != nil { return nil, err } @@ -291,22 +285,22 @@ func (sp *StateProcessor[ // finally compute diffs in validator set to duly update consensus nextEpoch := currentEpoch + 1 - nextActiveVals, err := sp.getActiveVals(st, nextEpoch) + nextActiveVals, err := getActiveVals(sp.cs, st, nextEpoch) if err != nil { return nil, err } - return sp.validatorSetsDiffs(currentActiveVals, nextActiveVals), nil + return validatorSetsDiffs(currentActiveVals, nextActiveVals), nil } // processBlockHeader processes the header and ensures it matches the local // state. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, ContextT, _, + ContextT, _, ]) processBlockHeader( ctx ContextT, - st BeaconStateT, - blk BeaconBlockT, + st *state.StateDB, + blk *ctypes.BeaconBlock, ) error { // Ensure the block slot matches the state slot. slot, err := st.GetSlot() @@ -383,9 +377,9 @@ func (sp *StateProcessor[ // processEffectiveBalanceUpdates as defined in the Ethereum 2.0 specification. // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#effective-balances-updates func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processEffectiveBalanceUpdates( - st BeaconStateT, + st *state.StateDB, slot math.Slot, ) error { // Update effective balances with hysteresis diff --git a/state-transition/core/state_processor_genesis.go b/state-transition/core/state_processor_genesis.go index bac428de88..fe3a6fee0a 100644 --- a/state-transition/core/state_processor_genesis.go +++ b/state-transition/core/state_processor_genesis.go @@ -31,15 +31,16 @@ import ( "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" "github.com/berachain/beacon-kit/primitives/version" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // InitializePreminedBeaconStateFromEth1 initializes the beacon state. // //nolint:gocognit,funlen // todo fix. func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) InitializePreminedBeaconStateFromEth1( - st BeaconStateT, + st *statedb.StateDB, deposits ctypes.Deposits, execPayloadHeader *ctypes.ExecutionPayloadHeader, genesisVersion common.Version, @@ -151,17 +152,17 @@ func (sp *StateProcessor[ return nil, err } - activeVals, err := sp.getActiveVals(st, 0) + activeVals, err := getActiveVals(sp.cs, st, 0) if err != nil { return nil, err } - return sp.validatorSetsDiffs(nil, activeVals), nil + return validatorSetsDiffs(nil, activeVals), nil } func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processGenesisActivation( - st BeaconStateT, + st *statedb.StateDB, ) error { switch { case sp.cs.DepositEth1ChainID() == spec.BartioChainID: diff --git a/state-transition/core/state_processor_payload.go b/state-transition/core/state_processor_payload.go index 967a2a671f..44db756233 100644 --- a/state-transition/core/state_processor_payload.go +++ b/state-transition/core/state_processor_payload.go @@ -28,17 +28,18 @@ import ( ctypes "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/errors" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" "golang.org/x/sync/errgroup" ) // processExecutionPayload processes the execution payload and ensures it // matches the local state. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, ContextT, _, + ContextT, _, ]) processExecutionPayload( ctx ContextT, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, ) error { var ( body = blk.GetBody() @@ -92,11 +93,11 @@ func (sp *StateProcessor[ // validateExecutionPayload validates the execution payload against both local // state and the execution engine. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, _, _, + _, _, ]) validateExecutionPayload( ctx context.Context, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, consensusTime math.U64, optimisticEngine bool, ) error { @@ -114,9 +115,9 @@ func (sp *StateProcessor[ // validateStatelessPayload performs stateless checks on the execution payload. func (sp *StateProcessor[ - BeaconBlockT, _, _, _, + _, _, ]) validateStatelessPayload( - blk BeaconBlockT, + blk *ctypes.BeaconBlock, ) error { body := blk.GetBody() payload := body.GetExecutionPayload() @@ -146,11 +147,11 @@ func (sp *StateProcessor[ // validateStatefulPayload performs stateful checks on the execution payload. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, _, _, + _, _, ]) validateStatefulPayload( ctx context.Context, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, consensusTime math.U64, optimisticEngine bool, ) error { diff --git a/state-transition/core/state_processor_randao.go b/state-transition/core/state_processor_randao.go index cd0e505ba3..49f16cb37f 100644 --- a/state-transition/core/state_processor_randao.go +++ b/state-transition/core/state_processor_randao.go @@ -27,17 +27,18 @@ import ( "github.com/berachain/beacon-kit/primitives/crypto" "github.com/berachain/beacon-kit/primitives/crypto/sha256" "github.com/berachain/beacon-kit/primitives/version" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" "github.com/go-faster/xor" ) // processRandaoReveal processes the randao reveal and // ensures it matches the local state. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, ContextT, _, + ContextT, _, ]) processRandaoReveal( ctx ContextT, - st BeaconStateT, - blk BeaconBlockT, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, ) error { slot, err := st.GetSlot() if err != nil { @@ -94,9 +95,9 @@ func (sp *StateProcessor[ // processRandaoMixesReset as defined in the Ethereum 2.0 specification. // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#randao-mixes-updates func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processRandaoMixesReset( - st BeaconStateT, + st *statedb.StateDB, ) error { slot, err := st.GetSlot() if err != nil { @@ -118,7 +119,7 @@ func (sp *StateProcessor[ // buildRandaoMix as defined in the Ethereum 2.0 specification. func (sp *StateProcessor[ - _, _, _, _, + _, _, ]) buildRandaoMix( mix common.Bytes32, reveal crypto.BLSSignature, diff --git a/state-transition/core/state_processor_rewards_penalties.go b/state-transition/core/state_processor_rewards_penalties.go index ddb3928b96..1512cb9cb3 100644 --- a/state-transition/core/state_processor_rewards_penalties.go +++ b/state-transition/core/state_processor_rewards_penalties.go @@ -24,11 +24,12 @@ import ( "github.com/berachain/beacon-kit/config/spec" "github.com/berachain/beacon-kit/primitives/constants" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) func (sp *StateProcessor[ - _, BeaconStateT, _, _, -]) processRewardsAndPenalties(st BeaconStateT) error { + _, _, +]) processRewardsAndPenalties(st *statedb.StateDB) error { slot, err := st.GetSlot() if err != nil { return err diff --git a/state-transition/core/state_processor_sidecar_verifier.go b/state-transition/core/state_processor_sidecar_verifier.go index 7e9e666701..00c2bd5aa4 100644 --- a/state-transition/core/state_processor_sidecar_verifier.go +++ b/state-transition/core/state_processor_sidecar_verifier.go @@ -25,12 +25,13 @@ import ( "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/crypto" "github.com/berachain/beacon-kit/primitives/version" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) GetSidecarVerifierFn( - st BeaconStateT, + st *statedb.StateDB, ) ( func(blkHeader *ctypes.BeaconBlockHeader, signature crypto.BLSSignature) error, error, diff --git a/state-transition/core/state_processor_slashing.go b/state-transition/core/state_processor_slashing.go index c92fbeb1af..230c41ef9c 100644 --- a/state-transition/core/state_processor_slashing.go +++ b/state-transition/core/state_processor_slashing.go @@ -23,14 +23,15 @@ package core import ( "github.com/berachain/beacon-kit/config/spec" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // processSlashingsReset as defined in the Ethereum 2.0 specification. // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#slashings-balances-updates func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processSlashingsReset( - st BeaconStateT, + st *statedb.StateDB, ) error { // processSlashingsReset does not really do anything right now. // However we cannot simply drop it because appHash accounts diff --git a/state-transition/core/state_processor_staking.go b/state-transition/core/state_processor_staking.go index 7f34b5df6f..72a79da5f1 100644 --- a/state-transition/core/state_processor_staking.go +++ b/state-transition/core/state_processor_staking.go @@ -33,8 +33,11 @@ import ( // processOperations processes the operations and ensures they match the // local state. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, _, _, -]) processOperations(st BeaconStateT, blk BeaconBlockT) error { + _, _, +]) processOperations( + st *state.StateDB, + blk *ctypes.BeaconBlock, +) error { // Verify that outstanding deposits are processed // up to the maximum number of deposits @@ -64,8 +67,11 @@ func (sp *StateProcessor[ // processDeposit processes the deposit and ensures it matches the local state. func (sp *StateProcessor[ - _, BeaconStateT, _, _, -]) processDeposit(st BeaconStateT, dep *ctypes.Deposit) error { + _, _, +]) processDeposit( + st *state.StateDB, + dep *ctypes.Deposit, +) error { eth1DepositIndex, err := st.GetEth1DepositIndex() if err != nil { return err @@ -85,8 +91,11 @@ func (sp *StateProcessor[ // applyDeposit processes the deposit and ensures it matches the local state. func (sp *StateProcessor[ - _, BeaconStateT, _, _, -]) applyDeposit(st BeaconStateT, dep *ctypes.Deposit) error { + _, _, +]) applyDeposit( + st *state.StateDB, + dep *ctypes.Deposit, +) error { idx, err := st.ValidatorIndexByPubkey(dep.GetPubkey()) if err != nil { // If the validator does not exist, we add the validator. @@ -138,8 +147,11 @@ func (sp *StateProcessor[ // createValidator creates a validator if the deposit is valid. func (sp *StateProcessor[ - _, BeaconStateT, _, _, -]) createValidator(st BeaconStateT, dep *ctypes.Deposit) error { + _, _, +]) createValidator( + st *state.StateDB, + dep *ctypes.Deposit, +) error { // Get the current slot. slot, err := st.GetSlot() if err != nil { @@ -195,8 +207,12 @@ func (sp *StateProcessor[ // addValidatorToRegistry adds a validator to the registry. func (sp *StateProcessor[ - _, BeaconStateT, _, _, -]) addValidatorToRegistry(st BeaconStateT, dep *ctypes.Deposit, slot math.Slot) error { + _, _, +]) addValidatorToRegistry( + st *state.StateDB, + dep *ctypes.Deposit, + slot math.Slot, +) error { var val *ctypes.Validator val = val.New( dep.GetPubkey(), diff --git a/state-transition/core/state_processor_validators.go b/state-transition/core/state_processor_validators.go index a651734c57..1659edcc12 100644 --- a/state-transition/core/state_processor_validators.go +++ b/state-transition/core/state_processor_validators.go @@ -25,18 +25,20 @@ import ( "fmt" "slices" + "github.com/berachain/beacon-kit/chain-spec/chain" "github.com/berachain/beacon-kit/config/spec" ctypes "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/primitives/bytes" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" "github.com/sourcegraph/conc/iter" ) func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processRegistryUpdates( - st BeaconStateT, + st *statedb.StateDB, ) error { slot, err := st.GetSlot() if err != nil { @@ -111,9 +113,9 @@ func (sp *StateProcessor[ } func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processValidatorSetCap( - st BeaconStateT, + st *statedb.StateDB, ) error { // Enforce the validator set cap by: // 1- retrieving validators active next epoch @@ -126,7 +128,7 @@ func (sp *StateProcessor[ } nextEpoch := sp.cs.SlotToEpoch(slot) + 1 - nextEpochVals, err := sp.getActiveVals(st, nextEpoch) + nextEpochVals, err := getActiveVals(sp.cs, st, nextEpoch) if err != nil { return fmt.Errorf( "registry update, failed retrieving next epoch vals: %w", @@ -187,10 +189,7 @@ func (sp *StateProcessor[ // Note: validatorSetsDiffs does not need to be a StateProcessor method // but it helps simplifying generic instantiation. -// TODO: Turn this into a free function -func (*StateProcessor[ - _, _, _, _, -]) validatorSetsDiffs( +func validatorSetsDiffs( prevEpochValidators []*ctypes.Validator, currEpochValidator []*ctypes.Validator, ) transition.ValidatorUpdates { @@ -243,9 +242,11 @@ func (*StateProcessor[ // nextEpochValidatorSet returns the current estimation of what next epoch // validator set would be. -func (sp *StateProcessor[ - _, BeaconStateT, _, _, -]) getActiveVals(st BeaconStateT, epoch math.Epoch) ([]*ctypes.Validator, error) { +func getActiveVals( + cs chain.ChainSpec, + st *statedb.StateDB, + epoch math.Epoch, +) ([]*ctypes.Validator, error) { vals, err := st.GetValidators() if err != nil { return nil, err @@ -258,19 +259,19 @@ func (sp *StateProcessor[ activeVals := make([]*ctypes.Validator, 0, len(vals)) switch { - case sp.cs.DepositEth1ChainID() == spec.BartioChainID: + case cs.DepositEth1ChainID() == spec.BartioChainID: // Bartio does not properly handle validators epochs, so // we have an ad-hoc definition of active validator there for _, val := range vals { - if val.GetEffectiveBalance() > math.U64(sp.cs.EjectionBalance()) { + if val.GetEffectiveBalance() > math.U64(cs.EjectionBalance()) { activeVals = append(activeVals, val) } } - case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && + case cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && slot < math.U64(spec.BoonetFork3Height): // Boonet inherits Bartio processing till fork 3 for _, val := range vals { - if val.GetEffectiveBalance() > math.U64(sp.cs.EjectionBalance()) { + if val.GetEffectiveBalance() > math.U64(cs.EjectionBalance()) { activeVals = append(activeVals, val) } } diff --git a/state-transition/core/state_processor_withdrawals.go b/state-transition/core/state_processor_withdrawals.go index 672bdb47e2..79732e8bc0 100644 --- a/state-transition/core/state_processor_withdrawals.go +++ b/state-transition/core/state_processor_withdrawals.go @@ -24,6 +24,7 @@ import ( "fmt" "github.com/berachain/beacon-kit/config/spec" + ctypes "github.com/berachain/beacon-kit/consensus-types/types" engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" "github.com/berachain/beacon-kit/errors" "github.com/berachain/beacon-kit/primitives/math" @@ -40,10 +41,10 @@ import ( // 3. This modification reduces the maximum validator withdrawals per block by // one. func (sp *StateProcessor[ - BeaconBlockT, BeaconStateT, _, _, + _, _, ]) processWithdrawals( - st BeaconStateT, - blk BeaconBlockT, + st *state.StateDB, + blk *ctypes.BeaconBlock, ) error { // Dequeue and verify the logs. var ( @@ -63,9 +64,9 @@ func (sp *StateProcessor[ } func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processWithdrawalsByFork( - st BeaconStateT, + st *state.StateDB, expectedWithdrawals engineprimitives.Withdrawals, payloadWithdrawals engineprimitives.Withdrawals, ) error { @@ -130,9 +131,9 @@ func (sp *StateProcessor[ } func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processWithdrawalsBartio( - st BeaconStateT, + st *state.StateDB, expectedWithdrawals engineprimitives.Withdrawals, payloadWithdrawals engineprimitives.Withdrawals, slot math.Slot, @@ -197,9 +198,9 @@ func (sp *StateProcessor[ } func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) processWithdrawalsDefault( - st BeaconStateT, + st *state.StateDB, expectedWithdrawals engineprimitives.Withdrawals, payloadWithdrawals engineprimitives.Withdrawals, slot math.Slot, diff --git a/state-transition/core/types.go b/state-transition/core/types.go index ec99946063..22dd35f998 100644 --- a/state-transition/core/types.go +++ b/state-transition/core/types.go @@ -33,21 +33,6 @@ import ( "github.com/karalabe/ssz" ) -// BeaconBlock represents a generic interface for a beacon block. -type BeaconBlock interface { - IsNil() bool - // GetProposerIndex returns the index of the proposer. - GetProposerIndex() math.ValidatorIndex - // GetSlot returns the slot number of the block. - GetSlot() math.Slot - // GetBody returns the body of the block. - GetBody() *ctypes.BeaconBlockBody - // GetParentBlockRoot returns the root of the parent block. - GetParentBlockRoot() common.Root - // GetStateRoot returns the state root of the block. - GetStateRoot() common.Root -} - // Context defines an interface for managing state transition context. type Context interface { context.Context diff --git a/state-transition/core/validation_deposits.go b/state-transition/core/validation_deposits.go index c08f1a5cae..f5be001ccf 100644 --- a/state-transition/core/validation_deposits.go +++ b/state-transition/core/validation_deposits.go @@ -25,12 +25,13 @@ import ( "github.com/berachain/beacon-kit/errors" "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/math" + statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) validateGenesisDeposits( - st BeaconStateT, + st *statedb.StateDB, deposits []*ctypes.Deposit, ) error { eth1DepositIndex, err := st.GetEth1DepositIndex() @@ -66,9 +67,9 @@ func (sp *StateProcessor[ } func (sp *StateProcessor[ - _, BeaconStateT, _, _, + _, _, ]) validateNonGenesisDeposits( - st BeaconStateT, + st *statedb.StateDB, blkDeposits []*ctypes.Deposit, blkDepositRoot common.Root, ) error { diff --git a/storage/pruner/types.go b/storage/pruner/types.go index e3f73a5ac3..51a30f41fb 100644 --- a/storage/pruner/types.go +++ b/storage/pruner/types.go @@ -28,17 +28,10 @@ package pruner import ( "context" "errors" - - "github.com/berachain/beacon-kit/primitives/math" ) var ErrInvalidRange = errors.New("range start greater than end") -// BeaconBlock is an interface for beacon blocks. -type BeaconBlock interface { - GetSlot() math.U64 -} - // Prunable is an interface representing a store that can be pruned. type Prunable interface { // Prune prunes the store from [start, end).