Skip to content

Conversation

@LaGregance
Copy link

Since the new EIP-1559 transaction format, we need to have a way to get the effective gas price spent by the transaction. This data is already available in the receipt returned by the node so only few change are needed.
This PR will mainly help developers that use go-ethereum as library in their go project to interact with the blockchain.

Basically, I just added the field EffectiveGasPrice to types.Receipt and manage it in MarshalJSON & UnmarshalJSON functions.

TxHash common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress common.Address `json:"contractAddress"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
EffectiveGasPrice *big.Int `json:"effectiveGasPrice,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the value being set?

Copy link
Author

Choose a reason for hiding this comment

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

Inside UnmarshalJSON in the file gen_receipt_json.go

Copy link
Member

Choose a reason for hiding this comment

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

He means within execution. At some point, probably during state processing, you need to set the effective gas price. The way it is right now, effective gas is never set, so it's 0 for all receipts

Copy link
Author

Choose a reason for hiding this comment

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

I think it's set in internal/ethapi/api.go:1641 in the function GetTransactionReceipt.
Personally I checked with my Node (Quicknode) that is running on Geth 1.10.26 and it's perfectly work.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see you add this field so you can use it in ethclient.TransactionReceipt()

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we will just have to pass in either the header, or the basefee, as a parameter into DeriveFields.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I will try to doing this this or next week.
Do you agree that if we pass the block header as parameter we can remove hash & number params ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, they can be removed in that case. Note: I haven't checked myself if the header is easily available at all call sites of DeriveFields. If it is, we're good. Otherwise we'll need to consider it further.

Copy link
Author

Choose a reason for hiding this comment

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

Not checked too, I keep you updated as soon as I know

Copy link
Author

Choose a reason for hiding this comment

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

Ok I think everything is done, I have just a little concern about the comment I made to accessors_chain.go that you can see below

@fjl fjl changed the title Add EffectiveGasPrice to types.Receipt core/types: add EffectiveGasPrice in Receipt Dec 7, 2022
Comment on lines +639 to +645
header := ReadHeader(db, hash, number)
var baseFee *big.Int
if header == nil {
baseFee = big.NewInt(0)
} else {
baseFee = header.BaseFee
}
Copy link
Author

Choose a reason for hiding this comment

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

Not sure if it's the good way, but accessors_chain_test.go fail at line 646 if we return nil in case the header does not exists.

@LaGregance
Copy link
Author

Hi, the pipeline seems to be stuck, someone know how to make it run ?

@fjl
Copy link
Contributor

fjl commented Dec 8, 2022

We had an issue with it today, just re-push and it will start the build again.

@gbl-tylers
Copy link

Are there any updates on this? Seems like a fairly big and obvious thing to be missing from the receipt

Comment on lines +429 to +434
// The effective gas price can be calculated based on baseFee for EIP1559 transactions
if txs[i].Type() == 2 {
rs[i].EffectiveGasPrice = new(big.Int).Add(baseFee, txs[i].EffectiveGasTipValue(baseFee))
} else {
rs[i].EffectiveGasPrice = new(big.Int).Set(txs[i].GasPrice())
}
Copy link
Contributor

@holiman holiman Jan 31, 2023

Choose a reason for hiding this comment

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

I think this logic will bitrot if we leave it here (as soon as we add a new tx type). I'd rather have a method

func (tx *Transaction) EffectiveGasPrice(baseFee *big.Int) (*big.Int, error) 

And that method should use the methods that the transaction types expose. If we do it this way, we can make it so any new type will be 'forced' to handle it

@fjl
Copy link
Contributor

fjl commented Feb 16, 2023

Superseded by #26713

@fjl fjl closed this Feb 16, 2023
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.

6 participants