Skip to content

Commit d819ea2

Browse files
MarekM25smartprogrammer93marcindsobczakbenaadamsrubo
committed
Refactoring (#6635)
* Resolved conflicts * max body size for http json rpc (#36) * Format * Self-recovery of TxPool max capacity * fix ProcessedTransactionsDbCleanerTests * Update txPool worst value if removal unsuccessful (#6702) (cherry picked from commit f262cb2) * Clearer error message for missing starting block state (#6672) * Update txPool worst value if removal unsuccessful (#6702) * Add Cancun hard-fork settings for Gnosis (#6709) * Cancun spec and config for mainnet (#6679) * Add Paris release spec class for completeness (#6633) * 0.0.0.0 to + --------- Co-authored-by: smartprogrammer <smartprogrammer@windowslive.com> Co-authored-by: Marcin Sobczak <marcindsobczak@gmail.com> Co-authored-by: Ben Adams <thundercat@illyriad.co.uk> Co-authored-by: Ruben Buniatyan <rubo@users.noreply.github.com> Co-authored-by: Ahmad Bitar <33181301+smartprogrammer93@users.noreply.github.com> Co-authored-by: Kamil Chodoła <kamil@nethermind.io> Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
1 parent 73aaee0 commit d819ea2

File tree

51 files changed

+726
-7054
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+726
-7054
lines changed

.github/workflows/hive-consensus-tests.yml

Lines changed: 125 additions & 6584 deletions
Large diffs are not rendered by default.

src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,13 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
181181
stopwatch?.Start();
182182
List<(Block Block, string ExpectedException)> correctRlp = DecodeRlps(test, failOnInvalidRlp);
183183

184-
if (test.GenesisRlp == null)
185-
{
186-
test.GenesisRlp = Rlp.Encode(new Block(JsonToEthereumTest.Convert(test.GenesisBlockHeader)));
187-
}
184+
test.GenesisRlp ??= Rlp.Encode(new Block(JsonToEthereumTest.Convert(test.GenesisBlockHeader)));
188185

189186
Block genesisBlock = Rlp.Decode<Block>(test.GenesisRlp.Bytes);
190187
Assert.That(genesisBlock.Header.Hash, Is.EqualTo(new Hash256(test.GenesisBlockHeader.Hash)));
191188

192189
ManualResetEvent genesisProcessed = new(false);
190+
193191
blockTree.NewHeadBlock += (_, args) =>
194192
{
195193
if (args.Block.Number == 0)
@@ -271,7 +269,6 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
271269
{
272270
Assert.That(suggestedBlock.Header.Hash, Is.EqualTo(new Hash256(testBlockJson.BlockHeader.Hash)));
273271

274-
275272
for (int uncleIndex = 0; uncleIndex < suggestedBlock.Uncles.Length; uncleIndex++)
276273
{
277274
Assert.That(suggestedBlock.Uncles[uncleIndex].Hash, Is.EqualTo(new Hash256(testBlockJson.UncleHeaders[uncleIndex].Hash)));

src/Nethermind/Nethermind.AuRa.Test/AuRaSealValidatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ TestCaseData GetTestCaseData(
144144
public (bool, object) validate_params(BlockHeader parentBlock, BlockHeader block, Action<AuRaParameters> modifyParameters, Repeat repeat, bool parentIsHead, bool isValidSealer)
145145
{
146146
_blockTree.Head.Returns(parentIsHead ? new Block(parentBlock) : new Block(Build.A.BlockHeader.WithNumber(parentBlock.Number - 1).TestObject));
147-
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), block.Beneficiary, block.AuRaStep.Value).Returns(isValidSealer);
147+
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), block.Beneficiary, block.AuRaStep.Value, out _).Returns(isValidSealer);
148148

149149
object cause = null;
150150

src/Nethermind/Nethermind.AuRa.Test/AuRaSealerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public void Setup()
6060
public bool can_seal(long auRaStep, bool validSealer)
6161
{
6262
_auRaStepCalculator.CurrentStep.Returns(auRaStep);
63-
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), _address, auRaStep).Returns(validSealer);
63+
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), _address, auRaStep, out _).Returns(validSealer);
6464
return _auRaSealer.CanSeal(10, _blockTree.Head.Hash);
6565
}
6666

6767
[Test]
6868
public async Task seal_can_recover_address()
6969
{
7070
_auRaStepCalculator.CurrentStep.Returns(11);
71-
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), _address, 11).Returns(true);
71+
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), _address, 11, out _).Returns(true);
7272
Block block = Build.A.Block.WithHeader(Build.A.BlockHeader.WithBeneficiary(_address).WithAura(11, null).TestObject).TestObject;
7373

7474
block = await _auRaSealer.SealBlock(block, CancellationToken.None);

src/Nethermind/Nethermind.AuRa.Test/Validators/ListValidatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static IEnumerable ValidateTestCases
4848

4949
[TestCaseSource(nameof(ValidateTestCases))]
5050
public bool should_validate_correctly(Address address, long index) =>
51-
_validSealerStrategy.IsValidSealer(GetListValidator(TestItem.AddressA, TestItem.AddressB).Validators, address, index);
51+
_validSealerStrategy.IsValidSealer(GetListValidator(TestItem.AddressA, TestItem.AddressB).Validators, address, index, out _);
5252

5353
[TestCase(1)]
5454
[TestCase(2)]

src/Nethermind/Nethermind.Blockchain.Test/BlockchainProcessorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Block[] Process(Hash256 newBranchStateRoot, List<Block> suggestedBlocks,
7878
if (blockTracer != NullBlockTracer.Instance)
7979
{
8080
// this is for block reruns on failure for diag tracing
81-
throw new InvalidBlockException(suggestedBlocks[0]);
81+
throw new InvalidBlockException(suggestedBlocks[0], "wrong tracer");
8282
}
8383

8484
_logger.Info($"Processing {suggestedBlocks.Last().ToString(Block.Format.Short)}");
@@ -96,7 +96,7 @@ public Block[] Process(Hash256 newBranchStateRoot, List<Block> suggestedBlocks,
9696
{
9797
_allowedToFail.Remove(hash);
9898
BlockProcessed?.Invoke(this, new BlockProcessedEventArgs(suggestedBlocks.Last(), Array.Empty<TxReceipt>()));
99-
throw new InvalidBlockException(suggestedBlock);
99+
throw new InvalidBlockException(suggestedBlock, "allowed to fail");
100100
}
101101

102102
notYet = true;

src/Nethermind/Nethermind.Blockchain/InvalidBlockException.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ namespace Nethermind.Blockchain;
88

99
public class InvalidBlockException : BlockchainException
1010
{
11-
public InvalidBlockException(Block block, Exception? innerException = null)
12-
: base($"Invalid block: {block}", innerException) => InvalidBlock = block;
11+
public InvalidBlockException(Block block, string message, Exception? innerException = null)
12+
: base($"Invalid block: {block} : {message}", innerException) => InvalidBlock = block.Header;
1313

14-
public Block InvalidBlock { get; }
14+
public InvalidBlockException(BlockHeader block, string message, Exception? innerException = null)
15+
: base($"Invalid block: {block} : {message}", innerException) => InvalidBlock = block;
16+
17+
public BlockHeader InvalidBlock { get; }
1518
}

src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ private void ValidateGasLimit(Block block)
108108
BlockHeader parentHeader = GetParentHeader(block);
109109
if (_gasLimitOverride?.IsGasLimitValid(parentHeader, block.GasLimit, out long? expectedGasLimit) == false)
110110
{
111-
if (_logger.IsWarn) _logger.Warn($"Invalid gas limit for block {block.Number}, hash {block.Hash}, expected value from contract {expectedGasLimit}, but found {block.GasLimit}.");
112-
throw new InvalidBlockException(block);
111+
string reason = $"Invalid gas limit, expected value from contract {expectedGasLimit}, but found {block.GasLimit}";
112+
if (_logger.IsWarn) _logger.Warn($"Proposed block is not valid {block.ToString(Block.Format.FullHashAndNumber)}. {reason}.");
113+
throw new InvalidBlockException(block, reason);
113114
}
114115
}
115116

@@ -121,8 +122,9 @@ private void ValidateTxs(Block block)
121122
AddingTxEventArgs args = CheckTxPosdaoRules(new AddingTxEventArgs(i, tx, block, block.Transactions));
122123
if (args.Action != TxAction.Add)
123124
{
124-
if (_logger.IsWarn) _logger.Warn($"Proposed block is not valid {block.ToString(Block.Format.FullHashAndNumber)}. {tx.ToShortString()} doesn't have required permissions. Reason: {args.Reason}.");
125-
throw new InvalidBlockException(block);
125+
string reason = $"{tx.ToShortString()} doesn't have required permissions: {args.Reason}";
126+
if (_logger.IsWarn) _logger.Warn($"Proposed block is not valid {block.ToString(Block.Format.FullHashAndNumber)}. {reason}.");
127+
throw new InvalidBlockException(block, reason);
126128
}
127129
}
128130
}

src/Nethermind/Nethermind.Consensus.AuRa/AuRaSealValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public bool ValidateParams(BlockHeader parent, BlockHeader header, bool isUncle
7575
// no worries we do this validation later before processing the block
7676
if (parent.Hash == _blockTree.Head?.Hash)
7777
{
78-
if (!_validSealerStrategy.IsValidSealer(_validatorStore.GetValidators(), header.Beneficiary, step))
78+
if (!_validSealerStrategy.IsValidSealer(_validatorStore.GetValidators(), header.Beneficiary, step, out Address expectedAddress))
7979
{
80-
if (_logger.IsError) _logger.Error($"Block from incorrect proposer at block {header.ToString(BlockHeader.Format.FullHashAndNumber)}, step {step} from author {header.Beneficiary}.");
80+
if (_logger.IsError) _logger.Error($"Proposed block is not valid {header.ToString(BlockHeader.Format.FullHashAndNumber)}. Incorrect proposer at step {step}, expected {expectedAddress}, but found {header.Beneficiary}.");
8181
return false;
8282
}
8383
}

src/Nethermind/Nethermind.Consensus.AuRa/AuRaSealer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ bool StepNotYetProduced(long step) => !_blockTree.Head.Header.AuRaStep.HasValue
7474

7575
bool IsThisNodeTurn(long step)
7676
{
77-
var validators = _validatorStore.GetValidators();
78-
return _validSealerStrategy.IsValidSealer(validators, _signer.Address, step);
77+
Address[] validators = _validatorStore.GetValidators();
78+
return _validSealerStrategy.IsValidSealer(validators, _signer.Address, step, out _);
7979
}
8080

8181
long currentStep = _auRaStepCalculator.CurrentStep;

0 commit comments

Comments
 (0)