graphql: fee history fields (#24452)
This PR adds the `NextBaseFeePerGas` to `Block` and `EffectiveTip` to `Transaction` to make it easier for clients to compute fee history themselves via graphql queries.
This commit is contained in:
parent
538a868384
commit
57cec89253
@ -117,7 +117,7 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
|
|||||||
reward, _ := tx.EffectiveGasTip(bf.block.BaseFee())
|
reward, _ := tx.EffectiveGasTip(bf.block.BaseFee())
|
||||||
sorter[i] = txGasAndReward{gasUsed: bf.receipts[i].GasUsed, reward: reward}
|
sorter[i] = txGasAndReward{gasUsed: bf.receipts[i].GasUsed, reward: reward}
|
||||||
}
|
}
|
||||||
sort.Sort(sorter)
|
sort.Stable(sorter)
|
||||||
|
|
||||||
var txIndex int
|
var txIndex int
|
||||||
sumGasUsed := sorter[0].gasUsed
|
sumGasUsed := sorter[0].gasUsed
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
|
"github.com/ethereum/go-ethereum/consensus/misc"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth/filters"
|
"github.com/ethereum/go-ethereum/eth/filters"
|
||||||
@ -253,6 +254,10 @@ func (t *Transaction) EffectiveGasPrice(ctx context.Context) (*hexutil.Big, erro
|
|||||||
if err != nil || tx == nil {
|
if err != nil || tx == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Pending tx
|
||||||
|
if t.block == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
header, err := t.block.resolveHeader(ctx)
|
header, err := t.block.resolveHeader(ctx)
|
||||||
if err != nil || header == nil {
|
if err != nil || header == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -293,6 +298,30 @@ func (t *Transaction) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Transaction) EffectiveTip(ctx context.Context) (*hexutil.Big, error) {
|
||||||
|
tx, err := t.resolve(ctx)
|
||||||
|
if err != nil || tx == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Pending tx
|
||||||
|
if t.block == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
header, err := t.block.resolveHeader(ctx)
|
||||||
|
if err != nil || header == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if header.BaseFee == nil {
|
||||||
|
return (*hexutil.Big)(tx.GasPrice()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tip, err := tx.EffectiveGasTip(header.BaseFee)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return (*hexutil.Big)(tip), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Transaction) Value(ctx context.Context) (hexutil.Big, error) {
|
func (t *Transaction) Value(ctx context.Context) (hexutil.Big, error) {
|
||||||
tx, err := t.resolve(ctx)
|
tx, err := t.resolve(ctx)
|
||||||
if err != nil || tx == nil {
|
if err != nil || tx == nil {
|
||||||
@ -606,6 +635,22 @@ func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
|
|||||||
return (*hexutil.Big)(header.BaseFee), nil
|
return (*hexutil.Big)(header.BaseFee), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Block) NextBaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
|
||||||
|
header, err := b.resolveHeader(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
chaincfg := b.backend.ChainConfig()
|
||||||
|
if header.BaseFee == nil {
|
||||||
|
// Make sure next block doesn't enable EIP-1559
|
||||||
|
if !chaincfg.IsLondon(new(big.Int).Add(header.Number, common.Big1)) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nextBaseFee := misc.CalcBaseFee(chaincfg, header)
|
||||||
|
return (*hexutil.Big)(nextBaseFee), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Block) Parent(ctx context.Context) (*Block, error) {
|
func (b *Block) Parent(ctx context.Context) (*Block, error) {
|
||||||
if _, err := b.resolveHeader(ctx); err != nil {
|
if _, err := b.resolveHeader(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -69,7 +69,7 @@ const schema string = `
|
|||||||
transaction: Transaction!
|
transaction: Transaction!
|
||||||
}
|
}
|
||||||
|
|
||||||
#EIP-2718
|
#EIP-2718
|
||||||
type AccessTuple{
|
type AccessTuple{
|
||||||
address: Address!
|
address: Address!
|
||||||
storageKeys : [Bytes32!]!
|
storageKeys : [Bytes32!]!
|
||||||
@ -94,10 +94,12 @@ const schema string = `
|
|||||||
value: BigInt!
|
value: BigInt!
|
||||||
# GasPrice is the price offered to miners for gas, in wei per unit.
|
# GasPrice is the price offered to miners for gas, in wei per unit.
|
||||||
gasPrice: BigInt!
|
gasPrice: BigInt!
|
||||||
# MaxFeePerGas is the maximum fee per gas offered to include a transaction, in wei.
|
# MaxFeePerGas is the maximum fee per gas offered to include a transaction, in wei.
|
||||||
maxFeePerGas: BigInt
|
maxFeePerGas: BigInt
|
||||||
# MaxPriorityFeePerGas is the maximum miner tip per gas offered to include a transaction, in wei.
|
# MaxPriorityFeePerGas is the maximum miner tip per gas offered to include a transaction, in wei.
|
||||||
maxPriorityFeePerGas: BigInt
|
maxPriorityFeePerGas: BigInt
|
||||||
|
# EffectiveTip is the actual amount of reward going to miner after considering the max fee cap.
|
||||||
|
effectiveTip: BigInt
|
||||||
# Gas is the maximum amount of gas this transaction can consume.
|
# Gas is the maximum amount of gas this transaction can consume.
|
||||||
gas: Long!
|
gas: Long!
|
||||||
# InputData is the data supplied to the target of the transaction.
|
# InputData is the data supplied to the target of the transaction.
|
||||||
@ -187,8 +189,10 @@ const schema string = `
|
|||||||
gasLimit: Long!
|
gasLimit: Long!
|
||||||
# GasUsed is the amount of gas that was used executing transactions in this block.
|
# GasUsed is the amount of gas that was used executing transactions in this block.
|
||||||
gasUsed: Long!
|
gasUsed: Long!
|
||||||
# BaseFeePerGas is the fee perunit of gas burned by the protocol in this block.
|
# BaseFeePerGas is the fee per unit of gas burned by the protocol in this block.
|
||||||
baseFeePerGas: BigInt
|
baseFeePerGas: BigInt
|
||||||
|
# NextBaseFeePerGas is the fee per unit of gas which needs to be burned in the next block.
|
||||||
|
nextBaseFeePerGas: BigInt
|
||||||
# Timestamp is the unix timestamp at which this block was mined.
|
# Timestamp is the unix timestamp at which this block was mined.
|
||||||
timestamp: Long!
|
timestamp: Long!
|
||||||
# LogsBloom is a bloom filter that can be used to check if a block may
|
# LogsBloom is a bloom filter that can be used to check if a block may
|
||||||
@ -244,10 +248,10 @@ const schema string = `
|
|||||||
gas: Long
|
gas: Long
|
||||||
# GasPrice is the price, in wei, offered for each unit of gas.
|
# GasPrice is the price, in wei, offered for each unit of gas.
|
||||||
gasPrice: BigInt
|
gasPrice: BigInt
|
||||||
# MaxFeePerGas is the maximum fee per gas offered, in wei.
|
# MaxFeePerGas is the maximum fee per gas offered, in wei.
|
||||||
maxFeePerGas: BigInt
|
maxFeePerGas: BigInt
|
||||||
# MaxPriorityFeePerGas is the maximum miner tip per gas offered, in wei.
|
# MaxPriorityFeePerGas is the maximum miner tip per gas offered, in wei.
|
||||||
maxPriorityFeePerGas: BigInt
|
maxPriorityFeePerGas: BigInt
|
||||||
# Value is the value, in wei, sent along with the call.
|
# Value is the value, in wei, sent along with the call.
|
||||||
value: BigInt
|
value: BigInt
|
||||||
# Data is the data sent to the callee.
|
# Data is the data sent to the callee.
|
||||||
|
Loading…
Reference in New Issue
Block a user