Skip to content
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

Refactor TxValidator #7386

Merged
merged 28 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f045e23
Add default interface implementation
emlautarom1 Sep 3, 2024
6eeec81
Separate all validators
emlautarom1 Sep 3, 2024
6cef6ef
Merge signature validation
emlautarom1 Sep 3, 2024
a5758b8
Move to primary constructor
emlautarom1 Sep 3, 2024
cb523bd
Update `OptimismTxValidator`
emlautarom1 Sep 3, 2024
f6f0c92
Reorder imports (avoid diff)
emlautarom1 Sep 3, 2024
7d85f1e
`IntrinsicGasTxValidator`: Use singleton
emlautarom1 Sep 3, 2024
17ff03f
`ContractSizeTxValidator`: Use singleton
emlautarom1 Sep 3, 2024
37f626d
`NonBlobFieldsTxValidator`: Use singleton
emlautarom1 Sep 3, 2024
53f184c
`SignatureTxValidator`: Use singleton
emlautarom1 Sep 3, 2024
5f5dce2
`GasFieldsTxValidator`: Use singleton
emlautarom1 Sep 3, 2024
dd15a56
Use singleton for BlobTxValidator internals
emlautarom1 Sep 3, 2024
b416151
Merge branch 'master' into refactor/tx-validator
emlautarom1 Sep 4, 2024
1a95ca6
Move everything to the same file
emlautarom1 Sep 4, 2024
1430dc5
Rename `AddValidator` to `WithValidator`
emlautarom1 Sep 6, 2024
750e3fa
Use `<remarks>` instead of `<summary>`
emlautarom1 Sep 6, 2024
84dce88
Remove unnecessary nullability annotation
emlautarom1 Sep 6, 2024
86bc383
Rename `AdditonalCheck` to `ValidateChainId`
emlautarom1 Sep 6, 2024
1691e20
Use `static` modifier in lambdas when possible
emlautarom1 Sep 6, 2024
644ac9a
Remove `IsWellFormed` with no error message
emlautarom1 Sep 6, 2024
d4091c9
Add Blob EIP4844 no EIP1559 validation test
emlautarom1 Sep 6, 2024
fff2f90
Change `<summary>` to `<remark>`
emlautarom1 Sep 6, 2024
5e14c71
Add `bad gas fields` test with EIP1559 disabled
emlautarom1 Sep 6, 2024
04d7fff
Add remarks to tests
emlautarom1 Sep 6, 2024
840d3a3
Use small array instead of `Dictionary`
emlautarom1 Sep 6, 2024
9437715
Merge branch 'master' into refactor/tx-validator
emlautarom1 Sep 6, 2024
ec0d5a2
Refactor 'TxValidator' further (#7402)
LukaszRozmej Sep 9, 2024
0b5d838
Merge remote-tracking branch 'origin/master' into refactor/tx-validator
LukaszRozmej Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Api/IApiWithBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public interface IApiWithBlockchain : IApiWithStores, IBlockchainBridgeFactory
IHealthHintService? HealthHintService { get; set; }
IRpcCapabilitiesProvider? RpcCapabilitiesProvider { get; set; }
ITransactionComparerProvider? TransactionComparerProvider { get; set; }
ITxValidator? TxValidator { get; set; }
TxValidator? TxValidator { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like this to remain an interface. Any reason not to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required due to the change on NethermindApi


/// <summary>
/// Manager of block finalization
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Api/NethermindApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public ISealEngine SealEngine
public ITxPoolInfoProvider? TxPoolInfoProvider { get; set; }
public IHealthHintService? HealthHintService { get; set; }
public IRpcCapabilitiesProvider? RpcCapabilitiesProvider { get; set; }
public ITxValidator? TxValidator { get; set; }
public TxValidator? TxValidator { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like this to remain an interface. Any reason not to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change it to a concrete class since during initialization we might want to register validators for new TxTypes:

_api.TxValidator.WithValidator(TxType.DepositTx, new OptimismTxValidator()),

public IBlockFinalizationManager? FinalizationManager { get; set; }
public IGasLimitCalculator? GasLimitCalculator { get; set; }

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,50 @@ public void IsWellFormed_BlobTxHasProofOverTheSizeLimit_ReturnFalse()
Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance, out error), Is.False);
}

/// <remarks>
/// According to https://github.com/ethereum/EIPs/blob/e2c094cd0f50303eddcfb87f36899e00545dcaaf/EIPS/eip-4844.md?plain=1#L11
/// EIP 4844 implies 1559, thus the <c>ReleaseSpec</c> we're constructing here should not be possible.
/// </remarks>
[Test]
public void BlobTransactions_are_valid_with_eip4844_no_eip1559()
{
Transaction tx = Build.A.Transaction
.WithType(TxType.Blob)
.WithTimestamp(ulong.MaxValue)
.WithTo(TestItem.AddressA)
.WithMaxFeePerGas(1)
.WithMaxFeePerBlobGas(1)
.WithBlobVersionedHashes(1)
.WithChainId(TestBlockchainIds.ChainId)
.SignedAndResolved().TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
IReleaseSpec releaseSpec = new ReleaseSpec() { IsEip4844Enabled = true, IsEip1559Enabled = false };

txValidator.IsWellFormed(tx, releaseSpec).Should().BeTrue();
}

/// Same as <see cref="BlobTransactions_are_valid_with_eip4844_no_eip1559"/>
[Test]
public void BlobTransactions_bad_gas_fields_is_valid_when_no_eip1559()
{
Transaction tx = Build.A.Transaction
.WithType(TxType.Blob)
.WithTimestamp(ulong.MaxValue)
.WithTo(TestItem.AddressA)
.WithMaxFeePerGas(1)
.WithMaxPriorityFeePerGas(2)
.WithMaxFeePerBlobGas(1)
.WithBlobVersionedHashes(1)
.WithChainId(TestBlockchainIds.ChainId)
.SignedAndResolved().TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
IReleaseSpec releaseSpec = new ReleaseSpec() { IsEip4844Enabled = true, IsEip1559Enabled = false };

txValidator.IsWellFormed(tx, releaseSpec).Should().BeTrue();
}

private static byte[] MakeArray(int count, params byte[] elements) =>
elements.Take(Math.Min(count, elements.Length))
.Concat(new byte[Math.Max(0, count - elements.Length)])
Expand Down
Loading