diff --git a/beacon/blockchain/finalize_block.go b/beacon/blockchain/finalize_block.go index 50eef6fc56..3c2218ff19 100644 --- a/beacon/blockchain/finalize_block.go +++ b/beacon/blockchain/finalize_block.go @@ -151,45 +151,42 @@ func (s *Service) executeStateTransition( ) (transition.ValidatorUpdates, error) { startTime := time.Now() defer s.metrics.measureStateTransitionDuration(startTime) - valUpdates, err := s.stateProcessor.Transition( - &transition.Context{ - Context: ctx, - - MeterGas: true, - - // We set `OptimisticEngine` to true since this is called during - // FinalizeBlock. We want to assume the payload is valid. If it - // ends up not being valid later, the node will simply AppHash, - // which is completely fine. This means we were syncing from a - // bad peer, and we would likely AppHash anyways. - OptimisticEngine: true, - - // When we are NOT synced to the tip, process proposal - // does NOT get called and thus we must ensure that - // NewPayload is called to get the execution - // client the payload. - // - // When we are synced to the tip, we can skip the - // NewPayload call since we already gave our execution client - // the payload in process proposal. - // - // In both cases the payload was already accepted by a majority - // of validators in their process proposal call and thus - // the "verification aspect" of this NewPayload call is - // actually irrelevant at this point. - SkipPayloadVerification: false, - - // We skip randao validation in FinalizeBlock since either - // 1. we validated it during ProcessProposal at the head of the chain OR - // 2. we are bootstrapping and implicitly trust that the randao was validated by - // the super majority during ProcessProposal of the given block height. - SkipValidateRandao: true, - - ProposerAddress: blk.GetProposerAddress(), - ConsensusTime: blk.GetConsensusTime(), - }, + + // Notes about context attributes: + // - `OptimisticEngine`: set to true since this is called during + // FinalizeBlock. We want to assume the payload is valid. If it + // ends up not being valid later, the node will simply AppHash, + // which is completely fine. This means we were syncing from a + // bad peer, and we would likely AppHash anyways. + // - VerifyPayload: set to true. When we are NOT synced to the tip, + // process proposal does NOT get called and thus we must ensure that + // NewPayload is called to get the execution client the payload. + // When we are synced to the tip, we can skip the + // NewPayload call since we already gave our execution client + // the payload in process proposal. + // In both cases the payload was already accepted by a majority + // of validators in their process proposal call and thus + // the "verification aspect" of this NewPayload call is + // actually irrelevant at this point. + // VerifyRandao: set to false. We skip randao validation in FinalizeBlock + // since either + // 1. we validated it during ProcessProposal at the head of the chain OR + // 2. we are bootstrapping and implicitly trust that the randao was validated by + // the super majority during ProcessProposal of the given block height. + txCtx := transition.NewTransitionCtx( + ctx, + blk.GetConsensusTime(), + blk.GetProposerAddress(), + ). + WithVerifyPayload(true). + WithVerifyRandao(false). + WithVerifyResult(false). + WithMeterGas(true). + WithOptimisticEngine(true) + + return s.stateProcessor.Transition( + txCtx, st, blk.GetBeaconBlock(), ) - return valUpdates, err } diff --git a/beacon/blockchain/process_proposal.go b/beacon/blockchain/process_proposal.go index 4c2fb6eee1..b216a9ee19 100644 --- a/beacon/blockchain/process_proposal.go +++ b/beacon/blockchain/process_proposal.go @@ -331,22 +331,21 @@ func (s *Service) verifyStateRoot( ) error { startTime := time.Now() defer s.metrics.measureStateRootVerificationTime(startTime) - _, err := s.stateProcessor.Transition( - // We run with a non-optimistic engine here to ensure - // that the proposer does not try to push through a bad block. - &transition.Context{ - Context: ctx, - MeterGas: false, - OptimisticEngine: false, - SkipPayloadVerification: false, - SkipValidateResult: false, - SkipValidateRandao: false, - ProposerAddress: proposerAddress, - ConsensusTime: consensusTime, - }, - st, blk, - ) + // We run with a non-optimistic engine here to ensure + // that the proposer does not try to push through a bad block. + txCtx := transition.NewTransitionCtx( + ctx, + consensusTime, + proposerAddress, + ). + WithVerifyPayload(true). + WithVerifyRandao(true). + WithVerifyResult(true). + WithMeterGas(false). + WithOptimisticEngine(false) + + _, err := s.stateProcessor.Transition(txCtx, st, blk) return err } diff --git a/beacon/blockchain/service.go b/beacon/blockchain/service.go index f6af2ea16a..89a8f7e97b 100644 --- a/beacon/blockchain/service.go +++ b/beacon/blockchain/service.go @@ -29,7 +29,6 @@ import ( "github.com/berachain/beacon-kit/execution/deposit" "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/primitives/math" - "github.com/berachain/beacon-kit/primitives/transition" ) // Service is the blockchain service. @@ -59,7 +58,7 @@ type Service struct { // localBuilder is a local builder for constructing new beacon states. localBuilder LocalBuilder // stateProcessor is the state processor for beacon blocks and states. - stateProcessor StateProcessor[*transition.Context] + stateProcessor StateProcessor // metrics is the metrics for the service. metrics *chainMetrics // optimisticPayloadBuilds is a flag used when the optimistic payload @@ -79,7 +78,7 @@ func NewService( chainSpec chain.Spec, executionEngine ExecutionEngine, localBuilder LocalBuilder, - stateProcessor StateProcessor[*transition.Context], + stateProcessor StateProcessor, telemetrySink TelemetrySink, optimisticPayloadBuilds bool, ) *Service { diff --git a/beacon/blockchain/types.go b/beacon/blockchain/types.go index 98204a6cec..318039d536 100644 --- a/beacon/blockchain/types.go +++ b/beacon/blockchain/types.go @@ -32,6 +32,7 @@ import ( "github.com/berachain/beacon-kit/primitives/crypto" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" + "github.com/berachain/beacon-kit/state-transition/core" statedb "github.com/berachain/beacon-kit/state-transition/core/state" "github.com/berachain/beacon-kit/storage/block" depositdb "github.com/berachain/beacon-kit/storage/deposit" @@ -138,9 +139,7 @@ type ReadOnlyBeaconState[ // StateProcessor defines the interface for processing various state transitions // in the beacon chain. -type StateProcessor[ - ContextT any, -] interface { +type StateProcessor interface { // InitializePreminedBeaconStateFromEth1 initializes the premined beacon // state // from the eth1 deposits. @@ -156,7 +155,7 @@ type StateProcessor[ ) (transition.ValidatorUpdates, error) // Transition processes the state transition for a given block. Transition( - ContextT, + core.ReadOnlyContext, *statedb.StateDB, *ctypes.BeaconBlock, ) (transition.ValidatorUpdates, error) diff --git a/beacon/validator/block_builder.go b/beacon/validator/block_builder.go index 947f2b139f..60d3a51344 100644 --- a/beacon/validator/block_builder.go +++ b/beacon/validator/block_builder.go @@ -369,22 +369,22 @@ func (s *Service) computeStateRoot( ) (common.Root, error) { startTime := time.Now() defer s.metrics.measureStateRootComputationTime(startTime) - if _, err := s.stateProcessor.Transition( - // TODO: We should think about how having optimistic - // engine enabled here would affect the proposer when - // the payload in their block has come from a remote builder. - &transition.Context{ - Context: ctx, - MeterGas: false, - OptimisticEngine: true, - SkipPayloadVerification: true, - SkipValidateResult: true, - SkipValidateRandao: true, - ProposerAddress: proposerAddress, - ConsensusTime: consensusTime, - }, - st, blk, - ); err != nil { + + // TODO: We should think about how having optimistic + // engine enabled here would affect the proposer when + // the payload in their block has come from a remote builder. + txCtx := transition.NewTransitionCtx( + ctx, + consensusTime, + proposerAddress, + ). + WithVerifyPayload(false). + WithVerifyRandao(false). + WithVerifyResult(false). + WithMeterGas(false). + WithOptimisticEngine(true) + + if _, err := s.stateProcessor.Transition(txCtx, st, blk); err != nil { return common.Root{}, err } diff --git a/beacon/validator/service.go b/beacon/validator/service.go index ee2919756b..87a2e9e045 100644 --- a/beacon/validator/service.go +++ b/beacon/validator/service.go @@ -26,7 +26,6 @@ import ( "github.com/berachain/beacon-kit/chain" "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/primitives/crypto" - "github.com/berachain/beacon-kit/primitives/transition" ) // Service is responsible for building beacon blocks and sidecars. @@ -44,7 +43,7 @@ type Service struct { // sb is the beacon state backend. sb StorageBackend // stateProcessor is responsible for processing the state. - stateProcessor StateProcessor[*transition.Context] + stateProcessor StateProcessor // localPayloadBuilder represents the local block builder, this builder // is connected to this nodes execution client via the EngineAPI. // Building blocks are done by submitting forkchoice updates through. @@ -60,7 +59,7 @@ func NewService( logger log.Logger, chainSpec chain.Spec, sb StorageBackend, - stateProcessor StateProcessor[*transition.Context], + stateProcessor StateProcessor, signer crypto.BLSSigner, blobFactory BlobFactory, localPayloadBuilder PayloadBuilder, diff --git a/beacon/validator/types.go b/beacon/validator/types.go index 33d3065541..37c6a25e1b 100644 --- a/beacon/validator/types.go +++ b/beacon/validator/types.go @@ -33,6 +33,7 @@ import ( "github.com/berachain/beacon-kit/primitives/eip4844" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" + "github.com/berachain/beacon-kit/state-transition/core" statedb "github.com/berachain/beacon-kit/state-transition/core/state" depositdb "github.com/berachain/beacon-kit/storage/deposit" ) @@ -171,16 +172,14 @@ type SlotData interface { } // StateProcessor defines the interface for processing the state. -type StateProcessor[ - ContextT any, -] interface { +type StateProcessor interface { // ProcessSlot processes the slot. ProcessSlots( st *statedb.StateDB, slot math.Slot, ) (transition.ValidatorUpdates, error) // Transition performs the core state transition. Transition( - ctx ContextT, + ctx core.ReadOnlyContext, st *statedb.StateDB, blk *ctypes.BeaconBlock, ) (transition.ValidatorUpdates, error) diff --git a/cmd/beacond/types.go b/cmd/beacond/types.go index 0894c78d7a..1ed65e93fb 100644 --- a/cmd/beacond/types.go +++ b/cmd/beacond/types.go @@ -77,7 +77,7 @@ type ( SidecarFactory = dablob.SidecarFactory // StateProcessor is the type alias for the state processor interface. - StateProcessor = core.StateProcessor[*Context] + StateProcessor = core.StateProcessor // StorageBackend is the type alias for the storage backend interface. StorageBackend = storage.Backend diff --git a/node-core/components/api.go b/node-core/components/api.go index 26425d3903..41c002f8c6 100644 --- a/node-core/components/api.go +++ b/node-core/components/api.go @@ -42,7 +42,7 @@ type NodeAPIBackendInput struct { depinject.In ChainSpec chain.Spec - StateProcessor StateProcessor[*Context] + StateProcessor StateProcessor StorageBackend *storage.Backend } diff --git a/node-core/components/chain_service.go b/node-core/components/chain_service.go index 7484ed470b..247b534918 100644 --- a/node-core/components/chain_service.go +++ b/node-core/components/chain_service.go @@ -46,7 +46,7 @@ type ChainServiceInput struct { LocalBuilder LocalBuilder Logger *phuslu.Logger Signer crypto.BLSSigner - StateProcessor StateProcessor[*Context] + StateProcessor StateProcessor StorageBackend *storage.Backend BlobProcessor BlobProcessor TelemetrySink *metrics.TelemetrySink diff --git a/node-core/components/interfaces.go b/node-core/components/interfaces.go index 25917299bc..491fcadfe1 100644 --- a/node-core/components/interfaces.go +++ b/node-core/components/interfaces.go @@ -39,6 +39,7 @@ import ( "github.com/berachain/beacon-kit/primitives/eip4844" "github.com/berachain/beacon-kit/primitives/math" "github.com/berachain/beacon-kit/primitives/transition" + "github.com/berachain/beacon-kit/state-transition/core" statedb "github.com/berachain/beacon-kit/state-transition/core/state" "github.com/berachain/beacon-kit/storage/block" depositdb "github.com/berachain/beacon-kit/storage/deposit" @@ -203,39 +204,6 @@ type ( ) (*v1.ProcessProposalResponse, error) } - // // Context defines an interface for managing state transition context. - // Context[T any] interface { - // context.Context - // // Wrap returns a new context with the given context. - // Wrap(context.Context) T - // // OptimisticEngine sets the optimistic engine flag to true. - // OptimisticEngine() T - // // SkipPayloadVerification sets the skip payload verification flag to - // // true. - // SkipPayloadVerification() T - // // SkipValidateRandao sets the skip validate randao flag to true. - // SkipValidateRandao() T - // // SkipValidateResult sets the skip validate result flag to true. - // SkipValidateResult() T - // // GetOptimisticEngine returns whether to optimistically assume the - // // execution client has the correct state when certain errors are - // // returned - // // by the execution engine. - // GetOptimisticEngine() bool - // // GetSkipPayloadVerification returns whether to skip verifying the - // // payload - // // if - // // it already exists on the execution client. - // GetSkipPayloadVerification() bool - // // GetSkipValidateRandao returns whether to skip validating the RANDAO - // // reveal. - // GetSkipValidateRandao() bool - // // GetSkipValidateResult returns whether to validate the result of the - // // state - // // transition. - // GetSkipValidateResult() bool - // } - // Deposit is the interface for a deposit. Deposit[ T any, @@ -348,9 +316,7 @@ type ( // }. // StateProcessor defines the interface for processing the state. - StateProcessor[ - ContextT any, - ] interface { + StateProcessor interface { // InitializePreminedBeaconStateFromEth1 initializes the premined beacon // state // from the eth1 deposits. @@ -366,7 +332,7 @@ type ( ) (transition.ValidatorUpdates, error) // Transition performs the core state transition. Transition( - ctx ContextT, + ctx core.ReadOnlyContext, st *statedb.StateDB, blk *ctypes.BeaconBlock, ) (transition.ValidatorUpdates, error) diff --git a/node-core/components/state_processor.go b/node-core/components/state_processor.go index 6b4e94fa54..a6149caa70 100644 --- a/node-core/components/state_processor.go +++ b/node-core/components/state_processor.go @@ -45,8 +45,8 @@ type StateProcessorInput struct { // ProvideStateProcessor provides the state processor to the depinject // framework. -func ProvideStateProcessor(in StateProcessorInput) *core.StateProcessor[*Context] { - return core.NewStateProcessor[*Context]( +func ProvideStateProcessor(in StateProcessorInput) *core.StateProcessor { + return core.NewStateProcessor( in.Logger.With("service", "state-processor"), in.ChainSpec, in.ExecutionEngine, diff --git a/node-core/components/validator_service.go b/node-core/components/validator_service.go index 86f67a4b26..253cca1638 100644 --- a/node-core/components/validator_service.go +++ b/node-core/components/validator_service.go @@ -38,7 +38,7 @@ type ValidatorServiceInput struct { ChainSpec chain.Spec LocalBuilder LocalBuilder Logger *phuslu.Logger - StateProcessor StateProcessor[*Context] + StateProcessor StateProcessor StorageBackend *storage.Backend Signer crypto.BLSSigner SidecarFactory SidecarFactory diff --git a/primitives/transition/context.go b/primitives/transition/context.go index 77e04e29a5..1998359e01 100644 --- a/primitives/transition/context.go +++ b/primitives/transition/context.go @@ -28,71 +28,116 @@ import ( // Context is the context for the state transition. type Context struct { - context.Context + // consensusCtx is the context passed by CometBFT callbacks + // We pass it down to be able to cancel processing (although + // currently CometBFT context is set to TODO) + consensusCtx context.Context + // consensusTime returns the timestamp of current consensus request. + // It is used to build next payload and to validate currentpayload. + consensusTime math.U64 + // Address of current block proposer + proposerAddress []byte - MeterGas bool - // OptimisticEngine indicates whether to optimistically assume - // the execution client has the correct state certain errors - // are returned by the execution engine. - OptimisticEngine bool - // SkipPayloadVerification indicates whether to skip calling NewPayload - // on the execution client. This can be done when the node is not + // verifyPayload indicates whether to call NewPayload on the + // execution client. This can be done when the node is not // syncing, and the payload is already known to the execution client. - SkipPayloadVerification bool - // SkipValidateRandao indicates whether to skip validating the Randao mix. - SkipValidateRandao bool - // SkipValidateResult indicates whether to validate the result of + verifyPayload bool + // verifyRandao indicates whether to validate the Randao mix. + verifyRandao bool + // verifyResult indicates whether to validate the result of // the state transition. - SkipValidateResult bool - // Address of current block proposer - ProposerAddress []byte - // ConsensusTime returns the timestamp of current consensus request. - // It is used to build next payload and to validate currentpayload. - ConsensusTime math.U64 + verifyResult bool + + // meterGas controls whether gas data related to the execution + // layer payload should be meter or not. We currently meter only + // finalized blocks. + meterGas bool + // optimisticEngine indicates whether to optimistically assume + // the execution client has the correct state certain errors + // are returned by the execution engine. + optimisticEngine bool +} + +func NewTransitionCtx( + consensusCtx context.Context, + time math.U64, + address []byte, +) *Context { + return &Context{ + consensusCtx: consensusCtx, + consensusTime: time, + proposerAddress: address, + + // by default we don't meter gas + // (we care only about finalized blocks gas) + meterGas: false, + + // by default we don't have optimistic engine + // as it basically mute some checks + optimisticEngine: false, + + // by default we keep all verification + verifyPayload: true, + verifyRandao: true, + verifyResult: true, + } +} + +// Setters to control context attributes. +func (c *Context) WithMeterGas(meter bool) *Context { + c.meterGas = meter + return c +} + +func (c *Context) WithOptimisticEngine(optimistic bool) *Context { + c.optimisticEngine = optimistic + return c +} + +func (c *Context) WithVerifyPayload(verifyPayload bool) *Context { + c.verifyPayload = verifyPayload + return c +} + +func (c *Context) WithVerifyRandao(verifyRandao bool) *Context { + c.verifyRandao = verifyRandao + return c +} + +func (c *Context) WithVerifyResult(verifyResult bool) *Context { + c.verifyResult = verifyResult + return c } -func (c *Context) GetMeterGas() bool { - return c.MeterGas +// Getters of context attributes. +func (c *Context) ConsensusCtx() context.Context { + return c.consensusCtx } -// GetOptimisticEngine returns whether to optimistically assume the execution -// client has the correct state when certain errors are returned by the -// execution engine. -func (c *Context) GetOptimisticEngine() bool { - return c.OptimisticEngine +func (c *Context) ConsensusTime() math.U64 { + return c.consensusTime } -// GetSkipPayloadVerification returns whether to skip calling NewPayload on the -// execution client. This can be done when the node is not syncing, and the -// payload is already known to the execution client. -func (c *Context) GetSkipPayloadVerification() bool { - return c.SkipPayloadVerification +func (c *Context) ProposerAddress() []byte { + return c.proposerAddress } -// GetSkipValidateRandao returns whether to skip validating the Randao mix. -func (c *Context) GetSkipValidateRandao() bool { - return c.SkipValidateRandao +func (c *Context) VerifyPayload() bool { + return c.verifyPayload } -// GetSkipValidateResult returns whether to validate the result of the state -// transition. -func (c *Context) GetSkipValidateResult() bool { - return c.SkipValidateResult +func (c *Context) VerifyRandao() bool { + return c.verifyRandao } -// GetProposerAddress returns the address of the validator -// selected by consensus to propose the block. -func (c *Context) GetProposerAddress() []byte { - return c.ProposerAddress +func (c *Context) VerifyResult() bool { + return c.verifyResult } -// GetConsensusTime returns the timestamp of current consensus request. -// It is used to build next payload and to validate currentpayload. -func (c *Context) GetConsensusTime() math.U64 { - return c.ConsensusTime +func (c *Context) MeterGas() bool { + return c.meterGas } -// Unwrap returns the underlying standard context. -func (c *Context) Unwrap() context.Context { - return c.Context +func (c *Context) OptimisticEngine() bool { + return c.optimisticEngine } diff --git a/state-transition/core/core_test.go b/state-transition/core/core_test.go index 96cb3e6e64..53d9bb1761 100644 --- a/state-transition/core/core_test.go +++ b/state-transition/core/core_test.go @@ -34,8 +34,8 @@ import ( "github.com/berachain/beacon-kit/primitives/bytes" "github.com/berachain/beacon-kit/primitives/common" "github.com/berachain/beacon-kit/primitives/math" - "github.com/berachain/beacon-kit/primitives/transition" "github.com/berachain/beacon-kit/primitives/version" + "github.com/berachain/beacon-kit/state-transition/core" statetransition "github.com/berachain/beacon-kit/testing/state-transition" "github.com/stretchr/testify/require" ) @@ -143,7 +143,7 @@ func moveToEndOfEpoch( cs chain.Spec, sp *statetransition.TestStateProcessorT, st *statetransition.TestBeaconStateT, - ctx *transition.Context, + ctx core.ReadOnlyContext, depRoot common.Root, ) *types.BeaconBlock { t.Helper() diff --git a/state-transition/core/state_processor.go b/state-transition/core/state_processor.go index 4a534fc107..b0b48a4e33 100644 --- a/state-transition/core/state_processor.go +++ b/state-transition/core/state_processor.go @@ -37,7 +37,7 @@ import ( // StateProcessor is a basic Processor, which takes care of the // main state transition for the beacon chain. -type StateProcessor[ContextT Context] struct { +type StateProcessor struct { // logger is used for logging information and errors. logger log.Logger // cs is the chain specification for the beacon chain. @@ -57,9 +57,7 @@ type StateProcessor[ContextT Context] struct { } // NewStateProcessor creates a new state processor. -func NewStateProcessor[ - ContextT Context, -]( +func NewStateProcessor( logger log.Logger, cs chain.Spec, executionEngine ExecutionEngine, @@ -67,8 +65,8 @@ func NewStateProcessor[ signer crypto.BLSSigner, fGetAddressFromPubKey func(crypto.BLSPubkey) ([]byte, error), telemetrySink TelemetrySink, -) *StateProcessor[ContextT] { - return &StateProcessor[ContextT]{ +) *StateProcessor { + return &StateProcessor{ logger: logger, cs: cs, executionEngine: executionEngine, @@ -80,8 +78,8 @@ func NewStateProcessor[ } // Transition is the main function for processing a state transition. -func (sp *StateProcessor[ContextT]) Transition( - ctx ContextT, +func (sp *StateProcessor) Transition( + ctx ReadOnlyContext, st *state.StateDB, blk *ctypes.BeaconBlock, ) (transition.ValidatorUpdates, error) { @@ -106,7 +104,7 @@ func (sp *StateProcessor[ContextT]) Transition( // NOTE: if process slots is called across multiple epochs (the given slot is more than 1 multiple // ahead of the current state slot), then validator updates will be returned in the order they are // processed, which may effectually override each other. -func (sp *StateProcessor[_]) ProcessSlots( +func (sp *StateProcessor) ProcessSlots( st *state.StateDB, slot math.Slot, ) (transition.ValidatorUpdates, error) { var res transition.ValidatorUpdates @@ -143,7 +141,7 @@ func (sp *StateProcessor[_]) ProcessSlots( } // processSlot is run when a slot is missed. -func (sp *StateProcessor[_]) processSlot(st *state.StateDB) error { +func (sp *StateProcessor) processSlot(st *state.StateDB) error { stateSlot, err := st.GetSlot() if err != nil { return err @@ -181,8 +179,10 @@ func (sp *StateProcessor[_]) processSlot(st *state.StateDB) error { // ProcessBlock processes the block, it optionally verifies the // state root. -func (sp *StateProcessor[ContextT]) ProcessBlock( - ctx ContextT, st *state.StateDB, blk *ctypes.BeaconBlock, +func (sp *StateProcessor) ProcessBlock( + ctx ReadOnlyContext, + st *state.StateDB, + blk *ctypes.BeaconBlock, ) error { if err := sp.processBlockHeader(ctx, st, blk); err != nil { return err @@ -206,7 +206,7 @@ func (sp *StateProcessor[ContextT]) ProcessBlock( // If we are skipping validate, we can skip calculating the state // root to save compute. - if ctx.GetSkipValidateResult() { + if !ctx.VerifyResult() { return nil } @@ -225,7 +225,7 @@ func (sp *StateProcessor[ContextT]) ProcessBlock( // processEpoch processes the epoch and ensures it matches the local state. Currently // beacon-kit does not enforce rewards, penalties, and slashing for validators. -func (sp *StateProcessor[_]) processEpoch(st *state.StateDB) (transition.ValidatorUpdates, error) { +func (sp *StateProcessor) processEpoch(st *state.StateDB) (transition.ValidatorUpdates, error) { slot, err := st.GetSlot() if err != nil { return nil, err @@ -271,8 +271,10 @@ func (sp *StateProcessor[_]) processEpoch(st *state.StateDB) (transition.Validat } // processBlockHeader processes the header and ensures it matches the local state. -func (sp *StateProcessor[ContextT]) processBlockHeader( - ctx ContextT, st *state.StateDB, blk *ctypes.BeaconBlock, +func (sp *StateProcessor) processBlockHeader( + ctx ReadOnlyContext, + st *state.StateDB, + blk *ctypes.BeaconBlock, ) error { // Ensure the block slot matches the state slot. slot, err := st.GetSlot() @@ -304,10 +306,10 @@ func (sp *StateProcessor[ContextT]) processBlockHeader( if err != nil { return err } - if !bytes.Equal(stateProposerAddress, ctx.GetProposerAddress()) { + if !bytes.Equal(stateProposerAddress, ctx.ProposerAddress()) { return errors.Wrapf( ErrProposerMismatch, "store key: %s, consensus key: %s", - stateProposerAddress, ctx.GetProposerAddress(), + stateProposerAddress, ctx.ProposerAddress(), ) } @@ -344,7 +346,7 @@ func (sp *StateProcessor[ContextT]) processBlockHeader( // processEffectiveBalanceUpdates as defined in the Ethereum 2.0 specification. // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#effective-balances-updates -func (sp *StateProcessor[_]) processEffectiveBalanceUpdates(st *state.StateDB) error { +func (sp *StateProcessor) processEffectiveBalanceUpdates(st *state.StateDB) error { // Update effective balances with hysteresis validators, err := st.GetValidators() if err != nil { diff --git a/state-transition/core/state_processor_genesis.go b/state-transition/core/state_processor_genesis.go index 6cd1b72ad7..9234f0a8d1 100644 --- a/state-transition/core/state_processor_genesis.go +++ b/state-transition/core/state_processor_genesis.go @@ -35,7 +35,7 @@ import ( // InitializePreminedBeaconStateFromEth1 initializes the beacon state. // //nolint:gocognit,funlen // todo fix. -func (sp *StateProcessor[_]) InitializePreminedBeaconStateFromEth1( +func (sp *StateProcessor) InitializePreminedBeaconStateFromEth1( st *statedb.StateDB, deposits ctypes.Deposits, execPayloadHeader *ctypes.ExecutionPayloadHeader, @@ -149,7 +149,7 @@ func (sp *StateProcessor[_]) InitializePreminedBeaconStateFromEth1( return validatorSetsDiffs(nil, activeVals), nil } -func (sp *StateProcessor[_]) processGenesisActivation(st *statedb.StateDB) error { +func (sp *StateProcessor) processGenesisActivation(st *statedb.StateDB) error { vals, err := st.GetValidators() if err != nil { return fmt.Errorf("genesis activation, failed listing validators: %w", err) diff --git a/state-transition/core/state_processor_payload.go b/state-transition/core/state_processor_payload.go index 3aebb066ee..b92656403c 100644 --- a/state-transition/core/state_processor_payload.go +++ b/state-transition/core/state_processor_payload.go @@ -31,18 +31,20 @@ import ( // processExecutionPayload processes the execution payload and ensures it // matches the local state. -func (sp *StateProcessor[ContextT]) processExecutionPayload( - ctx ContextT, st *statedb.StateDB, blk *ctypes.BeaconBlock, +func (sp *StateProcessor) processExecutionPayload( + ctx ReadOnlyContext, + st *statedb.StateDB, + blk *ctypes.BeaconBlock, ) error { var ( body = blk.GetBody() payload = body.GetExecutionPayload() header = &ctypes.ExecutionPayloadHeader{} // appeases nilaway - g, gCtx = errgroup.WithContext(ctx) + g, gCtx = errgroup.WithContext(ctx.ConsensusCtx()) ) payloadTimestamp := payload.GetTimestamp().Unwrap() - consensusTimestamp := ctx.GetConsensusTime().Unwrap() + consensusTimestamp := ctx.ConsensusTime().Unwrap() sp.metrics.gaugeTimestamps(payloadTimestamp, consensusTimestamp) @@ -51,13 +53,13 @@ func (sp *StateProcessor[ContextT]) processExecutionPayload( "payload height", payload.GetNumber().Unwrap(), "payload timestamp", payloadTimestamp, "consensus timestamp", consensusTimestamp, - "skip payload verification", ctx.GetSkipPayloadVerification(), + "verify payload", ctx.VerifyPayload(), ) - // Skip payload verification if the context is configured as such. - if !ctx.GetSkipPayloadVerification() { + // Perform payload verification only if the context is configured as such. + if ctx.VerifyPayload() { g.Go(func() error { - return sp.validateExecutionPayload(gCtx, st, blk, ctx.GetOptimisticEngine()) + return sp.validateExecutionPayload(gCtx, st, blk, ctx.OptimisticEngine()) }) } @@ -72,7 +74,7 @@ func (sp *StateProcessor[ContextT]) processExecutionPayload( return err } - if ctx.GetMeterGas() { + if ctx.MeterGas() { sp.metrics.gaugeBlockGasUsed( payload.GetNumber(), payload.GetGasUsed(), payload.GetBlobGasUsed(), ) @@ -84,7 +86,7 @@ func (sp *StateProcessor[ContextT]) processExecutionPayload( // validateExecutionPayload validates the execution payload against both local // state and the execution engine. -func (sp *StateProcessor[_]) validateExecutionPayload( +func (sp *StateProcessor) validateExecutionPayload( ctx context.Context, st *statedb.StateDB, blk *ctypes.BeaconBlock, @@ -97,7 +99,7 @@ func (sp *StateProcessor[_]) validateExecutionPayload( } // validateStatelessPayload performs stateless checks on the execution payload. -func (sp *StateProcessor[_]) validateStatelessPayload(blk *ctypes.BeaconBlock) error { +func (sp *StateProcessor) validateStatelessPayload(blk *ctypes.BeaconBlock) error { body := blk.GetBody() payload := body.GetExecutionPayload() @@ -117,7 +119,7 @@ func (sp *StateProcessor[_]) validateStatelessPayload(blk *ctypes.BeaconBlock) e } // validateStatefulPayload performs stateful checks on the execution payload. -func (sp *StateProcessor[_]) validateStatefulPayload( +func (sp *StateProcessor) validateStatefulPayload( ctx context.Context, st *statedb.StateDB, blk *ctypes.BeaconBlock, optimisticEngine bool, ) error { body := blk.GetBody() diff --git a/state-transition/core/state_processor_randao.go b/state-transition/core/state_processor_randao.go index 830f4995fc..1430caa80d 100644 --- a/state-transition/core/state_processor_randao.go +++ b/state-transition/core/state_processor_randao.go @@ -34,8 +34,8 @@ import ( // processRandaoReveal processes the randao reveal and // ensures it matches the local state. -func (sp *StateProcessor[ContextT]) processRandaoReveal( - ctx ContextT, +func (sp *StateProcessor) processRandaoReveal( + ctx ReadOnlyContext, st *statedb.StateDB, blk *ctypes.BeaconBlock, ) error { @@ -60,7 +60,7 @@ func (sp *StateProcessor[ContextT]) processRandaoReveal( fd := ctypes.NewForkData(sp.cs.ActiveForkVersionForEpoch(epoch), genesisValidatorsRoot) - if !ctx.GetSkipValidateRandao() { + if ctx.VerifyRandao() { signingRoot := fd.ComputeRandaoSigningRoot(sp.cs.DomainTypeRandao(), epoch) reveal := body.GetRandaoReveal() if err = sp.signer.VerifySignature( @@ -85,7 +85,7 @@ func (sp *StateProcessor[ContextT]) processRandaoReveal( // processRandaoMixesReset as defined in the Ethereum 2.0 specification. // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#randao-mixes-updates -func (sp *StateProcessor[_]) processRandaoMixesReset( +func (sp *StateProcessor) processRandaoMixesReset( st *statedb.StateDB, ) error { slot, err := st.GetSlot() @@ -103,7 +103,7 @@ func (sp *StateProcessor[_]) processRandaoMixesReset( } // buildRandaoMix as defined in the Ethereum 2.0 specification. -func (sp *StateProcessor[_]) buildRandaoMix( +func (sp *StateProcessor) buildRandaoMix( mix common.Bytes32, reveal crypto.BLSSignature, ) common.Bytes32 { diff --git a/state-transition/core/state_processor_signature.go b/state-transition/core/state_processor_signature.go index a387252d2a..d92ac2fccc 100644 --- a/state-transition/core/state_processor_signature.go +++ b/state-transition/core/state_processor_signature.go @@ -26,7 +26,7 @@ import ( statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) -func (sp *StateProcessor[_]) GetSignatureVerifierFn(st *statedb.StateDB) ( +func (sp *StateProcessor) GetSignatureVerifierFn(st *statedb.StateDB) ( func(blk *ctypes.BeaconBlock, signature crypto.BLSSignature) error, error, ) { diff --git a/state-transition/core/state_processor_staking.go b/state-transition/core/state_processor_staking.go index 167de41b37..76a8833350 100644 --- a/state-transition/core/state_processor_staking.go +++ b/state-transition/core/state_processor_staking.go @@ -21,7 +21,6 @@ package core import ( - "context" "fmt" ctypes "github.com/berachain/beacon-kit/consensus-types/types" @@ -34,8 +33,10 @@ import ( ) // processOperations processes the operations and ensures they match the local state. -func (sp *StateProcessor[_]) processOperations( - ctx context.Context, st *state.StateDB, blk *ctypes.BeaconBlock, +func (sp *StateProcessor) processOperations( + ctx ReadOnlyContext, + st *state.StateDB, + blk *ctypes.BeaconBlock, ) error { // Verify that outstanding deposits are processed up to the maximum number of deposits. // @@ -51,7 +52,10 @@ func (sp *StateProcessor[_]) processOperations( // Instead we directly compare block deposits with our local store ones. if err := sp.validateNonGenesisDeposits( - ctx, st, deposits, blk.GetBody().GetEth1Data().DepositRoot, + ctx.ConsensusCtx(), + st, + deposits, + blk.GetBody().GetEth1Data().DepositRoot, ); err != nil { return err } @@ -66,7 +70,7 @@ func (sp *StateProcessor[_]) processOperations( } // processDeposit processes the deposit and ensures it matches the local state. -func (sp *StateProcessor[_]) processDeposit(st *state.StateDB, dep *ctypes.Deposit) error { +func (sp *StateProcessor) processDeposit(st *state.StateDB, dep *ctypes.Deposit) error { eth1DepositIndex, err := st.GetEth1DepositIndex() if err != nil { return err @@ -87,7 +91,7 @@ func (sp *StateProcessor[_]) processDeposit(st *state.StateDB, dep *ctypes.Depos } // applyDeposit processes the deposit and ensures it matches the local state. -func (sp *StateProcessor[_]) applyDeposit(st *state.StateDB, dep *ctypes.Deposit) error { +func (sp *StateProcessor) applyDeposit(st *state.StateDB, dep *ctypes.Deposit) error { idx, err := st.ValidatorIndexByPubkey(dep.GetPubkey()) if err != nil { sp.logger.Info("Validator does not exist so creating", @@ -112,7 +116,7 @@ func (sp *StateProcessor[_]) applyDeposit(st *state.StateDB, dep *ctypes.Deposit } // createValidator creates a validator if the deposit is valid. -func (sp *StateProcessor[_]) createValidator(st *state.StateDB, dep *ctypes.Deposit) error { +func (sp *StateProcessor) createValidator(st *state.StateDB, dep *ctypes.Deposit) error { // Get the current slot. slot, err := st.GetSlot() if err != nil { @@ -168,7 +172,7 @@ func (sp *StateProcessor[_]) createValidator(st *state.StateDB, dep *ctypes.Depo } // addValidatorToRegistry adds a validator to the registry. -func (sp *StateProcessor[_]) addValidatorToRegistry(st *state.StateDB, dep *ctypes.Deposit) error { +func (sp *StateProcessor) addValidatorToRegistry(st *state.StateDB, dep *ctypes.Deposit) error { val := ctypes.NewValidatorFromDeposit( dep.GetPubkey(), dep.GetWithdrawalCredentials(), diff --git a/state-transition/core/state_processor_staking_test.go b/state-transition/core/state_processor_staking_test.go index 625ce2c6ec..3cea9d5d68 100644 --- a/state-transition/core/state_processor_staking_test.go +++ b/state-transition/core/state_processor_staking_test.go @@ -78,7 +78,7 @@ func TestTransitionUpdateValidators(t *testing.T) { genPayloadHeader = new(types.ExecutionPayloadHeader).Empty() genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) valDiff, err := sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, @@ -111,7 +111,7 @@ func TestTransitionUpdateValidators(t *testing.T) { ) // make sure included deposit is already available in deposit store - require.NoError(t, ds.EnqueueDeposits(ctx, blk1.Body.Deposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), blk1.Body.Deposits)) // run the test valDiff, err = sp.Transition(ctx, st, blk1) @@ -207,7 +207,7 @@ func TestTransitionCreateValidator(t *testing.T) { genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) genVals, err := sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, @@ -240,7 +240,7 @@ func TestTransitionCreateValidator(t *testing.T) { ) // make sure included deposit is already available in deposit store - require.NoError(t, ds.EnqueueDeposits(ctx, blk1.Body.Deposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), blk1.Body.Deposits)) // run the test valDiff, err := sp.Transition(ctx, st, blk1) @@ -392,7 +392,7 @@ func TestTransitionWithdrawals(t *testing.T) { genPayloadHeader = new(types.ExecutionPayloadHeader).Empty() genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) _, err := sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, genPayloadHeader, genVersion, ) @@ -479,7 +479,7 @@ func TestTransitionMaxWithdrawals(t *testing.T) { genPayloadHeader = new(types.ExecutionPayloadHeader).Empty() genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) _, err = sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, genPayloadHeader, genVersion, ) @@ -616,7 +616,7 @@ func TestTransitionHittingValidatorsCap_ExtraSmall(t *testing.T) { ) } - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) _, err := sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, @@ -652,7 +652,7 @@ func TestTransitionHittingValidatorsCap_ExtraSmall(t *testing.T) { ) // make sure included deposit is already available in deposit store - require.NoError(t, ds.EnqueueDeposits(ctx, blk1.Body.Deposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), blk1.Body.Deposits)) // run the test valDiff, err := sp.Transition(ctx, st, blk1) @@ -857,7 +857,7 @@ func TestTransitionHittingValidatorsCap_ExtraBig(t *testing.T) { // make a deposit small to be ready for eviction genDeposits[0].Amount = minBalance - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) genVals, err := sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, @@ -894,7 +894,7 @@ func TestTransitionHittingValidatorsCap_ExtraBig(t *testing.T) { ) // make sure included deposit is already available in deposit store - require.NoError(t, ds.EnqueueDeposits(ctx, blk1.Body.Deposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), blk1.Body.Deposits)) // run the test valDiff, err := sp.Transition(ctx, st, blk1) @@ -1138,7 +1138,7 @@ func TestValidatorNotWithdrawable(t *testing.T) { genPayloadHeader = new(types.ExecutionPayloadHeader).Empty() genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) _, err := sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, genPayloadHeader, genVersion, ) @@ -1170,7 +1170,7 @@ func TestValidatorNotWithdrawable(t *testing.T) { Deposits: blockDeposits, }, ) - require.NoError(t, ds.EnqueueDeposits(ctx, blockDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), blockDeposits)) // Run transition. _, err = sp.Transition(ctx, st, blk) diff --git a/state-transition/core/state_processor_validators.go b/state-transition/core/state_processor_validators.go index 84b2c74e8d..b0d8ab2bb1 100644 --- a/state-transition/core/state_processor_validators.go +++ b/state-transition/core/state_processor_validators.go @@ -33,7 +33,7 @@ import ( "github.com/sourcegraph/conc/iter" ) -func (sp *StateProcessor[_]) processRegistryUpdates(st *statedb.StateDB) error { +func (sp *StateProcessor) processRegistryUpdates(st *statedb.StateDB) error { slot, err := st.GetSlot() if err != nil { return fmt.Errorf("registry update, failed loading slot: %w", err) @@ -94,7 +94,7 @@ func (sp *StateProcessor[_]) processRegistryUpdates(st *statedb.StateDB) error { return nil } -func (sp *StateProcessor[_]) processValidatorSetCap(st *statedb.StateDB) error { +func (sp *StateProcessor) processValidatorSetCap(st *statedb.StateDB) error { // Enforce the validator set cap by: // 1- retrieving validators active next epoch // 2- sorting them by stake diff --git a/state-transition/core/state_processor_withdrawals.go b/state-transition/core/state_processor_withdrawals.go index f9f0e14cb2..4de87aeb67 100644 --- a/state-transition/core/state_processor_withdrawals.go +++ b/state-transition/core/state_processor_withdrawals.go @@ -38,7 +38,7 @@ import ( // 3. This modification reduces the maximum validator withdrawals per block by one. // -func (sp *StateProcessor[_]) processWithdrawals( +func (sp *StateProcessor) processWithdrawals( st *state.StateDB, blk *ctypes.BeaconBlock, ) error { // Dequeue and verify the logs. diff --git a/state-transition/core/types.go b/state-transition/core/types.go index 7b914a0b66..b2f659c1a2 100644 --- a/state-transition/core/types.go +++ b/state-transition/core/types.go @@ -33,30 +33,16 @@ import ( "github.com/karalabe/ssz" ) -// Context defines an interface for managing state transition context. -type Context interface { - context.Context - GetMeterGas() bool - // GetOptimisticEngine returns whether to optimistically assume the - // execution client has the correct state when certain errors are returned - // by the execution engine. - GetOptimisticEngine() bool - // GetSkipPayloadVerification returns whether to skip verifying the payload - // if - // it already exists on the execution client. - GetSkipPayloadVerification() bool - // GetSkipValidateRandao returns whether to skip validating the RANDAO - // reveal. - GetSkipValidateRandao() bool - // GetSkipValidateResult returns whether to validate the result of the state - // transition. - GetSkipValidateResult() bool - // GetProposerAddress returns the address of the validator - // selected by consensus to propose the block - GetProposerAddress() []byte - // GetConsensusTime returns the timestamp of current consensus request. - // It is used to build next payload and to validate currentpayload. - GetConsensusTime() math.U64 +// ReadOnlyContext defines an interface for managing state transition context. +type ReadOnlyContext interface { + ConsensusCtx() context.Context + ConsensusTime() math.U64 + ProposerAddress() []byte + VerifyPayload() bool + VerifyRandao() bool + VerifyResult() bool + MeterGas() bool + OptimisticEngine() bool } // Withdrawals defines the interface for managing withdrawal operations. diff --git a/state-transition/core/validation_deposits.go b/state-transition/core/validation_deposits.go index 08eb577ab9..fe2f32019c 100644 --- a/state-transition/core/validation_deposits.go +++ b/state-transition/core/validation_deposits.go @@ -31,7 +31,7 @@ import ( statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) -func (sp *StateProcessor[_]) validateGenesisDeposits( +func (sp *StateProcessor) validateGenesisDeposits( st *statedb.StateDB, deposits []*ctypes.Deposit, ) error { eth1DepositIndex, err := st.GetEth1DepositIndex() @@ -69,7 +69,7 @@ func (sp *StateProcessor[_]) validateGenesisDeposits( return nil } -func (sp *StateProcessor[_]) validateNonGenesisDeposits( +func (sp *StateProcessor) validateNonGenesisDeposits( ctx context.Context, st *statedb.StateDB, blkDeposits []*ctypes.Deposit, diff --git a/state-transition/core/validation_deposits_test.go b/state-transition/core/validation_deposits_test.go index dcc4dc045d..ec6bd59fb6 100644 --- a/state-transition/core/validation_deposits_test.go +++ b/state-transition/core/validation_deposits_test.go @@ -63,7 +63,7 @@ func TestInvalidDeposits(t *testing.T) { genPayloadHeader = new(types.ExecutionPayloadHeader).Empty() genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) _, err := sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, genPayloadHeader, genVersion, ) @@ -101,7 +101,7 @@ func TestInvalidDeposits(t *testing.T) { ) // Add correct deposit to local store (honest validator will see this locally). - require.NoError(t, ds.EnqueueDeposits(ctx, types.Deposits{correctDeposit})) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), types.Deposits{correctDeposit})) // Run transition - should fail due to invalid deposit amount. _, err = sp.Transition(ctx, st, blk) @@ -131,7 +131,7 @@ func TestInvalidDepositsCount(t *testing.T) { genPayloadHeader = new(types.ExecutionPayloadHeader).Empty() genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) _, err := sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, genPayloadHeader, genVersion, ) @@ -169,7 +169,7 @@ func TestInvalidDepositsCount(t *testing.T) { ) // Add JUST 1 correct deposit to local store. This node SHOULD fail to verify. - require.NoError(t, ds.EnqueueDeposits(ctx, types.Deposits{correctDeposits[0]})) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), types.Deposits{correctDeposits[0]})) // Run transition. _, err = sp.Transition(ctx, st, blk) @@ -202,7 +202,7 @@ func TestLocalDepositsExceedBlockDeposits(t *testing.T) { genPayloadHeader = new(types.ExecutionPayloadHeader).Empty() genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) _, err = sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, genPayloadHeader, genVersion, ) @@ -241,7 +241,7 @@ func TestLocalDepositsExceedBlockDeposits(t *testing.T) { } // Add both deposits to local store (which includes more than what's in the block). - require.NoError(t, ds.EnqueueDeposits(ctx, append(blockDeposits, extraLocalDeposit))) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), append(blockDeposits, extraLocalDeposit))) // Run transition. _, err = sp.Transition(ctx, st, blk) @@ -273,7 +273,7 @@ func TestLocalDepositsExceedBlockDepositsBadRoot(t *testing.T) { genPayloadHeader = new(types.ExecutionPayloadHeader).Empty() genVersion = version.Deneb() ) - require.NoError(t, ds.EnqueueDeposits(ctx, genDeposits)) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), genDeposits)) _, err = sp.InitializePreminedBeaconStateFromEth1( st, genDeposits, genPayloadHeader, genVersion, ) @@ -313,7 +313,7 @@ func TestLocalDepositsExceedBlockDepositsBadRoot(t *testing.T) { ) // Add both deposits to local store (which includes more than what's in the block). - require.NoError(t, ds.EnqueueDeposits(ctx, append(blockDeposits, extraLocalDeposit))) + require.NoError(t, ds.EnqueueDeposits(ctx.ConsensusCtx(), append(blockDeposits, extraLocalDeposit))) // Run transition. _, err = sp.Transition(ctx, st, blk) diff --git a/testing/state-transition/state-transition.go b/testing/state-transition/state-transition.go index c950771943..1317ad4a68 100644 --- a/testing/state-transition/state-transition.go +++ b/testing/state-transition/state-transition.go @@ -55,7 +55,7 @@ import ( type ( TestBeaconStateMarshallableT = types.BeaconState TestBeaconStateT = statedb.StateDB - TestStateProcessorT = core.StateProcessor[*transition.Context] + TestStateProcessorT = core.StateProcessor ) type testKVStoreService struct { @@ -104,7 +104,7 @@ func SetupTestState(t *testing.T, cs chain.Spec) ( *TestStateProcessorT, *TestBeaconStateT, *depositstore.KVStore, - *transition.Context, + core.ReadOnlyContext, ) { t.Helper() @@ -122,7 +122,7 @@ func SetupTestState(t *testing.T, cs chain.Spec) ( require.NoError(t, err) beaconState := statedb.NewBeaconStateFromDB(kvStore, cs) - sp := core.NewStateProcessor[*transition.Context]( + sp := core.NewStateProcessor( noop.NewLogger[any](), cs, execEngine, @@ -134,12 +134,16 @@ func SetupTestState(t *testing.T, cs chain.Spec) ( nodemetrics.NewNoOpTelemetrySink(), ) - ctx := &transition.Context{ - Context: context.Background(), - SkipPayloadVerification: true, - SkipValidateResult: true, - ProposerAddress: dummyProposerAddr, - } + ctx := transition.NewTransitionCtx( + context.Background(), + 0, // time + dummyProposerAddr, + ). + WithVerifyPayload(false). + WithVerifyRandao(false). + WithVerifyResult(false). + WithMeterGas(false). + WithOptimisticEngine(true) return sp, beaconState, depositStore, ctx }