paxakos/invocation.rs
1//! Defines the [`Invocation`] trait.
2
3use crate::applicable::ProjectionOf;
4use crate::communicator::Acceptance;
5use crate::communicator::Vote;
6use crate::node::Snapshot;
7use crate::node_builder::NodeBuilderBlank;
8use crate::state;
9use crate::state::State;
10use crate::Commit;
11use crate::Conflict;
12use crate::CoordNum;
13use crate::LogEntry;
14use crate::NodeInfo;
15use crate::Promise;
16use crate::RoundNum;
17
18/// Shorthand to extract `Abstain` type out of `I`.
19pub type AbstainOf<I> = <I as Invocation>::Abstain;
20/// Shorthand to extract `CommunicationError` type out of `I`.
21pub type CommunicationErrorOf<I> = <I as Invocation>::CommunicationError;
22/// Shorthand to extract state's `Context` type out of `I`.
23pub type ContextOf<I> = state::ContextOf<StateOf<I>>;
24/// Shorthand to extract `CoordNum` type out of `I`.
25pub type CoordNumOf<I> = <I as Invocation>::CoordNum;
26/// Shorthand to extract state's `Event` type out of `I`.
27pub type EffectOf<I> = state::EffectOf<StateOf<I>>;
28/// Shorthand to extract `Ejection` type out of `I`.
29pub type EjectionOf<I> = <I as Invocation>::Ejection;
30/// Shorthand to extract state's `Frozen` type out of `I`.
31pub type FrozenStateOf<I> = state::FrozenOf<StateOf<I>>;
32/// Shorthand to extract state's `LogEntry` type out of `I`.
33pub type LogEntryOf<I> = state::LogEntryOf<StateOf<I>>;
34/// Shorthand to extract log entry `Id` type out of `I`.
35pub type LogEntryIdOf<I> = <LogEntryOf<I> as LogEntry>::Id;
36/// Shorthand to extract `Nay` type out of `I`.
37pub type NayOf<I> = <I as Invocation>::Nay;
38/// Shorthand to extract state's `Node` type (`impl NodeInfo`) out of `I`.
39pub type NodeOf<I> = state::NodeOf<StateOf<I>>;
40/// Shorthand to extract node (`impl NodeInfo`) `Id` type out of `I`.
41pub type NodeIdOf<I> = <NodeOf<I> as NodeInfo>::Id;
42/// Shorthand to extract state's `Outcome` type out of `I`.
43pub type OutcomeOf<I> = state::OutcomeOf<StateOf<I>>;
44/// Shorthand to extract `RoundNum` type out of `I`.
45pub type RoundNumOf<I> = <I as Invocation>::RoundNum;
46/// Shorthand to extract `State` type out of `I`.
47pub type StateOf<I> = <I as Invocation>::State;
48/// Shorthand to extract `Yea` type out of `I`.
49pub type YeaOf<I> = <I as Invocation>::Yea;
50
51/// Invokes `Acceptance` type constructor so as to be compatible with `I`.
52pub type AcceptanceFor<I> = Acceptance<CoordNumOf<I>, LogEntryOf<I>, YeaOf<I>, NayOf<I>>;
53/// Invokes `Commit` type constructor so as to be compatible with `I`.
54pub type CommitFor<I, A = LogEntryOf<I>> =
55 Commit<StateOf<I>, RoundNumOf<I>, ProjectionOf<A, StateOf<I>>>;
56/// Invokes `Conflict` type constructor so as to be compatible with `I`.
57pub type ConflictFor<I> = Conflict<CoordNumOf<I>, LogEntryOf<I>>;
58/// Invokes `Promise` type constructor so as to be compatible with `I`.
59pub type PromiseFor<I> = Promise<RoundNumOf<I>, CoordNumOf<I>, LogEntryOf<I>>;
60/// Invokes `Snapshot` type constructor so as to be compatible with `I`.
61pub type SnapshotFor<I> = Snapshot<StateOf<I>, RoundNumOf<I>, CoordNumOf<I>>;
62/// Invokes `Vote` type constructor so as to be compatible with `I`.
63pub type VoteFor<I> = Vote<RoundNumOf<I>, CoordNumOf<I>, LogEntryOf<I>, AbstainOf<I>>;
64
65/// A set of type arguments to invoke Paxakos with.
66///
67/// Idiomatic Rust code will usually have separate type parameters for every
68/// type. This has several advantages, for instance type bounds need only be
69/// placed on implementations which require them. However, as a generic
70/// implementation of a fairly complex algorithm, Paxakos would require rather a
71/// lot of individual type parameters. Therefore Paxakos foregoes the idiomatic
72/// approach and accepts a single `Invocation` argument in most places.
73pub trait Invocation: Send + Sized + 'static {
74 /// Round number type.
75 type RoundNum: RoundNum;
76 /// Coordination number type.
77 type CoordNum: CoordNum;
78
79 /// State type.
80 type State: State;
81
82 /// Additional data sent along with 'yea' votes.
83 type Yea: std::fmt::Debug + Send + Sync + 'static;
84 /// Additional data sent along with 'nay' votes.
85 type Nay: std::fmt::Debug + Send + Sync + 'static;
86 /// Additional data sent along with abstentions.
87 type Abstain: std::fmt::Debug + Send + Sync + 'static;
88
89 /// Reason the node's state may be ejected.
90 type Ejection: From<state::ErrorOf<Self::State>> + std::fmt::Debug + Send + Sync + 'static;
91
92 /// Communication error type.
93 type CommunicationError: std::fmt::Debug + Send + Sync + 'static;
94
95 /// Constructs a blank node builder for this set of type arguments.
96 fn node_builder() -> NodeBuilderBlank<Self> {
97 NodeBuilderBlank::new()
98 }
99}