diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 2ba53e99be..b50df3fdea 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -274,11 +274,7 @@ type TxPool struct { signer types.Signer mu sync.RWMutex - txFeed event.Feed dropTxFeed event.Feed - scope event.SubscriptionScope - signer types.Signer - mu sync.RWMutex istanbul atomic.Bool // Fork indicator whether we are in the istanbul stage. eip2718 atomic.Bool // Fork indicator whether we are using EIP-2718 type transactions. eip1559 atomic.Bool // Fork indicator whether we are using EIP-1559 type transactions. @@ -457,10 +453,7 @@ func (pool *TxPool) loop() { for _, tx = range list { toRemove = append(toRemove, tx.Hash()) } - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: list, - Reason: dropOld, - }) + queuedEvictionMeter.Mark(int64(len(list))) } } @@ -514,12 +507,6 @@ func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subsc return pool.scope.Track(pool.txFeed.Subscribe(ch)) } -// SubscribeDropTxsEvent registers a subscription of DropTxsEvent and -// starts sending event to the given channel. -func (pool *TxPool) SubscribeDropTxsEvent(ch chan<- DropTxsEvent) event.Subscription { - return pool.scope.Track(pool.dropTxFeed.Subscribe(ch)) -} - // GasPrice returns the current gas price enforced by the transaction pool. func (pool *TxPool) GasPrice() *big.Int { pool.gasPriceMu.RLock() @@ -562,10 +549,6 @@ func (pool *TxPool) SetGasPrice(price *big.Int) { } pool.priced.Removed(len(drop)) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: drop, - Reason: dropGasPriceUpdated, - }) } log.Info("Transaction pool price threshold updated", "price", price) @@ -1001,10 +984,6 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e dropped := pool.removeTx(tx.Hash(), false) pool.changesSinceReorg += dropped } - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: drop, - Reason: dropUnderpriced, - }) } // Try to replace an existing transaction in the pending pool @@ -1026,11 +1005,6 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e pool.all.Remove(old.Hash()) pool.priced.Removed(1) pendingReplaceMeter.Mark(1) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: []*types.Transaction{old}, - Reason: dropReplaced, - Replacement: tx, - }) } pool.all.Add(tx, isLocal) @@ -1106,10 +1080,6 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction, local boo pool.all.Remove(old.Hash()) pool.priced.Removed(1) queuedReplaceMeter.Mark(1) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: []*types.Transaction{old}, - Reason: dropReplaced, - }) } else { // Nothing was replaced, bump the queued counter queuedGauge.Inc(1) @@ -1187,10 +1157,6 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T pool.all.Remove(old.Hash()) pool.priced.Removed(1) pendingReplaceMeter.Mark(1) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: []*types.Transaction{old}, - Reason: dropReplaced, - }) } else { // Nothing was replaced, bump the pending counter pendingGauge.Inc(1) @@ -1526,10 +1492,6 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) int { // Reduce the pending counter pendingGauge.Dec(int64(1 + len(invalids))) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: invalids, - Reason: dropUnexecutable, - }) return 1 + len(invalids) } @@ -1985,11 +1947,6 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans log.Trace("Removed old queued transactions", "count", forwardsLen) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: forwards, - Reason: dropLowNonce, - }) - // Drop all transactions that are too costly (low balance or out of gas) balance.SetFromBig(pool.currentState.GetBalance(addr)) @@ -2003,10 +1960,6 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans log.Trace("Removed unpayable queued transactions", "count", dropsLen) queuedNofundsMeter.Mark(int64(dropsLen)) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: drops, - Reason: dropUnpayable, - }) // Gather all executable transactions and promote them readies = list.Ready(pool.pendingNonces.get(addr)) @@ -2035,10 +1988,6 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans } queuedRateLimitMeter.Mark(int64(capsLen)) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: caps, - Reason: dropAccountCap, - }) } // Mark all the items dropped as removed @@ -2160,11 +2109,6 @@ func (pool *TxPool) truncatePending() { log.Trace("Removed fairness-exceeding pending transaction", "hash", hash) } - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: caps, - Reason: dropAccountCap, - }) - pool.priced.Removed(capsLen) pendingGauge.Dec(int64(capsLen)) @@ -2205,11 +2149,6 @@ func (pool *TxPool) truncatePending() { log.Trace("Removed fairness-exceeding pending transaction", "hash", hash) } - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: caps, - Reason: dropAccountCap, - }) - pool.priced.Removed(capsLen) pendingGauge.Dec(int64(capsLen)) @@ -2280,10 +2219,6 @@ func (pool *TxPool) truncateQueue() { for _, tx = range listFlatten { pool.removeTx(tx.Hash(), true) } - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: txs, - Reason: dropTruncating, - }) drop -= size queuedRateLimitMeter.Mark(int64(size)) @@ -2301,12 +2236,6 @@ func (pool *TxPool) truncateQueue() { pool.removeTx(txs[i].Hash(), true) drop-- - - queuedRateLimitMeter.Mark(1) - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: []*types.Transaction{txs[i]}, - Reason: dropTruncating, - }) } } } @@ -2349,10 +2278,7 @@ func (pool *TxPool) demoteUnexecutables() { pool.all.Remove(hash) log.Trace("Removed old pending transaction", "hash", hash) } - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: olds, - Reason: dropLowNonce, - }) + // Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later balance.SetFromBig(pool.currentState.GetBalance(addr)) drops, invalids := list.Filter(balance, pool.currentMaxGas.Load()) @@ -2366,10 +2292,6 @@ func (pool *TxPool) demoteUnexecutables() { pool.all.Remove(hash) } - pool.dropTxFeed.Send(DropTxsEvent{ - Txs: drops, - Reason: dropUnpayable, - }) pendingNofundsMeter.Mark(int64(dropsLen)) diff --git a/eth/dropped_tx_subscription.go b/eth/dropped_tx_subscription.go deleted file mode 100644 index f6bb7a9cb3..0000000000 --- a/eth/dropped_tx_subscription.go +++ /dev/null @@ -1,17 +0,0 @@ -// This file extends the EthAPIBackend with functions for BlockNative's dropped -// transaction feeds. -// -// As this is part of a fork, and not included in core geth, keeping it in a -// separate file helps protect against potential merge conflicts. If this were -// ever to be merged into core geth, it should be relocated to ./api_backend.go - -package eth - -import ( - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/event" -) - -func (b *EthAPIBackend) SubscribeDropTxsEvent(ch chan<- core.DropTxsEvent) event.Subscription { - return b.eth.TxPool().SubscribeDropTxsEvent(ch) -} diff --git a/eth/filters/dropped_tx_subscription.go b/eth/filters/dropped_tx_subscription.go index ba5800f548..e4d89de866 100644 --- a/eth/filters/dropped_tx_subscription.go +++ b/eth/filters/dropped_tx_subscription.go @@ -1,14 +1,9 @@ package filters import ( - "context" - "time" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/internal/ethapi" - "github.com/ethereum/go-ethereum/rpc" ) type dropNotification struct { @@ -69,41 +64,3 @@ func newRPCPendingTransaction(tx *types.Transaction) *ethapi.RPCTransaction { } return result } - -// DroppedTransactions send a notification each time a transaction is dropped from the mempool -func (api *PublicFilterAPI) DroppedTransactions(ctx context.Context) (*rpc.Subscription, error) { - notifier, supported := rpc.NotifierFromContext(ctx) - if !supported { - return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported - } - - rpcSub := notifier.CreateSubscription() - - go func() { - dropped := make(chan core.DropTxsEvent) - droppedSub := api.backend.SubscribeDropTxsEvent(dropped) - - for { - select { - case d := <-dropped: - for _, tx := range d.Txs { - notification := &dropNotification{ - Tx: newRPCPendingTransaction(tx), - Reason: d.Reason, - Replacement: newRPCPendingTransaction(d.Replacement), - Time: time.Now().UnixNano(), - } - notifier.Notify(rpcSub.ID, notification) - } - case <-rpcSub.Err(): - droppedSub.Unsubscribe() - return - case <-notifier.Closed(): - droppedSub.Unsubscribe() - return - } - } - }() - - return rpcSub, nil -} diff --git a/eth/tracers/call_tracer.go b/eth/tracers/call_tracer.go index 099f9ddefc..8595b37631 100644 --- a/eth/tracers/call_tracer.go +++ b/eth/tracers/call_tracer.go @@ -3,14 +3,13 @@ package tracers import ( "fmt" "math/big" + "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/vm" - "time" - "github.com/ethereum/go-ethereum/log" "github.com/holiman/uint256" @@ -73,9 +72,9 @@ func (tracer *CallTracer) CaptureStart(evm *vm.EVM, from common.Address, to comm Calls: []*call{}, }} } -func (tracer *CallTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) { +func (tracer *CallTracer) CaptureEnd(output []byte, gasUsed uint64, err error) { tracer.callStack[tracer.i()].GasUsed = hexutil.Uint64(gasUsed) - tracer.callStack[tracer.i()].Time = fmt.Sprintf("%v", t) + tracer.callStack[tracer.i()].Time = fmt.Sprintf("%v", time.Since(tracer.callStack[tracer.i()].startTime)) tracer.callStack[tracer.i()].Output = hexutil.Bytes(output) } @@ -200,3 +199,7 @@ func (tracer *CallTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64 func (tracer *CallTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { } func (tracer *CallTracer) CaptureExit(output []byte, gasUsed uint64, err error) {} + +func (tracer *CallTracer) CaptureTxStart(_ uint64) {} + +func (tracer *CallTracer) CaptureTxEnd(_ uint64) {} diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 15ad48160a..2710d9acb7 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -84,8 +84,6 @@ type Backend interface { TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) TxPoolContentFrom(addr common.Address) (types.Transactions, types.Transactions) SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription - SubscribeDropTxsEvent(chan<- core.DropTxsEvent) event.Subscription - ChainConfig() *params.ChainConfig Engine() consensus.Engine