Skip to content

feat: implement deferred state updates for message validation - #1

Closed
diegomrsantos wants to merge 4 commits into
feat/fork-infrastructurefrom
feat/deferred-validation-state
Closed

diegomrsantos wants to merge 4 commits into
feat/fork-infrastructurefrom
feat/deferred-validation-state

Conversation

@diegomrsantos

Copy link
Copy Markdown
Owner

Issue Addressed

Improves message validation architecture by separating validation logic from state mutation.

Proposed Changes

  1. Add StateUpdate types - New types to capture deferred state changes:

    • StateUpdate enum with None, Consensus, and PartialSignature variants
    • ConsensusStateUpdate and PartialSignatureStateUpdate structs
  2. Add apply methods - New methods to apply deferred state updates:

    • DutyState::apply_consensus_update()
    • DutyState::apply_partial_signature_update()
  3. Refactor validation - Validation functions now return (ValidatedSSVMessage, StateUpdate) instead of mutating state directly

  4. Explicit commit - Validator::commit() method to apply state updates when processing

Motivation

Validation should be a pure operation that doesn't produce side effects. By returning a StateUpdate instead of mutating state during validation, callers have explicit control over when state changes are applied. This makes the code easier to reason about and test.

Additional Info

  • All existing tests pass
  • The old update_* methods are kept for test compatibility
  • Added #[must_use] to StateUpdate to prevent accidental omission of commit

diegomrsantos and others added 4 commits January 14, 2026 21:49
Add new types to represent deferred state changes from message validation:
- StateUpdate enum with None, Consensus, and PartialSignature variants
- ConsensusStateUpdate captures signers, slot, epoch, round, message type
- PartialSignatureStateUpdate captures signer, slot, epoch, kind

This separation allows validation checks to be decoupled from state
mutations, enabling callers to decide when/if to apply state changes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add methods to DutyState, OperatorState, and SignerState to apply
deferred state updates:
- DutyState::apply_consensus_update()
- DutyState::apply_partial_signature_update()
- OperatorState::apply_consensus_update()
- SignerState::apply_update()

These methods mirror the existing update methods but take pre-computed
StateUpdate values instead of raw messages, enabling deferred application.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactor validation functions to return StateUpdate alongside the
validated message instead of mutating state directly:

- validate_consensus_message returns (ValidatedSSVMessage, StateUpdate)
- validate_partial_signature_message returns (ValidatedSSVMessage, StateUpdate)
- ValidatedMessage now includes state_update field
- Validator::commit() applies deferred state updates

This enables callers to decide when to apply state changes, which is
important for fork transitions where messages may be validated on
multiple topics but should only update state once.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Call Validator::commit() to apply deferred state updates when a
validated message is actually processed.

The commit happens after all checks pass (ownership verification,
doppelganger check) but before dispatching to QBFT or signature
collector, ensuring state is only updated for messages we will process.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant