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

EIP 7742 implementation #7518

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open

EIP 7742 implementation #7518

wants to merge 52 commits into from

Conversation

yerke26
Copy link
Contributor

@yerke26 yerke26 commented Sep 30, 2024

Resolves #7526

Changes

removed MAX_BLOB_GAS_PER_BLOCK, TARGET_BLOB_GAS_PER_BLOCK
Get target_blob_count, max_blob_count from Engine Api
added target_blob_count, max_blob_count to ExecutionPayload
added target_blob_count, max_blob_count to BlockHeader
removed verifications related to MAX_BLOB_GAS_PER_BLOCK
used target_blob_count * Eip4844Constants.GasPerBlob instead of TARGET_BLOB_GAS_PER_BLOCK

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Optional. Remove if not applicable.

Documentation

Requires documentation update

  • Yes
  • No

If yes, link the PR to the docs update or the issue with the details labeled docs. Remove if not applicable.

Requires explanation in Release Notes

  • Yes
  • No

If yes, fill in the details here. Remove if not applicable.

Remarks

Optional. Remove if not applicable.

@yerke26 yerke26 requested a review from rubo as a code owner September 30, 2024 14:33
@yerke26 yerke26 marked this pull request as draft September 30, 2024 14:33
Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

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

very quick check: no HeaderDecoder changes?

@yerke26 yerke26 changed the title Get target_blob_count, max_blob_count from Engine Api EIP 7742 implementation Oct 1, 2024
@yerke26 yerke26 marked this pull request as ready for review October 2, 2024 10:15
# Conflicts:
#	src/Nethermind/Nethermind.JsonRpc/Modules/Eth/FeeHistory/FeeHistoryOracle.cs
Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

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

Red flag, don't see the change in PrepareBlockForProcessing in BlockchainProcessor. Perhaps, check how other fields from header are used

@@ -137,7 +137,7 @@ private void SelectBlobTransactions(IEnumerable<Transaction> blobTransactions, B
checkedBlobTransactions++;

ulong txBlobGas = (ulong)(blobTx.BlobVersionedHashes?.Length ?? 0) * _eip4844Config.GasPerBlob;
if (txBlobGas > _eip4844Config.MaxBlobGasPerBlock - blobGasCounter)
if (!spec.IsEip7742Enabled && txBlobGas > _eip4844Config.MaxBlobGasPerBlock - blobGasCounter)
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm is this handled correcty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same thing here, need to skip the logic related to MaxBlobGasPerBlock

Copy link
Contributor

Choose a reason for hiding this comment

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

i think its assumed that the CL will do the verification regarding the MaxBlockGas/MaxBlobCount because that value is provided for blockProduction?

Copy link
Contributor

Choose a reason for hiding this comment

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

update: here we can't skip this logic, it might need to be modified
now we recieve MaxBlobCount in payload attributes and we need to use that to construct the block.

Copy link
Contributor

Choose a reason for hiding this comment

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

so the idea with the EIP is to remove validation logic, but here it is for block construction and not validation

Copy link
Contributor

Choose a reason for hiding this comment

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

@yerke26 this needs to be corrected

src/Nethermind/Nethermind.TxPool/TxPool.cs Outdated Show resolved Hide resolved
@@ -112,8 +112,9 @@ public ResultWrapper<Address> eth_coinbase()
{
return ResultWrapper<UInt256?>.Success(UInt256.Zero);
}
IReleaseSpec? spec = _blockFinder.Head?.Header is null ? null : specProvider.GetSpec(_blockFinder.Head.Header);
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens when the spec is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if spec is null, then in TryCalculateFeePerBlobGas we assume that Eip7742 is diabled

# Conflicts:
#	src/Nethermind/Nethermind.AuRa.Test/Contract/ReportingValidatorContractTests.cs
#	src/Nethermind/Nethermind.Consensus/Requests/RequestProcessor.cs
#	src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs
#	src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V4.cs
#	src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV4.cs
#	src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Prague.cs
#	src/Nethermind/Nethermind.Merge.Plugin/Handlers/EngineRpcCapabilitiesProvider.cs
#	src/Nethermind/Nethermind.Merge.Plugin/Handlers/ForkchoiceUpdatedHandler.cs
#	src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Prague.cs
#	src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs
#	src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs
Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

I havn't yet reviewed the whole thing, but I think the number of small changes to pass around spec provider suggest we are doing it wrong.

What I think we should do is some kind of refactor.

One thing we could do is change BlobGasCalculator from static class to an instance class (with interface for potential extensions). This would allow us to inject SpecProvider to its constructor and be done with it.

We could also make fee calculator part of the spec. This is similar to what was discussed (but not executed) in: #7761 (comment) in regards to BaseFeeCalculator.

We could even calculate BlobBaseFee in some transient BlockHeader property on start of processing. But that has it's own downsides.

Or as BLOBBASEFEE is the only place that uses it from BlockContext and it already has access to spec and header - lazy calculate it there and only then store it in block context.

Whichever thing we do I thing the current approach should be changed as this change seems to invasive for me, for such a small thing.

src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs Outdated Show resolved Hide resolved
@tanishqjasoria
Copy link
Contributor

tanishqjasoria commented Dec 4, 2024

One thing we could do is change BlobGasCalculator from static class to an instance class (with interface for potential extensions). This would allow us to inject SpecProvider to its constructor and be done with it.

these were my initial thoughts as well, but then we might need to pass BlobGasCalculator around if we change it to an instance class.

@LukaszRozmej
Copy link
Member

One thing we could do is change BlobGasCalculator from static class to an instance class (with interface for potential extensions). This would allow us to inject SpecProvider to its constructor and be done with it.

these were my initial thoughts as well, but then we might need to pass BlobGasCalculator around if we change it to an instance class.

Yeah the easiest workaround is to calculate BlobBaseFee lazily from BLOBBASEFEE opcode implementation

@@ -36,18 +37,21 @@ public abstract partial class Contract
protected IAbiEncoder AbiEncoder { get; }
public AbiDefinition AbiDefinition { get; }
public Address? ContractAddress { get; protected set; }
protected ISpecProvider SpecProvider { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed ?

/// Gets the <c>BLOB_GASPRICE_UPDATE_FRACTION</c> parameter.
/// </summary>
/// <remarks>Defaults to 3338477.</remarks>
public static UInt256 BlobGasPriceUpdateFraction { get; private set; } = 1112825;
Copy link
Contributor

Choose a reason for hiding this comment

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

can just be normal constant.

/// <param name="abiEncoder">Binary interface encoder/decoder.</param>
/// <param name="contractAddress">Address where contract is deployed.</param>
/// <param name="abiDefinition">Binary definition of contract.</param>
protected Contract(IAbiEncoder? abiEncoder = null, Address? contractAddress = null, AbiDefinition? abiDefinition = null)
protected Contract(ISpecProvider specProvider, IAbiEncoder? abiEncoder = null, Address? contractAddress = null, AbiDefinition? abiDefinition = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

This isnt actually used and it causes a lot of changes.

@@ -85,10 +84,16 @@ static bool FakeExponentialOverflow(UInt256 factor, UInt256 num, UInt256 denomin
return false;
}

return !FakeExponentialOverflow(Eip4844Constants.MinBlobGasPrice, excessBlobGas, Eip4844Constants.BlobGasPriceUpdateFraction, out feePerBlobGas);
var denominator = spec?.IsEip7742Enabled ?? false
? Eip7742Constants.BlobGasPriceUpdateFraction * targetBlobCount
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does Eip7742Constants.BlobGasPriceUpdateFraction come from? The eip doesn't mention updating the rate of change?

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.

Implement EIP-7442 Uncouple blob count between CL and EL
5 participants