mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
Add bor.isValidatorAction and call it while validating underpriced tx
This commit is contained in:
parent
e189cb8215
commit
27fc66ef24
2 changed files with 31 additions and 2 deletions
|
|
@ -1218,6 +1218,24 @@ func (c *Bor) CommitStates(
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Bor) isValidatorAction(chain consensus.ChainReader, from common.Address, tx *types.Transaction) bool {
|
||||
header := chain.CurrentHeader()
|
||||
snap, err := c.snapshot(chain, header.Number.Uint64(), header.Hash(), nil)
|
||||
if err != nil {
|
||||
log.Error("Failed fetching snapshot", err)
|
||||
}
|
||||
|
||||
_isValidatorAction := false
|
||||
for _, validator := range snap.ValidatorSet.Validators {
|
||||
if bytes.Compare(validator.Address.Bytes(), from.Bytes()) == 0 {
|
||||
_isValidatorAction = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// @todo only either of proposeState and proposeSpan should pass this check
|
||||
return _isValidatorAction
|
||||
}
|
||||
|
||||
//
|
||||
// Private methods
|
||||
//
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
|
||||
"github.com/maticnetwork/bor/common"
|
||||
"github.com/maticnetwork/bor/common/prque"
|
||||
"github.com/maticnetwork/bor/consensus"
|
||||
"github.com/maticnetwork/bor/core/state"
|
||||
"github.com/maticnetwork/bor/core/types"
|
||||
"github.com/maticnetwork/bor/event"
|
||||
|
|
@ -116,14 +117,22 @@ const (
|
|||
TxStatusIncluded
|
||||
)
|
||||
|
||||
// bor acts as a way to be able to type cast consensus.Engine;
|
||||
// since importing "github.com/maticnetwork/bor/consensus/bor" results in a cyclic dependency
|
||||
type bor interface {
|
||||
isValidatorAction(chain consensus.ChainReader, from common.Address, tx *types.Transaction) bool
|
||||
}
|
||||
|
||||
// blockChain provides the state of blockchain and current gas limit to do
|
||||
// some pre checks in tx pool and event subscribers.
|
||||
type blockChain interface {
|
||||
CurrentBlock() *types.Block
|
||||
GetBlock(hash common.Hash, number uint64) *types.Block
|
||||
StateAt(root common.Hash) (*state.StateDB, error)
|
||||
|
||||
SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Subscription
|
||||
|
||||
Engine() consensus.Engine
|
||||
CurrentHeader() *types.Header
|
||||
}
|
||||
|
||||
// TxPoolConfig are the configuration parameters of the transaction pool.
|
||||
|
|
@ -527,7 +536,9 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
|||
}
|
||||
// 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 {
|
||||
if !local &&
|
||||
!pool.chain.Engine().(bor).isValidatorAction(pool.chain.(consensus.ChainReader), from, tx) &&
|
||||
pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
|
||||
return ErrUnderpriced
|
||||
}
|
||||
// Ensure the transaction adheres to nonce ordering
|
||||
|
|
|
|||
Loading…
Reference in a new issue