Skip to content

Commit

Permalink
Add Round::may_produce_result()
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Nov 15, 2024
1 parent e4b20f6 commit 2a00e23
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions examples/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ impl<Id: PartyId> Round<Id> for Round2<Id> {
BTreeSet::new()
}

fn may_produce_result(&self) -> bool {
true
}

fn message_destinations(&self) -> &BTreeSet<Id> {
&self.context.other_ids
}
Expand Down
4 changes: 4 additions & 0 deletions manul/benches/empty_rounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl<Id: PartyId> Round<Id> for EmptyRound<Id> {
}
}

fn may_produce_result(&self) -> bool {
self.inputs.rounds_num == self.round_counter
}

fn message_destinations(&self) -> &BTreeSet<Id> {
&self.inputs.other_ids
}
Expand Down
13 changes: 10 additions & 3 deletions manul/src/combinators/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ where
.map(|round_id| round_id.group_under(1))
.collect::<BTreeSet<_>>();

// If there are no next rounds, this is the result round.
// This means that in the chain the next round will be the entry round of the second protocol.
if next_rounds.is_empty() {
if round.as_ref().may_produce_result() {
tracing::debug!("Adding {}", T::EntryPoint::entry_round().group_under(2));
next_rounds.insert(T::EntryPoint::entry_round().group_under(2));
}

next_rounds
}
ChainState::Protocol2(round) => round
Expand All @@ -391,6 +391,13 @@ where
}
}

fn may_produce_result(&self) -> bool {
match &self.state {
ChainState::Protocol1 { .. } => false,
ChainState::Protocol2(round) => round.as_ref().may_produce_result(),
}
}

fn message_destinations(&self) -> &BTreeSet<Id> {
match &self.state {
ChainState::Protocol1 { round, .. } => round.as_ref().message_destinations(),
Expand Down
4 changes: 4 additions & 0 deletions manul/src/combinators/misbehave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ where
self.round.as_ref().possible_next_rounds()
}

fn may_produce_result(&self) -> bool {
self.round.as_ref().may_produce_result()
}

fn message_destinations(&self) -> &BTreeSet<Id> {
self.round.as_ref().message_destinations()
}
Expand Down
6 changes: 6 additions & 0 deletions manul/src/protocol/object_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub(crate) trait ObjectSafeRound<Id: PartyId>: 'static + Debug + Send + Sync {

fn possible_next_rounds(&self) -> BTreeSet<RoundId>;

fn may_produce_result(&self) -> bool;

fn message_destinations(&self) -> &BTreeSet<Id>;

fn expecting_messages_from(&self) -> &BTreeSet<Id>;
Expand Down Expand Up @@ -133,6 +135,10 @@ where
self.round.possible_next_rounds()
}

fn may_produce_result(&self) -> bool {
self.round.may_produce_result()
}

fn message_destinations(&self) -> &BTreeSet<Id> {
self.round.message_destinations()
}
Expand Down
7 changes: 7 additions & 0 deletions manul/src/protocol/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ pub trait Round<Id: PartyId>: 'static + Debug + Send + Sync {
/// Returns an empty set if this round only finalizes into a result.
fn possible_next_rounds(&self) -> BTreeSet<RoundId>;

/// Returns ``true`` if this round's [`Round::finalize`] may return [`FinalizeOutcome::Result`].
///
/// The blanket implementation returns ``false``.
fn may_produce_result(&self) -> bool {
false
}

/// The destinations of the messages to be sent out by this round.
///
/// The way it is interpreted by the execution layer is
Expand Down

0 comments on commit 2a00e23

Please sign in to comment.