set min gas price for tx

This commit is contained in:
MestryOmkar 2018-12-10 11:12:07 +05:30
parent 0bb2ba1116
commit 08843fa176

View file

@ -81,7 +81,11 @@ var (
ErrZeroGasPrice = errors.New("zero gas price") ErrZeroGasPrice = errors.New("zero gas price")
ErrUnderMinGasPrice = errors.New("under min gas price")
ErrDuplicateSpecialTransaction = errors.New("duplicate a special transaction") ErrDuplicateSpecialTransaction = errors.New("duplicate a special transaction")
ErrMinDeploySMC = errors.New("smart contract creation cost is under allowance")
) )
var ( var (
@ -587,7 +591,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
} }
// 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 && tx.To() != nil && pool.gasPrice.Cmp(tx.GasPrice()) > 0 { if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
if !tx.IsSpecialTransaction() || (pool.IsMasterNode != nil && !pool.IsMasterNode(from)) { if !tx.IsSpecialTransaction() || (pool.IsMasterNode != nil && !pool.IsMasterNode(from)) {
return ErrUnderpriced return ErrUnderpriced
} }
@ -619,6 +623,16 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if tx.GasPrice().Cmp(new(big.Int).SetInt64(0)) == 0 { if tx.GasPrice().Cmp(new(big.Int).SetInt64(0)) == 0 {
return ErrZeroGasPrice return ErrZeroGasPrice
} }
// under min gas price
if tx.GasPrice().Cmp(new(big.Int).SetInt64(common.MinGasPrice)) < 0 {
return ErrUnderMinGasPrice
}
}
minGasDeploySMC := new(big.Int).Mul(new(big.Int).SetUint64(10), new(big.Int).SetUint64(params.Ether))
if tx.To() == nil && (tx.Cost().Cmp(minGasDeploySMC) < 0 || tx.GasPrice().Cmp(new(big.Int).SetUint64(10000*params.Shannon)) < 0) {
return ErrMinDeploySMC
} }
return nil return nil
@ -1229,4 +1243,4 @@ func (as *accountSet) containsTx(tx *types.Transaction) bool {
// add inserts a new address into the set to track. // add inserts a new address into the set to track.
func (as *accountSet) add(addr common.Address) { func (as *accountSet) add(addr common.Address) {
as.accounts[addr] = struct{}{} as.accounts[addr] = struct{}{}
} }