Skip to content

Commit 2c9e42c

Browse files
galaiosunny2022da
authored andcommitted
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 <[email protected]>
1 parent 1e09e32 commit 2c9e42c

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

beacon/engine/types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,11 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
217217
if err != nil {
218218
return nil, err
219219
}
220-
if len(params.ExtraData) > 32 {
221-
return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData))
222-
}
220+
221+
// TODO(galaio): need hardfork, skip check
222+
//if len(params.ExtraData) > 32 {
223+
// return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData))
224+
//}
223225
if len(params.LogsBloom) != 256 {
224226
return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom))
225227
}

core/blockchain.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
18871887
if err != nil {
18881888
return it.index, err
18891889
}
1890-
log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG)
1890+
log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG.Type())
1891+
}
1892+
// TODO(galaio): need hardfork
1893+
if bc.chainConfig.Optimism != nil && len(block.Header().Extra) > 0 {
1894+
txDAG, err := types.DecodeTxDAG(block.Header().Extra)
1895+
if err != nil {
1896+
return it.index, err
1897+
}
1898+
log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG.Type())
18911899
}
18921900

18931901
// Enable prefetching to pull in trie node paths while processing transactions

core/parallel_state_processor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,14 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
741741
return nil, nil, 0, err
742742
}
743743
}
744+
// TODO(galaio): need hardfork
745+
if p.bc.chainConfig.Optimism != nil && len(block.Header().Extra) > 0 {
746+
txDAG, err = types.DecodeTxDAG(block.Header().Extra)
747+
if err != nil {
748+
return nil, nil, 0, err
749+
}
750+
log.Info("dispatch chain with", "block", block.NumberU64(), "txDAG", txDAG.Type())
751+
}
744752
// From now on, entering parallel execution.
745753
p.doStaticDispatchV2(p.allTxReqs, txDAG) // todo: put txReqs in unit?
746754

miner/worker.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,25 @@ func (w *worker) generateWork(genParams *generateParams) *newPayloadResult {
13361336
return &newPayloadResult{err: fmt.Errorf("empty block root")}
13371337
}
13381338

1339+
// Because the TxDAG appends after sidecar, so we only enable after cancun
1340+
if w.chainConfig.IsCancun(block.Number(), block.Time()) && w.chainConfig.Optimism == nil {
1341+
txDAG, _ := work.state.MVStates2TxDAG()
1342+
rawTxDAG, err := types.EncodeTxDAG(txDAG)
1343+
if err != nil {
1344+
return &newPayloadResult{err: err}
1345+
}
1346+
block = block.WithTxDAG(rawTxDAG)
1347+
}
1348+
1349+
// TODO(galaio): need hardfork
1350+
if w.chainConfig.Optimism != nil {
1351+
txDAG, _ := work.state.MVStates2TxDAG()
1352+
rawTxDAG, err := types.EncodeTxDAG(txDAG)
1353+
if err != nil {
1354+
return &newPayloadResult{err: err}
1355+
}
1356+
block.Header().Extra = rawTxDAG
1357+
}
13391358
assembleBlockTimer.UpdateSince(start)
13401359
log.Debug("assembleBlockTimer", "duration", common.PrettyDuration(time.Since(start)), "parentHash", genParams.parentHash)
13411360

@@ -1443,7 +1462,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
14431462
}
14441463

14451464
// Because the TxDAG appends after sidecar, so we only enable after cancun
1446-
if w.chainConfig.IsCancun(env.header.Number, env.header.Time) {
1465+
if w.chainConfig.IsCancun(env.header.Number, env.header.Time) && w.chainConfig.Optimism == nil {
14471466
for i := len(env.txs); i < len(block.Transactions()); i++ {
14481467
env.state.RecordSystemTxRWSet(i)
14491468
}
@@ -1455,6 +1474,16 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
14551474
block = block.WithTxDAG(rawTxDAG)
14561475
}
14571476

1477+
// TODO(galaio): need hardfork
1478+
if w.chainConfig.Optimism != nil {
1479+
txDAG, _ := env.state.MVStates2TxDAG()
1480+
rawTxDAG, err := types.EncodeTxDAG(txDAG)
1481+
if err != nil {
1482+
return err
1483+
}
1484+
block.Header().Extra = rawTxDAG
1485+
}
1486+
14581487
// If we're post merge, just ignore
14591488
if !w.isTTDReached(block.Header()) {
14601489
select {

0 commit comments

Comments
 (0)