diff --git a/mod/beacon/blockchain/execution_engine.go b/mod/beacon/blockchain/execution_engine.go index f4864ee5ef..294c6cd5eb 100644 --- a/mod/beacon/blockchain/execution_engine.go +++ b/mod/beacon/blockchain/execution_engine.go @@ -40,6 +40,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) sendPostBlockFCU( ctx context.Context, st BeaconStateT, @@ -75,6 +76,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) sendNextFCUWithAttributes( ctx context.Context, st BeaconStateT, @@ -130,6 +132,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) sendNextFCUWithoutAttributes( ctx context.Context, blk BeaconBlockT, @@ -171,6 +174,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) calculateNextTimestamp(blk BeaconBlockT) uint64 { //#nosec:G701 // not an issue in practice. return max( diff --git a/mod/beacon/blockchain/payload.go b/mod/beacon/blockchain/payload.go index 025225aece..0799b3f6a7 100644 --- a/mod/beacon/blockchain/payload.go +++ b/mod/beacon/blockchain/payload.go @@ -41,6 +41,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) forceStartupHead( ctx context.Context, st BeaconStateT, @@ -79,6 +80,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) handleRebuildPayloadForRejectedBlock( ctx context.Context, st BeaconStateT, @@ -112,6 +114,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) rebuildPayloadForRejectedBlock( ctx context.Context, st BeaconStateT, @@ -199,6 +202,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) handleOptimisticPayloadBuild( ctx context.Context, st BeaconStateT, @@ -226,6 +230,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) optimisticPayloadBuild( ctx context.Context, st BeaconStateT, diff --git a/mod/beacon/blockchain/process.go b/mod/beacon/blockchain/process.go index 8551b67c56..aee6380f21 100644 --- a/mod/beacon/blockchain/process.go +++ b/mod/beacon/blockchain/process.go @@ -45,6 +45,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) ProcessGenesisData( ctx context.Context, genesisData GenesisT, @@ -71,6 +72,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) ProcessBlockAndBlobs( ctx context.Context, blk BeaconBlockT, @@ -146,6 +148,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) processBeaconBlock( ctx context.Context, st BeaconStateT, @@ -191,6 +194,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) processBlobSidecars( ctx context.Context, slot math.Slot, diff --git a/mod/beacon/blockchain/receive.go b/mod/beacon/blockchain/receive.go index 3b63975100..50beb9eca1 100644 --- a/mod/beacon/blockchain/receive.go +++ b/mod/beacon/blockchain/receive.go @@ -44,6 +44,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) ReceiveBlockAndBlobs( ctx context.Context, blk BeaconBlockT, @@ -84,6 +85,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) VerifyIncomingBlock( ctx context.Context, blk BeaconBlockT, @@ -161,6 +163,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) verifyStateRoot( ctx context.Context, st BeaconStateT, @@ -206,6 +209,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) VerifyIncomingBlobs( _ context.Context, blk BeaconBlockT, @@ -259,6 +263,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) shouldBuildOptimisticPayloads() bool { return s.optimisticPayloadBuilds && s.lb.Enabled() } diff --git a/mod/beacon/blockchain/service.go b/mod/beacon/blockchain/service.go index 9c31c4ad21..a4c01b1427 100644 --- a/mod/beacon/blockchain/service.go +++ b/mod/beacon/blockchain/service.go @@ -49,6 +49,7 @@ type Service[ Version() uint32 GetSuggestedFeeRecipient() common.ExecutionAddress }, + WithdrawalT any, ] struct { // sb represents the backend storage for beacon states and associated // sidecars. @@ -111,6 +112,7 @@ func NewService[ Version() uint32 GetSuggestedFeeRecipient() common.ExecutionAddress }, + WithdrawalT any, ]( sb StorageBackend[ AvailabilityStoreT, @@ -140,12 +142,12 @@ func NewService[ ) *Service[ AvailabilityStoreT, BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT, BeaconStateT, BlobSidecarsT, DepositT, ExecutionPayloadT, - ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, WithdrawalT, ] { return &Service[ AvailabilityStoreT, BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT, BeaconStateT, BlobSidecarsT, DepositT, ExecutionPayloadT, - ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, WithdrawalT, ]{ sb: sb, logger: logger, @@ -174,6 +176,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) Name() string { return "blockchain" } @@ -190,6 +193,7 @@ func (s *Service[ ExecutionPayloadHeaderT, GenesisT, PayloadAttributesT, + _, ]) Start( context.Context, ) error { diff --git a/mod/execution/pkg/engine/engine.go b/mod/execution/pkg/engine/engine.go index 05cb882484..7efb10aea4 100644 --- a/mod/execution/pkg/engine/engine.go +++ b/mod/execution/pkg/engine/engine.go @@ -39,10 +39,11 @@ import ( // from the Ethereum 2.0 Specification. type Engine[ ExecutionPayloadT ExecutionPayload[ - ExecutionPayloadT, *engineprimitives.Withdrawal, + ExecutionPayloadT, WithdrawalT, ], PayloadAttributesT engineprimitives.PayloadAttributer, PayloadIDT ~[8]byte, + WithdrawalT Withdrawal[WithdrawalT], ] struct { // ec is the engine client that the engine will use to // interact with the execution layer. @@ -61,10 +62,11 @@ type Engine[ // New creates a new Engine. func New[ ExecutionPayloadT ExecutionPayload[ - ExecutionPayloadT, *engineprimitives.Withdrawal, + ExecutionPayloadT, WithdrawalT, ], PayloadAttributesT engineprimitives.PayloadAttributer, PayloadIDT ~[8]byte, + WithdrawalT Withdrawal[WithdrawalT], ]( ec *client.EngineClient[ExecutionPayloadT, PayloadAttributesT], logger log.Logger[any], @@ -74,9 +76,9 @@ func New[ ], telemtrySink TelemetrySink, ) *Engine[ - ExecutionPayloadT, PayloadAttributesT, PayloadIDT, + ExecutionPayloadT, PayloadAttributesT, PayloadIDT, WithdrawalT, ] { - return &Engine[ExecutionPayloadT, PayloadAttributesT, PayloadIDT]{ + return &Engine[ExecutionPayloadT, PayloadAttributesT, PayloadIDT, WithdrawalT]{ ec: ec, logger: logger, metrics: newEngineMetrics(telemtrySink, logger), @@ -85,9 +87,7 @@ func New[ } // Start spawns any goroutines required by the service. -func (ee *Engine[ - ExecutionPayloadT, PayloadAttributesT, PayloadIDT, -]) Start( +func (ee *Engine[_, _, _, _]) Start( ctx context.Context, ) error { go func() { @@ -101,7 +101,7 @@ func (ee *Engine[ // GetPayload returns the payload and blobs bundle for the given slot. func (ee *Engine[ - ExecutionPayloadT, _, _, + ExecutionPayloadT, _, _, _, ]) GetPayload( ctx context.Context, req *engineprimitives.GetPayloadRequest[engineprimitives.PayloadID], @@ -114,7 +114,7 @@ func (ee *Engine[ // NotifyForkchoiceUpdate notifies the execution client of a forkchoice update. func (ee *Engine[ - _, PayloadAttributesT, _, + _, PayloadAttributesT, _, _, ]) NotifyForkchoiceUpdate( ctx context.Context, req *engineprimitives.ForkchoiceUpdateRequest[PayloadAttributesT], @@ -186,11 +186,12 @@ func (ee *Engine[ // VerifyAndNotifyNewPayload verifies the new payload and notifies the // execution client. func (ee *Engine[ - ExecutionPayloadT, _, _, + ExecutionPayloadT, _, _, WithdrawalT, ]) VerifyAndNotifyNewPayload( ctx context.Context, req *engineprimitives.NewPayloadRequest[ - ExecutionPayloadT, *engineprimitives.Withdrawal], + ExecutionPayloadT, WithdrawalT, + ], ) error { // Log the new payload attempt. ee.metrics.markNewPayloadCalled( diff --git a/mod/execution/pkg/engine/types.go b/mod/execution/pkg/engine/types.go index 826ebedccb..21146ee65a 100644 --- a/mod/execution/pkg/engine/types.go +++ b/mod/execution/pkg/engine/types.go @@ -62,3 +62,17 @@ type TelemetrySink interface { // provided keys. SetGauge(key string, value int64, args ...string) } + +// Withdrawal is the interface for a withdrawal. +type Withdrawal[WithdrawalT any] interface { + // Equals returns true if the withdrawal is equal to the other. + Equals(WithdrawalT) bool + // GetAmount returns the amount of the withdrawal. + GetAmount() math.Gwei + // GetIndex returns the public key of the validator. + GetIndex() math.U64 + // GetValidatorIndex returns the index of the validator. + GetValidatorIndex() math.ValidatorIndex + // GetAddress returns the address of the withdrawal. + GetAddress() common.ExecutionAddress +} diff --git a/mod/node-core/pkg/components/chain_service.go b/mod/node-core/pkg/components/chain_service.go index 77a317a4ba..82bfdf69da 100644 --- a/mod/node-core/pkg/components/chain_service.go +++ b/mod/node-core/pkg/components/chain_service.go @@ -25,6 +25,7 @@ import ( "cosmossdk.io/depinject" "github.com/berachain/beacon-kit/mod/beacon/blockchain" "github.com/berachain/beacon-kit/mod/config" + engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" "github.com/berachain/beacon-kit/mod/node-core/pkg/components/metrics" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/crypto" @@ -63,6 +64,8 @@ func ProvideChainService( *ExecutionPayload, *ExecutionPayloadHeader, *Genesis, + *engineprimitives.PayloadAttributes[*Withdrawal], + *Withdrawal, ]( in.StorageBackend, in.Logger.With("service", "blockchain"), diff --git a/mod/node-core/pkg/components/defaults.go b/mod/node-core/pkg/components/defaults.go index 240f2c9861..2ab70b1086 100644 --- a/mod/node-core/pkg/components/defaults.go +++ b/mod/node-core/pkg/components/defaults.go @@ -56,7 +56,11 @@ func DefaultComponentsWithStandardTypes() []any { *engineprimitives.PayloadAttributes[*Withdrawal], ], ProvideExecutionEngine[ - *ExecutionPayload, *Withdrawal], + *ExecutionPayload, + *engineprimitives.PayloadAttributes[*Withdrawal], + engineprimitives.PayloadID, + *Withdrawal, + ], ProvideJWTSecret, ProvideLocalBuilder, ProvideServiceRegistry, diff --git a/mod/node-core/pkg/components/engine.go b/mod/node-core/pkg/components/engine.go index ef26bc6781..84afb3ad55 100644 --- a/mod/node-core/pkg/components/engine.go +++ b/mod/node-core/pkg/components/engine.go @@ -27,7 +27,7 @@ import ( "cosmossdk.io/log" "github.com/berachain/beacon-kit/mod/config" engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" - engineclient "github.com/berachain/beacon-kit/mod/execution/pkg/client" + "github.com/berachain/beacon-kit/mod/execution/pkg/client" execution "github.com/berachain/beacon-kit/mod/execution/pkg/engine" "github.com/berachain/beacon-kit/mod/interfaces" "github.com/berachain/beacon-kit/mod/node-core/pkg/components/metrics" @@ -39,8 +39,9 @@ import ( // EngineClientInputs is the input for the EngineClient. type EngineClientInputs struct { depinject.In - ChainSpec common.ChainSpec - Config *config.Config + ChainSpec common.ChainSpec + Config *config.Config + // TODO: this feels like a hood way to handle it. JWTSecret *jwt.Secret `optional:"true"` Logger log.Logger TelemetrySink *metrics.TelemetrySink @@ -67,8 +68,8 @@ func ProvideEngineClient[ WithdrawalT any, ]( in EngineClientInputs, -) *engineclient.EngineClient[ExecutionPayloadT, PayloadAttributesT] { - return engineclient.New[ExecutionPayloadT, PayloadAttributesT]( +) *client.EngineClient[ExecutionPayloadT, PayloadAttributesT] { + return client.New[ExecutionPayloadT, PayloadAttributesT]( &in.Config.Engine, in.Logger.With("service", "engine.client"), in.JWTSecret, @@ -77,11 +78,18 @@ func ProvideEngineClient[ ) } -// ExecutionEngineInput is the input for the execution engine for the depinject -// framework. -type ExecutionEngineInput struct { +// EngineClientInputs is the input for the EngineClient. +type ExecutionEngineInputs[ + ExecutionPayloadT interfaces.ExecutionPayload[ + ExecutionPayloadT, common.ExecutionAddress, + common.ExecutionHash, common.Bytes32, + math.U64, math.Wei, []byte, WithdrawalT, + ], + PayloadAttributesT engineprimitives.PayloadAttributer, + WithdrawalT any, +] struct { depinject.In - EngineClient *EngineClient + EngineClient *client.EngineClient[ExecutionPayloadT, PayloadAttributesT] Logger log.Logger StatusFeed *StatusFeed TelemetrySink *metrics.TelemetrySink @@ -95,14 +103,24 @@ func ProvideExecutionEngine[ common.ExecutionHash, common.Bytes32, math.U64, math.Wei, []byte, WithdrawalT, ], - WithdrawalT any, + PayloadAttributesT engineprimitives.PayloadAttributer, + PayloadIDT ~[8]byte, + WithdrawalT execution.Withdrawal[WithdrawalT], ]( - in ExecutionEngineInput, -) *ExecutionEngine { + in ExecutionEngineInputs[ + ExecutionPayloadT, + PayloadAttributesT, + WithdrawalT, + ], +) *execution.Engine[ + ExecutionPayloadT, PayloadAttributesT, + PayloadIDT, WithdrawalT, +] { return execution.New[ - *ExecutionPayload, - *engineprimitives.PayloadAttributes[*Withdrawal], - engineprimitives.PayloadID, + ExecutionPayloadT, + PayloadAttributesT, + PayloadIDT, + WithdrawalT, ]( in.EngineClient, in.Logger.With("service", "execution-engine"), diff --git a/mod/node-core/pkg/components/types.go b/mod/node-core/pkg/components/types.go index ca6698bf16..bcef0b93e3 100644 --- a/mod/node-core/pkg/components/types.go +++ b/mod/node-core/pkg/components/types.go @@ -120,6 +120,7 @@ type ( *ExecutionPayloadHeader, *Genesis, *engineprimitives.PayloadAttributes[*Withdrawal], + *Withdrawal, ] // DBManager is a type alias for the database manager. @@ -153,7 +154,7 @@ type ( // EngineClient is a type alias for the engine client. ExecutionEngine = execution.Engine[ *ExecutionPayload, *engineprimitives.PayloadAttributes[*Withdrawal], - engineprimitives.PayloadID, + engineprimitives.PayloadID, *Withdrawal, ] // ExecutionPayload type aliases.