Skip to content

Commit b7fdd9f

Browse files
galaiosunny2022da
authored andcommitted
TxDAG: support TxDAG transfer, it can be used in QA performance testing; (bnb-chain#10)
* txdag: support txdag transfer in extra; * txdag: support txdag transfer in extra; --------- Co-authored-by: galaio <[email protected]>
1 parent c9acb32 commit b7fdd9f

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

beacon/engine/types.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
192192
if err != nil {
193193
return nil, err
194194
}
195-
if len(params.ExtraData) > 32 {
196-
return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData))
197-
}
195+
196+
// TODO(galaio): need hardfork, skip check
197+
//if len(params.ExtraData) > 32 {
198+
// return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData))
199+
//}
198200
if len(params.LogsBloom) != 256 {
199201
return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom))
200202
}

core/blockchain.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
19301930
if err != nil {
19311931
return it.index, err
19321932
}
1933-
log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG)
1933+
log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG.Type())
1934+
}
1935+
// TODO(galaio): need hardfork
1936+
if bc.chainConfig.Optimism != nil && len(block.Header().Extra) > 0 {
1937+
txDAG, err := types.DecodeTxDAG(block.Header().Extra)
1938+
if err != nil {
1939+
return it.index, err
1940+
}
1941+
log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG.Type())
19341942
}
19351943

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

core/parallel_state_processor.go

+8
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

+30-1
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,25 @@ func (w *worker) generateWork(genParams *generateParams) *newPayloadResult {
12671267
return &newPayloadResult{err: fmt.Errorf("empty block root")}
12681268
}
12691269

1270+
// Because the TxDAG appends after sidecar, so we only enable after cancun
1271+
if w.chainConfig.IsCancun(block.Number(), block.Time()) && w.chainConfig.Optimism == nil {
1272+
txDAG, _ := work.state.MVStates2TxDAG()
1273+
rawTxDAG, err := types.EncodeTxDAG(txDAG)
1274+
if err != nil {
1275+
return &newPayloadResult{err: err}
1276+
}
1277+
block = block.WithTxDAG(rawTxDAG)
1278+
}
1279+
1280+
// TODO(galaio): need hardfork
1281+
if w.chainConfig.Optimism != nil {
1282+
txDAG, _ := work.state.MVStates2TxDAG()
1283+
rawTxDAG, err := types.EncodeTxDAG(txDAG)
1284+
if err != nil {
1285+
return &newPayloadResult{err: err}
1286+
}
1287+
block.Header().Extra = rawTxDAG
1288+
}
12701289
assembleBlockTimer.UpdateSince(start)
12711290
log.Debug("assembleBlockTimer", "duration", common.PrettyDuration(time.Since(start)), "parentHash", genParams.parentHash)
12721291

@@ -1374,7 +1393,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
13741393
}
13751394

13761395
// Because the TxDAG appends after sidecar, so we only enable after cancun
1377-
if w.chainConfig.IsCancun(env.header.Number, env.header.Time) {
1396+
if w.chainConfig.IsCancun(env.header.Number, env.header.Time) && w.chainConfig.Optimism == nil {
13781397
for i := len(env.txs); i < len(block.Transactions()); i++ {
13791398
env.state.RecordSystemTxRWSet(i)
13801399
}
@@ -1386,6 +1405,16 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
13861405
block = block.WithTxDAG(rawTxDAG)
13871406
}
13881407

1408+
// TODO(galaio): need hardfork
1409+
if w.chainConfig.Optimism != nil {
1410+
txDAG, _ := env.state.MVStates2TxDAG()
1411+
rawTxDAG, err := types.EncodeTxDAG(txDAG)
1412+
if err != nil {
1413+
return err
1414+
}
1415+
block.Header().Extra = rawTxDAG
1416+
}
1417+
13891418
// If we're post merge, just ignore
13901419
if !w.isTTDReached(block.Header()) {
13911420
select {

0 commit comments

Comments
 (0)