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

add effectiveGasPrice field to eth_getTransactionReceipt, eth_getBlockReceipts #2252

Merged
merged 1 commit into from
Jun 30, 2021
Merged

Conversation

dubuqingfeng
Copy link
Contributor

Some projects would like to have effectiveGasPrice in eth_getTransactionReceipt.

So add effectiveGasPrice field to eth_getTransactionReceipt, eth_getBlockReceipts.

ethereum/execution-specs#206

the effectiveGasPrice field:

The actual value per gas deducted from the senders account. Before EIP-1559, this is equal to the transaction's gas price. After, it is equal to 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.

Refence:

https://notes.ethereum.org/@timbeiko/london-json-rpc
ethereum/execution-specs#206

} else {
baseFee, _ := uint256.FromBig(block.BaseFee())
gasPrice := new(big.Int).Add(block.BaseFee(), txn.GetEffectiveGasTip(baseFee).ToBig())
fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think need create hexutil.Uint256() method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main reason for using hexutil.Uint64 is because I think EffectiveGasPrice type might be uint64,
but I see the GasPrice uses uint256.
Is there any specific reason for using uint256?
And how to do the "overflow" check here?
I think it would be nice to have hexutil.Uint256().

Before:

baseFee, _ := uint256.FromBig(block.BaseFee())
gasPrice := baseFee.Add(baseFee, txn.GetEffectiveGasTip(baseFee))
fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())

After:

baseFee, _ := uint256.FromBig(block.BaseFee())
gasPrice := baseFee.Add(baseFee, txn.GetEffectiveGasTip(baseFee))
fields["effectiveGasPrice"] = hexutil.Uint256(gasPrice)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any specific reason for using uint256? - we just using uint256 everywhere where go-ethereum using big.Int (because it's more compatible with ETH spec/paper). But why GasPrice is big.Int (answer is as usually "security"): 1ETH it's 2^60 Wei - which is already almost MaxUint64=2^64. It means using Uint64 for any operations with Wei is bad idea - in general - but in this case it's fine.

How to handle overflow - just return error on overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants