mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
core/txpool: get tx by sender and nonce
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
3cbadcdf3d
commit
acdf44bc14
4 changed files with 52 additions and 0 deletions
|
|
@ -1208,6 +1208,26 @@ func (p *BlobPool) Get(hash common.Hash) *types.Transaction {
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBySenderAndNonce returns a transaction of a sender and its corresponding nonce.
|
||||||
|
func (p *BlobPool) GetBySenderAndNonce(sender common.Address, nonce uint64) *types.Transaction {
|
||||||
|
p.lock.RLock()
|
||||||
|
defer p.lock.RUnlock()
|
||||||
|
|
||||||
|
txs, ok := p.index[sender]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
next := p.state.GetNonce(sender)
|
||||||
|
offset := int(nonce - next)
|
||||||
|
|
||||||
|
if offset < 0 || offset >= len(txs) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.Get(txs[offset].hash)
|
||||||
|
}
|
||||||
|
|
||||||
// Add inserts a set of blob transactions into the pool if they pass validation (both
|
// Add inserts a set of blob transactions into the pool if they pass validation (both
|
||||||
// consensus validity and pool restrictions).
|
// consensus validity and pool restrictions).
|
||||||
func (p *BlobPool) Add(txs []*types.Transaction, local bool, sync bool) []error {
|
func (p *BlobPool) Add(txs []*types.Transaction, local bool, sync bool) []error {
|
||||||
|
|
|
||||||
|
|
@ -1072,6 +1072,25 @@ func (pool *LegacyPool) Get(hash common.Hash) *types.Transaction {
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBySenderAndNonce returns a transaction of a sender and it's corresponding nonce.
|
||||||
|
func (pool *LegacyPool) GetBySenderAndNonce(sender common.Address, nonce uint64) *types.Transaction {
|
||||||
|
// Check if the transaction is in the pending pool
|
||||||
|
if txList := pool.pending[sender]; txList != nil {
|
||||||
|
if tx := txList.txs.items[nonce]; tx != nil {
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the transaction is in the queue pool
|
||||||
|
if txList := pool.queue[sender]; txList != nil {
|
||||||
|
if tx := txList.txs.items[nonce]; tx != nil {
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// get returns a transaction if it is contained in the pool and nil otherwise.
|
// get returns a transaction if it is contained in the pool and nil otherwise.
|
||||||
func (pool *LegacyPool) get(hash common.Hash) *types.Transaction {
|
func (pool *LegacyPool) get(hash common.Hash) *types.Transaction {
|
||||||
return pool.all.Get(hash)
|
return pool.all.Get(hash)
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,9 @@ type SubPool interface {
|
||||||
// Get returns a transaction if it is contained in the pool, or nil otherwise.
|
// Get returns a transaction if it is contained in the pool, or nil otherwise.
|
||||||
Get(hash common.Hash) *types.Transaction
|
Get(hash common.Hash) *types.Transaction
|
||||||
|
|
||||||
|
// GetBySenderAndNonce returns a transaction of a sender and it's corresponding nonce.
|
||||||
|
GetBySenderAndNonce(sender common.Address, nonce uint64) *types.Transaction
|
||||||
|
|
||||||
// Add enqueues a batch of transactions into the pool if they are valid. Due
|
// Add enqueues a batch of transactions into the pool if they are valid. Due
|
||||||
// to the large transaction churn, add may postpone fully integrating the tx
|
// to the large transaction churn, add may postpone fully integrating the tx
|
||||||
// to a later point to batch multiple ones together.
|
// to a later point to batch multiple ones together.
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,16 @@ func (p *TxPool) Get(hash common.Hash) *types.Transaction {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBySenderAndNonce returns a transaction of a sender and it's corresponding nonce.
|
||||||
|
func (p *TxPool) GetBySenderAndNonce(sender common.Address, nonce uint64) *types.Transaction {
|
||||||
|
for _, subpool := range p.subpools {
|
||||||
|
if tx := subpool.GetBySenderAndNonce(sender, nonce); tx != nil {
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Add enqueues a batch of transactions into the pool if they are valid. Due
|
// Add enqueues a batch of transactions into the pool if they are valid. Due
|
||||||
// to the large transaction churn, add may postpone fully integrating the tx
|
// to the large transaction churn, add may postpone fully integrating the tx
|
||||||
// to a later point to batch multiple ones together.
|
// to a later point to batch multiple ones together.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue