Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,44 @@ public void ValidateProcessedBlock_StateRootIsWrong_ErrorIsSet()
Assert.That(error, Does.StartWith("InvalidStateRoot"));
}

[Test]
public void ValidateProcessedBlock_ReceiptCountMismatch_DoesNotThrow()
{
TxValidator txValidator = new(TestBlockchainIds.ChainId);
ISpecProvider specProvider = Substitute.For<ISpecProvider>();
BlockValidator sut = new(txValidator, Always.Valid, Always.Valid, specProvider, LimboLogs.Instance);
Block suggestedBlock = Build.A.Block.TestObject;
Block processedBlock = Build.A.Block
.WithStateRoot(Keccak.Zero)
.WithTransactions(2, specProvider)
.TestObject;

Assert.DoesNotThrow(() => sut.ValidateProcessedBlock(
processedBlock,
[],
suggestedBlock));
}

[Test]
public void ValidateProcessedBlock_ReceiptCountMismatch_ReturnsFalse()
{
TxValidator txValidator = new(TestBlockchainIds.ChainId);
ISpecProvider specProvider = Substitute.For<ISpecProvider>();
BlockValidator sut = new(txValidator, Always.Valid, Always.Valid, specProvider, LimboLogs.Instance);
Block suggestedBlock = Build.A.Block.TestObject;
Block processedBlock = Build.A.Block
.WithStateRoot(Keccak.Zero)
.WithTransactions(3, specProvider)
.TestObject;

bool result = sut.ValidateProcessedBlock(
processedBlock,
[Build.A.Receipt.TestObject],
suggestedBlock);

Assert.That(result, Is.False);
}

private static IEnumerable<TestCaseData> BadSuggestedBlocks()
{
BlockHeader parent = Build.A.BlockHeader.TestObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,20 @@ public bool ValidateProcessedBlock(Block processedBlock, TxReceipt[] receipts, B
error ??= BlockErrorMessages.InvalidRequestsHash(suggestedBlock.Header.RequestsHash, processedBlock.Header.RequestsHash);
}

for (int i = 0; i < processedBlock.Transactions.Length; i++)
if (receipts.Length != processedBlock.Transactions.Length)
{
if (receipts[i].Error is not null && receipts[i].GasUsed == 0 && receipts[i].Error == "invalid")
if (_logger.IsWarn) _logger.Warn($"- receipt count mismatch: expected {processedBlock.Transactions.Length} receipts to match transaction count, got {receipts.Length}");
error ??= BlockErrorMessages.ReceiptCountMismatch(processedBlock.Transactions.Length, receipts.Length);
}
else
{
for (int i = 0; i < processedBlock.Transactions.Length; i++)
{
if (_logger.IsWarn) _logger.Warn($"- invalid transaction {i}");
error ??= BlockErrorMessages.InvalidTxInBlock(i);
if (receipts[i].Error is not null && receipts[i].GasUsed == 0 && receipts[i].Error == "invalid")
{
if (_logger.IsWarn) _logger.Warn($"- invalid transaction {i}");
error ??= BlockErrorMessages.InvalidTxInBlock(i);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Core/Messages/BlockErrorMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,7 @@ public static string InvalidDepositEventLayout(string error) =>

public static string ExceededBlockSizeLimit(int limit) =>
$"ExceededBlockSizeLimit: Exceeded block size limit of {limit} bytes.";

public static string ReceiptCountMismatch(int expectedCount, int actualCount) =>
$"ReceiptCountMismatch: Expected {expectedCount} receipts to match transaction count, but got {actualCount}.";
}