diff --git a/mod/engine-primitives/pkg/engine-primitives/requests.go b/mod/engine-primitives/pkg/engine-primitives/requests.go index 27500c6cec..5bd5e7fbae 100644 --- a/mod/engine-primitives/pkg/engine-primitives/requests.go +++ b/mod/engine-primitives/pkg/engine-primitives/requests.go @@ -253,20 +253,20 @@ func BuildForkchoiceUpdateRequest( } // GetPayloadRequest represents a request to get a payload. -type GetPayloadRequest struct { +type GetPayloadRequest[PayloadIDT ~[8]byte] struct { // PayloadID is the payload ID. - PayloadID PayloadID + PayloadID PayloadIDT // ForkVersion is the fork version that we are // currently on. ForkVersion uint32 } // BuildGetPayloadRequest builds a get payload request. -func BuildGetPayloadRequest( - payloadID PayloadID, +func BuildGetPayloadRequest[PayloadIDT ~[8]byte]( + payloadID PayloadIDT, forkVersion uint32, -) *GetPayloadRequest { - return &GetPayloadRequest{ +) *GetPayloadRequest[PayloadIDT] { + return &GetPayloadRequest[PayloadIDT]{ PayloadID: payloadID, ForkVersion: forkVersion, } diff --git a/mod/execution/pkg/engine/engine.go b/mod/execution/pkg/engine/engine.go index 1e932ace77..2b72a9d713 100644 --- a/mod/execution/pkg/engine/engine.go +++ b/mod/execution/pkg/engine/engine.go @@ -41,6 +41,7 @@ type Engine[ ExecutionPayloadT ExecutionPayload[ ExecutionPayloadT, *engineprimitives.Withdrawal, ], + PayloadIDT ~[8]byte, ] struct { // ec is the engine client that the engine will use to // interact with the execution layer. @@ -61,6 +62,7 @@ func New[ ExecutionPayloadT ExecutionPayload[ ExecutionPayloadT, *engineprimitives.Withdrawal, ], + PayloadIDT ~[8]byte, ]( ec *client.EngineClient[ExecutionPayloadT], logger log.Logger[any], @@ -69,8 +71,8 @@ func New[ *asynctypes.Event[*service.StatusEvent], ], telemtrySink TelemetrySink, -) *Engine[ExecutionPayloadT] { - return &Engine[ExecutionPayloadT]{ +) *Engine[ExecutionPayloadT, PayloadIDT] { + return &Engine[ExecutionPayloadT, PayloadIDT]{ ec: ec, logger: logger, metrics: newEngineMetrics(telemtrySink, logger), @@ -79,7 +81,7 @@ func New[ } // Start spawns any goroutines required by the service. -func (ee *Engine[ExecutionPayloadT]) Start( +func (ee *Engine[ExecutionPayloadT, PayloadIDT]) Start( ctx context.Context, ) error { go func() { @@ -92,9 +94,9 @@ func (ee *Engine[ExecutionPayloadT]) Start( } // GetPayload returns the payload and blobs bundle for the given slot. -func (ee *Engine[ExecutionPayloadT]) GetPayload( +func (ee *Engine[ExecutionPayloadT, PayloadIDT]) GetPayload( ctx context.Context, - req *engineprimitives.GetPayloadRequest, + req *engineprimitives.GetPayloadRequest[engineprimitives.PayloadID], ) (engineprimitives.BuiltExecutionPayloadEnv[ExecutionPayloadT], error) { return ee.ec.GetPayload( ctx, req.PayloadID, @@ -103,7 +105,7 @@ func (ee *Engine[ExecutionPayloadT]) GetPayload( } // NotifyForkchoiceUpdate notifies the execution client of a forkchoice update. -func (ee *Engine[ExecutionPayloadT]) NotifyForkchoiceUpdate( +func (ee *Engine[ExecutionPayloadT, PayloadIDT]) NotifyForkchoiceUpdate( ctx context.Context, req *engineprimitives.ForkchoiceUpdateRequest, ) (*engineprimitives.PayloadID, *common.ExecutionHash, error) { @@ -174,7 +176,7 @@ func (ee *Engine[ExecutionPayloadT]) NotifyForkchoiceUpdate( // VerifyAndNotifyNewPayload verifies the new payload and notifies the // execution client. -func (ee *Engine[ExecutionPayloadT]) VerifyAndNotifyNewPayload( +func (ee *Engine[ExecutionPayloadT, PayloadIDT]) VerifyAndNotifyNewPayload( ctx context.Context, req *engineprimitives.NewPayloadRequest[ ExecutionPayloadT, *engineprimitives.Withdrawal], diff --git a/mod/log/pkg/phuslu/formatter.go b/mod/log/pkg/phuslu/formatter.go index 5b3ebc8f14..acf3951d6e 100644 --- a/mod/log/pkg/phuslu/formatter.go +++ b/mod/log/pkg/phuslu/formatter.go @@ -86,11 +86,9 @@ func (f *Formatter) Format( f.ensureLineBreak(buffer) if args.Stack != "" { + buffer.Bytes = append(buffer.Bytes, args.Stack...) if args.Stack[len(args.Stack)-1] != '\n' { - buffer.Bytes = append(buffer.Bytes, args.Stack...) buffer.Bytes = append(buffer.Bytes, '\n') - } else { - buffer.Bytes = append(buffer.Bytes, args.Stack...) } } diff --git a/mod/log/pkg/phuslu/phuslu.go b/mod/log/pkg/phuslu/phuslu.go index f7fdacce55..6c6a9b5e47 100644 --- a/mod/log/pkg/phuslu/phuslu.go +++ b/mod/log/pkg/phuslu/phuslu.go @@ -99,8 +99,11 @@ func (l Logger[ImplT]) With(keyVals ...any) ImplT { // Add the new context to the existing context. for i := 0; i < len(keyVals); i += 2 { - key, val := keyVals[i].(string), keyVals[i+1] - newLogger.context[key] = val + key, ok := keyVals[i].(string) + if !ok { + panic("context key must be a string") + } + newLogger.context[key] = keyVals[i+1] } return any(&newLogger).(ImplT) diff --git a/mod/node-core/pkg/components/engine.go b/mod/node-core/pkg/components/engine.go index 1b02c75435..901238ccb6 100644 --- a/mod/node-core/pkg/components/engine.go +++ b/mod/node-core/pkg/components/engine.go @@ -26,6 +26,7 @@ import ( "cosmossdk.io/depinject" "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" execution "github.com/berachain/beacon-kit/mod/execution/pkg/engine" "github.com/berachain/beacon-kit/mod/interfaces" @@ -88,7 +89,7 @@ func ProvideExecutionEngine[ ]( in ExecutionEngineInput, ) *ExecutionEngine { - return execution.New[*ExecutionPayload]( + return execution.New[*ExecutionPayload, engineprimitives.PayloadID]( in.EngineClient, in.Logger.With("service", "execution-engine"), in.StatusFeed, diff --git a/mod/node-core/pkg/components/types.go b/mod/node-core/pkg/components/types.go index 2d38b69d1a..4929bbb574 100644 --- a/mod/node-core/pkg/components/types.go +++ b/mod/node-core/pkg/components/types.go @@ -141,7 +141,9 @@ type ( EngineClient = engineclient.EngineClient[*ExecutionPayload] // EngineClient is a type alias for the engine client. - ExecutionEngine = execution.Engine[*ExecutionPayload] + ExecutionEngine = execution.Engine[ + *ExecutionPayload, engineprimitives.PayloadID, + ] // ExecutionPayload type aliases. ExecutionPayload = types.ExecutionPayload @@ -161,7 +163,8 @@ type ( // LocalBuilder is a type alias for the local builder. LocalBuilder = payloadbuilder.PayloadBuilder[ - BeaconState, *ExecutionPayload, *ExecutionPayloadHeader, + BeaconState, *ExecutionPayload, + *ExecutionPayloadHeader, engineprimitives.PayloadID, ] // StateProcessor is the type alias for the state processor inteface. diff --git a/mod/payload/pkg/builder/attributes.go b/mod/payload/pkg/builder/attributes.go index f10f25dc09..33c93855ae 100644 --- a/mod/payload/pkg/builder/attributes.go +++ b/mod/payload/pkg/builder/attributes.go @@ -29,7 +29,7 @@ import ( // slot. The attribute is required to initiate a payload build process in the // context of an `engine_forkchoiceUpdated` call. func (pb *PayloadBuilder[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadIDT, ]) getPayloadAttribute( st BeaconStateT, slot math.Slot, diff --git a/mod/payload/pkg/builder/builder.go b/mod/payload/pkg/builder/builder.go index 8b837afd76..42f5b0d9c1 100644 --- a/mod/payload/pkg/builder/builder.go +++ b/mod/payload/pkg/builder/builder.go @@ -21,7 +21,6 @@ package builder import ( - engineprimitves "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives" "github.com/berachain/beacon-kit/mod/log" "github.com/berachain/beacon-kit/mod/payload/pkg/cache" "github.com/berachain/beacon-kit/mod/primitives" @@ -44,6 +43,7 @@ type PayloadBuilder[ GetBlockHash() common.ExecutionHash GetParentHash() common.ExecutionHash }, + PayloadIDT ~[8]byte, ] struct { // cfg holds the configuration settings for the PayloadBuilder. cfg *Config @@ -52,12 +52,12 @@ type PayloadBuilder[ // logger is used for logging within the PayloadBuilder. logger log.Logger[any] // ee is the execution engine. - ee ExecutionEngine[ExecutionPayloadT] + ee ExecutionEngine[ExecutionPayloadT, PayloadIDT] // pc is the payload ID cache, it is used to store // "in-flight" payloads that are being built on // the execution client. pc *cache.PayloadIDCache[ - engineprimitves.PayloadID, [32]byte, math.Slot, + PayloadIDT, [32]byte, math.Slot, ] } @@ -75,19 +75,20 @@ func New[ GetBlockHash() common.ExecutionHash GetParentHash() common.ExecutionHash }, + PayloadIDT ~[8]byte, ]( cfg *Config, chainSpec primitives.ChainSpec, logger log.Logger[any], - ee ExecutionEngine[ExecutionPayloadT], + ee ExecutionEngine[ExecutionPayloadT, PayloadIDT], pc *cache.PayloadIDCache[ - engineprimitves.PayloadID, [32]byte, math.Slot, + PayloadIDT, [32]byte, math.Slot, ], ) *PayloadBuilder[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadIDT, ] { return &PayloadBuilder[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadIDT, ]{ cfg: cfg, chainSpec: chainSpec, @@ -99,7 +100,7 @@ func New[ // Enabled returns true if the payload builder is enabled. func (pb *PayloadBuilder[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadIDT, ]) Enabled() bool { return pb.cfg.Enabled } diff --git a/mod/payload/pkg/builder/payload.go b/mod/payload/pkg/builder/payload.go index 7e977af020..a2e6de94ac 100644 --- a/mod/payload/pkg/builder/payload.go +++ b/mod/payload/pkg/builder/payload.go @@ -34,7 +34,7 @@ import ( // RequestPayloadAsync builds a payload for the given slot and // returns the payload ID. func (pb *PayloadBuilder[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadIDT, ]) RequestPayloadAsync( ctx context.Context, st BeaconStateT, @@ -43,7 +43,7 @@ func (pb *PayloadBuilder[ parentBlockRoot primitives.Root, headEth1BlockHash common.ExecutionHash, finalEth1BlockHash common.ExecutionHash, -) (*engineprimitives.PayloadID, error) { +) (*PayloadIDT, error) { if !pb.Enabled() { return nil, ErrPayloadBuilderDisabled } @@ -66,7 +66,7 @@ func (pb *PayloadBuilder[ } // Submit the forkchoice update to the execution client. - var payloadID *engineprimitives.PayloadID + var payloadID *PayloadIDT payloadID, _, err = pb.ee.NotifyForkchoiceUpdate( ctx, &engineprimitives.ForkchoiceUpdateRequest{ State: &engineprimitives.ForkchoiceStateV1{ @@ -105,7 +105,7 @@ func (pb *PayloadBuilder[ // RequestPayloadSync request a payload for the given slot and // blocks until the payload is delivered. func (pb *PayloadBuilder[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadIDT, ]) RequestPayloadSync( ctx context.Context, st BeaconStateT, @@ -153,7 +153,7 @@ func (pb *PayloadBuilder[ // Get the payload from the execution client. return pb.ee.GetPayload( ctx, - &engineprimitives.GetPayloadRequest{ + &engineprimitives.GetPayloadRequest[PayloadIDT]{ PayloadID: *payloadID, ForkVersion: pb.chainSpec.ActiveForkVersionForSlot(slot), }, @@ -165,7 +165,7 @@ func (pb *PayloadBuilder[ // retrieve a payload, it will build a new payload and wait for the // execution client to return the payload. func (pb *PayloadBuilder[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadIDT, ]) RetrievePayload( ctx context.Context, slot math.Slot, @@ -184,7 +184,7 @@ func (pb *PayloadBuilder[ envelope, err := pb.ee.GetPayload( ctx, - &engineprimitives.GetPayloadRequest{ + &engineprimitives.GetPayloadRequest[PayloadIDT]{ PayloadID: payloadID, ForkVersion: pb.chainSpec.ActiveForkVersionForSlot(slot), }, @@ -235,7 +235,7 @@ func (pb *PayloadBuilder[ // TODO: This should be moved onto a "sync service" // of some kind. func (pb *PayloadBuilder[ - BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, + BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadIDT, ]) SendForceHeadFCU( ctx context.Context, st BeaconStateT, diff --git a/mod/payload/pkg/builder/types.go b/mod/payload/pkg/builder/types.go index 4221c657ad..b2f0d2b30c 100644 --- a/mod/payload/pkg/builder/types.go +++ b/mod/payload/pkg/builder/types.go @@ -53,16 +53,16 @@ type BeaconState[ExecutionPayloadHeaderT interface { } // ExecutionEngine is the interface for the execution engine. -type ExecutionEngine[ExecutionPayloadT any] interface { +type ExecutionEngine[ExecutionPayloadT any, PayloadIDT ~[8]byte] interface { // GetPayload returns the payload and blobs bundle for the given slot. GetPayload( ctx context.Context, - req *engineprimitives.GetPayloadRequest, + req *engineprimitives.GetPayloadRequest[PayloadIDT], ) (engineprimitives.BuiltExecutionPayloadEnv[ExecutionPayloadT], error) // NotifyForkchoiceUpdate notifies the execution client of a forkchoice // update. NotifyForkchoiceUpdate( ctx context.Context, req *engineprimitives.ForkchoiceUpdateRequest, - ) (*engineprimitives.PayloadID, *common.ExecutionHash, error) + ) (*PayloadIDT, *common.ExecutionHash, error) }