Skip to content

Commit

Permalink
GasPrice API returns smallest units, EstimateGas returns higher estim…
Browse files Browse the repository at this point in the history
…ate, EstimateFeeForQi works, higher fee cap
  • Loading branch information
jdowning100 committed Oct 18, 2024
1 parent 9e77c53 commit 86dd208
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
2 changes: 2 additions & 0 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ func (v *BlockValidator) ApplyPoWFilter(wo *types.WorkObject) pubsub.ValidationR
if err == nil || err.Error() == consensus.ErrUnknownAncestor.Error() {
return pubsub.ValidationAccept
} else if err.Error() == consensus.ErrFutureBlock.Error() {
v.hc.logger.WithField("hash", wo.Hash()).WithError(err).Debug("Future block, ignoring")
// Weird future block, don't fail, but neither propagate
return pubsub.ValidationIgnore
} else {
v.hc.logger.WithField("hash", wo.Hash()).WithError(err).Debug("Invalid block, rejecting")
return pubsub.ValidationReject
}
}
Expand Down
49 changes: 29 additions & 20 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,12 @@ func (pool *TxPool) GetMinGasPrice() *big.Int {
return big.NewInt(0)
}
baseFeeMin := pool.chain.CalcMinBaseFee(currentHeader)
baseFeeMinInGwei := new(big.Int).Div(baseFeeMin, new(big.Int).SetInt64(int64(params.GWei)))

// Increase this estimate by ~10% so that we account for the difficulty adjustment
baseFeeMinInGwei = new(big.Int).Mul(baseFeeMinInGwei, big.NewInt(100))
baseFeeMinInGwei = new(big.Int).Div(baseFeeMinInGwei, big.NewInt(90))
baseFeeMin = new(big.Int).Mul(baseFeeMin, big.NewInt(100))
baseFeeMin = new(big.Int).Div(baseFeeMin, big.NewInt(90))

return baseFeeMinInGwei
return baseFeeMin
}

// Nonce returns the next nonce of an account, with all transactions executable
Expand Down Expand Up @@ -720,22 +719,19 @@ func (pool *TxPool) TxPoolPending(enforceTips bool) (map[common.AddressBytes]typ
for addr, list := range pool.pending {
txs := list.Flatten()

// If the miner requests tip enforcement, cap the lists now
if enforceTips && !pool.locals.contains(addr) {
for i, tx := range txs {
// make sure that the tx has atleast min base fee as the gas
// price
currentBlock := pool.chain.CurrentBlock()
minBaseFee := pool.chain.CalcMinBaseFee(currentBlock)
if minBaseFee.Cmp(tx.GasPrice()) > 0 {
pool.logger.WithFields(log.Fields{
"tx": tx.Hash().String(),
"gasPrice": tx.GasPrice().String(),
"minBaseFee": minBaseFee.String(),
}).Debug("TX has incorrect or low gas price")
txs = txs[:i]
break
}
for i, tx := range txs {
// make sure that the tx has atleast min base fee as the gas
// price
currentBlock := pool.chain.CurrentBlock()
minBaseFee := pool.chain.CalcMinBaseFee(currentBlock)
if minBaseFee.Cmp(tx.GasPrice()) > 0 {
pool.logger.WithFields(log.Fields{
"tx": tx.Hash().String(),
"gasPrice": tx.GasPrice().String(),
"minBaseFee": minBaseFee.String(),
}).Debug("TX has incorrect or low gas price")
txs = txs[:i]
break
}
}
if len(txs) > 0 {
Expand Down Expand Up @@ -815,6 +811,16 @@ func (pool *TxPool) validateTx(tx *types.Transaction) error {
return err
}
}
currentBlock := pool.chain.CurrentBlock()
minBaseFee := pool.chain.CalcMinBaseFee(currentBlock)
if minBaseFee.Cmp(tx.GasPrice()) > 0 {
pool.logger.WithFields(log.Fields{
"tx": tx.Hash().String(),
"gasPrice": tx.GasPrice().String(),
"minBaseFee": minBaseFee.String(),
}).Debug("TX has incorrect or low gas price")
return fmt.Errorf("tx has incorrect or low gas price, have %s, want %s", tx.GasPrice().String(), minBaseFee.String())
}

// Drop non-local transactions under our own minimal accepted gas price or tip
if tx.CompareFee(pool.gasPrice) < 0 {
Expand Down Expand Up @@ -1876,6 +1882,9 @@ func (pool *TxPool) reset(oldHead, newHead *types.WorkObject) {
pool.qiGasScalingFactor = math.Log(float64(rawdb.ReadUTXOSetSize(pool.db, newHead.Hash())))
pool.pendingNonces = newTxNoncer(statedb)
pool.currentMaxGas = newHead.GasLimit()
if pool.currentMaxGas == 0 {
pool.currentMaxGas = params.GenesisGasLimit
}

// Inject any transactions discarded due to reorgs
pool.logger.WithField("count", len(reinject)).Debug("Reinjecting stale transactions")
Expand Down
5 changes: 5 additions & 0 deletions internal/quaiapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,9 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
return 0, errors.New("block not found")
}
hi = block.GasLimit()
if hi == 0 {
hi = params.GasCeil
}
}
// Normalize the max fee per gas the call is willing to spend.
var feeCap *big.Int
Expand Down Expand Up @@ -825,6 +828,8 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
return 0, fmt.Errorf("gas required exceeds allowance (%d)", cap)
}
}
// Add 10% to the final gas estimate
hi = hi + hi/10
return hexutil.Uint64(hi), nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ func (s *PublicBlockChainQuaiAPI) EstimateFeeForQi(ctx context.Context, args Tra
}

// Calculate the base fee
quaiBaseFee := header.BaseFee()
feeInQuai := new(big.Int).Mul(new(big.Int).SetUint64(uint64(gas)), quaiBaseFee)
minGasPrice := s.b.GetMinGasPrice()
feeInQuai := new(big.Int).Mul(new(big.Int).SetUint64(uint64(gas)), minGasPrice)
feeInQi := misc.QuaiToQi(header, feeInQuai)
if feeInQi.Cmp(big.NewInt(0)) == 0 {
// Minimum fee is 1 qit or smallest unit
Expand Down
2 changes: 1 addition & 1 deletion quai/quaiconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var Defaults = Config{
},
TxPool: core.DefaultTxPoolConfig,
RPCGasCap: params.GasCeil,
RPCTxFeeCap: 100, // 100 quai
RPCTxFeeCap: 10000, // 10000 quai
}

//go:generate gencodec -type Config -formats toml -out gen_config.go
Expand Down
2 changes: 1 addition & 1 deletion quaiclient/ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (ec *Client) PendingCallContract(ctx context.Context, msg quai.CallMsg) ([]
// execution of a transaction.
func (ec *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
var hex hexutil.Big
if err := ec.c.CallContext(ctx, &hex, "eth_gasPrice"); err != nil {
if err := ec.c.CallContext(ctx, &hex, "quai_gasPrice"); err != nil {
return nil, err
}
return (*big.Int)(&hex), nil
Expand Down

0 comments on commit 86dd208

Please sign in to comment.