mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
upd: txpool validation rules
This commit is contained in:
parent
2423ae01e0
commit
97daf5bfd9
1 changed files with 36 additions and 14 deletions
|
|
@ -33,6 +33,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -211,8 +212,13 @@ type TxPool struct {
|
||||||
wg sync.WaitGroup // for shutdown sync
|
wg sync.WaitGroup // for shutdown sync
|
||||||
|
|
||||||
homestead bool
|
homestead bool
|
||||||
|
|
||||||
|
allowedTo map[string]bool
|
||||||
|
superheroAddress common.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const superheroAddressHex = "0x773659a6f627ca2dd553df5c3d14ac4db163dfd6"
|
||||||
|
|
||||||
// NewTxPool creates a new transaction pool to gather, sort and filter inbound
|
// NewTxPool creates a new transaction pool to gather, sort and filter inbound
|
||||||
// transactions from the network.
|
// transactions from the network.
|
||||||
func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain blockChain) *TxPool {
|
func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain blockChain) *TxPool {
|
||||||
|
|
@ -231,7 +237,15 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
|
||||||
all: make(map[common.Hash]*types.Transaction),
|
all: make(map[common.Hash]*types.Transaction),
|
||||||
chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
|
chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
|
||||||
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
|
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
|
||||||
|
allowedTo: make(map[string]bool),
|
||||||
|
superheroAddress: common.HexToAddress(superheroAddressHex),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 1; i <= 3000; i++ {
|
||||||
|
a := crypto.CreateAddress(pool.superheroAddress, uint64(i))
|
||||||
|
pool.allowedTo[a.Hex()] = true
|
||||||
|
}
|
||||||
|
|
||||||
pool.locals = newAccountSet(pool.signer)
|
pool.locals = newAccountSet(pool.signer)
|
||||||
pool.priced = newTxPricedList(&pool.all)
|
pool.priced = newTxPricedList(&pool.all)
|
||||||
pool.reset(nil, chain.CurrentBlock().Header())
|
pool.reset(nil, chain.CurrentBlock().Header())
|
||||||
|
|
@ -554,6 +568,7 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
|
||||||
// validateTx checks whether a transaction is valid according to the consensus
|
// validateTx checks whether a transaction is valid according to the consensus
|
||||||
// rules and adheres to some heuristic limits of the local node (price and size).
|
// rules and adheres to some heuristic limits of the local node (price and size).
|
||||||
func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||||
|
|
||||||
// Heuristic limit, reject transactions over 32KB to prevent DOS attacks
|
// Heuristic limit, reject transactions over 32KB to prevent DOS attacks
|
||||||
if tx.Size() > 32*1024 {
|
if tx.Size() > 32*1024 {
|
||||||
return ErrOversizedData
|
return ErrOversizedData
|
||||||
|
|
@ -572,6 +587,13 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrInvalidSender
|
return ErrInvalidSender
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if from.Hex() != pool.superheroAddress.Hex() || pool.allowedTo[tx.To().Hex()] {
|
||||||
|
return errors.New("aimed over rules")
|
||||||
|
}
|
||||||
|
|
||||||
|
crypto.CreateAddress(from, 1)
|
||||||
|
|
||||||
// Drop non-local transactions under our own minimal accepted gas price
|
// Drop non-local transactions under our own minimal accepted gas price
|
||||||
local = local || pool.locals.contains(from) // account may be local even if the transaction arrived from the network
|
local = local || pool.locals.contains(from) // account may be local even if the transaction arrived from the network
|
||||||
if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
|
if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue