Skip to content

Commit

Permalink
Transaction processor refactor (#5799)
Browse files Browse the repository at this point in the history
* Bump to 1.19.0-rc

* Disable removing tx index on archive (#5693)

(cherry picked from commit 76dd8bd)

* Add Shanghai hard-fork settings for Chiado testnet (#5688)

(cherry picked from commit b81686a)

* Split function into small

* If account exists

* Fix test

* AddToBalanceAndCreateIfNotExists

* Add required to sync message

* Extract some execution logic into methods

* start refactor

* continue refactor

* refactor finished?

* Fix: Swap BuyGas and IncNonce in TransactionProcessor

* Tests are all passing

* Fix test attribute

* fix fee paying on system txs

* use [TestCase] on [TestFixture] classes

* Change method ordering in TxProcessor

* Rename blk to header

* Add warning when tx sender doesn't exist

* Fix merge error

* AddToBalanceAndCreateIfNotExists

* Update TransactionProcessor.cs

* fix format

* Delete unused QuickFail

* Add tests

---------

Co-authored-by: Kamil Chodoła <kamil@nethermind.io>
Co-authored-by: Amirul Ashraf <asdacap@gmail.com>
Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com>
Co-authored-by: Nikita Mescheryakov <deffriann@proton.me>
Co-authored-by: Ahmad Bitar <33181301+smartprogrammer93@users.noreply.github.com>
Co-authored-by: smartprogrammer <smartprogrammer@windowslive.com>
Co-authored-by: Nikita Mescheryakov <deffriann@protonmail.com>
  • Loading branch information
8 people committed Jun 19, 2023
1 parent b2114af commit bed6a37
Show file tree
Hide file tree
Showing 8 changed files with 436 additions and 316 deletions.
2 changes: 1 addition & 1 deletion src/Nethermind/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
<_Parameter2>$(Commit)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

</Project>
60 changes: 48 additions & 12 deletions src/Nethermind/Nethermind.Evm.Test/TransactionProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void Will_not_cause_quick_fail_above_block_gas_limit_during_calls(bool wi
Assert.That(tracer.TxReceipts[0].StatusCode, Is.EqualTo(StatusCode.Success));
}

[Test]
[TestCase]
public void Balance_is_not_changed_on_call_and_restore()
{
long gasLimit = 100000;
Expand All @@ -279,7 +279,7 @@ public void Balance_is_not_changed_on_call_and_restore()
_stateProvider.GetBalance(TestItem.PrivateKeyA.Address).Should().Be(1.Ether());
}

[Test]
[TestCase]
public void Account_is_not_created_on_call_and_restore()
{
long gasLimit = 100000;
Expand All @@ -296,7 +296,7 @@ public void Account_is_not_created_on_call_and_restore()
_stateProvider.AccountExists(TestItem.PrivateKeyD.Address).Should().BeFalse();
}

[Test]
[TestCase]
public void Nonce_is_not_changed_on_call_and_restore()
{
long gasLimit = 100000;
Expand Down Expand Up @@ -330,6 +330,42 @@ public void Can_estimate_with_value(bool systemUser)
}

[Test]
public void Should_reject_tx_with_high_value()
{
Transaction tx = Build.A.Transaction.WithValue(UInt256.MaxValue).WithGasLimit(21000)
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, _isEip155Enabled)
.TestObject;

long blockNumber = _isEip155Enabled
? MainnetSpecProvider.ByzantiumBlockNumber
: MainnetSpecProvider.ByzantiumBlockNumber - 1;
Block block = Build.A.Block.WithNumber(blockNumber).WithTransactions(tx).TestObject;
BlockReceiptsTracer tracer = BuildTracer(block, tx, true, true);

Execute(tracer, tx, block);

tracer.TxReceipts[0].StatusCode.Should().Be(StatusCode.Failure);
}

[TestCase(562949953421312ul)]
[TestCase(562949953421311ul)]
public void Should_reject_tx_with_high_max_fee_per_gas(ulong topDigit)
{
Transaction tx = Build.A.Transaction.WithMaxFeePerGas(new(0, 0, 0, topDigit)).WithGasLimit(32768)
.WithType(TxType.EIP1559).WithValue(0)
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, _isEip155Enabled)
.TestObject;

long blockNumber = MainnetSpecProvider.LondonBlockNumber;
Block block = Build.A.Block.WithNumber(blockNumber).WithTransactions(tx).TestObject;
BlockReceiptsTracer tracer = BuildTracer(block, tx, true, true);

Execute(tracer, tx, block);

tracer.TxReceipts[0].StatusCode.Should().Be(StatusCode.Failure);
}

[TestCase]
public void Can_estimate_simple()
{
long gasLimit = 100000;
Expand All @@ -345,7 +381,7 @@ public void Can_estimate_simple()
estimator.Estimate(tx, block.Header, tracer).Should().Be(21000);
}

[Test]
[TestCase]
public void Can_estimate_with_refund()
{
byte[] initByteCode = Prepare.EvmCode
Expand Down Expand Up @@ -458,7 +494,7 @@ private void ConfirmEnoughEstimate(Transaction tx, Block block, long estimate)
}


[Test]
[TestCase]
public void Can_estimate_with_stipend()
{
byte[] initByteCode = Prepare.EvmCode
Expand Down Expand Up @@ -496,7 +532,7 @@ public void Can_estimate_with_stipend()



[Test]
[TestCase]
public void Can_estimate_with_stipend_and_refund()
{
byte[] initByteCode = Prepare.EvmCode
Expand Down Expand Up @@ -540,7 +576,7 @@ public void Can_estimate_with_stipend_and_refund()



[Test]
[TestCase]
public void Can_estimate_with_single_call()
{
byte[] initByteCode = Prepare.EvmCode
Expand Down Expand Up @@ -580,7 +616,7 @@ public void Can_estimate_with_single_call()



[Test]
[TestCase]
public void Disables_Eip158_for_system_transactions()
{
long blockNumber = MainnetSpecProvider.SpuriousDragonBlockNumber + 1;
Expand All @@ -601,7 +637,7 @@ public void Disables_Eip158_for_system_transactions()



[Test]
[TestCase]
public void Balance_is_changed_on_buildup_and_restored()
{
long gasLimit = 100000;
Expand All @@ -618,7 +654,7 @@ public void Balance_is_changed_on_buildup_and_restored()



[Test]
[TestCase]
public void Account_is_not_created_on_buildup_and_restore()
{
long gasLimit = 100000;
Expand All @@ -640,7 +676,7 @@ public void Account_is_not_created_on_buildup_and_restore()



[Test]
[TestCase]
public void Nonce_is_not_changed_on_buildup_and_restore()
{
long gasLimit = 100000;
Expand All @@ -656,7 +692,7 @@ public void Nonce_is_not_changed_on_buildup_and_restore()



[Test]
[TestCase]
public void State_changed_twice_in_buildup_should_have_correct_gas_cost()
{
long gasLimit = 100000;
Expand Down
Loading

0 comments on commit bed6a37

Please sign in to comment.