mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 11:20:45 +00:00
Fixed prevent tx zero gas price add to tx pool.
This commit is contained in:
parent
9765dea721
commit
9a6c1c5382
2 changed files with 14 additions and 6 deletions
|
|
@ -78,6 +78,8 @@ var (
|
||||||
// than some meaningful limit a user might use. This is not a consensus error
|
// than some meaningful limit a user might use. This is not a consensus error
|
||||||
// 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")
|
||||||
|
|
||||||
|
ErrZeroGasPrice = errors.New("zero gas price")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -586,8 +588,9 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||||
if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 {
|
if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 {
|
||||||
return ErrInsufficientFunds
|
return ErrInsufficientFunds
|
||||||
}
|
}
|
||||||
if tx.To() != nil && tx.To().String() != common.BlockSigners {
|
|
||||||
intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, pool.homestead)
|
if tx.To() == nil || (tx.To() != nil && tx.To().String() != common.BlockSigners) {
|
||||||
|
intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, pool.homestead)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -595,6 +598,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||||
if tx.Gas() < intrGas {
|
if tx.Gas() < intrGas {
|
||||||
return ErrIntrinsicGas
|
return ErrIntrinsicGas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check zero gas price.
|
||||||
|
if tx.GasPrice().Cmp(new(big.Int).SetInt64(0)) == 0 {
|
||||||
|
return ErrZeroGasPrice
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -1287,12 +1287,12 @@ func TestTransactionPoolRepricingKeepsLocals(t *testing.T) {
|
||||||
// Create transaction (both pending and queued) with a linearly growing gasprice
|
// Create transaction (both pending and queued) with a linearly growing gasprice
|
||||||
for i := uint64(0); i < 500; i++ {
|
for i := uint64(0); i < 500; i++ {
|
||||||
// Add pending
|
// Add pending
|
||||||
p_tx := pricedTransaction(i, 100000, big.NewInt(int64(i)), keys[2])
|
p_tx := pricedTransaction(i, 100000, big.NewInt(int64(i+1)), keys[2])
|
||||||
if err := pool.AddLocal(p_tx); err != nil {
|
if err := pool.AddLocal(p_tx); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// Add queued
|
// Add queued
|
||||||
q_tx := pricedTransaction(i+501, 100000, big.NewInt(int64(i)), keys[2])
|
q_tx := pricedTransaction(i+501, 100000, big.NewInt(int64(i+1)), keys[2])
|
||||||
if err := pool.AddLocal(q_tx); err != nil {
|
if err := pool.AddLocal(q_tx); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -1411,7 +1411,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
|
||||||
t.Fatalf("pool internal state corrupted: %v", err)
|
t.Fatalf("pool internal state corrupted: %v", err)
|
||||||
}
|
}
|
||||||
// Ensure that adding local transactions can push out even higher priced ones
|
// Ensure that adding local transactions can push out even higher priced ones
|
||||||
tx := pricedTransaction(1, 100000, big.NewInt(0), keys[2])
|
tx := pricedTransaction(1, 100000, big.NewInt(1), keys[2])
|
||||||
if err := pool.AddLocal(tx); err != nil {
|
if err := pool.AddLocal(tx); err != nil {
|
||||||
t.Fatalf("failed to add underpriced local transaction: %v", err)
|
t.Fatalf("failed to add underpriced local transaction: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -1776,4 +1776,4 @@ func benchmarkPoolBatchInsert(b *testing.B, size int) {
|
||||||
for _, batch := range batches {
|
for _, batch := range batches {
|
||||||
pool.AddRemotes(batch)
|
pool.AddRemotes(batch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue