-
Notifications
You must be signed in to change notification settings - Fork 599
Add shard blob tx gas calculations #5596
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
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6cd45c7
Add data gas calculations
flcl42 7886362
ChainSpecs/BlockProcessing: Fix syncing on Genesis block due to Exces…
spencer-tb 2cd8bd7
TxValidator: Move KZG version check into network wrapper verification.
spencer-tb da546b4
ExcessData gas on genesis block
flcl42 1fa67f8
Check versioned hash earlier
flcl42 bd49c9d
Remake gas, preview
flcl42 a7120a8
Fix recursion
flcl42 6630c96
Add tests, refactor
flcl42 f363565
Get rid of parent block header finder
flcl42 2127d3b
Clean up
flcl42 4548a9f
Clean up checks
flcl42 d86ec23
Fix tests
flcl42 a132a10
Fix header mapping to rpc
flcl42 25b56af
Fix data gas calculations
flcl42 f0a5e4c
Add safety checks
flcl42 4fc22f1
Fix and improve
flcl42 3e6253d
Blob gas info in receipts (#5767)
deffrian 14e9ce2
Increase data gas limits
flcl42 7c61b53
Clean up
flcl42 d41f110
Add more blob space
flcl42 d2b5311
Fix tests; clean up
flcl42 9913404
Add tests, refacator
flcl42 d093db7
Merge remote-tracking branch 'origin/master' into feature/eip-4844-ga…
flcl42 6105dfb
Fix MaxFeePerDataGas affects consensus on low balance
flcl42 da4d479
Improve max fee per data gas fix
flcl42 a681613
Fix receipts
flcl42 9f25cb6
Merge remote-tracking branch 'origin/master' into feature/eip-4844-ga…
flcl42 ec698ab
Merge remote-tracking branch 'origin/master' into feature/eip-4844-ga…
flcl42 8c2dc1d
Add overflow checks
flcl42 8a73222
Fix tests
flcl42 c307703
Fix encoding; improve text; clean up
flcl42 e7d3e4c
Merge remote-tracking branch 'origin/master' into feature/eip-4844-ga…
flcl42 06f9de5
Merge remote-tracking branch 'origin/master' into feature/eip-4844-ga…
flcl42 b7bc7b6
Merge remote-tracking branch 'origin/master' into feature/eip-4844-ga…
flcl42 f8fdd8d
Add gas fields to the local 4844 network genesis
flcl42 2a66fb5
Refactor BlockValidator
flcl42 fbdf0a9
Add additional check
flcl42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.