From 431071884be33cc6781f29873f619a893e64c098 Mon Sep 17 00:00:00 2001 From: archbear <132924729+archbear@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:26:25 -0400 Subject: [PATCH] introduce interfaces for payload buidler (#1929) --- mod/payload/pkg/builder/builder.go | 18 ++++-------------- mod/payload/pkg/builder/types.go | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/mod/payload/pkg/builder/builder.go b/mod/payload/pkg/builder/builder.go index edd681f66f..089429f8ae 100644 --- a/mod/payload/pkg/builder/builder.go +++ b/mod/payload/pkg/builder/builder.go @@ -22,8 +22,6 @@ package builder import ( "github.com/berachain/beacon-kit/mod/log" - "github.com/berachain/beacon-kit/mod/payload/pkg/attributes" - "github.com/berachain/beacon-kit/mod/payload/pkg/cache" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" ) @@ -49,13 +47,9 @@ type PayloadBuilder[ // 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[ - PayloadIDT, [32]byte, math.Slot, - ] + pc PayloadCache[PayloadIDT, [32]byte, math.Slot] // attributesFactory is used to create attributes for the - attributesFactory *attributes.Factory[ - BeaconStateT, PayloadAttributesT, WithdrawalT, - ] + attributesFactory AttributesFactory[BeaconStateT, PayloadAttributesT] } // New creates a new service. @@ -71,12 +65,8 @@ func New[ chainSpec common.ChainSpec, logger log.Logger[any], ee ExecutionEngine[ExecutionPayloadT, PayloadAttributesT, PayloadIDT], - pc *cache.PayloadIDCache[ - PayloadIDT, [32]byte, math.Slot, - ], - af *attributes.Factory[ - BeaconStateT, PayloadAttributesT, WithdrawalT, - ], + pc PayloadCache[PayloadIDT, [32]byte, math.Slot], + af AttributesFactory[BeaconStateT, PayloadAttributesT], ) *PayloadBuilder[ BeaconStateT, ExecutionPayloadT, ExecutionPayloadHeaderT, PayloadAttributesT, PayloadIDT, WithdrawalT, diff --git a/mod/payload/pkg/builder/types.go b/mod/payload/pkg/builder/types.go index 7788abb941..1e784a9784 100644 --- a/mod/payload/pkg/builder/types.go +++ b/mod/payload/pkg/builder/types.go @@ -33,7 +33,7 @@ import ( // BeaconState defines the interface for accessing various state-related data // required for block processing. type BeaconState[ - ExecutionPayloadHeaderT ExecutionPayloadHeader, + ExecutionPayloadHeaderT any, WithdrawalT any, ] interface { // GetRandaoMixAtIndex retrieves the RANDAO mix at a specified index. @@ -52,8 +52,15 @@ type BeaconState[ GetBlockRootAtIndex(uint64) (common.Root, error) } +type PayloadCache[PayloadIDT, RootT, SlotT any] interface { + Get(slot SlotT, stateRoot RootT) (PayloadIDT, bool) + Has(slot SlotT, stateRoot RootT) bool + Set(slot SlotT, stateRoot RootT, pid PayloadIDT) + UnsafePrunePrior(slot SlotT) +} + // ExecutionPayload is the interface for the execution payload. -type ExecutionPayload[T constraints.ForkTyped[T]] interface { +type ExecutionPayload[T any] interface { constraints.ForkTyped[T] // GetBlockHash returns the block hash. GetBlockHash() common.ExecutionHash @@ -71,6 +78,19 @@ type ExecutionPayloadHeader interface { GetParentHash() common.ExecutionHash } +// AttributesFactory is the interface for the attributes factory. +type AttributesFactory[ + BeaconStateT any, + PayloadAttributesT any, +] interface { + BuildPayloadAttributes( + st BeaconStateT, + slot math.U64, + timestamp uint64, + prevHeadRoot [32]byte, + ) (PayloadAttributesT, error) +} + // PayloadAttributes is the interface for the payload attributes. type PayloadAttributes[ SelfT any,