Skip to content

Commit

Permalink
Merge branch 'support_4844' into testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu committed Jul 8, 2024
2 parents df2aeba + bd01933 commit cdfd84a
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 20 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethstorage/da-server v0.0.0-20240628094857-ed2ee4ff52d9 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/ferranbt/fastssz v0.1.2 // indirect
Expand Down Expand Up @@ -205,6 +206,7 @@ require (
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/urfave/cli v1.22.14 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.uber.org/automaxprocs v1.5.2 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-2024052213450
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240522134500-19555bdbdc95/go.mod h1:7xh2awFQqsiZxFrHKTgEd+InVfDRrkKVUIuK8SAFHp0=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethstorage/da-server v0.0.0-20240628094857-ed2ee4ff52d9 h1:yRJRj81rP83R5dZEsYitAFcqRagK/e+UxhiSSK4/Wds=
github.com/ethstorage/da-server v0.0.0-20240628094857-ed2ee4ff52d9/go.mod h1:YeveZNzQFdseeqS0mQavqfyMI+U9l1GQu0CEwezTZA8=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
Expand Down Expand Up @@ -780,6 +782,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
Expand All @@ -797,6 +800,8 @@ github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqri
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk=
github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
Expand Down
13 changes: 13 additions & 0 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ type DeployConfig struct {

// UseInterop is a flag that indicates if the system is using interop
UseInterop bool `json:"useInterop,omitempty"`
// l2 blob related configs
EnableL2Blob bool `json:"enable_l2_blob,omitempty"`
DACURLS []string `json:"dac_urls,omitempty"`
}

// Copy will deeply copy the DeployConfig. This does a JSON roundtrip to copy
Expand Down Expand Up @@ -618,6 +621,15 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHas
}
}

var l2BlobConfig *rollup.L2BlobConfig
if d.EnableL2Blob {
l2BlobConfig = &rollup.L2BlobConfig{
EnableL2Blob: true,
}
if len(d.DACURLS) > 0 {
l2BlobConfig.DACConfig = &rollup.DACConfig{URLS: d.DACURLS}
}
}
return &rollup.Config{
Genesis: rollup.Genesis{
L1: eth.BlockID{
Expand Down Expand Up @@ -652,6 +664,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHas
FjordTime: d.FjordTime(l1StartBlock.Time()),
InteropTime: d.InteropTime(l1StartBlock.Time()),
PlasmaConfig: plasma,
L2BlobConfig: l2BlobConfig,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions op-node/p2p/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ func BuildBlocksValidator(log log.Logger, cfg *rollup.Config, runCfg GossipRunti

if blockVersion.HasBlobProperties() {
// [REJECT] if the block is on a topic >= V3 and has a blob gas used value that is not zero
if payload.BlobGasUsed == nil || (payload.BlobGasUsed != nil && *payload.BlobGasUsed != 0) {
if payload.BlobGasUsed == nil || (!cfg.IsL2BlobEnabled() && *payload.BlobGasUsed != 0) {
log.Warn("payload is on v3 topic, but has non-zero blob gas used", "bad_hash", payload.BlockHash.String(), "blob_gas_used", payload.BlobGasUsed)
return pubsub.ValidationReject
}

// [REJECT] if the block is on a topic >= V3 and has an excess blob gas value that is not zero
if payload.ExcessBlobGas == nil || (payload.ExcessBlobGas != nil && *payload.ExcessBlobGas != 0) {
if payload.ExcessBlobGas == nil || (!cfg.IsL2BlobEnabled() && *payload.ExcessBlobGas != 0) {
log.Warn("payload is on v3 topic, but has non-zero excess blob gas", "bad_hash", payload.BlockHash.String(), "excess_blob_gas", payload.ExcessBlobGas)
return pubsub.ValidationReject
}
Expand Down
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 @@ -74,6 +74,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 @@ -82,6 +84,10 @@ func NewEngineController(engine ExecEngine, log log.Logger, metrics Metrics, rol
syncStatus = syncStatusWillStartEL
}

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

Expand Down Expand Up @@ -212,7 +219,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
14 changes: 14 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,18 @@ func confirmPayload(
if err := sanityCheckPayload(payload); err != nil {
return nil, BlockInsertPayloadErr, err
}
if envelope.BlobsBundle != nil && len(envelope.BlobsBundle.Blobs) > 0 {
// When updateSafe, it must be deriving instead of sequencing. Deriving is based on onchain-data which doesn't contain L2 blob.
if updateSafe {
return nil, BlockInsertPayloadErr, fmt.Errorf("got blobs when updateSafe")
}
if dacClient != nil {
err = dacClient.UploadBlobs(ctx, 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
80 changes: 80 additions & 0 deletions op-node/rollup/derive/span_batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256"
)

type spanBatchTxData interface {
Expand Down Expand Up @@ -45,6 +46,18 @@ type spanBatchDynamicFeeTxData struct {

func (txData *spanBatchDynamicFeeTxData) txType() byte { return types.DynamicFeeTxType }

type spanBatchBlobTxData struct {
Value *uint256.Int
GasTipCap *uint256.Int // a.k.a. maxPriorityFeePerGas
GasFeeCap *uint256.Int // a.k.a. maxFeePerGas
Data []byte
AccessList types.AccessList
BlobFeeCap *uint256.Int // a.k.a. maxFeePerBlobGas
BlobHashes []common.Hash
}

func (txData *spanBatchBlobTxData) txType() byte { return types.BlobTxType }

// Type returns the transaction type.
func (tx *spanBatchTx) Type() uint8 {
return tx.inner.txType()
Expand Down Expand Up @@ -93,6 +106,13 @@ func (tx *spanBatchTx) decodeTyped(b []byte) (spanBatchTxData, error) {
return nil, fmt.Errorf("failed to decode spanBatchDynamicFeeTxData: %w", err)
}
return &inner, nil
case types.BlobTxType:
var inner spanBatchBlobTxData
err := rlp.DecodeBytes(b[1:], &inner)
if err != nil {
return nil, fmt.Errorf("failed to decode spanBatchBlobTxData: %w", err)
}
return &inner, nil
default:
return nil, types.ErrTxTypeNotSupported
}
Expand Down Expand Up @@ -168,6 +188,40 @@ func (tx *spanBatchTx) convertToFullTx(nonce, gas uint64, to *common.Address, ch
R: R,
S: S,
}
case types.BlobTxType:
if to == nil {
return nil, fmt.Errorf("invalid blob tx: to can't be nil")
}
VU256, overflow := uint256.FromBig(V)
if overflow {
return nil, fmt.Errorf("invalid blob tx: V overflow:%v", V)
}
RU256, overflow := uint256.FromBig(R)
if overflow {
return nil, fmt.Errorf("invalid blob tx: R overflow:%v", R)
}
SU256, overflow := uint256.FromBig(S)
if overflow {
return nil, fmt.Errorf("invalid blob tx: S overflow:%v", R)
}
batchTxInner := tx.inner.(*spanBatchBlobTxData)
inner = &types.BlobTx{
ChainID: uint256.MustFromBig(chainID),
Nonce: nonce,
GasTipCap: batchTxInner.GasTipCap,
GasFeeCap: batchTxInner.GasFeeCap,
Gas: gas,
To: *to,
Value: batchTxInner.Value,
Data: batchTxInner.Data,
AccessList: batchTxInner.AccessList,
BlobFeeCap: batchTxInner.BlobFeeCap,
BlobHashes: batchTxInner.BlobHashes,
V: VU256,
R: RU256,
S: SU256,
}

default:
return nil, fmt.Errorf("invalid tx type: %d", tx.Type())
}
Expand Down Expand Up @@ -199,6 +253,32 @@ func newSpanBatchTx(tx types.Transaction) (*spanBatchTx, error) {
Data: tx.Data(),
AccessList: tx.AccessList(),
}
case types.BlobTxType:
gasTipCap, overflow := uint256.FromBig(tx.GasTipCap())
if overflow {
return nil, fmt.Errorf("tx.GasTipCap() overflow: %v", tx.GasTipCap())
}
gasFeeCap, overflow := uint256.FromBig(tx.GasFeeCap())
if overflow {
return nil, fmt.Errorf("tx.GasFeeCap() overflow: %v", tx.GasFeeCap())
}
value, overflow := uint256.FromBig(tx.Value())
if overflow {
return nil, fmt.Errorf("tx.Value() overflow: %v", tx.Value())
}
blobFeeCap, overflow := uint256.FromBig(tx.BlobGasFeeCap())
if overflow {
return nil, fmt.Errorf("tx.BlobGasFeeCap() overflow: %v", tx.BlobGasFeeCap())
}
inner = &spanBatchBlobTxData{
Value: value,
GasTipCap: gasTipCap,
GasFeeCap: gasFeeCap,
Data: tx.Data(),
AccessList: tx.AccessList(),
BlobFeeCap: blobFeeCap,
BlobHashes: tx.BlobHashes(),
}
default:
return nil, fmt.Errorf("invalid tx type: %d", tx.Type())
}
Expand Down
4 changes: 4 additions & 0 deletions op-node/rollup/derive/span_batch_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ func (btx *spanBatchTxs) recoverV(chainID *big.Int) error {
v = bit
case types.DynamicFeeTxType:
v = bit
case types.BlobTxType:
v = bit
default:
return fmt.Errorf("invalid tx type: %d", txType)
}
Expand Down Expand Up @@ -386,6 +388,8 @@ func convertVToYParity(v uint64, txType int) (uint, error) {
yParityBit = uint(v)
case types.DynamicFeeTxType:
yParityBit = uint(v)
case types.BlobTxType:
yParityBit = uint(v)
default:
return 0, fmt.Errorf("invalid tx type: %d", txType)
}
Expand Down
2 changes: 2 additions & 0 deletions op-node/rollup/derive/span_batch_txs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,15 @@ func TestSpanBatchTxsRecoverV(t *testing.T) {

chainID := big.NewInt(rng.Int63n(1000))
londonSigner := types.NewLondonSigner(chainID)
cancunSigner := types.NewCancunSigner(chainID)
totalblockTxCount := 20 + rng.Intn(100)

cases := []txTypeTest{
{"unprotected legacy tx", testutils.RandomLegacyTx, types.HomesteadSigner{}},
{"legacy tx", testutils.RandomLegacyTx, londonSigner},
{"access list tx", testutils.RandomAccessListTx, londonSigner},
{"dynamic fee tx", testutils.RandomDynamicFeeTx, londonSigner},
{"blob tx", testutils.RandomBlobTx, cancunSigner},
}

for _, testCase := range cases {
Expand Down
31 changes: 31 additions & 0 deletions op-node/rollup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethstorage/da-server/pkg/da/client"

plasma "github.com/ethereum-optimism/optimism/op-plasma"
"github.com/ethereum-optimism/optimism/op-service/eth"
Expand Down Expand Up @@ -140,6 +141,36 @@ type Config struct {

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

L2BlobConfig *L2BlobConfig `json:"l2_blob_config,omitempty"`
}

type L2BlobConfig struct {
DACConfig *DACConfig `json:"dac_config,omitempty"`
EnableL2Blob bool `json:"enable_l2_blob,omitempty"`
}
type DACConfig struct {
URLS []string
}

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

func (dacConfig *DACConfig) Client() DACClient {

return client.New(dacConfig.URLS)
}

func (cfg *Config) IsL2BlobEnabled() bool {
return cfg.L2BlobConfig != nil && cfg.L2BlobConfig.EnableL2Blob
}

func (cfg *Config) DACConfig() *DACConfig {
if cfg.L2BlobConfig == nil {
return nil
}
return cfg.L2BlobConfig.DACConfig
}

// ValidateL1Config checks L1 config variables for errors.
Expand Down
7 changes: 5 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 Expand Up @@ -238,6 +239,8 @@ func (envelope *ExecutionPayloadEnvelope) CheckBlockHash() (actual common.Hash,
Nonce: types.BlockNonce{}, // zeroed, proof-of-work legacy
BaseFee: (*uint256.Int)(&payload.BaseFeePerGas).ToBig(),
ParentBeaconRoot: envelope.ParentBeaconBlockRoot,
BlobGasUsed: (*uint64)(payload.BlobGasUsed),
ExcessBlobGas: (*uint64)(payload.ExcessBlobGas),
}

if payload.CanyonBlock() {
Expand Down
2 changes: 2 additions & 0 deletions op-service/sources/engine_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func (s *EngineAPIClient) NewPayload(ctx context.Context, payload *eth.Execution
var err error
switch method := s.evp.NewPayloadVersion(uint64(payload.Timestamp)); method {
case eth.NewPayloadV3:
// now we pass empty array to skip checking versionedHashes
// TODO: sync with OP upstream once they support L2 blob tx
err = s.RPC.CallContext(execCtx, &result, string(method), payload, []common.Hash{}, parentBeaconBlockRoot)
case eth.NewPayloadV2:
err = s.RPC.CallContext(execCtx, &result, string(method), payload)
Expand Down
Loading

0 comments on commit cdfd84a

Please sign in to comment.