Skip to content

ParentMismatch is matched twice: #263 silently shadowed the handler #220 added #280

Open

Description

@SDL-A1

Migrated from SergioDemianLerner/rustock#280 (issue by @SDL-A1, 2026-10-07).
Original: SergioDemianLerner/rustock#280

What

Violation::ParentMismatch appears in two arms of the same match in crates/sync/src/service.rs:

2103:  Violation::ParentMismatch { at, .. } => {
2104:      warn!("Canonical index does not link at #{at}; repairing lineage");
           self.repair_canonical_gap(cursor.validated_head.number, at.saturating_sub(1));
       }
       ...
       // I1, I2, I3: the chain between the executed head and the head is not
       // contiguous. Reported correctly and acted on never, so the node stood
       // still -- execution asks for blocks across the break, fails, and
       // retries from the same place.
2148:  Violation::NoCanonicalEntry { at }
2149:  | Violation::CanonicalHeaderMissing { at, .. }
2150:  | Violation::ParentMismatch { at, .. } => {
2151:      self.reseat_head_above_executed(at);
       }

Rust takes match arms in order, so the second ParentMismatch is dead. reseat_head_above_executed never runs for it. Clippy reports it as unreachable pattern at service.rs:2150:23.

How it got there

48f893d  2026-09-30  Restore the sync guards reverted with #215, re-reviewed (#220)
         added the reseat arm, including ParentMismatch

8498a05  2026-10-05  Detect and repair a canonical index that does not link to itself (#263)
         added the repair arm ABOVE it

So #263 took over ParentMismatch handling from #220 without removing the now-dead pattern. Nothing caught it because clippy has never run in CI.

Why it matters

The comment on the shadowed arm says these violations were "Reported correctly and acted on never, so the node stood still" -- reseating was the fix for that. For ParentMismatch, that fix is now unreachable, and the only response is repair_canonical_gap.

This is the code path behind the mainnet wedge at #9,296,505 that cost 33 hours.

The question

Is the current behaviour intended?

  • If yes -- repair_canonical_gap supersedes reseating, because repairing the index removes the need -- then the dead pattern should be deleted from the second arm and the comment updated, so the code stops implying both apply.
  • If no -- a ParentMismatch that repair_canonical_gap does not resolve now leaves the node without the reseat that Restore the sync guards reverted with #215, re-reviewed #220 added for exactly that case -- then the arms need reordering or the repair arm needs to fall through to a reseat.

Deliberately not changed either way: deleting the dead pattern would silence clippy while preserving whichever behaviour is there, which is the wrong move if the answer is "no".

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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