mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
core/txpool/blobpool: limit gapped allowance based on sender
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
9cdd843502
commit
cb59ff5cf8
1 changed files with 21 additions and 3 deletions
|
|
@ -1738,9 +1738,14 @@ func (p *BlobPool) add(tx *types.Transaction) (err error) {
|
||||||
addGappedMeter.Mark(1)
|
addGappedMeter.Mark(1)
|
||||||
// Store the tx in memory, and revalidate later
|
// Store the tx in memory, and revalidate later
|
||||||
from, _ := types.Sender(p.signer, tx)
|
from, _ := types.Sender(p.signer, tx)
|
||||||
p.gapped[from] = append(p.gapped[from], tx)
|
allowance := p.gappedAllowance(from)
|
||||||
log.Trace("Blob transaction added to Gapped blob queue", "hash", tx.Hash(), "from", from, "nonce", tx.Nonce(), "qlen", len(p.gapped[from]))
|
if allowance >= 1 {
|
||||||
return nil
|
p.gapped[from] = append(p.gapped[from], tx)
|
||||||
|
log.Trace("blobpool:add added to Gapped blob queue", "allowance", allowance, "hash", tx.Hash(), "from", from, "nonce", tx.Nonce(), "qlen", len(p.gapped[from]))
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
log.Trace("blobpool:add no Gapped blob queue allowance", "allowance", allowance, "hash", tx.Hash(), "from", from, "nonce", tx.Nonce(), "qlen", len(p.gapped[from]))
|
||||||
|
}
|
||||||
case errors.Is(err, core.ErrInsufficientFunds):
|
case errors.Is(err, core.ErrInsufficientFunds):
|
||||||
addOverdraftedMeter.Mark(1)
|
addOverdraftedMeter.Mark(1)
|
||||||
case errors.Is(err, txpool.ErrAccountLimitExceeded):
|
case errors.Is(err, txpool.ErrAccountLimitExceeded):
|
||||||
|
|
@ -2139,6 +2144,19 @@ func (p *BlobPool) Nonce(addr common.Address) uint64 {
|
||||||
return p.state.GetNonce(addr)
|
return p.state.GetNonce(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gappedAllowance returns the number of gapped transactions still
|
||||||
|
// allowed for the given account. Allowance is based on a slow-start
|
||||||
|
// logic, allowing more gaps (resource usage) to accounts with a
|
||||||
|
// higher nonce. Can also return negative values.
|
||||||
|
func (p *BlobPool) gappedAllowance(addr common.Address) int {
|
||||||
|
// Gaps happen, but we don't want to allow too many.
|
||||||
|
// Use log10(nonce+1) as the allowance, with a minimum of 0.
|
||||||
|
nonce := p.state.GetNonce(addr)
|
||||||
|
allowance := int(math.Log10(float64(nonce + 1)))
|
||||||
|
// Cap the allowance to the remaining pool space
|
||||||
|
return min(allowance, maxTxsPerAccount-len(p.index[addr])) - len(p.gapped[addr])
|
||||||
|
}
|
||||||
|
|
||||||
// Stats retrieves the current pool stats, namely the number of pending and the
|
// Stats retrieves the current pool stats, namely the number of pending and the
|
||||||
// number of queued (non-executable) transactions.
|
// number of queued (non-executable) transactions.
|
||||||
func (p *BlobPool) Stats() (int, int) {
|
func (p *BlobPool) Stats() (int, int) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue