Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql: fee history fields #24452

Merged
merged 7 commits into from Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion eth/gasprice/feehistory.go
Expand Up @@ -117,7 +117,7 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
reward, _ := tx.EffectiveGasTip(bf.block.BaseFee())
sorter[i] = txGasAndReward{gasUsed: bf.receipts[i].GasUsed, reward: reward}
}
sort.Sort(sorter)
sort.Stable(sorter)

var txIndex int
sumGasUsed := sorter[0].gasUsed
Expand Down
42 changes: 42 additions & 0 deletions graphql/graphql.go
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"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/types"
"github.com/ethereum/go-ethereum/eth/filters"
Expand Down Expand Up @@ -285,6 +286,34 @@ 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
}
header, err := t.block.resolveHeader(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the non-finalized transaction, the t.block can be nil. Please add one more check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. I had copied some stuff from EffectiveGasPrice which has the same issue. Added a check in both methods.

Do you think it makes sense to compute and use the latest block's nextBaseFee for pending txes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can simply return an error instead? @fjl @karalabe What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safer to return an error rather than 'speculate' on the tip, for pending transactions.

if err != nil || header == nil {
return nil, err
}
if header.BaseFee == nil {
return (*hexutil.Big)(tx.GasPrice()), nil
}

// TODO: What to return for non-dynamicfee tx types?
s1na marked this conversation as resolved.
Show resolved Hide resolved
s1na marked this conversation as resolved.
Show resolved Hide resolved
switch tx.Type() {
case types.AccessListTxType:
return nil, nil
case types.DynamicFeeTxType:
tip, err := tx.EffectiveGasTip(header.BaseFee)
if err != nil {
return nil, err
}
return (*hexutil.Big)(tip), nil
default:
return nil, nil
}
}

func (t *Transaction) Value(ctx context.Context) (hexutil.Big, error) {
tx, err := t.resolve(ctx)
if err != nil || tx == nil {
Expand Down Expand Up @@ -598,6 +627,19 @@ func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
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
}
if header.BaseFee == nil {
s1na marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil
}
chaincfg := b.backend.ChainConfig()
nextBaseFee := misc.CalcBaseFee(chaincfg, header)
return (*hexutil.Big)(nextBaseFee), nil
}

func (b *Block) Parent(ctx context.Context) (*Block, error) {
if _, err := b.resolveHeader(ctx); err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion graphql/schema.go
Expand Up @@ -98,6 +98,8 @@ const schema string = `
maxFeePerGas: BigInt
# MaxPriorityFeePerGas is the maximum miner tip per gas offered to include a transaction, in wei.
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: Long!
# InputData is the data supplied to the target of the transaction.
Expand Down Expand Up @@ -187,8 +189,10 @@ const schema string = `
gasLimit: Long!
# GasUsed is the amount of gas that was used executing transactions in this block.
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
# NextBaseFeePerGas is the fee per unit of gas which needs to be burned in the next block.
s1na marked this conversation as resolved.
Show resolved Hide resolved
nextBaseFeePerGas: BigInt
# Timestamp is the unix timestamp at which this block was mined.
timestamp: Long!
# LogsBloom is a bloom filter that can be used to check if a block may
Expand Down