upd: txpool validation rules

This commit is contained in:
Antony Shchukin 2018-05-04 10:39:23 +03:00
parent 2423ae01e0
commit 97daf5bfd9

View file

@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params"
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
"github.com/ethereum/go-ethereum/crypto"
)
const (
@ -211,8 +212,13 @@ type TxPool struct {
wg sync.WaitGroup // for shutdown sync
homestead bool
allowedTo map[string]bool
superheroAddress common.Address
}
const superheroAddressHex = "0x773659a6f627ca2dd553df5c3d14ac4db163dfd6"
// NewTxPool creates a new transaction pool to gather, sort and filter inbound
// transactions from the network.
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),
chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
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.priced = newTxPricedList(&pool.all)
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
// rules and adheres to some heuristic limits of the local node (price and size).
func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// Heuristic limit, reject transactions over 32KB to prevent DOS attacks
if tx.Size() > 32*1024 {
return ErrOversizedData
@ -572,6 +587,13 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if err != nil {
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
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 {