From 418fe79515bd8b6dadb22150a2be5d7191bc3b87 Mon Sep 17 00:00:00 2001 From: Fridrik Asmundsson Date: Wed, 18 Dec 2024 10:17:08 +0000 Subject: [PATCH] Remove PayloadIDT generic type --- cmd/beacond/types.go | 37 ++--------------------- consensus-types/types/payload_requests.go | 12 ++++---- execution/engine/engine.go | 22 ++++++-------- node-core/components/chain_service.go | 2 +- node-core/components/engine.go | 4 +-- node-core/components/payload_builder.go | 13 ++------ node-core/components/state_processor.go | 2 +- payload/builder/builder.go | 25 +++++---------- payload/builder/payload.go | 32 ++++++-------------- payload/builder/types.go | 14 ++++----- payload/cache/payload_id.go | 34 +++++++++++---------- payload/cache/payload_id_fuzz_test.go | 11 ++++--- payload/cache/payload_id_test.go | 13 ++++---- 13 files changed, 77 insertions(+), 144 deletions(-) diff --git a/cmd/beacond/types.go b/cmd/beacond/types.go index 5a943433c3..3780eb2922 100644 --- a/cmd/beacond/types.go +++ b/cmd/beacond/types.go @@ -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" @@ -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" @@ -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" ) @@ -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 @@ -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 @@ -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] ) diff --git a/consensus-types/types/payload_requests.go b/consensus-types/types/payload_requests.go index ffa0a10543..b108f6ea5c 100644 --- a/consensus-types/types/payload_requests.go +++ b/consensus-types/types/payload_requests.go @@ -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, } diff --git a/execution/engine/engine.go b/execution/engine/engine.go index 430da79b9f..0a2d2e9fa9 100644 --- a/execution/engine/engine.go +++ b/execution/engine/engine.go @@ -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 @@ -48,14 +46,12 @@ 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), @@ -63,7 +59,7 @@ func New[ } // Start spawns any goroutines required by the service. -func (ee *Engine[_]) Start( +func (ee *Engine) Start( ctx context.Context, ) error { go func() { @@ -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, @@ -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) { @@ -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 { diff --git a/node-core/components/chain_service.go b/node-core/components/chain_service.go index 9a92ea18be..4ec665730a 100644 --- a/node-core/components/chain_service.go +++ b/node-core/components/chain_service.go @@ -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 diff --git a/node-core/components/engine.go b/node-core/components/engine.go index 1f5552f69c..ced7788cc2 100644 --- a/node-core/components/engine.go +++ b/node-core/components/engine.go @@ -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, diff --git a/node-core/components/payload_builder.go b/node-core/components/payload_builder.go index 70222e43aa..585d4a3671 100644 --- a/node-core/components/payload_builder.go +++ b/node-core/components/payload_builder.go @@ -40,7 +40,7 @@ type LocalBuilderInput[ AttributesFactory AttributesFactory[BeaconStateT] Cfg *config.Config ChainSpec chain.ChainSpec - ExecutionEngine *engine.Engine[PayloadID] + ExecutionEngine *engine.Engine Logger LoggerT } @@ -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, diff --git a/node-core/components/state_processor.go b/node-core/components/state_processor.go index 0f6b562344..255da6ed92 100644 --- a/node-core/components/state_processor.go +++ b/node-core/components/state_processor.go @@ -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 diff --git a/payload/builder/builder.go b/payload/builder/builder.go index 4fe5dd862d..2fec40e98b 100644 --- a/payload/builder/builder.go +++ b/payload/builder/builder.go @@ -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 @@ -39,11 +38,11 @@ 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] } @@ -51,22 +50,15 @@ type PayloadBuilder[ // 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, @@ -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 } diff --git a/payload/builder/payload.go b/payload/builder/payload.go index dd39637b1d..d2d8dba23a 100644 --- a/payload/builder/payload.go +++ b/payload/builder/payload.go @@ -32,10 +32,7 @@ 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, @@ -43,7 +40,7 @@ func (pb *PayloadBuilder[ parentBlockRoot common.Root, headEth1BlockHash common.ExecutionHash, finalEth1BlockHash common.ExecutionHash, -) (*PayloadIDT, error) { +) (*engineprimitives.PayloadID, error) { if !pb.Enabled() { return nil, ErrPayloadBuilderDisabled } @@ -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{ @@ -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, @@ -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, @@ -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, @@ -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), }, diff --git a/payload/builder/types.go b/payload/builder/types.go index fcf4915419..60336f5b97 100644 --- a/payload/builder/types.go +++ b/payload/builder/types.go @@ -48,10 +48,10 @@ type BeaconState interface { GetBlockRootAtIndex(uint64) (common.Root, error) } -type PayloadCache[PayloadIDT, RootT, SlotT any] interface { - Get(slot SlotT, stateRoot RootT) (PayloadIDT, bool) +type PayloadCache[RootT, SlotT any] interface { + Get(slot SlotT, stateRoot RootT) (engineprimitives.PayloadID, bool) Has(slot SlotT, stateRoot RootT) bool - Set(slot SlotT, stateRoot RootT, pid PayloadIDT) + Set(slot SlotT, stateRoot RootT, pid engineprimitives.PayloadID) UnsafePrunePrior(slot SlotT) } @@ -95,18 +95,16 @@ type PayloadAttributes[ } // ExecutionEngine is the interface for the execution engine. -type ExecutionEngine[ - PayloadIDT ~[8]byte, -] interface { +type ExecutionEngine interface { // GetPayload returns the payload and blobs bundle for the given slot. GetPayload( ctx context.Context, - req *ctypes.GetPayloadRequest[PayloadIDT], + req *ctypes.GetPayloadRequest, ) (ctypes.BuiltExecutionPayloadEnv, error) // NotifyForkchoiceUpdate notifies the execution client of a forkchoice // update. NotifyForkchoiceUpdate( ctx context.Context, req *ctypes.ForkchoiceUpdateRequest, - ) (*PayloadIDT, *common.ExecutionHash, error) + ) (*engineprimitives.PayloadID, *common.ExecutionHash, error) } diff --git a/payload/cache/payload_id.go b/payload/cache/payload_id.go index 0514e436a7..5f0ab10e5d 100644 --- a/payload/cache/payload_id.go +++ b/payload/cache/payload_id.go @@ -22,6 +22,8 @@ package cache import ( "sync" + + engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" ) // historicalPayloadIDCacheSize defines the maximum number of slots to retain @@ -33,30 +35,30 @@ const historicalPayloadIDCacheSize = 2 // on slot and parent block hash. It is designed to improve the efficiency of // payload ID retrieval by caching recent entries. type PayloadIDCache[ - PayloadIDT ~[8]byte, RootT ~[32]byte, SlotT ~uint64, + RootT ~[32]byte, SlotT ~uint64, ] struct { // mu protects access to the slotToStateRootToPayloadID map. mu sync.RWMutex // slotToStateRootToPayloadID is used for storing payload ID mappings - slotToStateRootToPayloadID map[SlotT]map[RootT]PayloadIDT + slotToStateRootToPayloadID map[SlotT]map[RootT]engineprimitives.PayloadID } // NewPayloadIDCache initializes and returns a new instance of PayloadIDCache. // It prepares the internal data structures for storing payload ID mappings. func NewPayloadIDCache[ - PayloadIDT ~[8]byte, RootT ~[32]byte, SlotT ~uint64, -]() *PayloadIDCache[PayloadIDT, RootT, SlotT] { - return &PayloadIDCache[PayloadIDT, RootT, SlotT]{ + RootT ~[32]byte, SlotT ~uint64, +]() *PayloadIDCache[RootT, SlotT] { + return &PayloadIDCache[RootT, SlotT]{ mu: sync.RWMutex{}, slotToStateRootToPayloadID: make( - map[SlotT]map[RootT]PayloadIDT, + map[SlotT]map[RootT]engineprimitives.PayloadID, ), } } // Has retrieves the payload ID associated with a given slot and eth1 hash. // Has checks if a payload ID exists for a given slot and eth1 hash. -func (p *PayloadIDCache[_, RootT, SlotT]) Has( +func (p *PayloadIDCache[RootT, SlotT]) Has( slot SlotT, stateRoot RootT, ) bool { @@ -67,19 +69,19 @@ func (p *PayloadIDCache[_, RootT, SlotT]) Has( } // Get was successful. -func (p *PayloadIDCache[PayloadIDT, RootT, SlotT]) Get( +func (p *PayloadIDCache[RootT, SlotT]) Get( slot SlotT, stateRoot RootT, -) (PayloadIDT, bool) { +) (engineprimitives.PayloadID, bool) { p.mu.RLock() defer p.mu.RUnlock() innerMap, ok := p.slotToStateRootToPayloadID[slot] if !ok { - return PayloadIDT{}, false + return engineprimitives.PayloadID{}, false } pid, ok := innerMap[stateRoot] if !ok { - return PayloadIDT{}, false + return engineprimitives.PayloadID{}, false } return pid, true } @@ -87,8 +89,8 @@ func (p *PayloadIDCache[PayloadIDT, RootT, SlotT]) Get( // Set updates or inserts a payload ID for a given slot and eth1 hash. // It also prunes entries in the cache that are older than the // historicalPayloadIDCacheSize limit. -func (p *PayloadIDCache[PayloadIDT, RootT, SlotT]) Set( - slot SlotT, stateRoot RootT, pid PayloadIDT, +func (p *PayloadIDCache[RootT, SlotT]) Set( + slot SlotT, stateRoot RootT, pid engineprimitives.PayloadID, ) { p.mu.Lock() defer p.mu.Unlock() @@ -101,7 +103,7 @@ func (p *PayloadIDCache[PayloadIDT, RootT, SlotT]) Set( // Update the cache with the new payload ID. innerMap, exists := p.slotToStateRootToPayloadID[slot] if !exists { - innerMap = make(map[RootT]PayloadIDT) + innerMap = make(map[RootT]engineprimitives.PayloadID) p.slotToStateRootToPayloadID[slot] = innerMap } innerMap[stateRoot] = pid @@ -109,7 +111,7 @@ func (p *PayloadIDCache[PayloadIDT, RootT, SlotT]) Set( // UnsafePrunePrior removes payload IDs from the cache for slots less than // the specified slot. Only used for testing. -func (p *PayloadIDCache[_, _, SlotT]) UnsafePrunePrior( +func (p *PayloadIDCache[_, SlotT]) UnsafePrunePrior( slot SlotT, ) { p.mu.Lock() @@ -120,7 +122,7 @@ func (p *PayloadIDCache[_, _, SlotT]) UnsafePrunePrior( // prunePrior removes payload IDs from the cache for slots less than // the specified slot. This method helps in managing the memory usage // of the cache by discarding outdated entries. -func (p *PayloadIDCache[_, _, SlotT]) prunePrior(slot SlotT) { +func (p *PayloadIDCache[_, SlotT]) prunePrior(slot SlotT) { for s := range p.slotToStateRootToPayloadID { if s < slot { delete(p.slotToStateRootToPayloadID, s) diff --git a/payload/cache/payload_id_fuzz_test.go b/payload/cache/payload_id_fuzz_test.go index 439a1f0f63..ca3cdb4e8d 100644 --- a/payload/cache/payload_id_fuzz_test.go +++ b/payload/cache/payload_id_fuzz_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" "github.com/berachain/beacon-kit/payload/cache" "github.com/stretchr/testify/require" ) @@ -37,8 +38,8 @@ func FuzzPayloadIDCacheBasic(f *testing.F) { var r [32]byte copy(r[:], _r) slot := s - pid := [8]byte(_p[:8]) - cacheUnderTest := cache.NewPayloadIDCache[[8]byte, [32]byte, uint64]() + pid := engineprimitives.PayloadID(_p[:8]) + cacheUnderTest := cache.NewPayloadIDCache[[32]byte, uint64]() cacheUnderTest.Set(slot, r, pid) p, ok := cacheUnderTest.Get(slot, r) @@ -46,7 +47,7 @@ func FuzzPayloadIDCacheBasic(f *testing.F) { require.Equal(t, pid, p) // Test overwriting the same slot and root with a different PayloadID - newPid := [8]byte{} + newPid := engineprimitives.PayloadID{} for i := range pid { newPid[i] = pid[i] + 1 // Simple mutation for a new PayloadID } @@ -81,7 +82,7 @@ func FuzzPayloadIDInvalidInput(f *testing.F) { var paddedPayload [8]byte copy(paddedPayload[:], _p[:min(len(_p), 8)]) pid := [8]byte(paddedPayload[:]) - cacheUnderTest := cache.NewPayloadIDCache[[8]byte, [32]byte, uint64]() + cacheUnderTest := cache.NewPayloadIDCache[[32]byte, uint64]() cacheUnderTest.Set(slot, r, pid) _, ok := cacheUnderTest.Get(slot, r) @@ -93,7 +94,7 @@ func FuzzPayloadIDCacheConcurrency(f *testing.F) { f.Add(uint64(1), []byte{1, 2, 3}, []byte{1, 2, 3, 4}) f.Fuzz(func(t *testing.T, s uint64, _r, _p []byte) { - cacheUnderTest := cache.NewPayloadIDCache[[8]byte, [32]byte, uint64]() + cacheUnderTest := cache.NewPayloadIDCache[[32]byte, uint64]() slot := s var wg sync.WaitGroup wg.Add(2) diff --git a/payload/cache/payload_id_test.go b/payload/cache/payload_id_test.go index 66cab800b0..be9a4f6395 100644 --- a/payload/cache/payload_id_test.go +++ b/payload/cache/payload_id_test.go @@ -23,24 +23,25 @@ package cache_test import ( "testing" + engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives" "github.com/berachain/beacon-kit/payload/cache" "github.com/stretchr/testify/require" ) func TestPayloadIDCache(t *testing.T) { - cacheUnderTest := cache.NewPayloadIDCache[[8]byte, [32]byte, uint64]() + cacheUnderTest := cache.NewPayloadIDCache[[32]byte, uint64]() t.Run("Get from empty cache", func(t *testing.T) { var r [32]byte p, ok := cacheUnderTest.Get(0, r) require.False(t, ok) - require.Equal(t, [8]byte{}, p) + require.Equal(t, engineprimitives.PayloadID{}, p) }) t.Run("Set and Get", func(t *testing.T) { slot := uint64(1234) r := [32]byte{1, 2, 3} - pid := [8]byte{1, 2, 3, 3, 7, 8, 7, 8} + pid := engineprimitives.PayloadID{1, 2, 3, 3, 7, 8, 7, 8} cacheUnderTest.Set(slot, r, pid) p, ok := cacheUnderTest.Get(slot, r) @@ -51,7 +52,7 @@ func TestPayloadIDCache(t *testing.T) { t.Run("Overwrite existing", func(t *testing.T) { slot := uint64(1234) r := [32]byte{1, 2, 3} - newPid := [8]byte{9, 9, 9, 9, 9, 9, 9, 9} + newPid := engineprimitives.PayloadID{9, 9, 9, 9, 9, 9, 9, 9} cacheUnderTest.Set(slot, r, newPid) p, ok := cacheUnderTest.Get(slot, r) @@ -62,14 +63,14 @@ func TestPayloadIDCache(t *testing.T) { t.Run("Prune and verify deletion", func(t *testing.T) { slot := uint64(9456456) r := [32]byte{4, 5, 6} - pid := [8]byte{4, 5, 6, 6, 9, 0, 9, 0} + pid := engineprimitives.PayloadID{4, 5, 6, 6, 9, 0, 9, 0} cacheUnderTest.Set(slot, r, pid) // Prune and attempt to retrieve pruned entry cacheUnderTest.UnsafePrunePrior(slot + 1) p, ok := cacheUnderTest.Get(slot, r) require.False(t, ok) - require.Equal(t, [8]byte{}, p) + require.Equal(t, engineprimitives.PayloadID{}, p) }) t.Run("Multiple entries and prune", func(t *testing.T) {