Skip to content

Commit

Permalink
TxDAG: support TxDAG transfer, it can be used in QA performance testi…
Browse files Browse the repository at this point in the history
…ng; (bnb-chain#10)

* txdag: support txdag transfer in extra;

* txdag: support txdag transfer in extra;

---------

Co-authored-by: galaio <[email protected]>
  • Loading branch information
galaio and galaio authored Jul 24, 2024
1 parent 5dd7b3b commit 46a3e46
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
8 changes: 5 additions & 3 deletions beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
10 changes: 9 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions core/parallel_state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
31 changes: 30 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,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)

Expand Down Expand Up @@ -1325,7 +1344,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)
}
Expand All @@ -1337,6 +1356,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 {
Expand Down

0 comments on commit 46a3e46

Please sign in to comment.