-
Notifications
You must be signed in to change notification settings - Fork 719
perf(prewarm): execute warm transactions with real fee and nonce semantics #12413
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
9 commits
Select commit
Hold shift + click to select a range
9404fdb
perf(prewarm): execute warm transactions with real fee and nonce sema…
svlachakis a56b945
fix(prewarm): update the warmup contract tests; charge underfunded wa…
svlachakis f61022a
test(prewarm): reproduce the same-sender deploy-chain warming bug
svlachakis 2e70e1d
Merge branch 'master' into perf/warmup-fidelity
svlachakis 9a82db7
Merge branch 'master' into perf/warmup-fidelity
svlachakis b3e8904
Merge remote-tracking branch 'origin/master' into perf/warmup-fidelity
svlachakis fa8c1d6
Merge branch 'master' into perf/warmup-fidelity
svlachakis b40b768
Merge branch 'master' into perf/warmup-fidelity
svlachakis 6a943ec
docs: shorten warmup comments
svlachakis 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
158 changes: 158 additions & 0 deletions
158
src/Nethermind/Nethermind.Evm.Test/TransactionProcessorWarmupTests.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 |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using System; | ||
| using Nethermind.Blockchain; | ||
| using Nethermind.Core; | ||
| using Nethermind.Core.Extensions; | ||
| using Nethermind.Core.Specs; | ||
| using Nethermind.Core.Test; | ||
| using Nethermind.Core.Test.Builders; | ||
| using Nethermind.Crypto; | ||
| using Nethermind.Evm.State; | ||
| using Nethermind.Evm.Tracing; | ||
| using Nethermind.Evm.TransactionProcessing; | ||
| using Nethermind.Int256; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Specs; | ||
| using Nethermind.Specs.Forks; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Nethermind.Evm.Test; | ||
|
|
||
| public class TransactionProcessorWarmupTests | ||
| { | ||
| private ISpecProvider _specProvider = null!; | ||
| private IEthereumEcdsa _ethereumEcdsa = null!; | ||
| private ITransactionProcessor _transactionProcessor = null!; | ||
| private IWorldState _stateProvider = null!; | ||
| private IDisposable _worldStateCloser = null!; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| _specProvider = new TestSpecProvider(Prague.Instance); | ||
| _stateProvider = TestWorldStateFactory.CreateForTest(); | ||
| _worldStateCloser = _stateProvider.BeginScope(IWorldState.PreGenesis); | ||
| EthereumCodeInfoRepository codeInfoRepository = new(_stateProvider); | ||
| EthereumVirtualMachine virtualMachine = new(new TestBlockhashProvider(_specProvider), _specProvider, LimboLogs.Instance); | ||
| _transactionProcessor = new EthereumTransactionProcessor(BlobBaseFeeCalculator.Instance, _specProvider, _stateProvider, virtualMachine, codeInfoRepository, LimboLogs.Instance); | ||
| _ethereumEcdsa = new EthereumEcdsa(_specProvider.ChainId); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() => _worldStateCloser?.Dispose(); | ||
|
|
||
| // Warmup must take the real execution path: no-op fee/nonce handling made same-sender | ||
| // warm sequences run with undebited balances and unbumped nonces, so deploy chains | ||
| // computed wrong CREATE addresses and warmed the wrong state. | ||
| [Test] | ||
| public void Warmup_InTheThrowawayScope_DebitsFeesAndBumpsTheNonce() | ||
| { | ||
| _stateProvider.CreateAccount(TestItem.AddressA, 1.Ether); | ||
| _stateProvider.Commit(_specProvider.GenesisSpec); | ||
| _stateProvider.CommitTree(0); | ||
|
|
||
| Transaction tx = Build.A.Transaction | ||
| .WithGasPrice(1) | ||
| .WithMaxFeePerGas(1) | ||
| .WithTo(TestItem.AddressB) | ||
| .WithValue(100.GWei) | ||
| .WithGasLimit(100_000) | ||
| .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA) | ||
| .TestObject; | ||
| Block block = Build.A.Block | ||
| .WithNumber(long.MaxValue) | ||
| .WithTimestamp(MainnetSpecProvider.PragueBlockTimestamp) | ||
| .WithTransactions(tx) | ||
| .WithGasLimit(10_000_000) | ||
| .TestObject; | ||
| UInt256 balanceBefore = _stateProvider.GetBalance(TestItem.AddressA); | ||
|
|
||
| _transactionProcessor.SetBlockExecutionContext(new BlockExecutionContext(block.Header, _specProvider.GetSpec(block.Header))); | ||
| TransactionResult result = _transactionProcessor.Warmup(tx, NullTxTracer.Instance); | ||
|
|
||
| Assert.That(result.TransactionExecuted, Is.True, "precondition: the warm execution ran"); | ||
| Assert.That(_stateProvider.GetNonce(TestItem.AddressA), Is.EqualTo(1UL), | ||
| "a warm execution must bump the nonce so a same-sender successor warms the right state"); | ||
| Assert.That(_stateProvider.GetBalance(TestItem.AddressA), Is.EqualTo(balanceBefore - 100.GWei - 21_000), | ||
| "a warm execution must debit value and gas so successors see real balances"); | ||
| Assert.That(tx.BlockGasUsed, Is.EqualTo(100_000UL), | ||
| "warmup must never mutate the shared transaction object: the getter must still fall back to the gas limit"); | ||
| } | ||
|
|
||
| // A sender funded earlier in the block by another sender's transaction has no balance in | ||
| // the parent state; per-sender warm groups cannot see that funding, so the warm pass must | ||
| // execute best-effort instead of losing the sender's warming to the balance check. | ||
| [Test] | ||
| public void Warmup_ForASenderWithoutParentStateBalance_StillExecutes() | ||
| { | ||
| _stateProvider.CreateAccount(TestItem.AddressA, UInt256.Zero); | ||
| _stateProvider.Commit(_specProvider.GenesisSpec); | ||
| _stateProvider.CommitTree(0); | ||
|
|
||
| Transaction tx = Build.A.Transaction | ||
| .WithGasPrice(1) | ||
| .WithMaxFeePerGas(1) | ||
| .WithTo(TestItem.AddressB) | ||
| .WithGasLimit(100_000) | ||
| .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA) | ||
| .TestObject; | ||
| Block block = Build.A.Block | ||
| .WithNumber(long.MaxValue) | ||
| .WithTimestamp(MainnetSpecProvider.PragueBlockTimestamp) | ||
| .WithTransactions(tx) | ||
| .WithGasLimit(10_000_000) | ||
| .TestObject; | ||
|
|
||
| _transactionProcessor.SetBlockExecutionContext(new BlockExecutionContext(block.Header, _specProvider.GetSpec(block.Header))); | ||
| TransactionResult result = _transactionProcessor.Warmup(tx, NullTxTracer.Instance); | ||
|
|
||
| Assert.That(result.TransactionExecuted, Is.True, | ||
| "an underfunded warm sender must still warm its execution path"); | ||
| Assert.That(_stateProvider.GetNonce(TestItem.AddressA), Is.EqualTo(1UL)); | ||
| } | ||
|
|
||
| // The motivating bug: with no-op nonce handling, every deploy in a same-sender warm chain | ||
| // computed the same CREATE address and warmed the wrong storage. With real semantics each | ||
| // deploy must land where the real execution will put it. | ||
| [Test] | ||
| public void Warmup_ForASameSenderDeployChain_DeploysAtConsecutiveCreateAddresses() | ||
| { | ||
| _stateProvider.CreateAccount(TestItem.AddressA, 1.Ether); | ||
| _stateProvider.Commit(_specProvider.GenesisSpec); | ||
| _stateProvider.CommitTree(0); | ||
|
|
||
| Transaction firstDeploy = Build.A.Transaction | ||
| .WithGasPrice(1) | ||
| .WithMaxFeePerGas(1) | ||
| .WithTo(null) | ||
| .WithNonce(0) | ||
| .WithGasLimit(100_000) | ||
| .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA) | ||
| .TestObject; | ||
| Transaction secondDeploy = Build.A.Transaction | ||
| .WithGasPrice(1) | ||
| .WithMaxFeePerGas(1) | ||
| .WithTo(null) | ||
| .WithNonce(1) | ||
| .WithGasLimit(100_000) | ||
| .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA) | ||
| .TestObject; | ||
| Block block = Build.A.Block | ||
| .WithNumber(long.MaxValue) | ||
| .WithTimestamp(MainnetSpecProvider.PragueBlockTimestamp) | ||
| .WithTransactions(firstDeploy, secondDeploy) | ||
| .WithGasLimit(10_000_000) | ||
| .TestObject; | ||
|
|
||
| _transactionProcessor.SetBlockExecutionContext(new BlockExecutionContext(block.Header, _specProvider.GetSpec(block.Header))); | ||
| _transactionProcessor.Warmup(firstDeploy, NullTxTracer.Instance); | ||
| _transactionProcessor.Warmup(secondDeploy, NullTxTracer.Instance); | ||
|
|
||
| Assert.That(_stateProvider.AccountExists(ContractAddress.From(TestItem.AddressA, 0)), Is.True, | ||
| "the first deploy must land at the nonce-0 CREATE address"); | ||
| Assert.That(_stateProvider.AccountExists(ContractAddress.From(TestItem.AddressA, 1)), Is.True, | ||
| "the successor must observe the bumped nonce and deploy at the nonce-1 CREATE address"); | ||
| } | ||
| } | ||
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.