Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOTE] This is a mistaken PR and should be closed immediately #115

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/txpool/blobpool/blobpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,11 @@ func (p *BlobPool) Stats() (int, int) {
return pending, 0 // No non-executable txs in the blob pool
}

func (pool *BlobPool) StatsDetail() (int, int, int) {
pending, queued := pool.Stats()
return pending, queued, 0
}

// Content retrieves the data content of the transaction pool, returning all the
// pending as well as queued transactions, grouped by account and sorted by nonce.
//
Expand Down
157 changes: 157 additions & 0 deletions core/txpool/legacypool/cache_for_miner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package legacypool

import (
"math/big"
"sort"
"sync"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/metrics"
)

var (
pendingCacheGauge = metrics.NewRegisteredGauge("txpool/legacypool/pending/cache", nil)
localCacheGauge = metrics.NewRegisteredGauge("txpool/legacypool/local/cache", nil)
)

// copy of pending transactions
type cacheForMiner struct {
txLock sync.Mutex
pending map[common.Address]map[*types.Transaction]struct{}
locals map[common.Address]bool
addrLock sync.Mutex
}

func newCacheForMiner() *cacheForMiner {
return &cacheForMiner{
pending: make(map[common.Address]map[*types.Transaction]struct{}),
locals: make(map[common.Address]bool),
}
}

func (pc *cacheForMiner) txsNum() int {
pc.txLock.Lock()
defer pc.txLock.Unlock()
num := 0
for _, txs := range pc.pending {
num += len(txs)
}
return num
}

func (pc *cacheForMiner) add(txs types.Transactions, signer types.Signer) {
if len(txs) == 0 {
return
}
pc.txLock.Lock()
defer pc.txLock.Unlock()
pendingCacheGauge.Inc(int64(len(txs)))
for _, tx := range txs {
addr, _ := types.Sender(signer, tx)
slots, ok := pc.pending[addr]
if !ok {
slots = make(map[*types.Transaction]struct{})
pc.pending[addr] = slots
}
slots[tx] = struct{}{}
}
}

func (pc *cacheForMiner) del(txs types.Transactions, signer types.Signer) {
if len(txs) == 0 {
return
}
pc.txLock.Lock()
defer pc.txLock.Unlock()
for _, tx := range txs {
addr, _ := types.Sender(signer, tx)
slots, ok := pc.pending[addr]
if !ok {
continue
}
pendingCacheGauge.Dec(1)
delete(slots, tx)
if len(slots) == 0 {
delete(pc.pending, addr)
}
}
}

func (pc *cacheForMiner) dump(pool txpool.LazyResolver, gasPrice, baseFee *big.Int) (map[common.Address][]*txpool.LazyTransaction, map[common.Address][]*txpool.LazyTransaction) {
pending := make(map[common.Address]types.Transactions)
pc.txLock.Lock()
for addr, txlist := range pc.pending {
pending[addr] = make(types.Transactions, 0, len(txlist))
for tx := range txlist {
pending[addr] = append(pending[addr], tx)
}
}
pc.txLock.Unlock()
// sorted by nonce
for addr := range pending {
sort.Sort(types.TxByNonce(pending[addr]))
}
pendingWithTips := make(map[common.Address]types.Transactions)
for addr, txs := range pending {
// If the miner requests tip enforcement, cap the lists now
if !pc.isLocal(addr) {
for i, tx := range txs {
if tx.EffectiveGasTipIntCmp(gasPrice, baseFee) < 0 {
txs = txs[:i]
break
}
}
}
if len(txs) > 0 {
pendingWithTips[addr] = txs
}
}

// convert into LazyTransaction
//lazyPendingWithTips, lazyPendingWithoutTips := make(map[common.Address][]*txpool.LazyTransaction), make(map[common.Address][]*txpool.LazyTransaction)
lazyPendingWithTips, lazyPendingWithoutTips := make(map[common.Address][]*txpool.LazyTransaction), make(map[common.Address][]*txpool.LazyTransaction)
for addr, txs := range pending {
for i, tx := range txs {
lazyTx := &txpool.LazyTransaction{
Pool: pool,
Hash: tx.Hash(),
Tx: tx,
Time: tx.Time(),
GasFeeCap: tx.GasFeeCap(),
GasTipCap: tx.GasTipCap(),
Gas: tx.Gas(),
BlobGas: tx.BlobGas(),
}
lazyPendingWithoutTips[addr] = append(lazyPendingWithoutTips[addr], lazyTx)
if len(pendingWithTips[addr]) > i {
lazyPendingWithTips[addr] = append(lazyPendingWithTips[addr], lazyTx)
}
}
}
return lazyPendingWithTips, lazyPendingWithoutTips
}

func (pc *cacheForMiner) markLocal(addr common.Address) {
pc.addrLock.Lock()
defer pc.addrLock.Unlock()
localCacheGauge.Inc(1)
pc.locals[addr] = true
}

func (pc *cacheForMiner) isLocal(addr common.Address) bool {
pc.addrLock.Lock()
defer pc.addrLock.Unlock()
return pc.locals[addr]
}

func (pc *cacheForMiner) flattenLocals() []common.Address {
pc.addrLock.Lock()
defer pc.addrLock.Unlock()
locals := make([]common.Address, 0, len(pc.locals))
for addr := range pc.locals {
locals = append(locals, addr)
}
return locals
}
Loading
Loading