Merge pull request #23050 from karalabe/1559-receipt-rpc

core, graphql, internal: expose effectiveGasPrice in receipts
This commit is contained in:
Péter Szilágyi 2021-06-16 09:52:31 +03:00 committed by GitHub
commit ae315ef7a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 8 deletions

View File

@ -512,7 +512,7 @@ func (pool *TxPool) Pending(enforceTips bool) (map[common.Address]types.Transact
// If the miner requests tip enforcement, cap the lists now
if enforceTips && !pool.locals.contains(addr) {
for i, tx := range txs {
if tx.EffectiveTipIntCmp(pool.gasPrice, pool.priced.urgent.baseFee) < 0 {
if tx.EffectiveGasTipIntCmp(pool.gasPrice, pool.priced.urgent.baseFee) < 0 {
txs = txs[:i]
break
}

View File

@ -356,8 +356,8 @@ func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int)
return tx.EffectiveGasTipValue(baseFee).Cmp(other.EffectiveGasTipValue(baseFee))
}
// EffectiveTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap.
func (tx *Transaction) EffectiveTipIntCmp(other *big.Int, baseFee *big.Int) int {
// EffectiveGasTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap.
func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) int {
if baseFee == nil {
return tx.GasTipCapIntCmp(other)
}

View File

@ -236,6 +236,21 @@ func (t *Transaction) GasPrice(ctx context.Context) (hexutil.Big, error) {
}
}
func (t *Transaction) EffectiveGasPrice(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)
if err != nil || header == nil {
return nil, err
}
if header.BaseFee == nil {
return (*hexutil.Big)(tx.GasPrice()), nil
}
return (*hexutil.Big)(math.BigMin(new(big.Int).Add(tx.GasTipCap(), header.BaseFee), tx.GasFeeCap())), nil
}
func (t *Transaction) MaxFeePerGas(ctx context.Context) (*hexutil.Big, error) {
tx, err := t.resolve(ctx)
if err != nil || tx == nil {

View File

@ -118,6 +118,13 @@ const schema string = `
# this transaction. If the transaction has not yet been mined, this field
# will be null.
cumulativeGasUsed: Long
# EffectiveGasPrice is actual value per gas deducted from the sender's
# account. Before EIP-1559, this is equal to the transaction's gas price.
# After EIP-1559, it is baseFeePerGas + min(maxFeePerGas - baseFeePerGas,
# maxPriorityFeePerGas). Legacy transactions and EIP-2930 transactions are
# coerced into the EIP-1559 format by setting both maxFeePerGas and
# maxPriorityFeePerGas as the transaction's gas price.
effectiveGasPrice: BigInt
# CreatedContract is the account that was created by a contract creation
# transaction. If the transaction was not a contract creation transaction,
# or it has not yet been mined, this field will be null.

View File

@ -1561,7 +1561,17 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
"logsBloom": receipt.Bloom,
"type": hexutil.Uint(tx.Type()),
}
// Assign the effective gas price paid
if !s.b.ChainConfig().IsLondon(bigblock) {
fields["effectiveGasPrice"] = hexutil.Uint64(tx.GasPrice().Uint64())
} else {
header, err := s.b.HeaderByHash(ctx, blockHash)
if err != nil {
return nil, err
}
gasPrice := new(big.Int).Add(header.BaseFee, tx.EffectiveGasTipValue(header.BaseFee))
fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())
}
// Assign receipt status or post state.
if len(receipt.PostState) > 0 {
fields["root"] = hexutil.Bytes(receipt.PostState)

File diff suppressed because one or more lines are too long

View File

@ -3807,7 +3807,9 @@ var outputTransactionReceiptFormatter = function (receipt){
receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
if(receipt.effectiveGasPrice !== undefined) {
receipt.effectiveGasPrice = utils.toBigNumber(receipt.effectiveGasPrice);
}
if(utils.isArray(receipt.logs)) {
receipt.logs = receipt.logs.map(function(log){
return outputLogFormatter(log);