Skip to content

Commit

Permalink
fix: Address merge issues and add missing tracer methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-smith committed Oct 9, 2023
1 parent 2de360e commit 9cffd0f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 146 deletions.
82 changes: 2 additions & 80 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)))
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))

Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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,
})
}
}
}
Expand Down Expand Up @@ -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())
Expand All @@ -2366,10 +2292,6 @@ func (pool *TxPool) demoteUnexecutables() {

pool.all.Remove(hash)
}
pool.dropTxFeed.Send(DropTxsEvent{
Txs: drops,
Reason: dropUnpayable,
})

pendingNofundsMeter.Mark(int64(dropsLen))

Expand Down
17 changes: 0 additions & 17 deletions eth/dropped_tx_subscription.go

This file was deleted.

43 changes: 0 additions & 43 deletions eth/filters/dropped_tx_subscription.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
}
11 changes: 7 additions & 4 deletions eth/tracers/call_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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) {}
2 changes: 0 additions & 2 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9cffd0f

Please sign in to comment.