Skip to content

Conversation

@LukaszRozmej
Copy link
Member

@LukaszRozmej LukaszRozmej commented Sep 30, 2025

We have something like ValidateOrphanedBlock used in some occasions in NewPayload and EraSync.
This validations were severely lacking. Updating them to have as much validations on BlockBody (basically all) and Header (the ones that don't need parent). Keep as much of the code reusable to force future changes to think of both cases.

Changes

  • Make parent in Validations non-optional
  • Add IHeaderValidator.ValidateOrphan method
  • Make Both paths (orphan and not) use same code path in HeaderValidator and BlockValidator with OnFlag for orphan to not miss orphan validation logic when adding new validations and in derived classes.
  • Some additional refactors, simplifications, unifications, removal of unused stuff

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Refactoring

Testing

Requires testing

  • Yes

If yes, did you write tests?

  • Yes

@LukaszRozmej LukaszRozmej changed the title Harden Orphan Block validations Harden Orphaned Block validations Oct 1, 2025
@Marchhill Marchhill requested review from Marchhill and asdacap and removed request for ak88 October 1, 2025 09:46
@benaadams benaadams requested a review from Copilot October 1, 2025 10:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR hardens orphaned block validations by improving validation consistency between regular blocks and orphaned blocks. The main purpose is to ensure that orphaned block validation (used in operations like NewPayload and EraSync) receives proper validation coverage.

  • Unified validation paths between regular and orphaned blocks to prevent missed validations
  • Added a new ValidateOrphan method to IHeaderValidator interface
  • Made parent parameters non-optional in various validation methods for consistency

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Nethermind/Nethermind.Consensus/Validators/HeaderValidator.cs Core validation logic refactored to use generic type flags for orphaned vs regular blocks
src/Nethermind/Nethermind.Consensus/Validators/BlockValidator.cs Block validation unified with orphaned validation using type flags
src/Nethermind/Nethermind.Consensus/Validators/IHeaderValidator.cs Added ValidateOrphaned method to interface
src/Nethermind/Nethermind.Consensus/Validators/IBlockValidator.cs Updated signatures to make parent parameter non-optional
src/Nethermind/Nethermind.Core/TypeFlags.cs Fixed interface method order for virtual static properties
Various validator implementations Updated to match new interface signatures and use type flags
Test files Updated to use new non-optional parent parameters and simplified test code

Copy link
Contributor

@Marchhill Marchhill left a comment

Choose a reason for hiding this comment

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

Looks good, only thing is whether to use this template approach to specify an orphaned blocks. It's fine but seems a bit less clear to me than having another argument and overloading

if (validateHashes)
private bool ValidateBlockSize(Block block, IReleaseSpec spec, ref string? errorMessage)
{
int encodedSize = block.EncodedSize ?? _blockDecoder.GetLength(block, RlpBehaviors.None);
Copy link
Contributor

Choose a reason for hiding this comment

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

small optimisation: could calculate the encoded size only if Eip7934 is enabled

protected readonly ISpecProvider _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider));
private readonly long? _daoBlockNumber = specProvider.DaoBlockNumber;
protected readonly ILogger _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
private readonly IBlockTree _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
Copy link
Contributor

@ak88 ak88 Oct 1, 2025

Choose a reason for hiding this comment

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

Since we dont get parent blocks anymore, maybe we can just pass genesis difficulty instead, and remove this dependency

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, not necessarily in this PR. @asdacap could you help with how to set it up in DI?

Copy link
Contributor

@emlautarom1 emlautarom1 left a comment

Choose a reason for hiding this comment

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

Just one comment on OP stack.

@LukaszRozmej
Copy link
Member Author

ok this is enough approvals for me

@LukaszRozmej LukaszRozmej merged commit 9647571 into master Oct 1, 2025
138 of 141 checks passed
@LukaszRozmej LukaszRozmej deleted the fix/harden-orphan-validation branch October 1, 2025 17:51
@LukaszRozmej LukaszRozmej mentioned this pull request Nov 4, 2025
3 tasks
flcl42 added a commit that referenced this pull request Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants