Skip to content

Commit

Permalink
9/n Remove PayloadIDT generic type (#2293)
Browse files Browse the repository at this point in the history
  • Loading branch information
fridrik01 authored Dec 20, 2024
1 parent 582b803 commit 497c9b4
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 144 deletions.
37 changes: 2 additions & 35 deletions cmd/beacond/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package main

import (
appmodule "cosmossdk.io/core/appmodule/v2"
"github.com/berachain/beacon-kit/beacon/blockchain"
"github.com/berachain/beacon-kit/beacon/validator"
"github.com/berachain/beacon-kit/consensus-types/types"
Expand All @@ -30,7 +29,6 @@ import (
dablob "github.com/berachain/beacon-kit/da/blob"
dastore "github.com/berachain/beacon-kit/da/store"
datypes "github.com/berachain/beacon-kit/da/types"
engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives"
engineclient "github.com/berachain/beacon-kit/execution/client"
"github.com/berachain/beacon-kit/execution/deposit"
execution "github.com/berachain/beacon-kit/execution/engine"
Expand All @@ -50,7 +48,6 @@ import (
"github.com/berachain/beacon-kit/storage/block"
depositdb "github.com/berachain/beacon-kit/storage/deposit"
"github.com/berachain/beacon-kit/storage/filedb"
"github.com/berachain/beacon-kit/storage/pruner"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -87,7 +84,7 @@ type (
EngineClient = engineclient.EngineClient

// EngineClient is a type alias for the engine client.
ExecutionEngine = execution.Engine[PayloadID]
ExecutionEngine = execution.Engine

// IndexDB is a type alias for the range DB.
IndexDB = filedb.RangeDB
Expand All @@ -96,10 +93,7 @@ type (
KVStore = beacondb.KVStore

// LocalBuilder is a type alias for the local builder.
LocalBuilder = payloadbuilder.PayloadBuilder[
*BeaconState,
PayloadID,
]
LocalBuilder = payloadbuilder.PayloadBuilder[*BeaconState]

// NodeAPIEngine is a type alias for the node API engine.
NodeAPIEngine = echo.Engine
Expand Down Expand Up @@ -216,31 +210,4 @@ type (

// NodeAPIContext is a type alias for the node API context.
NodeAPIContext = echo.Context

// PayloadID is a type alias for the payload ID.
PayloadID = engineprimitives.PayloadID

// SlashingInfo is a type alias for the slashing info.
SlashingInfo = types.SlashingInfo

// ValidatorUpdate is a type alias for the validator update.
ABCIValidatorUpdate = appmodule.ValidatorUpdate

// ValidatorUpdate is a type alias for the validator update.
ValidatorUpdate = transition.ValidatorUpdate

// ValidatorUpdates is a type alias for the validator updates.
ValidatorUpdates = transition.ValidatorUpdates
)

/* -------------------------------------------------------------------------- */
/* Pruners */
/* -------------------------------------------------------------------------- */

type (
// DAPruner is a type alias for the DA pruner.
DAPruner = pruner.Pruner[*IndexDB]

// DepositPruner is a type alias for the deposit pruner.
DepositPruner = pruner.Pruner[*DepositStore]
)
12 changes: 6 additions & 6 deletions consensus-types/types/payload_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,20 @@ func BuildForkchoiceUpdateRequestNoAttrs(
}

// GetPayloadRequest represents a request to get a payload.
type GetPayloadRequest[PayloadIDT ~[8]byte] struct {
type GetPayloadRequest struct {
// PayloadID is the payload ID.
PayloadID PayloadIDT
PayloadID engineprimitives.PayloadID
// ForkVersion is the fork version that we are
// currently on.
ForkVersion uint32
}

// BuildGetPayloadRequest builds a get payload request.
func BuildGetPayloadRequest[PayloadIDT ~[8]byte](
payloadID PayloadIDT,
func BuildGetPayloadRequest(
payloadID engineprimitives.PayloadID,
forkVersion uint32,
) *GetPayloadRequest[PayloadIDT] {
return &GetPayloadRequest[PayloadIDT]{
) *GetPayloadRequest {
return &GetPayloadRequest{
PayloadID: payloadID,
ForkVersion: forkVersion,
}
Expand Down
22 changes: 9 additions & 13 deletions execution/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ import (

// Engine is Beacon-Kit's implementation of the `ExecutionEngine`
// from the Ethereum 2.0 Specification.
type Engine[
PayloadIDT ~[8]byte,
] struct {
type Engine struct {
// ec is the engine client that the engine will use to
// interact with the execution layer.
ec *client.EngineClient
Expand All @@ -48,22 +46,20 @@ type Engine[
}

// New creates a new Engine.
func New[
PayloadIDT ~[8]byte,
](
func New(
engineClient *client.EngineClient,
logger log.Logger,
telemtrySink TelemetrySink,
) *Engine[PayloadIDT] {
return &Engine[PayloadIDT]{
) *Engine {
return &Engine{
ec: engineClient,
logger: logger,
metrics: newEngineMetrics(telemtrySink, logger),
}
}

// Start spawns any goroutines required by the service.
func (ee *Engine[_]) Start(
func (ee *Engine) Start(
ctx context.Context,
) error {
go func() {
Expand All @@ -76,9 +72,9 @@ func (ee *Engine[_]) Start(
}

// GetPayload returns the payload and blobs bundle for the given slot.
func (ee *Engine[_]) GetPayload(
func (ee *Engine) GetPayload(
ctx context.Context,
req *ctypes.GetPayloadRequest[engineprimitives.PayloadID],
req *ctypes.GetPayloadRequest,
) (ctypes.BuiltExecutionPayloadEnv, error) {
return ee.ec.GetPayload(
ctx, req.PayloadID,
Expand All @@ -87,7 +83,7 @@ func (ee *Engine[_]) GetPayload(
}

// NotifyForkchoiceUpdate notifies the execution client of a forkchoice update.
func (ee *Engine[_]) NotifyForkchoiceUpdate(
func (ee *Engine) NotifyForkchoiceUpdate(
ctx context.Context,
req *ctypes.ForkchoiceUpdateRequest,
) (*engineprimitives.PayloadID, *common.ExecutionHash, error) {
Expand Down Expand Up @@ -159,7 +155,7 @@ func (ee *Engine[_]) NotifyForkchoiceUpdate(

// VerifyAndNotifyNewPayload verifies the new payload and notifies the
// execution client.
func (ee *Engine[_]) VerifyAndNotifyNewPayload(
func (ee *Engine) VerifyAndNotifyNewPayload(
ctx context.Context,
req *ctypes.NewPayloadRequest,
) error {
Expand Down
2 changes: 1 addition & 1 deletion node-core/components/chain_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type ChainServiceInput[
ChainSpec chain.ChainSpec
Cfg *config.Config
EngineClient *client.EngineClient
ExecutionEngine *engine.Engine[PayloadID]
ExecutionEngine *engine.Engine
LocalBuilder LocalBuilder[BeaconStateT]
Logger LoggerT
Signer crypto.BLSSigner
Expand Down
4 changes: 2 additions & 2 deletions node-core/components/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func ProvideExecutionEngine[
LoggerT log.AdvancedLogger[LoggerT],
](
in ExecutionEngineInputs[LoggerT],
) *engine.Engine[PayloadID] {
return engine.New[PayloadID](
) *engine.Engine {
return engine.New(
in.EngineClient,
in.Logger.With("service", "execution-engine"),
in.TelemetrySink,
Expand Down
13 changes: 3 additions & 10 deletions node-core/components/payload_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type LocalBuilderInput[
AttributesFactory AttributesFactory[BeaconStateT]
Cfg *config.Config
ChainSpec chain.ChainSpec
ExecutionEngine *engine.Engine[PayloadID]
ExecutionEngine *engine.Engine
Logger LoggerT
}

Expand All @@ -58,20 +58,13 @@ func ProvideLocalBuilder[
in LocalBuilderInput[
BeaconStateT, LoggerT,
],
) *payloadbuilder.PayloadBuilder[
BeaconStateT,
PayloadID,
] {
return payloadbuilder.New[
BeaconStateT,
PayloadID,
](
) *payloadbuilder.PayloadBuilder[BeaconStateT] {
return payloadbuilder.New[BeaconStateT](
&in.Cfg.PayloadBuilder,
in.ChainSpec,
in.Logger.With("service", "payload-builder"),
in.ExecutionEngine,
cache.NewPayloadIDCache[
PayloadID,
[32]byte, math.Slot,
](),
in.AttributesFactory,
Expand Down
2 changes: 1 addition & 1 deletion node-core/components/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type StateProcessorInput[
depinject.In
Logger LoggerT
ChainSpec chain.ChainSpec
ExecutionEngine *engine.Engine[PayloadID]
ExecutionEngine *engine.Engine
DepositStore DepositStore
Signer crypto.BLSSigner
TelemetrySink *metrics.TelemetrySink
Expand Down
25 changes: 7 additions & 18 deletions payload/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
// execution client.
type PayloadBuilder[
BeaconStateT BeaconState,
PayloadIDT ~[8]byte,
] struct {
// cfg holds the configuration settings for the PayloadBuilder.
cfg *Config
Expand All @@ -39,34 +38,27 @@ type PayloadBuilder[
// logger is used for logging within the PayloadBuilder.
logger log.Logger
// ee is the execution engine.
ee ExecutionEngine[PayloadIDT]
ee ExecutionEngine
// pc is the payload ID cache, it is used to store
// "in-flight" payloads that are being built on
// the execution client.
pc PayloadCache[PayloadIDT, [32]byte, math.Slot]
pc PayloadCache[[32]byte, math.Slot]
// attributesFactory is used to create attributes for the
attributesFactory AttributesFactory[BeaconStateT]
}

// New creates a new service.
func New[
BeaconStateT BeaconState,
PayloadIDT ~[8]byte,
](
cfg *Config,
chainSpec chain.ChainSpec,
logger log.Logger,
ee ExecutionEngine[PayloadIDT],
pc PayloadCache[PayloadIDT, [32]byte, math.Slot],
ee ExecutionEngine,
pc PayloadCache[[32]byte, math.Slot],
af AttributesFactory[BeaconStateT],
) *PayloadBuilder[
BeaconStateT,
PayloadIDT,
] {
return &PayloadBuilder[
BeaconStateT,
PayloadIDT,
]{
) *PayloadBuilder[BeaconStateT] {
return &PayloadBuilder[BeaconStateT]{
cfg: cfg,
chainSpec: chainSpec,
logger: logger,
Expand All @@ -77,9 +69,6 @@ func New[
}

// Enabled returns true if the payload builder is enabled.
func (pb *PayloadBuilder[
BeaconStateT,
PayloadIDT,
]) Enabled() bool {
func (pb *PayloadBuilder[BeaconStateT]) Enabled() bool {
return pb.cfg.Enabled
}
32 changes: 9 additions & 23 deletions payload/builder/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ import (

// RequestPayloadAsync builds a payload for the given slot and
// returns the payload ID.
func (pb *PayloadBuilder[
BeaconStateT,
PayloadIDT,
]) RequestPayloadAsync(
func (pb *PayloadBuilder[BeaconStateT]) RequestPayloadAsync(
ctx context.Context,
st BeaconStateT,
slot math.Slot,
timestamp uint64,
parentBlockRoot common.Root,
headEth1BlockHash common.ExecutionHash,
finalEth1BlockHash common.ExecutionHash,
) (*PayloadIDT, error) {
) (*engineprimitives.PayloadID, error) {
if !pb.Enabled() {
return nil, ErrPayloadBuilderDisabled
}
Expand All @@ -67,7 +64,7 @@ func (pb *PayloadBuilder[
}

// Submit the forkchoice update to the execution client.
var payloadID *PayloadIDT
var payloadID *engineprimitives.PayloadID
payloadID, _, err = pb.ee.NotifyForkchoiceUpdate(
ctx, &ctypes.ForkchoiceUpdateRequest{
State: &engineprimitives.ForkchoiceStateV1{
Expand All @@ -93,10 +90,7 @@ func (pb *PayloadBuilder[

// RequestPayloadSync request a payload for the given slot and
// blocks until the payload is delivered.
func (pb *PayloadBuilder[
BeaconStateT,
PayloadIDT,
]) RequestPayloadSync(
func (pb *PayloadBuilder[BeaconStateT]) RequestPayloadSync(
ctx context.Context,
st BeaconStateT,
slot math.Slot,
Expand Down Expand Up @@ -149,10 +143,7 @@ func (pb *PayloadBuilder[
// 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,
PayloadIDT,
]) RetrievePayload(
func (pb *PayloadBuilder[BeaconStateT]) RetrievePayload(
ctx context.Context,
slot math.Slot,
parentBlockRoot common.Root,
Expand Down Expand Up @@ -213,10 +204,7 @@ func (pb *PayloadBuilder[
//
// TODO: This should be moved onto a "sync service"
// of some kind.
func (pb *PayloadBuilder[
BeaconStateT,
PayloadIDT,
]) SendForceHeadFCU(
func (pb *PayloadBuilder[BeaconStateT]) SendForceHeadFCU(
ctx context.Context,
st BeaconStateT,
slot math.Slot,
Expand Down Expand Up @@ -254,16 +242,14 @@ func (pb *PayloadBuilder[
return err
}

func (pb *PayloadBuilder[
_, PayloadIDT,
]) getPayload(
func (pb *PayloadBuilder[_]) getPayload(
ctx context.Context,
payloadID PayloadIDT,
payloadID engineprimitives.PayloadID,
slot math.U64,
) (ctypes.BuiltExecutionPayloadEnv, error) {
envelope, err := pb.ee.GetPayload(
ctx,
&ctypes.GetPayloadRequest[PayloadIDT]{
&ctypes.GetPayloadRequest{
PayloadID: payloadID,
ForkVersion: pb.chainSpec.ActiveForkVersionForSlot(slot),
},
Expand Down
Loading

0 comments on commit 497c9b4

Please sign in to comment.