Repository navigation
feat: implement deferred state updates for message validation - #1
Closed
diegomrsantos wants to merge 4 commits into
Closed
diegomrsantos wants to merge 4 commits into
diegomrsantos wants to merge 4 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Addressed
Improves message validation architecture by separating validation logic from state mutation.
Proposed Changes
Add StateUpdate types - New types to capture deferred state changes:
StateUpdateenum withNone,Consensus, andPartialSignaturevariantsConsensusStateUpdateandPartialSignatureStateUpdatestructsAdd apply methods - New methods to apply deferred state updates:
DutyState::apply_consensus_update()DutyState::apply_partial_signature_update()Refactor validation - Validation functions now return
(ValidatedSSVMessage, StateUpdate)instead of mutating state directlyExplicit commit -
Validator::commit()method to apply state updates when processingMotivation
Validation should be a pure operation that doesn't produce side effects. By returning a
StateUpdateinstead 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
update_*methods are kept for test compatibility#[must_use]toStateUpdateto prevent accidental omission of commit