From f2ff2a410c26afd5182e0d2e152c4cd78a220ee3 Mon Sep 17 00:00:00 2001 From: galaio <12880651+galaio@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:36:56 +0800 Subject: [PATCH] txdag: remove legacy TxDAG transfer logic; (#16) Co-authored-by: galaio --- beacon/engine/types.go | 8 ++--- core/block_validator.go | 7 ----- core/blockchain.go | 20 ++----------- core/parallel_state_processor.go | 18 ++---------- core/types/block.go | 21 -------------- eth/handler_eth.go | 3 -- eth/protocols/eth/peer.go | 1 - eth/protocols/eth/protocol.go | 3 -- miner/worker.go | 50 +++++--------------------------- 9 files changed, 16 insertions(+), 115 deletions(-) diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 55fb0366f5..487693ea18 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -192,11 +192,9 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash, if err != nil { return nil, err } - - // 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.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/block_validator.go b/core/block_validator.go index f2446927cc..538cea51b0 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -156,13 +156,6 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error { if ancestorErr != nil { return ancestorErr } - - // TODO(galaio): add more TxDAG hash when TxDAG in consensus, txDAG check here - if len(block.TxDAG()) > 0 { - if _, err := types.DecodeTxDAG(block.TxDAG()); err != nil { - return errors.New("wrong TxDAG in block body") - } - } return nil } diff --git a/core/blockchain.go b/core/blockchain.go index c5078159bd..7667919203 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1935,22 +1935,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) return it.index, err } - // TODO(galaio): use txDAG in some accelerate scenarios, like state pre-fetcher. - //if bc.enableTxDAG && len(block.TxDAG()) > 0 { - // txDAG, err := types.DecodeTxDAG(block.TxDAG()) - // if err != nil { - // return it.index, err - // } - // log.Info("Insert chain", "block", block.NumberU64(), "txDAG", txDAG) - //} - // TODO(galaio): need hardfork - if bc.enableTxDAG && 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()) - } + // TODO(galaio): load TxDAG from block, use txDAG in some accelerate scenarios, like state pre-fetcher. + //if bc.enableTxDAG {} // Enable prefetching to pull in trie node paths while processing transactions statedb.StartPrefetcher("chain") @@ -2850,13 +2836,13 @@ func (bc *BlockChain) SetupTxDAGGeneration(output string) { } // write handler - bc.txDAGWriteCh = make(chan TxDAGOutputItem, 10000) go func() { writeHandle, err := os.OpenFile(output, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) if err != nil { log.Error("OpenFile when open the txDAG output file", "file", output) return } + bc.txDAGWriteCh = make(chan TxDAGOutputItem, 10000) defer writeHandle.Close() for { select { diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index 93c56f5c31..77d86902af 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -801,28 +801,14 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat var ( txDAG types.TxDAG - err error ) if p.bc.enableTxDAG { - if len(block.TxDAG()) != 0 { - txDAG, err = types.DecodeTxDAG(block.TxDAG()) - if err != nil { - return nil, nil, 0, err - } - } - // load cache txDAG from file + // TODO(galaio): load TxDAG from block + // or load cache txDAG from file if txDAG == nil && len(p.bc.txDAGMapping) > 0 { txDAG = p.bc.txDAGMapping[block.NumberU64()] } } - // TODO(galaio): need hardfork - if p.bc.enableTxDAG && 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/core/types/block.go b/core/types/block.go index 47b4abec39..b32931b054 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -197,8 +197,6 @@ type Block struct { uncles []*Header transactions Transactions withdrawals Withdrawals - // TODO(galaio): package txDAG in consensus later - txDAG []byte // caches hash atomic.Value @@ -425,10 +423,6 @@ func (b *Block) SanityCheck() error { return b.header.SanityCheck() } -func (b *Block) TxDAG() []byte { - return b.txDAG -} - type writeCounter uint64 func (c *writeCounter) Write(b []byte) (int, error) { @@ -458,7 +452,6 @@ func (b *Block) WithSeal(header *Header) *Block { transactions: b.transactions, uncles: b.uncles, withdrawals: b.withdrawals, - txDAG: b.txDAG, } } @@ -469,7 +462,6 @@ func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block { transactions: make([]*Transaction, len(transactions)), uncles: make([]*Header, len(uncles)), withdrawals: b.withdrawals, - txDAG: b.txDAG, } copy(block.transactions, transactions) for i := range uncles { @@ -484,7 +476,6 @@ func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block { header: b.header, transactions: b.transactions, uncles: b.uncles, - txDAG: b.txDAG, } if withdrawals != nil { block.withdrawals = make([]*Withdrawal, len(withdrawals)) @@ -493,18 +484,6 @@ func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block { return block } -// WithTxDAG returns a block containing the given txDAG. -func (b *Block) WithTxDAG(txDAG []byte) *Block { - block := &Block{ - header: b.header, - transactions: b.transactions, - uncles: b.uncles, - withdrawals: b.withdrawals, - txDAG: txDAG, - } - return block -} - // Hash returns the keccak256 hash of b's header. // The hash is computed on the first call and cached thereafter. func (b *Block) Hash() common.Hash { diff --git a/eth/handler_eth.go b/eth/handler_eth.go index 4d16ead37a..7c43bae9d0 100644 --- a/eth/handler_eth.go +++ b/eth/handler_eth.go @@ -81,9 +81,6 @@ func (h *ethHandler) Handle(peer *eth.Peer, packet eth.Packet) error { return h.handleBlockAnnounces(peer, hashes, numbers) case *eth.NewBlockPacket: - if len(packet.TxDAG) != 0 { - packet.Block = packet.Block.WithTxDAG(packet.TxDAG) - } return h.handleBlockBroadcast(peer, packet.Block, packet.TD) case *eth.NewPooledTransactionHashesPacket67: diff --git a/eth/protocols/eth/peer.go b/eth/protocols/eth/peer.go index 6278924b60..98ad22a8cf 100644 --- a/eth/protocols/eth/peer.go +++ b/eth/protocols/eth/peer.go @@ -294,7 +294,6 @@ func (p *Peer) SendNewBlock(block *types.Block, td *big.Int) error { return p2p.Send(p.rw, NewBlockMsg, &NewBlockPacket{ Block: block, TD: td, - TxDAG: block.TxDAG(), }) } diff --git a/eth/protocols/eth/protocol.go b/eth/protocols/eth/protocol.go index 6c7ea3b404..0f44f83de1 100644 --- a/eth/protocols/eth/protocol.go +++ b/eth/protocols/eth/protocol.go @@ -188,7 +188,6 @@ type BlockHeadersRLPPacket struct { type NewBlockPacket struct { Block *types.Block TD *big.Int - TxDAG []byte `rlp:"optional"` } // sanityCheck verifies that the values are reasonable, as a DoS protection @@ -239,8 +238,6 @@ type BlockBody struct { Transactions []*types.Transaction // Transactions contained within a block Uncles []*types.Header // Uncles contained within a block Withdrawals []*types.Withdrawal `rlp:"optional"` // Withdrawals contained within a block - // TODO(galio): add block body later - //TxDAGs [][]byte `rlp:"optional"` // TxDAGs contained within a block } // Unpack retrieves the transactions and uncles from the range packet and returns diff --git a/miner/worker.go b/miner/worker.go index e5445faf67..7b0dd9d73c 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1219,25 +1219,14 @@ 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.chain.TxDAGEnabled() && w.chainConfig.IsCancun(block.Number(), block.Time()) && w.chainConfig.Optimism == nil { - txDAG, _ := work.state.ResolveTxDAG([]common.Address{work.coinbase, params.OptimismBaseFeeRecipient, params.OptimismL1FeeRecipient}) - rawTxDAG, err := types.EncodeTxDAG(txDAG) - if err != nil { - return &newPayloadResult{err: err} - } - block = block.WithTxDAG(rawTxDAG) - } - - // TODO(galaio): need hardfork - if w.chain.TxDAGEnabled() && w.chainConfig.Optimism != nil { - txDAG, _ := work.state.ResolveTxDAG([]common.Address{work.coinbase, params.OptimismBaseFeeRecipient, params.OptimismL1FeeRecipient}) - rawTxDAG, err := types.EncodeTxDAG(txDAG) - if err != nil { - return &newPayloadResult{err: err} - } - block.Header().Extra = rawTxDAG - } + // TODO(galaio): fulfill TxDAG to mined block + //if w.chain.TxDAGEnabled() && w.chainConfig.Optimism != nil { + // txDAG, _ := work.state.ResolveTxDAG([]common.Address{work.coinbase, params.OptimismBaseFeeRecipient, params.OptimismL1FeeRecipient}) + // rawTxDAG, err := types.EncodeTxDAG(txDAG) + // if err != nil { + // return &newPayloadResult{err: err} + // } + //} assembleBlockTimer.UpdateSince(start) log.Debug("assembleBlockTimer", "duration", common.PrettyDuration(time.Since(start)), "parentHash", genParams.parentHash) @@ -1347,29 +1336,6 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti return err } - // Because the TxDAG appends after sidecar, so we only enable after cancun - if w.chain.TxDAGEnabled() && 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) - } - txDAG, _ := env.state.ResolveTxDAG([]common.Address{env.coinbase, params.OptimismBaseFeeRecipient, params.OptimismL1FeeRecipient}) - rawTxDAG, err := types.EncodeTxDAG(txDAG) - if err != nil { - return err - } - block = block.WithTxDAG(rawTxDAG) - } - - // TODO(galaio): need hardfork - if w.chain.TxDAGEnabled() && w.chainConfig.Optimism != nil { - txDAG, _ := env.state.ResolveTxDAG([]common.Address{env.coinbase, params.OptimismBaseFeeRecipient, params.OptimismL1FeeRecipient}) - 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 {