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

Gas accounting for EIP-4844 #4992

Merged
merged 36 commits into from
Feb 23, 2023
Merged

Conversation

fab-10
Copy link
Contributor

@fab-10 fab-10 commented Jan 24, 2023

Signed-off-by: Fabio Di Fabio [email protected]

PR description

This PR introduces the gas accounting for EIP-4844, specifically it introduce a data gas price and a data gas cost.

There is a new fee market named after Cancun that can calculate the data price, a new gas calculator to compute the gas
used by a blob transaction and a new gas limit calculator to track the max data gas per block.
There are changes also to the transactions selection during the block creation to take in account the data gas used and check it against the limits.

Fixed Issue(s)

fixes #4825

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if
    updates are required.

Changelog

Signed-off-by: Fabio Di Fabio <[email protected]>
Signed-off-by: Fabio Di Fabio <[email protected]>
@@ -83,6 +84,9 @@ public abstract class MainnetProtocolSpecs {
public static final int SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT = 24576;
public static final int SHANGHAI_INIT_CODE_SIZE_LIMIT = 2 * SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT;

private static final int CANCUN_MIN_DATA_GAS_PRICE = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can move that to CancunGasCalculator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

dataGas = 0L;
}

final long gasAvailable = transaction.getGasLimit() - intrinsicGas - accessListGas - dataGas;
LOG.trace(
"Gas available for execution {} = {} - {} (limit - intrinsic)",
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add dataGas to the log ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will add also accessListGas that is missing too

transaction.getPayload().size(), maxInitcodeSize));
}

if (transaction.getType().supportsBlob()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if we want to push all the cost verification in the same method maybe we can also move this one ?

/** The Cancun gas calculator. */
public class CancunGasCalculator extends LondonGasCalculator {

public static final int CANCUN_DATA_GAS_PER_BLOB = 131072; // 2^17
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can link the EIP in a comment for future dev

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in the class doc

final long gasAvailable = transaction.getGasLimit() - intrinsicGas - accessListGas;
final long dataGas;
if (feeMarket.implementsDataFee()) {
dataGas = gasCalculator.dataGasCost(transaction.getVersionedHashes().orElseThrow().size());
Copy link
Contributor

Choose a reason for hiding this comment

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

we can use blobcount for this one or remove this one because we are already calculating this value in 306 line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed

Comment on lines 20 to 21
public static final long CANCUN_DATA_GAS_PER_BLOB = 131072; // 2^17
public static final long CANCUN_TARGET_DATA_GAS_PER_BLOCK = 262144; // 2^18
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static final long CANCUN_DATA_GAS_PER_BLOB = 131072; // 2^17
public static final long CANCUN_TARGET_DATA_GAS_PER_BLOCK = 262144; // 2^18
public static final long CANCUN_DATA_GAS_PER_BLOB = 1 << 17;
public static final long CANCUN_TARGET_DATA_GAS_PER_BLOCK = 1 << 18;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

included

Signed-off-by: Fabio Di Fabio <[email protected]>
garyschulte pushed a commit that referenced this pull request Jan 25, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
fab-10 and others added 6 commits January 30, 2023 19:30
* adding test for nonblob blob transaction
* Do not add consumed data gas to gas used in the transaction receipt

Signed-off-by: Jiri Peinlich <[email protected]>
Signed-off-by: Fabio Di Fabio <[email protected]>
Co-authored-by: Jiri Peinlich <[email protected]>
Signed-off-by: Fabio Di Fabio <[email protected]>
Co-authored-by: Justin Florentine <[email protected]>
This reverts commit 0719ded.

Signed-off-by: Fabio Di Fabio <[email protected]>
* adding test for nonblob blob transaction
* Do not add consumed data gas to gas used in the transaction receipt

Signed-off-by: Jiri Peinlich <[email protected]>
Signed-off-by: Fabio Di Fabio <[email protected]>
Co-authored-by: Jiri Peinlich <[email protected]>
jflo pushed a commit that referenced this pull request Jun 30, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jun 30, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jun 30, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jun 30, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jun 30, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jun 30, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
Signed-off-by: Gabriel-Trintinalia <[email protected]>
jflo pushed a commit that referenced this pull request Jun 30, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
Signed-off-by: Gabriel-Trintinalia <[email protected]>
@siladu siladu mentioned this pull request Jul 4, 2023
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
Signed-off-by: Gabriel-Trintinalia <[email protected]>
jflo pushed a commit that referenced this pull request Jul 5, 2023
merge of #4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
Signed-off-by: Gabriel-Trintinalia <[email protected]>
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
Signed-off-by: Gabriel-Trintinalia <[email protected]>
jflo pushed a commit to jflo/besu that referenced this pull request Jul 20, 2023
merge of hyperledger#4992 into interop feature branch

Signed-off-by: Fabio Di Fabio <[email protected]>
(cherry picked from commit 949e3fe)
(cherry picked from commit 9734c983ce00bda161434506688f12ee07bbd820)
Signed-off-by: Gabriel-Trintinalia <[email protected]>
elenduuche pushed a commit to elenduuche/besu that referenced this pull request Aug 16, 2023
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 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.

data gas accounting
4 participants