Skip to content

Commit 4f479f2

Browse files
committed
Temporary
1 parent 2995b59 commit 4f479f2

File tree

3 files changed

+67
-74
lines changed

3 files changed

+67
-74
lines changed

manul/src/protocol.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub use errors::{
2626
};
2727
pub use message::{DirectMessage, EchoBroadcast, NormalBroadcast, ProtocolMessage, ProtocolMessagePart};
2828
pub use round::{
29-
Artifact, CommunicationInfo, EchoRoundParticipation, EntryPoint, FinalizeOutcome, IdSet, NoProtocolErrors, PartyId,
30-
Payload, Protocol, ProtocolError, RequiredMessageParts, RequiredMessages, Round,
29+
Artifact, CommunicationInfo, EchoRoundCommunicationInfo, EntryPoint, FinalizeOutcome, IdSet, NoProtocolErrors,
30+
PartyId, Payload, Protocol, ProtocolError, RequiredMessageParts, RequiredMessages, Round, RoundCommunicationInfo,
3131
};
3232
pub use round_id::{RoundId, TransitionInfo};
3333

manul/src/protocol/round.rs

+33-33
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,22 @@ impl<Id: Ord> IdSet<Id> {
5757
}
5858
}
5959

60-
/// Describes what other parties this rounds sends messages to, and what other parties it expects messages from.
60+
/// Encapsulates the communication info for the main round and the possible echo round.
6161
#[derive(Debug, Clone)]
6262
pub struct CommunicationInfo<Id> {
63+
/// Communication info for the main part of the round (that is, not considering the echo round).
64+
pub main_round: RoundCommunicationInfo<Id>,
65+
66+
/// The specific way the node participates in the echo round following this round.
67+
///
68+
/// `None` means that, if there is an echo round, the message destinations and expected messages senders
69+
/// are the same as in the main round.
70+
pub echo_round: EchoRoundCommunicationInfo<Id>,
71+
}
72+
73+
/// Describes what other parties this rounds sends messages to, and what other parties it expects messages from.
74+
#[derive(Debug, Clone)]
75+
pub struct RoundCommunicationInfo<Id> {
6376
/// The destinations of the messages to be sent out by this round.
6477
///
6578
/// The way it is interpreted by the execution layer is
@@ -69,29 +82,35 @@ pub struct CommunicationInfo<Id> {
6982
/// for each element of the returned set.
7083
pub message_destinations: BTreeSet<Id>,
7184

72-
/// Returns the set of node IDs from which this round expects messages.
85+
/// The set of node IDs from which this round expects messages.
7386
///
74-
/// The execution layer will not call [`finalize`](`Round::finalize`) until all these nodes have responded
75-
/// (and the corresponding [`receive_message`](`Round::receive_message`) finished successfully).
87+
/// The execution layer will not call [`finalize`](`Round::finalize`) until enough nodes to constitute the quorum
88+
/// have responded (and the corresponding [`receive_message`](`Round::receive_message`) finished successfully).
7689
pub expecting_messages_from: IdSet<Id>,
77-
78-
/// Returns the specific way the node participates in the echo round following this round.
79-
///
80-
/// Returns [`EchoRoundParticipation::Default`] by default; this works fine when every node
81-
/// sends messages to every other one, or do not send or receive any echo broadcasts.
82-
/// Otherwise, review the options in [`EchoRoundParticipation`] and pick the appropriate one.
83-
pub echo_round_participation: EchoRoundParticipation<Id>,
8490
}
8591

86-
impl<Id: PartyId> CommunicationInfo<Id> {
92+
impl<Id: PartyId> RoundCommunicationInfo<Id> {
8793
/// A regular round that sends messages to all `other_parties`, and expects messages back from them.
88-
pub fn regular(other_parties: &BTreeSet<Id>) -> Self {
94+
pub fn all_to_all(other_parties: &BTreeSet<Id>) -> Self {
8995
Self {
9096
message_destinations: other_parties.clone(),
9197
expecting_messages_from: IdSet::new_non_threshold(other_parties.clone()),
92-
echo_round_participation: EchoRoundParticipation::Default,
9398
}
9499
}
100+
101+
pub fn none() -> Self {
102+
Self {
103+
message_destinations: BTreeSet::new(),
104+
expecting_messages_from: IdSet::empty(),
105+
}
106+
}
107+
}
108+
109+
#[derive(Debug, Clone)]
110+
pub enum EchoRoundCommunicationInfo<Id> {
111+
None,
112+
SameAsMainRound,
113+
Custom(RoundCommunicationInfo<Id>),
95114
}
96115

97116
/// Possible successful outcomes of [`Round::finalize`].
@@ -376,25 +395,6 @@ pub trait PartyId: 'static + Debug + Clone + Ord + Send + Sync + Serialize + for
376395

377396
impl<T> PartyId for T where T: 'static + Debug + Clone + Ord + Send + Sync + Serialize + for<'de> Deserialize<'de> {}
378397

379-
/// The specific way the node participates in the echo round (if any).
380-
#[derive(Debug, Clone)]
381-
pub enum EchoRoundParticipation<Id> {
382-
/// The default behavior: sends broadcasts and receives echoed messages, or does neither.
383-
///
384-
/// That is, this node will be a part of the echo round if [`Round::make_echo_broadcast`] generates a message.
385-
Default,
386-
387-
/// This node sends broadcasts that will be echoed, but does not receive any.
388-
Send,
389-
390-
/// This node receives broadcasts that it needs to echo, but does not send any itself.
391-
Receive {
392-
/// The other participants of the echo round
393-
/// (that is, the nodes to which echoed messages will be sent).
394-
echo_targets: BTreeSet<Id>,
395-
},
396-
}
397-
398398
mod sealed {
399399
/// A dyn safe trait to get the type's ID.
400400
pub trait DynTypeId: 'static {

manul/src/session/session.rs

+32-39
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use super::{
2323
LocalError, RemoteError,
2424
};
2525
use crate::protocol::{
26-
Artifact, BoxedFormat, BoxedRound, CommunicationInfo, DirectMessage, EchoBroadcast, EchoRoundParticipation,
26+
Artifact, BoxedFormat, BoxedRound, CommunicationInfo, DirectMessage, EchoBroadcast, EchoRoundCommunicationInfo,
2727
EntryPoint, FinalizeOutcome, IdSet, NormalBroadcast, PartyId, Payload, Protocol, ProtocolMessage,
28-
ProtocolMessagePart, ReceiveError, ReceiveErrorType, RoundId, TransitionInfo,
28+
ProtocolMessagePart, ReceiveError, ReceiveErrorType, RoundCommunicationInfo, RoundId, TransitionInfo,
2929
};
3030

3131
/// A set of types needed to execute a session.
@@ -97,13 +97,6 @@ impl AsRef<[u8]> for SessionId {
9797
}
9898
}
9999

100-
#[derive(Debug)]
101-
pub(crate) struct EchoRoundInfo<Verifier> {
102-
pub(crate) message_destinations: BTreeSet<Verifier>,
103-
pub(crate) expecting_messages_from: IdSet<Verifier>,
104-
pub(crate) expected_echos: BTreeSet<Verifier>,
105-
}
106-
107100
/// An object encapsulating the currently active round, transport protocol,
108101
/// and the database of messages and errors from the previous rounds.
109102
#[derive(Debug)]
@@ -114,8 +107,9 @@ pub struct Session<P: Protocol<SP::Verifier>, SP: SessionParameters> {
114107
format: BoxedFormat,
115108
round: BoxedRound<SP::Verifier, P>,
116109
message_destinations: BTreeSet<SP::Verifier>,
117-
communication_info: CommunicationInfo<SP::Verifier>,
118-
echo_round_info: Option<EchoRoundInfo<SP::Verifier>>,
110+
main_round_cinfo: CommunicationInfo<SP::Verifier>,
111+
echo_round_cinfo: CommunicationInfo<SP::Verifier>,
112+
expected_echos: BTreeSet<SP::Verifier>,
119113
echo_broadcast: SignedMessagePart<EchoBroadcast>,
120114
normal_broadcast: SignedMessagePart<NormalBroadcast>,
121115
transition_info: TransitionInfo,
@@ -174,40 +168,39 @@ where
174168
let normal = round.as_ref().make_normal_broadcast(rng, &format)?;
175169
let normal_broadcast = SignedMessagePart::new::<SP>(rng, &signer, &session_id, &transition_info.id(), normal)?;
176170

177-
let communication_info = round.as_ref().communication_info();
178-
let message_destinations = communication_info
171+
let CommunicationInfo {
172+
main_round: main_round_cinfo,
173+
echo_round: echo_round_cinfo,
174+
} = round.as_ref().communication_info();
175+
176+
let (echo_round_cinfo, expected_echos) = match echo_round_cinfo {
177+
EchoRoundCommunicationInfo::None => {
178+
let echo_round_cinfo = RoundCommunicationInfo::none();
179+
let expected_echos = BTreeSet::new();
180+
(echo_round_cinfo, expected_echos)
181+
}
182+
EchoRoundCommunicationInfo::SameAsMainRound => {
183+
let echo_round_cinfo = main_round_cinfo.clone();
184+
let mut expected_echos = main_round_cinfo.expecting_messages_from.all().clone();
185+
// Add our own echo message to the expected list because we expect it to be sent back from other nodes.
186+
expected_echos.insert(verifier.clone());
187+
(echo_round_cinfo, expected_echos)
188+
}
189+
EchoRoundCommunicationInfo::Custom(cinfo) => {
190+
let mut expected_echos = main_round_cinfo.expecting_messages_from.all().clone();
191+
// Add our own echo message to the expected list because we expect it to be sent back from other nodes.
192+
expected_echos.insert(verifier.clone());
193+
(cinfo, expected_echos)
194+
}
195+
};
196+
197+
let message_destinations = main_round_cinfo
179198
.message_destinations
180199
.difference(&transcript.banned_ids())
181200
.cloned()
182201
.collect::<BTreeSet<_>>();
183202

184203
let round_sends_echo_broadcast = !echo_broadcast.payload().is_none();
185-
let echo_round_info = match &communication_info.echo_round_participation {
186-
EchoRoundParticipation::Default => {
187-
if round_sends_echo_broadcast {
188-
// Add our own echo message to the expected list because we expect it to be sent back from other nodes.
189-
let mut expected_echos = communication_info.expecting_messages_from.all().clone();
190-
expected_echos.insert(verifier.clone());
191-
Some(EchoRoundInfo {
192-
message_destinations: communication_info.message_destinations.clone(),
193-
// TODO: this is not correct in general
194-
expecting_messages_from: IdSet::new_non_threshold(
195-
communication_info.message_destinations.clone(),
196-
),
197-
expected_echos,
198-
})
199-
} else {
200-
None
201-
}
202-
}
203-
EchoRoundParticipation::Send => None,
204-
EchoRoundParticipation::Receive { echo_targets } => Some(EchoRoundInfo {
205-
message_destinations: echo_targets.clone(),
206-
// TODO: this is not correct in general
207-
expecting_messages_from: IdSet::new_non_threshold(echo_targets.clone()),
208-
expected_echos: communication_info.expecting_messages_from.all().clone(),
209-
}),
210-
};
211204

212205
Ok(Self {
213206
session_id,

0 commit comments

Comments
 (0)