Re-enable gas price.

This change removes all the places we had intentionally disabled non-0
gas price.
This commit is contained in:
Joel Burget 2018-02-16 10:03:47 -05:00
parent 3214705480
commit 5e1547551d
No known key found for this signature in database
GPG Key ID: A9FCA9D0FA87DA46
7 changed files with 22 additions and 39 deletions

View File

@ -28,7 +28,6 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/state"
@ -322,11 +321,7 @@ func (bc *BlockChain) GasLimit() *big.Int {
bc.mu.RLock()
defer bc.mu.RUnlock()
if bc.Config().IsQuorum {
return math.MaxBig256 // HACK(joel) a very large number
} else {
return bc.currentBlock.GasLimit()
}
return bc.currentBlock.GasLimit()
}
// LastBlockHash return the hash of the HEAD block.

View File

@ -104,10 +104,6 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, author *common
privateState = statedb
}
if config.IsQuorum && tx.GasPrice() != nil && tx.GasPrice().Cmp(common.Big0) > 0 {
return nil, nil, nil, ErrInvalidGasPrice
}
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number))
if err != nil {
return nil, nil, nil, err

View File

@ -292,8 +292,10 @@ func (st *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *big
}
requiredGas = new(big.Int).Set(st.gasUsed())
st.refundGas()
st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(st.gasUsed(), st.gasPrice))
if !isPrivate {
st.refundGas()
st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(st.gasUsed(), st.gasPrice))
}
if isPrivate {
return ret, new(big.Int), new(big.Int), vmerr != nil, err

View File

@ -78,8 +78,6 @@ var (
// than some meaningful limit a user might use. This is not a consensus error
// making the transaction invalid, rather a DOS protection.
ErrOversizedData = errors.New("oversized data")
ErrInvalidGasPrice = errors.New("Gas price not 0")
)
var (
@ -546,11 +544,6 @@ 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 {
isQuorum := pool.chainconfig.IsQuorum
if isQuorum && tx.GasPrice().Cmp(common.Big0) != 0 {
return ErrInvalidGasPrice
}
// Heuristic limit, reject transactions over 32KB to prevent DOS attacks
if tx.Size() > 32*1024 {
return ErrOversizedData
@ -571,7 +564,7 @@ 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 !isQuorum && !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
return ErrUnderpriced
}
// Ensure the transaction adheres to nonce ordering
@ -584,7 +577,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrInsufficientFunds
}
intrGas := IntrinsicGas(tx.Data(), tx.To() == nil, pool.homestead)
if !isQuorum && tx.Gas().Cmp(intrGas) < 0 {
if tx.Gas().Cmp(intrGas) < 0 {
return ErrIntrinsicGas
}
return nil
@ -614,7 +607,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
// If the transaction pool is full, discard underpriced transactions
if uint64(len(pool.all)) >= pool.config.GlobalSlots+pool.config.GlobalQueue {
// If the new transaction is underpriced, don't accept it
if !pool.chainconfig.IsQuorum && pool.priced.Underpriced(tx, pool.locals) {
if pool.priced.Underpriced(tx, pool.locals) {
log.Trace("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
underpricedTxCounter.Inc(1)
return false, ErrUnderpriced
@ -899,16 +892,14 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
delete(pool.all, hash)
pool.priced.Removed()
}
if !isQuorum {
// Drop all transactions that are too costly (low balance or out of gas)
drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
for _, tx := range drops {
hash := tx.Hash()
log.Trace("Removed unpayable queued transaction", "hash", hash)
delete(pool.all, hash)
pool.priced.Removed()
queuedNofundsCounter.Inc(1)
}
// Drop all transactions that are too costly (low balance or out of gas)
drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
for _, tx := range drops {
hash := tx.Hash()
log.Trace("Removed unpayable queued transaction", "hash", hash)
delete(pool.all, hash)
pool.priced.Removed()
queuedNofundsCounter.Inc(1)
}
// Gather all executable transactions and promote them
for _, tx := range list.Ready(pool.pendingState.GetNonce(addr)) {

View File

@ -194,7 +194,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
evm.StateDB.CreateAccount(addr)
}
if evm.ChainConfig().IsQuorum {
// skip transfer if value /= 0 (see note: Quorum, States, and Value Transfer)
// skip transfer if value == 0 (see note: Quorum, States, and Value Transfer)
if value.Sign() != 0 {
if evm.quorumReadOnly {
return nil, gas, ErrReadOnlyValueTransfer
@ -391,7 +391,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
evm.StateDB.SetNonce(contractAddr, 1)
}
if evm.ChainConfig().IsQuorum {
// skip transfer if value /= 0 (see note: Quorum, States, and Value Transfer)
// skip transfer if value == 0 (see note: Quorum, States, and Value Transfer)
if value.Sign() != 0 {
if evm.quorumReadOnly {
return nil, common.Address{}, gas, ErrReadOnlyValueTransfer

View File

@ -196,11 +196,8 @@ func (b *EthApiBackend) ProtocolVersion() int {
}
func (b *EthApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
if b.ChainConfig().IsQuorum {
return big.NewInt(0), nil
} else {
return b.gpo.SuggestPrice(ctx)
}
// NOTE(joel): this was set to 0 in the previous version of Quorum
return b.gpo.SuggestPrice(ctx)
}
func (b *EthApiBackend) ChainDb() ethdb.Database {

View File

@ -617,6 +617,8 @@ func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr
gas = big.NewInt(50000000)
}
// NOTE(joel): let's keep the default gas price 0 for now, but note this as a
// spot that might be tweaked in the future.
if gasPrice.Sign() == 0 && !s.b.ChainConfig().IsQuorum {
gasPrice = new(big.Int).SetUint64(defaultGasPrice)
}