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

return the round of a unit with the unit data when the unit is finalized #376

Merged
merged 1 commit into from
Mar 18, 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
6 changes: 3 additions & 3 deletions 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.35"
aleph-bft = "^0.36"
```
- The main entry point is the `run_session` function, which returns a Future that runs the
consensus algorithm.
Expand Down
4 changes: 2 additions & 2 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-bft"
version = "0.35.0"
version = "0.36.0"
edition = "2021"
authors = ["Cardinal Cryptography"]
categories = ["algorithms", "data-structures", "cryptography", "database"]
Expand All @@ -14,7 +14,7 @@ description = "AlephBFT is an asynchronous and Byzantine fault tolerant consensu

[dependencies]
aleph-bft-rmc = { path = "../rmc", version = "0.12" }
aleph-bft-types = { path = "../types", version = "0.12" }
aleph-bft-types = { path = "../types", version = "0.13" }
anyhow = "1.0"
async-trait = "0.1"
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] }
Expand Down
29 changes: 12 additions & 17 deletions consensus/src/runway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,23 +649,18 @@ where
}

fn on_ordered_batch(&mut self, batch: Vec<H::Hash>) {
let data_iter: Vec<_> = batch
.iter()
.map(|h| {
let unit = self
.store
.unit_by_hash(h)
.expect("Ordered units must be in store")
.as_signable();

(unit.data().clone(), unit.creator())
})
.collect();

for (d, creator) in data_iter {
if let Some(d) = d {
self.finalization_handler.data_finalized(d, creator);
}
for hash in batch {
let unit = self
.store
.unit_by_hash(&hash)
.expect("Ordered units must be in store")
.as_signable();

self.finalization_handler.unit_finalized(
unit.creator(),
unit.round(),
unit.data().clone(),
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/ordering/src/dataio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct FinalizationHandler {
}

impl FinalizationHandlerT<Data> for FinalizationHandler {
fn data_finalized(&mut self, d: Data, _creator: NodeIndex) {
fn data_finalized(&mut self, d: Data) {
if let Err(e) = self.tx.unbounded_send(d) {
error!(target: "finalization-handler", "Error when sending data from FinalizationHandler {:?}.", e);
}
Expand Down
4 changes: 2 additions & 2 deletions mock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-bft-mock"
version = "0.13.0"
version = "0.14.0"
edition = "2021"
authors = ["Cardinal Cryptography"]
documentation = "https://docs.rs/?"
Expand All @@ -11,7 +11,7 @@ readme = "./README.md"
description = "Mock implementations of traits required by the aleph-bft package. Do NOT use outside of testing!"

[dependencies]
aleph-bft-types = { path = "../types", version = "0.12" }
aleph-bft-types = { path = "../types", version = "0.13" }
async-trait = "0.1"
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] }
futures = "0.3"
Expand Down
6 changes: 2 additions & 4 deletions mock/src/dataio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use aleph_bft_types::{
DataProvider as DataProviderT, FinalizationHandler as FinalizationHandlerT, NodeIndex,
};
use aleph_bft_types::{DataProvider as DataProviderT, FinalizationHandler as FinalizationHandlerT};
use async_trait::async_trait;
use codec::{Decode, Encode};
use futures::{channel::mpsc::unbounded, future::pending, AsyncWrite};
Expand Down Expand Up @@ -75,7 +73,7 @@ pub struct FinalizationHandler {
}

impl FinalizationHandlerT<Data> for FinalizationHandler {
fn data_finalized(&mut self, d: Data, _creator: NodeIndex) {
fn data_finalized(&mut self, d: Data) {
if let Err(e) = self.tx.unbounded_send(d) {
error!(target: "finalization-handler", "Error when sending data from FinalizationHandler {:?}.", e);
}
Expand Down
2 changes: 1 addition & 1 deletion rmc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description = "Reliable MultiCast - a primitive for Reliable Broadcast protocol.

[dependencies]
aleph-bft-crypto = { path = "../crypto", version = "0.9" }
aleph-bft-types = { path = "../types", version = "0.12" }
aleph-bft-types = { path = "../types", version = "0.13" }
async-trait = "0.1"
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] }
futures = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-bft-types"
version = "0.12.0"
version = "0.13.0"
edition = "2021"
authors = ["Cardinal Cryptography"]
documentation = "https://docs.rs/?"
Expand Down
13 changes: 12 additions & 1 deletion types/src/dataio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use async_trait::async_trait;

use crate::NodeIndex;
use crate::Round;

/// The source of data items that consensus should order.
///
Expand All @@ -21,5 +22,15 @@ pub trait DataProvider<Data>: Sync + Send + 'static {
pub trait FinalizationHandler<Data>: Sync + Send + 'static {
/// Data, provided by [DataProvider::get_data], has been finalized.
/// The calls to this function follow the order of finalization.
fn data_finalized(&mut self, data: Data, creator: NodeIndex);
fn data_finalized(&mut self, data: Data);
/// A unit has been finalized. You can overwrite the default implementation for advanced finalization handling
/// in which case the method [`FinalizationHandler::data_finalized`] will not be called anymore if a unit is finalized.
/// Please note that this interface is less stable as it exposes intrinsics which migh be subject to change.
/// Do not implement this method and only implement [`FinalizationHandler::data_finalized`] unless you
/// absolutely know what you are doing.
fn unit_finalized(&mut self, _creator: NodeIndex, _round: Round, data: Option<Data>) {
if let Some(d) = data {
self.data_finalized(d);
}
}
}
Loading