Skip to content

Commit

Permalink
chore(engine): splitted up NotifyAndVerifyNewPayload (#2495)
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Benegiamo <[email protected]>
Co-authored-by: Friðrik Ásmundsson <[email protected]>
  • Loading branch information
abi87 and fridrik01 authored Feb 15, 2025
1 parent 2dc5822 commit ac596fd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 151 deletions.
102 changes: 0 additions & 102 deletions cmd/beacond/types.go

This file was deleted.

40 changes: 15 additions & 25 deletions execution/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ func (ee *Engine) NotifyForkchoiceUpdate(
return payloadID, latestValidHash, nil
}

// VerifyAndNotifyNewPayload verifies the new payload and notifies the
// execution client.
//
//nolint:funlen
func (ee *Engine) VerifyAndNotifyNewPayload(
// NotifyNewPayload notifies the execution client of the new payload.
func (ee *Engine) NotifyNewPayload(
ctx context.Context,
req *ctypes.NewPayloadRequest,
) error {
Expand All @@ -145,14 +142,6 @@ func (ee *Engine) VerifyAndNotifyNewPayload(
req.Optimistic,
)

// First we verify the block hash and versioned hashes are valid.
//
// TODO: is this required? Or will the EL handle this for us during
// new payload?
if err := req.HasValidVersionedAndBlockHashes(); err != nil {
return err
}

// Otherwise we will send the payload to the execution client.
lastValidHash, err := ee.ec.NewPayload(
ctx,
Expand All @@ -164,11 +153,18 @@ func (ee *Engine) VerifyAndNotifyNewPayload(
// We abstract away some of the complexity and categorize status codes
// to make it easier to reason about.
switch {
// If we get accepted or syncing, we are going to optimistically
// say that the block is valid, this is utilized during syncing
// to allow the beacon-chain to continue processing blocks, while
// its execution client is fetching things over it's p2p layer.
case err == nil:
ee.metrics.markNewPayloadValid(
req.ExecutionPayload.GetBlockHash(),
req.ExecutionPayload.GetParentHash(),
req.Optimistic,
)

case errors.Is(err, engineerrors.ErrSyncingPayloadStatus):
// If we get accepted or syncing, we are going to optimistically
// say that the block is valid, this is utilized during syncing
// to allow the beacon-chain to continue processing blocks, while
// its execution client is fetching things over it's p2p layer.
ee.metrics.markNewPayloadSyncingPayloadStatus(
req.ExecutionPayload.GetBlockHash(),
req.ExecutionPayload.GetParentHash(),
Expand Down Expand Up @@ -206,20 +202,14 @@ func (ee *Engine) VerifyAndNotifyNewPayload(
req.Optimistic,
err,
)

err = errors.Join(err, engineerrors.ErrPreDefinedJSONRPC)
case err != nil:

default:
ee.metrics.markNewPayloadUndefinedError(
req.ExecutionPayload.GetBlockHash(),
req.Optimistic,
err,
)
default:
ee.metrics.markNewPayloadValid(
req.ExecutionPayload.GetBlockHash(),
req.ExecutionPayload.GetParentHash(),
req.Optimistic,
)
}

// Under the optimistic condition, we are fine ignoring the error. This
Expand Down
2 changes: 0 additions & 2 deletions node-core/components/chain_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/berachain/beacon-kit/beacon/blockchain"
"github.com/berachain/beacon-kit/chain"
"github.com/berachain/beacon-kit/config"
"github.com/berachain/beacon-kit/execution/client"
"github.com/berachain/beacon-kit/execution/deposit"
"github.com/berachain/beacon-kit/execution/engine"
"github.com/berachain/beacon-kit/log/phuslu"
Expand All @@ -41,7 +40,6 @@ type ChainServiceInput struct {

ChainSpec chain.Spec
Cfg *config.Config
EngineClient *client.EngineClient
ExecutionEngine *engine.Engine
LocalBuilder LocalBuilder
Logger *phuslu.Logger
Expand Down
22 changes: 11 additions & 11 deletions state-transition/core/mocks/execution_engine.mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions state-transition/core/state_processor_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,21 @@ func (sp *StateProcessor) validateStatefulPayload(
}

parentBeaconBlockRoot := blk.GetParentBlockRoot()
if err = sp.executionEngine.VerifyAndNotifyNewPayload(
ctx, ctypes.BuildNewPayloadRequest(
payload,
body.GetBlobKzgCommitments().ToVersionedHashes(),
&parentBeaconBlockRoot,
optimisticEngine,
),
); err != nil {
payloadReq := ctypes.BuildNewPayloadRequest(
payload,
body.GetBlobKzgCommitments().ToVersionedHashes(),
&parentBeaconBlockRoot,
optimisticEngine,
)

// First we verify the block hash and versioned hashes are valid.
// TODO: is this required? Or will the EL handle this for us during
// new payload?
if err = payloadReq.HasValidVersionedAndBlockHashes(); err != nil {
return err
}

if err = sp.executionEngine.NotifyNewPayload(ctx, payloadReq); err != nil {
return err
}

Expand Down
5 changes: 2 additions & 3 deletions state-transition/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ type Withdrawals interface {

// ExecutionEngine is the interface for the execution engine.
type ExecutionEngine interface {
// VerifyAndNotifyNewPayload verifies the new payload and notifies the
// execution client.
VerifyAndNotifyNewPayload(
// NotifyNewPayload notifies the execution client of the new payload.
NotifyNewPayload(
ctx context.Context,
req *ctypes.NewPayloadRequest,
) error
Expand Down

0 comments on commit ac596fd

Please sign in to comment.