Skip to content

Commit

Permalink
introduce interfaces for payload buidler (#1929)
Browse files Browse the repository at this point in the history
  • Loading branch information
archbear authored Aug 19, 2024
1 parent 5cfbd50 commit 4310718
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
18 changes: 4 additions & 14 deletions mod/payload/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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.
Expand All @@ -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,
Expand Down
24 changes: 22 additions & 2 deletions mod/payload/pkg/builder/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 4310718

Please sign in to comment.