Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate user interrupt and terminating due to errors in SessionOutome #58

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Serialization format is a part of `SessionParameters` now; `Round` and `Protocol` methods receive dynamic serializers/deserializers. ([#33])
- Renamed `(Verified)MessageBundle` to `(Verified)Message`. Both are now generic over `Verifier`. ([#56])
- `Session::preprocess_message()` now returns a `PreprocessOutcome` instead of just an `Option`. ([#57])
- `Session::terminate_due_to_errors()` replaces `terminate()`; `terminate()` now signals user interrupt. ([#58])


### Added
Expand All @@ -41,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#47]: https://github.com/entropyxyz/manul/pull/47
[#56]: https://github.com/entropyxyz/manul/pull/56
[#57]: https://github.com/entropyxyz/manul/pull/57
[#58]: https://github.com/entropyxyz/manul/pull/58


## [0.0.1] - 2024-10-12
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/async_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
// Terminating.
CanFinalize::Never => {
tracing::warn!("{key:?}: This session cannot ever be finalized. Terminating.");
return session.terminate(accum);
return session.terminate_due_to_errors(accum);
}
}

Expand Down
28 changes: 25 additions & 3 deletions manul/src/session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,11 @@ where
RoundAccumulator::new(self.round.expecting_messages_from())
}

/// Terminates the session.
pub fn terminate(self, accum: RoundAccumulator<P, SP>) -> Result<SessionReport<P, SP>, LocalError> {
fn terminate_inner(
self,
accum: RoundAccumulator<P, SP>,
not_enough_messages: bool,
) -> Result<SessionReport<P, SP>, LocalError> {
let round_id = self.round_id();
let transcript = self.transcript.update(
round_id,
Expand All @@ -422,7 +425,26 @@ where
accum.unprovable_errors,
accum.still_have_not_sent_messages,
)?;
Ok(SessionReport::new(SessionOutcome::NotEnoughMessages, transcript))
let outcome = if not_enough_messages {
SessionOutcome::NotEnoughMessages
} else {
SessionOutcome::Terminated
};
Ok(SessionReport::new(outcome, transcript))
}

/// Terminates the session, recording the reason as a user decision.
pub fn terminate(self, accum: RoundAccumulator<P, SP>) -> Result<SessionReport<P, SP>, LocalError> {
self.terminate_inner(accum, false)
}

/// Terminates the session, recording the reason as the session being not possible to finalize
/// due to the number of misbehaving nodes.
///
/// Will be usually called after receiving [`CanFinalize::Never`] from
/// [`can_finalize`](`Self::can_finalize`).
pub fn terminate_due_to_errors(self, accum: RoundAccumulator<P, SP>) -> Result<SessionReport<P, SP>, LocalError> {
self.terminate_inner(accum, false)
}

/// Attempts to finalize the current round.
Expand Down
5 changes: 4 additions & 1 deletion manul/src/session/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ pub enum SessionOutcome<P: Protocol> {
/// The execution stalled because of an unattributable error,
/// but the protocol created a proof that this node performed its duties correctly.
///
/// This protocol is supposed to be passed to a third party for adjudication.
/// This proof is supposed to be passed to a third party for adjudication,
/// along with the proofs from the other nodes.
StalledWithProof(P::CorrectnessProof),
/// The execution stalled because not enough messages were received to finalize the round.
NotEnoughMessages,
/// The execution was terminated by the user.
Terminated,
}

/// The report of a session execution.
Expand Down
2 changes: 1 addition & 1 deletion manul/src/testing/run_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
}
}
CanFinalize::NotYet => break State::InProgress { session, accum },
CanFinalize::Never => break State::Finished(session.terminate(accum)?),
CanFinalize::Never => break State::Finished(session.terminate_due_to_errors(accum)?),
}

let destinations = session.message_destinations();
Expand Down
Loading