mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-16 08:53:46 +00:00
core/txpool: relocate error
This commit is contained in:
parent
5d0503d1ec
commit
847f621e41
4 changed files with 14 additions and 26 deletions
|
|
@ -51,10 +51,6 @@ var (
|
||||||
// making the transaction invalid, rather a DOS protection.
|
// making the transaction invalid, rather a DOS protection.
|
||||||
ErrOversizedData = errors.New("oversized data")
|
ErrOversizedData = errors.New("oversized data")
|
||||||
|
|
||||||
// ErrFutureReplacePending is returned if a future transaction replaces a pending
|
|
||||||
// one. Future transactions should only be able to replace other future transactions.
|
|
||||||
ErrFutureReplacePending = errors.New("future transaction tries to replace pending")
|
|
||||||
|
|
||||||
// ErrAlreadyReserved is returned if the sender address has a pending transaction
|
// ErrAlreadyReserved is returned if the sender address has a pending transaction
|
||||||
// in a different subpool. For example, this error is returned in response to any
|
// in a different subpool. For example, this error is returned in response to any
|
||||||
// input transaction of non-blob type when a blob transaction from this sender
|
// input transaction of non-blob type when a blob transaction from this sender
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,10 @@ var (
|
||||||
// signed by an address which already has in-flight transactions known to the
|
// signed by an address which already has in-flight transactions known to the
|
||||||
// pool.
|
// pool.
|
||||||
ErrAuthorityReserved = errors.New("authority already reserved")
|
ErrAuthorityReserved = errors.New("authority already reserved")
|
||||||
|
|
||||||
|
// ErrFutureReplacePending is returned if a future transaction replaces a pending
|
||||||
|
// one. Future transactions should only be able to replace other future transactions.
|
||||||
|
ErrFutureReplacePending = errors.New("future transaction tries to replace pending")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -581,17 +585,8 @@ func (pool *LegacyPool) validateTx(tx *types.Transaction) error {
|
||||||
opts := &txpool.ValidationOptionsWithState{
|
opts := &txpool.ValidationOptionsWithState{
|
||||||
State: pool.currentState,
|
State: pool.currentState,
|
||||||
|
|
||||||
FirstNonceGap: nil, // Pool allows arbitrary arrival order, don't invalidate nonce gaps
|
FirstNonceGap: nil, // Pool allows arbitrary arrival order, don't invalidate nonce gaps
|
||||||
UsedAndLeftSlots: func(addr common.Address) (int, int) {
|
UsedAndLeftSlots: nil, // Pool has own mechanism to limit the number of transactions
|
||||||
var have int
|
|
||||||
if list := pool.pending[addr]; list != nil {
|
|
||||||
have += list.Len()
|
|
||||||
}
|
|
||||||
if list := pool.queue[addr]; list != nil {
|
|
||||||
have += list.Len()
|
|
||||||
}
|
|
||||||
return have, math.MaxInt
|
|
||||||
},
|
|
||||||
ExistingExpenditure: func(addr common.Address) *big.Int {
|
ExistingExpenditure: func(addr common.Address) *big.Int {
|
||||||
if list := pool.pending[addr]; list != nil {
|
if list := pool.pending[addr]; list != nil {
|
||||||
return list.totalcost.ToBig()
|
return list.totalcost.ToBig()
|
||||||
|
|
@ -610,7 +605,7 @@ func (pool *LegacyPool) validateTx(tx *types.Transaction) error {
|
||||||
if err := txpool.ValidateTransactionWithState(tx, pool.signer, opts); err != nil {
|
if err := txpool.ValidateTransactionWithState(tx, pool.signer, opts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return pool.validateAuth(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateAuth verifies that the transaction complies with code authorization
|
// validateAuth verifies that the transaction complies with code authorization
|
||||||
|
|
@ -672,11 +667,6 @@ func (pool *LegacyPool) add(tx *types.Transaction) (replaced bool, err error) {
|
||||||
invalidTxMeter.Mark(1)
|
invalidTxMeter.Mark(1)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if err := pool.validateAuth(tx); err != nil {
|
|
||||||
log.Trace("Discarding invalid transaction", "hash", hash, "err", err)
|
|
||||||
invalidTxMeter.Mark(1)
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
// already validated by this point
|
// already validated by this point
|
||||||
from, _ := types.Sender(pool.signer, tx)
|
from, _ := types.Sender(pool.signer, tx)
|
||||||
|
|
||||||
|
|
@ -747,7 +737,7 @@ func (pool *LegacyPool) add(tx *types.Transaction) (replaced bool, err error) {
|
||||||
pool.priced.Put(dropTx)
|
pool.priced.Put(dropTx)
|
||||||
}
|
}
|
||||||
log.Trace("Discarding future transaction replacing pending tx", "hash", hash)
|
log.Trace("Discarding future transaction replacing pending tx", "hash", hash)
|
||||||
return false, txpool.ErrFutureReplacePending
|
return false, ErrFutureReplacePending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1645,8 +1645,8 @@ func TestUnderpricing(t *testing.T) {
|
||||||
t.Fatalf("failed to add well priced transaction: %v", err)
|
t.Fatalf("failed to add well priced transaction: %v", err)
|
||||||
}
|
}
|
||||||
// Ensure that replacing a pending transaction with a future transaction fails
|
// Ensure that replacing a pending transaction with a future transaction fails
|
||||||
if err := pool.addRemoteSync(pricedTransaction(5, 100000, big.NewInt(6), keys[1])); err != txpool.ErrFutureReplacePending {
|
if err := pool.addRemoteSync(pricedTransaction(5, 100000, big.NewInt(6), keys[1])); err != ErrFutureReplacePending {
|
||||||
t.Fatalf("adding future replace transaction error mismatch: have %v, want %v", err, txpool.ErrFutureReplacePending)
|
t.Fatalf("adding future replace transaction error mismatch: have %v, want %v", err, ErrFutureReplacePending)
|
||||||
}
|
}
|
||||||
pending, queued = pool.Stats()
|
pending, queued = pool.Stats()
|
||||||
if pending != 4 {
|
if pending != 4 {
|
||||||
|
|
|
||||||
|
|
@ -268,8 +268,10 @@ func ValidateTransactionWithState(tx *types.Transaction, signer types.Signer, op
|
||||||
// Transaction takes a new nonce value out of the pool. Ensure it doesn't
|
// Transaction takes a new nonce value out of the pool. Ensure it doesn't
|
||||||
// overflow the number of permitted transactions from a single account
|
// overflow the number of permitted transactions from a single account
|
||||||
// (i.e. max cancellable via out-of-bound transaction).
|
// (i.e. max cancellable via out-of-bound transaction).
|
||||||
if used, left := opts.UsedAndLeftSlots(from); left <= 0 {
|
if opts.UsedAndLeftSlots != nil {
|
||||||
return fmt.Errorf("%w: pooled %d txs", ErrAccountLimitExceeded, used)
|
if used, left := opts.UsedAndLeftSlots(from); left <= 0 {
|
||||||
|
return fmt.Errorf("%w: pooled %d txs", ErrAccountLimitExceeded, used)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue