From b7fdd9f00594494fa62a6a2a344462ad9d434195 Mon Sep 17 00:00:00 2001 From: galaio <12880651+galaio@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:58:15 +0800 Subject: [PATCH] TxDAG: support TxDAG transfer, it can be used in QA performance testing; (#10) * txdag: support txdag transfer in extra; * txdag: support txdag transfer in extra; --------- Co-authored-by: galaio --- beacon/engine/types.go | 8 +++++--- core/blockchain.go | 10 +++++++++- core/parallel_state_processor.go | 8 ++++++++ miner/worker.go | 31 ++++++++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 487693ea18..55fb0366f5 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -192,9 +192,11 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash, if err != nil { return nil, err } - if len(params.ExtraData) > 32 { - return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData)) - } + + // TODO(galaio): need hardfork, skip check + //if len(params.ExtraData) > 32 { + // return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData)) + //} if len(params.LogsBloom) != 256 { return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom)) } diff --git a/core/blockchain.go b/core/blockchain.go index 467029db7c..53f9d4d531 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1930,7 +1930,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) if err != nil { return it.index, err } - log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG) + log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG.Type()) + } + // TODO(galaio): need hardfork + if bc.chainConfig.Optimism != nil && len(block.Header().Extra) > 0 { + txDAG, err := types.DecodeTxDAG(block.Header().Extra) + if err != nil { + return it.index, err + } + log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG.Type()) } // Enable prefetching to pull in trie node paths while processing transactions diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index e0338f28c9..9fe363f151 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -741,6 +741,14 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat return nil, nil, 0, err } } + // TODO(galaio): need hardfork + if p.bc.chainConfig.Optimism != nil && len(block.Header().Extra) > 0 { + txDAG, err = types.DecodeTxDAG(block.Header().Extra) + if err != nil { + return nil, nil, 0, err + } + log.Info("dispatch chain with", "block", block.NumberU64(), "txDAG", txDAG.Type()) + } // From now on, entering parallel execution. p.doStaticDispatchV2(p.allTxReqs, txDAG) // todo: put txReqs in unit? diff --git a/miner/worker.go b/miner/worker.go index 2c22aefda6..efa125df13 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1267,6 +1267,25 @@ func (w *worker) generateWork(genParams *generateParams) *newPayloadResult { return &newPayloadResult{err: fmt.Errorf("empty block root")} } + // Because the TxDAG appends after sidecar, so we only enable after cancun + if w.chainConfig.IsCancun(block.Number(), block.Time()) && w.chainConfig.Optimism == nil { + txDAG, _ := work.state.MVStates2TxDAG() + rawTxDAG, err := types.EncodeTxDAG(txDAG) + if err != nil { + return &newPayloadResult{err: err} + } + block = block.WithTxDAG(rawTxDAG) + } + + // TODO(galaio): need hardfork + if w.chainConfig.Optimism != nil { + txDAG, _ := work.state.MVStates2TxDAG() + rawTxDAG, err := types.EncodeTxDAG(txDAG) + if err != nil { + return &newPayloadResult{err: err} + } + block.Header().Extra = rawTxDAG + } assembleBlockTimer.UpdateSince(start) log.Debug("assembleBlockTimer", "duration", common.PrettyDuration(time.Since(start)), "parentHash", genParams.parentHash) @@ -1374,7 +1393,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti } // Because the TxDAG appends after sidecar, so we only enable after cancun - if w.chainConfig.IsCancun(env.header.Number, env.header.Time) { + if w.chainConfig.IsCancun(env.header.Number, env.header.Time) && w.chainConfig.Optimism == nil { for i := len(env.txs); i < len(block.Transactions()); i++ { env.state.RecordSystemTxRWSet(i) } @@ -1386,6 +1405,16 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti block = block.WithTxDAG(rawTxDAG) } + // TODO(galaio): need hardfork + if w.chainConfig.Optimism != nil { + txDAG, _ := env.state.MVStates2TxDAG() + rawTxDAG, err := types.EncodeTxDAG(txDAG) + if err != nil { + return err + } + block.Header().Extra = rawTxDAG + } + // If we're post merge, just ignore if !w.isTTDReached(block.Header()) { select {