-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shard blob tx gas calculations (#5596)
* Add data gas calculations * ChainSpecs/BlockProcessing: Fix syncing on Genesis block due to ExcessDataGas mismatch. * TxValidator: Move KZG version check into network wrapper verification. * ExcessData gas on genesis block * Check versioned hash earlier * Remake gas, preview * Fix recursion * Add tests, refactor * Get rid of parent block header finder * Clean up * Clean up checks * Fix tests * Fix header mapping to rpc * Fix data gas calculations * Add safety checks * Fix and improve * Blob gas info in receipts (#5767) * Blob gas info in receipts * Fix gas price * Fix spaces * Add tests * Supports blobs * Ignore on null * Fix suggestions * Fix build --------- Co-authored-by: Nikita Mescheryakov <[email protected]> * Increase data gas limits * Clean up * Add more blob space * Fix tests; clean up * Add tests, refacator * Fix MaxFeePerDataGas affects consensus on low balance * Improve max fee per data gas fix * Fix receipts * Add overflow checks * Fix tests * Fix encoding; improve text; clean up * Add gas fields to the local 4844 network genesis * Refactor BlockValidator * Add additional check --------- Co-authored-by: spencer-tb <[email protected]> Co-authored-by: Nikita Mescheryakov <[email protected]> Co-authored-by: Nikita Mescheryakov <[email protected]>
- Loading branch information
1 parent
54e54be
commit 578290e
Showing
62 changed files
with
1,137 additions
and
323 deletions.
There are no files selected for viewing
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
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
100 changes: 74 additions & 26 deletions
100
src/Nethermind/Nethermind.Blockchain.Test/Validators/ShardBlobBlockValidatorTests.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 |
---|---|---|
@@ -1,57 +1,105 @@ | ||
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Nethermind.Blockchain.Find; | ||
using Nethermind.Consensus.Validators; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Logging; | ||
using Nethermind.Specs.Forks; | ||
using Nethermind.Specs.Test; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Blockchain.Test.Validators; | ||
|
||
public class ShardBlobBlockValidatorTests | ||
{ | ||
[Test] | ||
public void Not_null_ExcessDataGas_is_invalid_pre_cancun() | ||
[TestCaseSource(nameof(DataGasFieldsPerForkTestCases))] | ||
public static bool Data_gas_fields_should_be_set(IReleaseSpec spec, ulong? dataGasUsed, ulong? excessDataGas) | ||
{ | ||
ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, Shanghai.Instance)); | ||
BlockValidator blockValidator = new(Always.Valid, Always.Valid, Always.Valid, specProvider, LimboLogs.Instance); | ||
bool isValid = blockValidator.ValidateSuggestedBlock(Build.A.Block | ||
.WithWithdrawalsRoot(TestItem.KeccakA) | ||
.WithWithdrawals(TestItem.WithdrawalA_1Eth) | ||
.WithExcessDataGas(1).TestObject); | ||
Assert.False(isValid); | ||
} | ||
|
||
[Test] | ||
public void Null_ExcessDataGas_is_invalid_post_cancun() | ||
{ | ||
ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, Cancun.Instance)); | ||
BlockValidator blockValidator = new(Always.Valid, Always.Valid, Always.Valid, specProvider, LimboLogs.Instance); | ||
bool isValid = blockValidator.ValidateSuggestedBlock(Build.A.Block | ||
ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, spec)); | ||
HeaderValidator headerValidator = new(Substitute.For<IBlockTree>(), Always.Valid, specProvider, TestLogManager.Instance); | ||
BlockValidator blockValidator = new(Always.Valid, headerValidator, Always.Valid, specProvider, TestLogManager.Instance); | ||
return blockValidator.ValidateSuggestedBlock(Build.A.Block | ||
.WithDataGasUsed(dataGasUsed) | ||
.WithExcessDataGas(excessDataGas) | ||
.WithWithdrawalsRoot(TestItem.KeccakA) | ||
.WithWithdrawals(TestItem.WithdrawalA_1Eth) | ||
.WithParent(Build.A.BlockHeader.TestObject) | ||
.TestObject); | ||
Assert.False(isValid); | ||
} | ||
|
||
[TestCase(0, ExpectedResult = true)] | ||
[TestCase(Eip4844Constants.MaxBlobsPerBlock - 1, ExpectedResult = true)] | ||
[TestCase(Eip4844Constants.MaxBlobsPerBlock, ExpectedResult = true)] | ||
[TestCase(Eip4844Constants.MaxBlobsPerBlock + 1, ExpectedResult = false)] | ||
public bool Blobs_per_block_count_is_valid(int blobsCount) | ||
[TestCase(0ul, ExpectedResult = true)] | ||
[TestCase(Eip4844Constants.MaxDataGasPerBlock - Eip4844Constants.DataGasPerBlob, ExpectedResult = true)] | ||
[TestCase(Eip4844Constants.MaxDataGasPerBlock, ExpectedResult = true)] | ||
[TestCase(Eip4844Constants.MaxDataGasPerBlock + Eip4844Constants.DataGasPerBlob, ExpectedResult = false)] | ||
public bool Blobs_per_block_count_is_valid(ulong dataGasUsed) | ||
{ | ||
ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, Cancun.Instance)); | ||
BlockValidator blockValidator = new(Always.Valid, Always.Valid, Always.Valid, specProvider, LimboLogs.Instance); | ||
BlockValidator blockValidator = new(Always.Valid, Always.Valid, Always.Valid, specProvider, TestLogManager.Instance); | ||
return blockValidator.ValidateSuggestedBlock( | ||
Build.A.Block | ||
.WithWithdrawalsRoot(TestItem.KeccakA) | ||
.WithWithdrawals(TestItem.WithdrawalA_1Eth) | ||
.WithExcessDataGas(1) | ||
.WithTransactions(Build.A.Transaction.WithBlobVersionedHashes(blobsCount).TestObject) | ||
.WithDataGasUsed(dataGasUsed) | ||
.WithExcessDataGas(0) | ||
.WithTransactions(Enumerable.Range(0, (int)(dataGasUsed / Eip4844Constants.DataGasPerBlob)) | ||
.Select(i => Build.A.Transaction.WithType(TxType.Blob) | ||
.WithMaxFeePerDataGas(ulong.MaxValue) | ||
.WithBlobVersionedHashes(1).TestObject).ToArray()) | ||
.TestObject); | ||
} | ||
|
||
public static IEnumerable<TestCaseData> DataGasFieldsPerForkTestCases | ||
{ | ||
get | ||
{ | ||
yield return new TestCaseData(Shanghai.Instance, null, null) | ||
{ | ||
TestName = "Data gas fields are not set pre-Cancun", | ||
ExpectedResult = true | ||
}; | ||
yield return new TestCaseData(Shanghai.Instance, 0ul, null) | ||
{ | ||
TestName = "DataGasUsed is set pre-Cancun", | ||
ExpectedResult = false | ||
}; | ||
yield return new TestCaseData(Shanghai.Instance, null, 0ul) | ||
{ | ||
TestName = "ExcessDataGas is set pre-Cancun", | ||
ExpectedResult = false | ||
}; | ||
yield return new TestCaseData(Shanghai.Instance, 0ul, 0ul) | ||
{ | ||
TestName = "Data gas fields are set pre-Cancun", | ||
ExpectedResult = false | ||
}; | ||
|
||
|
||
yield return new TestCaseData(Cancun.Instance, null, null) | ||
{ | ||
TestName = "Data gas fields are not set post-Cancun", | ||
ExpectedResult = false | ||
}; | ||
yield return new TestCaseData(Cancun.Instance, 0ul, null) | ||
{ | ||
TestName = "Just DataGasUsed is set post-Cancun", | ||
ExpectedResult = false | ||
}; | ||
yield return new TestCaseData(Cancun.Instance, null, 0ul) | ||
{ | ||
TestName = "Just ExcessDataGas is set post-Cancun", | ||
ExpectedResult = false | ||
}; | ||
yield return new TestCaseData(Cancun.Instance, 0ul, 0ul) | ||
{ | ||
TestName = "Data gas fields are set post-Cancun", | ||
ExpectedResult = true | ||
}; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.