-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use blob gas instead of count (#6229)
* Use blob gas instead of count * Shuffle 4844 constants, add GetMaxBlobsPerBlock * Reorder constants again; make 4844 settings testable; add tests
- Loading branch information
Showing
8 changed files
with
146 additions
and
29 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/Nethermind/Nethermind.Blockchain.Test/TestEip4844Config.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core; | ||
|
||
namespace Nethermind.Consensus.Producers.Test; | ||
|
||
public class TestEip4844Config : IEip4844Config | ||
{ | ||
public TestEip4844Config(ulong? maxBlobGasPerBlock = null) | ||
{ | ||
MaxBlobGasPerBlock = maxBlobGasPerBlock ?? Eip4844Constants.MaxBlobGasPerBlock; | ||
} | ||
|
||
public ulong MaxBlobGasPerBlock { get; } | ||
|
||
public ulong GasPerBlob => Eip4844Constants.GasPerBlob; | ||
|
||
public int GetMaxBlobsPerBlock() => (int)(MaxBlobGasPerBlock / GasPerBlob); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/Nethermind/Nethermind.Blockchain.Test/TxPoolSourceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Consensus.Transactions; | ||
using Nethermind.Logging; | ||
using Nethermind.Specs.Forks; | ||
using Nethermind.TxPool; | ||
using NUnit.Framework; | ||
using Nethermind.Consensus.Comparers; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Specs; | ||
using Nethermind.Core; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using NSubstitute; | ||
|
||
namespace Nethermind.Consensus.Producers.Test; | ||
|
||
public class TxPoolSourceTests | ||
{ | ||
[TestCaseSource(nameof(BlobTransactionsWithBlobGasLimitPerBlock))] | ||
public void GetTransactions_should_respect_customizable_blob_gas_limit(int[] blobCountPerTx, ulong customMaxBlobGasPerBlock) | ||
{ | ||
TestSingleReleaseSpecProvider specProvider = new(Cancun.Instance); | ||
TransactionComparerProvider transactionComparerProvider = new(specProvider, Build.A.BlockTree().TestObject); | ||
|
||
ITxPool txPool = Substitute.For<ITxPool>(); | ||
Dictionary<Address, Transaction[]> transactionsWithBlobs = blobCountPerTx | ||
.Select((blobsCount, index) => (blobCount: blobsCount, index)) | ||
.ToDictionary( | ||
pair => new Address((new byte[19]).Concat(new byte[] { (byte)pair.index }).ToArray()), | ||
pair => new Transaction[] { Build.A.Transaction.WithShardBlobTxTypeAndFields(pair.blobCount).TestObject }); | ||
txPool.GetPendingTransactions().Returns(new Transaction[0]); | ||
txPool.GetPendingLightBlobTransactionsBySender().Returns(transactionsWithBlobs); | ||
|
||
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); | ||
|
||
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())); | ||
}); | ||
} | ||
|
||
public static IEnumerable<TestCaseData> BlobTransactionsWithBlobGasLimitPerBlock() | ||
{ | ||
yield return new TestCaseData(new int[] { 1, 2, 4 }, Eip4844Constants.GasPerBlob * 6); | ||
yield return new TestCaseData(new int[] { 1, 2, 6 }, Eip4844Constants.GasPerBlob * 6); | ||
yield return new TestCaseData(new int[] { 1, 6 }, Eip4844Constants.GasPerBlob * 6); | ||
yield return new TestCaseData(new int[] { 6, 1, 5 }, Eip4844Constants.GasPerBlob * 6); | ||
yield return new TestCaseData(new int[] { 1, 2 }, Eip4844Constants.GasPerBlob * 2); | ||
yield return new TestCaseData(new int[] { 1, 1 }, Eip4844Constants.GasPerBlob * 2); | ||
yield return new TestCaseData(new int[] { 2, 1 }, Eip4844Constants.GasPerBlob * 2); | ||
yield return new TestCaseData(new int[] { 2, 2 }, Eip4844Constants.GasPerBlob * 2); | ||
yield return new TestCaseData(new int[] { 3 }, Eip4844Constants.GasPerBlob * 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
namespace Nethermind.Core; | ||
|
||
/// <summary> | ||
/// <see cref="Eip4844Constants" /> wrapper, made for testing convenience. | ||
/// </summary> | ||
public interface IEip4844Config | ||
{ | ||
ulong MaxBlobGasPerBlock { get; } | ||
ulong GasPerBlob { get; } | ||
int GetMaxBlobsPerBlock(); | ||
} | ||
|
||
public class ConstantEip4844Config : IEip4844Config | ||
{ | ||
public ulong MaxBlobGasPerBlock => Eip4844Constants.MaxBlobGasPerBlock; | ||
public ulong GasPerBlob => Eip4844Constants.GasPerBlob; | ||
public int GetMaxBlobsPerBlock() => Eip4844Constants.GetMaxBlobsPerBlock(); | ||
|
||
static ConstantEip4844Config() => Instance = new ConstantEip4844Config(); | ||
private ConstantEip4844Config() { } | ||
|
||
public static IEip4844Config Instance { get; private set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters