From 2c0460c48adc3d7d88a3a04fb1d4ade82231cab8 Mon Sep 17 00:00:00 2001 From: avalonche Date: Wed, 4 Oct 2023 11:45:05 +1100 Subject: [PATCH] fix nil pointers in lazy tx --- eth/sync.go | 2 +- miner/algo_greedy.go | 4 ++-- miner/algo_greedy_multisnap.go | 4 ++-- miner/ordering.go | 2 +- miner/stress/clique/main.go | 2 +- miner/worker.go | 10 +++++----- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/eth/sync.go b/eth/sync.go index a27a294a5..497c4cc93 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -39,7 +39,7 @@ func (h *handler) syncTransactions(p *eth.Peer) { for _, batch := range h.txpool.Pending(false) { for _, tx := range batch { // don't share any transactions marked as private - if !h.txpool.IsPrivateTxHash(tx.Tx.Hash()) { + if !h.txpool.IsPrivateTxHash(tx.Hash) { hashes = append(hashes, tx.Hash) } } diff --git a/miner/algo_greedy.go b/miner/algo_greedy.go index 92fb940ed..1f63c9e53 100644 --- a/miner/algo_greedy.go +++ b/miner/algo_greedy.go @@ -55,7 +55,7 @@ func (b *greedyBuilder) mergeOrdersIntoEnvDiff( break } - if tx := order.Tx(); tx != nil { + if tx := order.Tx(); tx != nil && tx.Resolve() != nil { receipt, skip, err := envDiff.commitTx(tx.Tx, b.chainData) switch skip { case shiftTx: @@ -65,7 +65,7 @@ func (b *greedyBuilder) mergeOrdersIntoEnvDiff( } if err != nil { - log.Trace("could not apply tx", "hash", tx.Tx.Hash(), "err", err) + log.Trace("could not apply tx", "hash", tx.Hash, "err", err) continue } effGapPrice, err := tx.Tx.EffectiveGasTip(envDiff.baseEnvironment.header.BaseFee) diff --git a/miner/algo_greedy_multisnap.go b/miner/algo_greedy_multisnap.go index 9ec409cf8..5b1b2d0fc 100644 --- a/miner/algo_greedy_multisnap.go +++ b/miner/algo_greedy_multisnap.go @@ -67,8 +67,8 @@ func (b *greedyMultiSnapBuilder) buildBlock(simBundles []types.SimulatedBundle, return b.inputEnvironment, usedBundles, usedSbundles } - if tx := order.Tx(); tx != nil { - receipt, skip, err := changes.commitTx(tx.Resolve(), b.chainData) + if tx := order.Tx(); tx != nil && tx.Resolve() != nil { + receipt, skip, err := changes.commitTx(tx.Tx, b.chainData) switch skip { case shiftTx: orders.Shift() diff --git a/miner/ordering.go b/miner/ordering.go index 94f1ae8d0..8c4c630c6 100644 --- a/miner/ordering.go +++ b/miner/ordering.go @@ -80,7 +80,7 @@ func (t *txWithMinerFee) Price() *big.Int { } func (t *txWithMinerFee) Profit(baseFee *big.Int, gasUsed uint64) *big.Int { - if tx := t.Tx(); tx != nil { + if tx := t.Tx(); tx != nil && tx.Resolve() != nil { profit := new(big.Int).Sub(tx.Tx.GasPrice(), baseFee) if gasUsed != 0 { profit.Mul(profit, new(big.Int).SetUint64(gasUsed)) diff --git a/miner/stress/clique/main.go b/miner/stress/clique/main.go index 16fa827d6..0e8e51ab5 100644 --- a/miner/stress/clique/main.go +++ b/miner/stress/clique/main.go @@ -146,7 +146,7 @@ func main() { // makeGenesis creates a custom Clique genesis block based on some pre-defined // signer and faucet accounts. -func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core.Genesis { +func makeGenesis(faucets, sealers []*ecdsa.PrivateKey) *core.Genesis { // Create a Clique network based off of the Sepolia config genesis := core.DefaultSepoliaGenesisBlock() genesis.GasLimit = 25000000 diff --git a/miner/worker.go b/miner/worker.go index 383bbbaef..a1f458f25 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1041,13 +1041,13 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn // Check whether the tx is replay protected. If we're not in the EIP155 hf // phase, start ignoring the sender until we do. if tx.Tx.Protected() && !w.chainConfig.IsEIP155(env.header.Number) { - log.Trace("Ignoring replay protected transaction", "hash", tx.Tx.Hash(), "eip155", w.chainConfig.EIP155Block) + log.Trace("Ignoring replay protected transaction", "hash", tx.Hash, "eip155", w.chainConfig.EIP155Block) txs.Pop() continue } // Start executing the transaction - env.state.SetTxContext(tx.Tx.Hash(), env.tcount) + env.state.SetTxContext(tx.Hash, env.tcount) logs, err := w.commitTransaction(env, tx.Tx) switch { @@ -1065,7 +1065,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn default: // Transaction is regarded as invalid, drop all consecutive transactions from // the same sender because of `nonce-too-high` clause. - log.Debug("Transaction failed, account skipped", "hash", tx.Tx.Hash(), "err", err) + log.Debug("Transaction failed, account skipped", "hash", tx.Hash, "err", err) txs.Pop() } } @@ -1228,7 +1228,7 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) ([] mempoolTxHashes := make(map[common.Hash]struct{}, len(pending)) for _, txs := range pending { for _, tx := range txs { - mempoolTxHashes[tx.Tx.Hash()] = struct{}{} + mempoolTxHashes[tx.Hash] = struct{}{} } } @@ -1298,7 +1298,7 @@ func (w *worker) fillTransactionsAlgoWorker(interrupt *atomic.Int32, env *enviro mempoolTxHashes := make(map[common.Hash]struct{}, len(pending)) for _, txs := range pending { for _, tx := range txs { - mempoolTxHashes[tx.Tx.Hash()] = struct{}{} + mempoolTxHashes[tx.Hash] = struct{}{} } } bundlesToConsider, sbundlesToConsider, err := w.getSimulatedBundles(env)