Skip to content

feat(flashblocks): Extract Validation & Sequencing Logic from StateProcessor #310

@refcell

Description

@refcell

Summary

Extract pure validation logic from StateProcessor into dedicated, unit-testable types.

This is a first pass at incremental refactoring to improve flashblocks testability and legibility.

Problem

Flashblock validation logic is embedded in StateProcessor::process_flashblock() and is_next_flashblock(), making it impossible to unit test without the full integration harness.

Solution

Create src/validation.rs with three pure types:

1. FlashblockSequenceValidator - Validates flashblock ordering

pub enum FlashblockValidation {
    NextInBlock,
    FirstOfNextBlock,
    Duplicate,
    NonSequentialGap { expected: u64, got: u64 },
    NewBlockNonZeroIndex { block_number: u64, index: u64 },
}

2. ReorgDetector - Detects chain reorgs by comparing tx sets

pub enum ReorgDetection {
    NoReorg,
    Reorg { expected_count: usize, actual_count: usize },
}

3. ReconciliationStrategy - Explicit handling strategies for canonical blocks

pub enum ReconciliationStrategy {
    CatchUp { canonical_block: u64 },
    Reorg { from_block: u64 },
    DepthExceeded { depth: u64, max_depth: u64 },
    Continue,
}

Acceptance

  • Unit tests for all validation states
  • Integration tests still pass
  • No public API changes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions