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 7840 implementation #7964

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c38a641
add MaxBlobCount, TargetBlobCount to chainSpec
yerke26 Dec 23, 2024
10342cc
Change FeeOracleHistory to use right MaxBlobCount
yerke26 Dec 23, 2024
5ef5d36
fix BlobGasUsedRatio
yerke26 Dec 24, 2024
6f45bc6
remove TargetBlobCount, MaxBlobCount constants
yerke26 Dec 30, 2024
0035b43
add PragueTransitionTimestamp
yerke26 Jan 6, 2025
d68374c
Merge branch 'master' into eip-7840
yerke26 Jan 6, 2025
b668cdf
remove PragueTransitionTimestamp, instead use Eip7002TransitionTimestamp
yerke26 Jan 7, 2025
eb77784
remove Eip4844MaxBlobCount, Eip4844TargetBlobCount from chainSpecParams
yerke26 Jan 7, 2025
b8bef08
fix TxValidatorTests
yerke26 Jan 7, 2025
7059480
fix TxValidatorTests
yerke26 Jan 7, 2025
b638d63
fix CancunStateTests
yerke26 Jan 7, 2025
0d5a076
fix TransactionProcessorEip4844Tests
yerke26 Jan 7, 2025
91f1b1f
fix TxPoolTests
yerke26 Jan 7, 2025
e494aa9
fix tests
yerke26 Jan 7, 2025
44481ba
fix FeeHistoryOracleTests
yerke26 Jan 7, 2025
05772a0
fix whitespaces
yerke26 Jan 7, 2025
b6b50b7
Merge branch 'master' into eip-7840
MarekM25 Jan 7, 2025
09a914d
remove hardcoded values
yerke26 Jan 7, 2025
1d271bd
Fix build errors
MarekM25 Jan 7, 2025
87acb12
Merge branch 'eip-7840' of https://github.com/nethermindeth/nethermin…
MarekM25 Jan 7, 2025
0aa4346
Fix OverridableReleaseSpec
MarekM25 Jan 7, 2025
87fc57d
remove hardcoded values
yerke26 Jan 7, 2025
f28e72a
add blobSchedule to chainSpec
yerke26 Jan 7, 2025
8804ccd
fix FeeHistoryOracleTests
yerke26 Jan 7, 2025
8c1c6f3
fix EthRpcModuleTests
yerke26 Jan 8, 2025
d9d60ab
fix PooledTxsRequestor
yerke26 Jan 8, 2025
6058cb1
use the release spec from the testcase and add prague count test
tanishqjasoria Jan 8, 2025
78b9e33
rename
tanishqjasoria Jan 8, 2025
22b7d1d
fix fee history oracle pre cancun
tanishqjasoria Jan 8, 2025
4fbd890
fix gnosis and chiado specs
tanishqjasoria Jan 8, 2025
6952229
Merge branch 'master' into eip-7840
tanishqjasoria Jan 8, 2025
5b4c0d1
fix whitespaces
yerke26 Jan 8, 2025
cb445ee
Merge branch 'master' into eip-7840
MarekM25 Jan 8, 2025
e181b43
fix default blobCount and targetCount
MarekM25 Jan 8, 2025
43e1655
fix PooledTxsRequestor to use spec at current head
yerke26 Jan 9, 2025
0c309ea
fix PooledTxsRequestorTests
yerke26 Jan 9, 2025
c2737fc
CalculateMaxBlobTxSize through transitionActivations
yerke26 Jan 9, 2025
362f18c
set default TargetBlobCount, MaxBlobCount to zero
yerke26 Jan 9, 2025
2f1f6f2
fix defaults
MarekM25 Jan 9, 2025
43bda5a
set default value for gnosisChain
yerke26 Jan 9, 2025
1ecf556
add Eip7840DefaultBlobCountFraction for gnosis chain
yerke26 Jan 10, 2025
3872a10
fix gnosis, chiado chains json
yerke26 Jan 10, 2025
58a3ff9
revert default value changes
yerke26 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/Nethermind/Nethermind.Blockchain.Test/TestEip4844Config.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static IEnumerable EnoughShardBlobTransactionsSelectedTestCases
tx.MaxFeePerBlobGas = 1;
});
maxTransactionsSelected.Transactions[1].BlobVersionedHashes =
new byte[Eip4844Constants.MaxBlobGasPerTransaction / Eip4844Constants.GasPerBlob - 1][];
new byte[2 - 1][];
maxTransactionsSelected.ExpectedSelectedTransactions.AddRange(
maxTransactionsSelected.Transactions.OrderBy(static t => t.Nonce).Take(2));
yield return new TestCaseData(maxTransactionsSelected).SetName("Enough transactions selected");
Expand All @@ -174,7 +174,7 @@ public static IEnumerable EnoughShardBlobTransactionsSelectedTestCases
enoughTransactionsSelected.Transactions.OrderBy(static t => t.Nonce).ToArray();
expectedSelectedTransactions[0].Type = TxType.Blob;
expectedSelectedTransactions[0].BlobVersionedHashes =
new byte[Eip4844Constants.MaxBlobGasPerTransaction / Eip4844Constants.GasPerBlob][];
new byte[1 / Eip4844Constants.GasPerBlob][];
expectedSelectedTransactions[0].MaxFeePerBlobGas = 1;
expectedSelectedTransactions[1].Type = TxType.Blob;
expectedSelectedTransactions[1].BlobVersionedHashes = new byte[1][];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ public void GetTransactions_should_respect_customizable_blob_gas_limit(int[] blo
ITxFilterPipeline txFilterPipeline = Substitute.For<ITxFilterPipeline>();
txFilterPipeline.Execute(Arg.Any<Transaction>(), Arg.Any<BlockHeader>()).Returns(true);

TestEip4844Config eip4844Config = new(customMaxBlobGasPerBlock);

TxPoolTxSource transactionSelector = new(txPool, specProvider, transactionComparerProvider, LimboLogs.Instance, txFilterPipeline, eip4844Config);
TxPoolTxSource transactionSelector = new(txPool, specProvider, transactionComparerProvider, LimboLogs.Instance, txFilterPipeline);

IEnumerable<Transaction> txs = transactionSelector.GetTransactions(new BlockHeader { }, long.MaxValue);
int blobsCount = txs.Sum(tx => tx.BlobVersionedHashes?.Length ?? 0);

Assert.Multiple(() =>
{
Assert.That((ulong)blobsCount * eip4844Config.GasPerBlob, Is.LessThanOrEqualTo(eip4844Config.MaxBlobGasPerBlock));
Assert.That(blobsCount, Is.LessThanOrEqualTo(eip4844Config.GetMaxBlobsPerBlock()));
Assert.That((ulong)blobsCount * Eip4844Constants.GasPerBlob, Is.LessThanOrEqualTo(1));
Assert.That(blobsCount, Is.LessThanOrEqualTo(1));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace Nethermind.Blockchain.Test.Validators;

public class ShardBlobBlockValidatorTests
{
private const int MaxBlobCount = 6;
private const int TargetBlobCount = 3;

[TestCaseSource(nameof(BlobGasFieldsPerForkTestCases))]
public static bool Blob_gas_fields_should_be_set(IReleaseSpec spec, ulong? blobGasUsed, ulong? excessBlobGas)
{
Expand All @@ -35,7 +38,10 @@ public static bool Blob_gas_fields_should_be_set(IReleaseSpec spec, ulong? blobG
[TestCaseSource(nameof(BlobsPerBlockCountTestCases))]
public bool Blobs_per_block_count_is_valid(ulong blobGasUsed)
{
ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, Cancun.Instance));
ISpecProvider specProvider = new OverridableSpecProvider(
new CustomSpecProvider(((ForkActivation)0, Cancun.Instance)),
r => new OverridableReleaseSpec(r) { MaxBlobCount = MaxBlobCount, TargetBlobCount = TargetBlobCount });
yerke26 marked this conversation as resolved.
Show resolved Hide resolved

BlockValidator blockValidator = new(Always.Valid, Always.Valid, Always.Valid, specProvider, TestLogManager.Instance);
return blockValidator.ValidateSuggestedBlock(
Build.A.Block
Expand All @@ -55,11 +61,11 @@ private static IEnumerable<TestCaseData> BlobsPerBlockCountTestCases()
{
yield return new TestCaseData(0UL) { ExpectedResult = true };

yield return new TestCaseData(Eip4844Constants.MaxBlobGasPerBlock - Eip4844Constants.GasPerBlob) { ExpectedResult = true };
yield return new TestCaseData((MaxBlobCount - 1) * Eip4844Constants.GasPerBlob) { ExpectedResult = true };

yield return new TestCaseData(Eip4844Constants.MaxBlobGasPerBlock) { ExpectedResult = true };
yield return new TestCaseData(MaxBlobCount * Eip4844Constants.GasPerBlob) { ExpectedResult = true };

yield return new TestCaseData(Eip4844Constants.MaxBlobGasPerBlock + Eip4844Constants.GasPerBlob) { ExpectedResult = false };
yield return new TestCaseData((MaxBlobCount + 1) * Eip4844Constants.GasPerBlob) { ExpectedResult = false };
}

private static IEnumerable<TestCaseData> BlobGasFieldsPerForkTestCases()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Nethermind.Blockchain.Test.Validators;

public class TxValidatorTests
{
private const int MaxBlobCount = 6;
private const int TargetBlobCount = 3;

[SetUp]
public void Setup()
{
Expand Down Expand Up @@ -725,19 +728,19 @@ static TransactionBuilder<Transaction> MakeTestObject(int blobCount = 1) => Buil
TestName = "More than minimum BlobVersionedHashes",
ExpectedResult = true
};
yield return new TestCaseData(MakeTestObject((int)(Eip4844Constants.MaxBlobGasPerBlock / Eip4844Constants.GasPerBlob - 1))
yield return new TestCaseData(MakeTestObject(MaxBlobCount - 1)
.SignedAndResolved().TestObject)
{
TestName = "Less than maximum BlobVersionedHashes",
ExpectedResult = true
};
yield return new TestCaseData(MakeTestObject((int)(Eip4844Constants.MaxBlobGasPerBlock / Eip4844Constants.GasPerBlob))
yield return new TestCaseData(MakeTestObject(MaxBlobCount)
.SignedAndResolved().TestObject)
{
TestName = "Maximum BlobVersionedHashes",
ExpectedResult = true
};
yield return new TestCaseData(MakeTestObject((int)(Eip4844Constants.MaxBlobGasPerBlock / Eip4844Constants.GasPerBlob + 1))
yield return new TestCaseData(MakeTestObject(MaxBlobCount + 1)
.SignedAndResolved().TestObject)
{
TestName = "Too many BlobVersionedHashes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static string InvalidTxInBlock(int i) =>

//Block's blob gas used in header is above the limit.
public static readonly string BlobGasUsedAboveBlockLimit =
$"BlockBlobGasExceeded: A block cannot have more than {Eip4844Constants.MaxBlobGasPerBlock} blob gas.";
"BlockBlobGasExceeded: A block cannot have more than {0} blob gas.";
smartprogrammer93 marked this conversation as resolved.
Show resolved Hide resolved

//Block's excess blob gas in header is incorrect.
public const string IncorrectExcessBlobGas =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static string InvalidTxChainId(ulong expected, ulong? actual) =>
"blob transaction missing blob hashes";

public static readonly string BlobTxGasLimitExceeded =
$"BlobTxGasLimitExceeded: Transaction exceeded {Eip4844Constants.MaxBlobGasPerTransaction}.";
smartprogrammer93 marked this conversation as resolved.
Show resolved Hide resolved
"BlobTxGasLimitExceeded: Transaction exceeded {0}.";

public const string BlobTxMissingBlobs =
"BlobTxMissingBlobs: Blob transaction must have blobs.";
Expand Down
14 changes: 6 additions & 8 deletions src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@ public class TxPoolTxSource : ITxSource
private readonly ITxFilterPipeline _txFilterPipeline;
private readonly ISpecProvider _specProvider;
protected readonly ILogger _logger;
private readonly IEip4844Config _eip4844Config;

public TxPoolTxSource(
ITxPool? transactionPool,
ISpecProvider? specProvider,
ITransactionComparerProvider? transactionComparerProvider,
ILogManager? logManager,
ITxFilterPipeline? txFilterPipeline,
IEip4844Config? eip4844ConstantsProvider = null)
ITxFilterPipeline? txFilterPipeline)
{
_transactionPool = transactionPool ?? throw new ArgumentNullException(nameof(transactionPool));
_transactionComparerProvider = transactionComparerProvider ?? throw new ArgumentNullException(nameof(transactionComparerProvider));
_txFilterPipeline = txFilterPipeline ?? throw new ArgumentNullException(nameof(txFilterPipeline));
_specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider));
_logger = logManager?.GetClassLogger<TxPoolTxSource>() ?? throw new ArgumentNullException(nameof(logManager));
_eip4844Config = eip4844ConstantsProvider ?? ConstantEip4844Config.Instance;
}

public IEnumerable<Transaction> GetTransactions(BlockHeader parent, long gasLimit, PayloadAttributes? payloadAttributes = null)
Expand All @@ -62,7 +59,7 @@ public IEnumerable<Transaction> GetTransactions(BlockHeader parent, long gasLimi

int checkedTransactions = 0;
int selectedTransactions = 0;
using ArrayPoolList<Transaction> selectedBlobTxs = new(_eip4844Config.GetMaxBlobsPerBlock());
using ArrayPoolList<Transaction> selectedBlobTxs = new((int)(spec.MaxBlobCount * Eip4844Constants.GasPerBlob));

SelectBlobTransactions(blobTransactions, parent, spec, selectedBlobTxs);

Expand Down Expand Up @@ -126,18 +123,19 @@ private void SelectBlobTransactions(IEnumerable<Transaction> blobTransactions, B
UInt256 blobGasCounter = 0;
UInt256 feePerBlobGas = UInt256.Zero;

var maxBlobGasPerBlock = spec.MaxBlobCount * Eip4844Constants.GasPerBlob;
foreach (Transaction blobTx in blobTransactions)
{
if (blobGasCounter >= _eip4844Config.MaxBlobGasPerBlock)
if (blobGasCounter >= maxBlobGasPerBlock)
{
if (_logger.IsTrace) _logger.Trace($"Declining {blobTx.ToShortString()}, no more blob space. Block already have {blobGasCounter} blob gas which is max value allowed.");
break;
}

checkedBlobTransactions++;

ulong txBlobGas = (ulong)(blobTx.BlobVersionedHashes?.Length ?? 0) * _eip4844Config.GasPerBlob;
if (txBlobGas > _eip4844Config.MaxBlobGasPerBlock - blobGasCounter)
ulong txBlobGas = (ulong)(blobTx.BlobVersionedHashes?.Length ?? 0) * Eip4844Constants.GasPerBlob;
if (txBlobGas > maxBlobGasPerBlock - blobGasCounter)
{
if (_logger.IsTrace) _logger.Trace($"Declining {blobTx.ToShortString()}, not enough blob space.");
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ protected virtual bool ValidateEip4844Fields(Block block, IReleaseSpec spec, out

ulong blobGasUsed = BlobGasCalculator.CalculateBlobGas(blobsInBlock);

if (blobGasUsed > Eip4844Constants.MaxBlobGasPerBlock)
if (blobGasUsed > spec.MaxBlobCount * Eip4844Constants.GasPerBlob)
{
error = BlockErrorMessages.BlobGasUsedAboveBlockLimit;
error = string.Format(BlockErrorMessages.BlobGasUsedAboveBlockLimit, spec.MaxBlobCount * Eip4844Constants.GasPerBlob);
if (_logger.IsDebug) _logger.Debug($"{Invalid(block)} {error}.");
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ public ValidationResult IsWellFormed(Transaction transaction, IReleaseSpec relea
{ To: null } => TxErrorMessages.TxMissingTo,
{ MaxFeePerBlobGas: null } => TxErrorMessages.BlobTxMissingMaxFeePerBlobGas,
{ BlobVersionedHashes: null } => TxErrorMessages.BlobTxMissingBlobVersionedHashes,
_ => ValidateBlobFields(transaction)
_ => ValidateBlobFields(transaction, releaseSpec)
};

private ValidationResult ValidateBlobFields(Transaction transaction)
private ValidationResult ValidateBlobFields(Transaction transaction, IReleaseSpec spec)
{
int blobCount = transaction.BlobVersionedHashes!.Length;
ulong totalDataGas = BlobGasCalculator.CalculateBlobGas(blobCount);
return totalDataGas > Eip4844Constants.MaxBlobGasPerTransaction ? TxErrorMessages.BlobTxGasLimitExceeded
var maxBlobGasPerBlock = spec.MaxBlobCount * Eip4844Constants.GasPerBlob;
return totalDataGas > maxBlobGasPerBlock ? string.Format(TxErrorMessages.BlobTxGasLimitExceeded, maxBlobGasPerBlock)
: blobCount < Eip4844Constants.MinBlobsPerTransaction ? TxErrorMessages.BlobTxMissingBlobs
: ValidateBlobVersionedHashes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ private static ISpecProvider CreateSpecProvider(ISpecProvider specProvider)
{
return specProvider is TestSpecProvider { AllowTestChainOverride: false }
? specProvider
: new OverridableSpecProvider(specProvider, static s => new OverridableReleaseSpec(s) { IsEip3607Enabled = false });
: new OverridableSpecProvider(specProvider, static s => new OverridableReleaseSpec(s)
{
IsEip3607Enabled = false,
MaxBlobCount = 6,
TargetBlobCount = 3,
});
}

private void BlockAddedToMain(object? sender, BlockEventArgs e)
Expand Down
26 changes: 0 additions & 26 deletions src/Nethermind/Nethermind.Core/Eip4844Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ public class Eip4844Constants
/// <remarks>Defaults to 131072.</remarks>
public const ulong GasPerBlob = 131072;

/// <summary>
/// Gets the <c>MAX_BLOB_GAS_PER_BLOCK</c> parameter.
/// </summary>
/// <remarks>Defaults to 786432.</remarks>
public static ulong MaxBlobGasPerBlock { get; private set; } = 786432;

/// <summary>
/// Gets the <c>MAX_BLOB_GAS_PER_BLOCK</c> parameter.
/// </summary>
/// <remarks>The same as <see cref="MaxBlobGasPerBlock"/>.</remarks>
public static ulong MaxBlobGasPerTransaction => MaxBlobGasPerBlock;

/// <summary>
/// Gets the <c>TARGET_BLOB_GAS_PER_BLOCK</c> parameter.
/// </summary>
/// <remarks>Defaults to 393216.</remarks>
public static ulong TargetBlobGasPerBlock { get; private set; } = MaxBlobGasPerBlock / 2;

/// <summary>
/// Gets the <c>BLOB_GASPRICE_UPDATE_FRACTION</c> parameter.
/// </summary>
Expand All @@ -59,15 +41,7 @@ public static void OverrideIfAny(
if (blobGasPriceUpdateFraction.HasValue)
BlobGasPriceUpdateFraction = blobGasPriceUpdateFraction.Value;

if (maxBlobGasPerBlock.HasValue)
MaxBlobGasPerBlock = maxBlobGasPerBlock.Value;

if (minBlobGasPrice.HasValue)
MinBlobGasPrice = minBlobGasPrice.Value;

if (targetBlobGasPerBlock.HasValue)
TargetBlobGasPerBlock = targetBlobGasPerBlock.Value;
}

public static int GetMaxBlobsPerBlock() => (int)(MaxBlobGasPerBlock / GasPerBlob);
}
26 changes: 0 additions & 26 deletions src/Nethermind/Nethermind.Core/IEip4844Config.cs

This file was deleted.

6 changes: 6 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec
/// <remarks>Backward compatibility for early Kovan blocks.</remarks>
bool ValidateChainId => true;

/// <summary>
/// EIP-7780: Add blob schedule to EL config files
/// </summary>
public ulong TargetBlobCount { get; set; }
public ulong MaxBlobCount { get; set; }

public ulong WithdrawalTimestamp { get; }

public ulong Eip4844TransitionTimestamp { get; }
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec
public virtual bool IsEip4895Enabled => spec.IsEip4895Enabled;
public virtual bool IsEip4844Enabled => spec.IsEip4844Enabled;
public virtual bool IsEip4788Enabled => spec.IsEip4788Enabled;
public ulong TargetBlobCount { get; set; }
yerke26 marked this conversation as resolved.
Show resolved Hide resolved
public ulong MaxBlobCount { get; set; }
yerke26 marked this conversation as resolved.
Show resolved Hide resolved
public virtual Address? Eip4788ContractAddress => spec.Eip4788ContractAddress;
public bool IsEip6110Enabled => spec.IsEip6110Enabled;
public Address DepositContractAddress => spec.DepositContractAddress;
Expand Down
Loading
Loading