Skip to content

Commit

Permalink
return the creator of a unit with the unit data when the unit is fina…
Browse files Browse the repository at this point in the history
…lized
  • Loading branch information
joschisan committed Oct 1, 2023
1 parent 60900ad commit 9207da6
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 21 deletions.
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.29"
aleph-bft = "^0.30"
```
- 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.29.0"
version = "0.30.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.10" }
aleph-bft-types = { path = "../types", version = "0.9" }
aleph-bft-types = { path = "../types", version = "0.10" }
anyhow = "1.0"
async-trait = "0.1"
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] }
Expand Down
17 changes: 10 additions & 7 deletions consensus/src/runway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,18 +657,21 @@ where
fn on_ordered_batch(&mut self, batch: Vec<H::Hash>) {
let data_iter: Vec<_> = batch
.iter()
.filter_map(|h| {
self.store
.map(|h| {
let unit = self
.store
.unit_by_hash(h)
.expect("Ordered units must be in store")
.as_signable()
.data()
.clone()
.as_signable();

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

for d in data_iter {
self.finalization_handler.data_finalized(d);
for (d, creator) in data_iter {
if let Some(d) = d {
self.finalization_handler.data_finalized(d, creator);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/src/aleph_bft_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The FinalizationHandler trait is an abstraction for a component that should hand

```rust
pub trait FinalizationHandler<Data> {
fn data_finalized(&mut self, data: Data);
fn data_finalized(&mut self, data: Data, creator: NodeIndex);
}
```

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) {
fn data_finalized(&mut self, d: Data, _creator: NodeIndex) {
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.10.0"
version = "0.11.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.9" }
aleph-bft-types = { path = "../types", version = "0.10" }
async-trait = "0.1"
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] }
futures = "0.3"
Expand Down
6 changes: 4 additions & 2 deletions mock/src/dataio.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use aleph_bft_types::{DataProvider as DataProviderT, FinalizationHandler as FinalizationHandlerT};
use aleph_bft_types::{
DataProvider as DataProviderT, FinalizationHandler as FinalizationHandlerT, NodeIndex,
};
use async_trait::async_trait;
use codec::{Decode, Encode};
use futures::{channel::mpsc::unbounded, future::pending};
Expand Down Expand Up @@ -71,7 +73,7 @@ pub struct FinalizationHandler {
}

impl FinalizationHandlerT<Data> for FinalizationHandler {
fn data_finalized(&mut self, d: Data) {
fn data_finalized(&mut self, d: Data, _creator: NodeIndex) {
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 types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-bft-types"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
authors = ["Cardinal Cryptography"]
documentation = "https://docs.rs/?"
Expand Down
4 changes: 3 additions & 1 deletion types/src/dataio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use async_trait::async_trait;

use crate::NodeIndex;

/// The source of data items that consensus should order.
///
/// AlephBFT internally calls [`DataProvider::get_data`] whenever a new unit is created and data needs to be placed inside.
Expand All @@ -19,5 +21,5 @@ 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);
fn data_finalized(&mut self, data: Data, creator: NodeIndex);
}

0 comments on commit 9207da6

Please sign in to comment.