Skip to content

Commit aa69d36

Browse files
committed
core, graphql, internal: expose effectiveGasPrice in receipts
1 parent 7a7abe3 commit aa69d36

File tree

7 files changed

+42
-8
lines changed

7 files changed

+42
-8
lines changed

core/tx_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func (pool *TxPool) Pending(enforceTips bool) (map[common.Address]types.Transact
512512
// If the miner requests tip enforcement, cap the lists now
513513
if enforceTips && !pool.locals.contains(addr) {
514514
for i, tx := range txs {
515-
if tx.EffectiveTipIntCmp(pool.gasPrice, pool.priced.urgent.baseFee) < 0 {
515+
if tx.EffectiveGasTipIntCmp(pool.gasPrice, pool.priced.urgent.baseFee) < 0 {
516516
txs = txs[:i]
517517
break
518518
}

core/types/transaction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int)
356356
return tx.EffectiveGasTipValue(baseFee).Cmp(other.EffectiveGasTipValue(baseFee))
357357
}
358358

359-
// EffectiveTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap.
360-
func (tx *Transaction) EffectiveTipIntCmp(other *big.Int, baseFee *big.Int) int {
359+
// EffectiveGasTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap.
360+
func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) int {
361361
if baseFee == nil {
362362
return tx.GasTipCapIntCmp(other)
363363
}

graphql/graphql.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ func (t *Transaction) GasPrice(ctx context.Context) (hexutil.Big, error) {
236236
}
237237
}
238238

239+
func (t *Transaction) EffectiveGasPrice(ctx context.Context) (*hexutil.Big, error) {
240+
tx, err := t.resolve(ctx)
241+
if err != nil || tx == nil {
242+
return nil, err
243+
}
244+
header, err := t.block.resolveHeader(ctx)
245+
if err != nil || header == nil {
246+
return nil, err
247+
}
248+
if header.BaseFee == nil {
249+
return (*hexutil.Big)(tx.GasPrice()), nil
250+
}
251+
return (*hexutil.Big)(math.BigMin(new(big.Int).Add(tx.GasTipCap(), header.BaseFee), tx.GasFeeCap())), nil
252+
}
253+
239254
func (t *Transaction) MaxFeePerGas(ctx context.Context) (*hexutil.Big, error) {
240255
tx, err := t.resolve(ctx)
241256
if err != nil || tx == nil {

graphql/schema.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ const schema string = `
118118
# this transaction. If the transaction has not yet been mined, this field
119119
# will be null.
120120
cumulativeGasUsed: Long
121+
# EffectiveGasPrice is actual value per gas deducted from the sender's
122+
# account. Before EIP-1559, this is equal to the transaction's gas price.
123+
# After EIP-1559, it is baseFeePerGas + min(maxFeePerGas - baseFeePerGas,
124+
# maxPriorityFeePerGas). Legacy transactions and EIP-2930 transactions are
125+
# coerced into the EIP-1559 format by setting both maxFeePerGas and
126+
# maxPriorityFeePerGas as the transaction's gas price.
127+
effectiveGasPrice: BigInt
121128
# CreatedContract is the account that was created by a contract creation
122129
# transaction. If the transaction was not a contract creation transaction,
123130
# or it has not yet been mined, this field will be null.

internal/ethapi/api.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,17 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
15611561
"logsBloom": receipt.Bloom,
15621562
"type": hexutil.Uint(tx.Type()),
15631563
}
1564-
1564+
// Assign the effective gas price paid
1565+
if !s.b.ChainConfig().IsLondon(bigblock) {
1566+
fields["effectiveGasPrice"] = hexutil.Uint64(tx.GasPrice().Uint64())
1567+
} else {
1568+
header, err := s.b.HeaderByHash(ctx, blockHash)
1569+
if err != nil {
1570+
return nil, err
1571+
}
1572+
gasPrice := new(big.Int).Add(header.BaseFee, tx.EffectiveGasTipValue(header.BaseFee))
1573+
fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())
1574+
}
15651575
// Assign receipt status or post state.
15661576
if len(receipt.PostState) > 0 {
15671577
fields["root"] = hexutil.Bytes(receipt.PostState)

internal/jsre/deps/bindata.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/jsre/deps/web3.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)