Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ More details are available [in the book][reference-link-implementation-details].
- Import AlephBFT in your crate
```toml
[dependencies]
aleph-bft = "^0.42"
aleph-bft = "^0.43"
```
- The main entry point is the `run_session` function, which returns a Future that runs the
consensus algorithm.
Expand Down
2 changes: 1 addition & 1 deletion consensus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-bft"
version = "0.42.2"
version = "0.43.0"
edition = "2021"
authors = ["Cardinal Cryptography"]
categories = ["algorithms", "data-structures", "cryptography", "database"]
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/reconstruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<D: Data, H: Hasher, K: MultiKeychain> From<ReconstructedUnit<Signed<FullUni
}

/// What we need to request to reconstruct units.
#[derive(Debug, PartialEq, Eq)]
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum Request<H: Hasher> {
/// We need a unit at this coordinate.
Coord(UnitCoord),
Expand Down
147 changes: 139 additions & 8 deletions consensus/src/dissemination/mod.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,156 @@
use crate::{
dag::Request as ReconstructionRequest,
network::UnitMessage,
runway::{NewestUnitResponse, Salt},
units::{UncheckedSignedUnit, UnitCoord},
Data, Hasher, NodeIndex, Signature, UncheckedSigned,
units::UncheckedSignedUnit,
Data, Hasher, NodeIndex, Recipient, Signature, UncheckedSigned,
};

mod responder;
mod task;

pub use responder::Responder;
pub use task::DisseminationTask;

/// Some form of message with the intended recipients.
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct Addressed<T> {
message: T,
recipients: Vec<Recipient>,
}

impl<T> Addressed<T> {
/// Message with the given recipients.
pub fn new(message: T, recipients: Vec<Recipient>) -> Self {
Addressed {
message,
recipients,
}
}

/// Message with the single specified recipient.
pub fn addressed_to(message: T, node_id: NodeIndex) -> Self {
Addressed::new(message, vec![Recipient::Node(node_id)])
}

/// All the recipients of this message.
pub fn recipients(&self) -> &Vec<Recipient> {
&self.recipients
}

/// The associated message.
pub fn message(&self) -> &T {
&self.message
}

/// Convert the underlying message. Cannot be done through a `From` implementation due to it
/// overriding the blanked identity `From` implementation.
pub fn into<U: From<T>>(self) -> Addressed<U> {
let Addressed {
message,
recipients,
} = self;
Addressed {
message: message.into(),
recipients,
}
}
}

/// Possible requests for information from other nodes.
#[derive(Debug)]
pub enum Request<H: Hasher> {
Coord(UnitCoord),
Parents(H::Hash),
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum DisseminationRequest<H: Hasher> {
/// A request for unit information in normal operation.
Unit(ReconstructionRequest<H>),
/// Request for what the specified node thinks about our newest unit.
NewestUnit(NodeIndex, Salt),
}

impl<H: Hasher> From<ReconstructionRequest<H>> for DisseminationRequest<H> {
fn from(request: ReconstructionRequest<H>) -> Self {
DisseminationRequest::Unit(request)
}
}

/// Responses to requests.
#[derive(Debug)]
pub enum Response<H: Hasher, D: Data, S: Signature> {
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum DisseminationResponse<H: Hasher, D: Data, S: Signature> {
/// Response to a coord request, just a single unit.
Coord(UncheckedSignedUnit<H, D, S>),
/// All the parents of the specified unit.
Parents(H::Hash, Vec<UncheckedSignedUnit<H, D, S>>),
/// The newest unit response for initial unit collection.
NewestUnit(UncheckedSigned<NewestUnitResponse<H, D, S>, S>),
}

/// A message that has to be passed between committe members for consensus to work.
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum DisseminationMessage<H: Hasher, D: Data, S: Signature> {
/// Unit, either broadcast or in response to a coord request.
Unit(UncheckedSignedUnit<H, D, S>),
/// Request coming from the specified node for something.
Request(NodeIndex, DisseminationRequest<H>),
/// Response to a parent request.
ParentsResponse(H::Hash, Vec<UncheckedSignedUnit<H, D, S>>),
/// Response to initial unit collection.
NewestUnitResponse(UncheckedSigned<NewestUnitResponse<H, D, S>, S>),
}

impl<H: Hasher, D: Data, S: Signature> From<UnitMessage<H, D, S>>
for DisseminationMessage<H, D, S>
{
fn from(message: UnitMessage<H, D, S>) -> Self {
use DisseminationMessage::*;
match message {
UnitMessage::Unit(u) => Unit(u),
UnitMessage::CoordRequest(node_id, coord) => {
Request(node_id, ReconstructionRequest::Coord(coord).into())
}
UnitMessage::ParentsRequest(node_id, hash) => {
Request(node_id, ReconstructionRequest::ParentsOf(hash).into())
}
UnitMessage::ParentsResponse(h, units) => ParentsResponse(h, units),
UnitMessage::NewestRequest(node_id, salt) => {
Request(node_id, DisseminationRequest::NewestUnit(node_id, salt))
}
UnitMessage::NewestResponse(response) => NewestUnitResponse(response),
}
}
}

impl<H: Hasher, D: Data, S: Signature> From<DisseminationMessage<H, D, S>>
for UnitMessage<H, D, S>
{
fn from(message: DisseminationMessage<H, D, S>) -> Self {
use DisseminationMessage::*;
match message {
Unit(u) => UnitMessage::Unit(u),
Request(node_id, DisseminationRequest::Unit(ReconstructionRequest::Coord(coord))) => {
UnitMessage::CoordRequest(node_id, coord)
}
Request(
node_id,
DisseminationRequest::Unit(ReconstructionRequest::ParentsOf(hash)),
) => UnitMessage::ParentsRequest(node_id, hash),
ParentsResponse(h, units) => UnitMessage::ParentsResponse(h, units),
Request(node_id, DisseminationRequest::NewestUnit(_, salt)) => {
UnitMessage::NewestRequest(node_id, salt)
}
NewestUnitResponse(response) => UnitMessage::NewestResponse(response),
}
}
}

impl<H: Hasher, D: Data, S: Signature> From<DisseminationResponse<H, D, S>>
for DisseminationMessage<H, D, S>
{
fn from(message: DisseminationResponse<H, D, S>) -> Self {
use DisseminationMessage::*;
use DisseminationResponse::*;
match message {
Coord(u) => Unit(u),
Parents(h, units) => ParentsResponse(h, units),
NewestUnit(response) => NewestUnitResponse(response),
}
}
}
Loading
Loading