mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
eth: track provenance of mempool transactions
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
2a1784baef
commit
b2e6162da7
1 changed files with 11 additions and 1 deletions
|
|
@ -199,6 +199,9 @@ type TxFetcher struct {
|
|||
requests map[string]*txRequest // In-flight transaction retrievals
|
||||
alternates map[common.Hash]map[string]struct{} // In-flight transaction alternate origins if retrieval fails
|
||||
|
||||
// txFromPeer stores where we received a transaction from
|
||||
txFromPeer map[common.Hash]string
|
||||
|
||||
// Callbacks
|
||||
hasTx func(common.Hash) bool // Retrieves a tx from the local txpool
|
||||
addTxs func([]*types.Transaction) []error // Insert a batch of transactions into local txpool
|
||||
|
|
@ -235,6 +238,7 @@ func NewTxFetcherForTests(
|
|||
fetching: make(map[common.Hash]string),
|
||||
requests: make(map[string]*txRequest),
|
||||
alternates: make(map[common.Hash]map[string]struct{}),
|
||||
txFromPeer: make(map[common.Hash]string),
|
||||
underpriced: lru.NewCache[common.Hash, time.Time](maxTxUnderpricedSetSize),
|
||||
hasTx: hasTx,
|
||||
addTxs: addTxs,
|
||||
|
|
@ -353,7 +357,8 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool)
|
|||
}
|
||||
// Track a few interesting failure types
|
||||
switch {
|
||||
case err == nil: // Noop, but need to handle to not count these
|
||||
case err == nil:
|
||||
f.txFromPeer[batch[j].Hash()] = peer
|
||||
|
||||
case errors.Is(err, txpool.ErrAlreadyKnown):
|
||||
duplicate++
|
||||
|
|
@ -1034,3 +1039,8 @@ func rotateStrings(slice []string, n int) {
|
|||
slice[i] = orig[(i+n)%len(orig)]
|
||||
}
|
||||
}
|
||||
|
||||
func (f *TxFetcher) TxFromPeer(hash common.Hash) (string, bool) {
|
||||
provenance, ok := f.txFromPeer[hash]
|
||||
return provenance, ok
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue