Skip to content

Commit

Permalink
add support for blob tx
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu committed Apr 9, 2024
1 parent 5137f3b commit 5816e0b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
9 changes: 8 additions & 1 deletion op-node/rollup/derive/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type EngineController struct {
buildingInfo eth.PayloadInfo
buildingSafe bool
safeAttrs *AttributesWithParent

dacClient rollup.DACClient
}

func NewEngineController(engine ExecEngine, log log.Logger, metrics Metrics, rollupCfg *rollup.Config, syncMode sync.Mode) *EngineController {
Expand All @@ -81,6 +83,10 @@ func NewEngineController(engine ExecEngine, log log.Logger, metrics Metrics, rol
syncStatus = syncStatusWillStartEL
}

var dacClient rollup.DACClient
if rollupCfg.DACConfig != nil {
dacClient = rollupCfg.DACConfig.Client()
}
return &EngineController{
engine: engine,
log: log,
Expand All @@ -89,6 +95,7 @@ func NewEngineController(engine ExecEngine, log log.Logger, metrics Metrics, rol
syncMode: syncMode,
syncStatus: syncStatus,
clock: clock.SystemClock,
dacClient: dacClient,
}
}

Expand Down Expand Up @@ -209,7 +216,7 @@ func (e *EngineController) ConfirmPayload(ctx context.Context, agossip async.Asy
}
// Update the safe head if the payload is built with the last attributes in the batch.
updateSafe := e.buildingSafe && e.safeAttrs != nil && e.safeAttrs.isLastInSpan
envelope, errTyp, err := confirmPayload(ctx, e.log, e.engine, fc, e.buildingInfo, updateSafe, agossip, sequencerConductor)
envelope, errTyp, err := confirmPayload(ctx, e.log, e.engine, fc, e.buildingInfo, updateSafe, agossip, sequencerConductor, e.dacClient)
if err != nil {
return nil, errTyp, fmt.Errorf("failed to complete building on top of L2 chain %s, id: %s, error (%d): %w", e.buildingOnto, e.buildingInfo.ID, errTyp, err)
}
Expand Down
13 changes: 13 additions & 0 deletions op-node/rollup/derive/engine_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup/async"
"github.com/ethereum-optimism/optimism/op-node/rollup/conductor"
"github.com/ethereum-optimism/optimism/op-service/eth"
Expand Down Expand Up @@ -128,6 +129,7 @@ func confirmPayload(
updateSafe bool,
agossip async.AsyncGossiper,
sequencerConductor conductor.SequencerConductor,
dacClient rollup.DACClient,
) (out *eth.ExecutionPayloadEnvelope, errTyp BlockInsertionErrType, err error) {
var envelope *eth.ExecutionPayloadEnvelope
// if the payload is available from the async gossiper, it means it was not yet imported, so we reuse it
Expand All @@ -150,6 +152,17 @@ func confirmPayload(
if err := sanityCheckPayload(payload); err != nil {
return nil, BlockInsertPayloadErr, err
}
if envelope.BlobsBundle != nil && len(envelope.BlobsBundle.Blobs) > 0 {
if updateSafe {
return nil, BlockInsertPayloadErr, fmt.Errorf("got blobs when updateSafe")
}
if dacClient != nil {
err = dacClient.UploadBlobs(envelope)
if err != nil {
return nil, BlockInsertTemporaryErr, fmt.Errorf("UploadBlobs failed: %w", err)
}
}
}
if err := sequencerConductor.CommitUnsafePayload(ctx, envelope); err != nil {
return nil, BlockInsertTemporaryErr, fmt.Errorf("failed to commit unsafe payload to conductor: %w", err)
}
Expand Down
14 changes: 14 additions & 0 deletions op-node/rollup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ type Config struct {

// UsePlasma is activated when the chain is in plasma mode.
UsePlasma bool `json:"use_plasma"`

DACConfig *DACConfig `json:"dac_config,omitempty"`
}

type DACConfig struct {
URL string
}

type DACClient interface {
UploadBlobs(*eth.ExecutionPayloadEnvelope) error
}

func (dacConfig *DACConfig) Client() DACClient {
return nil
}

// ValidateL1Config checks L1 config variables for errors.
Expand Down
5 changes: 3 additions & 2 deletions op-service/eth/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ type (
)

type ExecutionPayloadEnvelope struct {
ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot,omitempty"`
ExecutionPayload *ExecutionPayload `json:"executionPayload"`
ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot,omitempty"`
ExecutionPayload *ExecutionPayload `json:"executionPayload"`
BlobsBundle *engine.BlobsBundleV1 `json:"blobsBundle"`
}

type ExecutionPayload struct {
Expand Down

0 comments on commit 5816e0b

Please sign in to comment.