Skip to content

Commit

Permalink
mv terminator to types
Browse files Browse the repository at this point in the history
  • Loading branch information
woocash2 committed Sep 26, 2023
1 parent a2192b5 commit 480a542
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 31 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion consensus/src/alerts/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use crate::{
handler::{Handler, OnNetworkAlertResponse, OnOwnAlertResponse, RmcResponse},
Alert, AlertData, AlertMessage, ForkingNotification, NetworkMessage,
},
Data, Hasher, MultiKeychain, Multisigned, NodeIndex, Receiver, Recipient, Sender, Terminator,
Data, Hasher, MultiKeychain, Multisigned, NodeIndex, Receiver, Recipient, Sender,
};
use aleph_bft_rmc::{DoublingDelayScheduler, Message as RmcMessage, ReliableMulticast};
use aleph_bft_types::Terminator;
use futures::{channel::mpsc, FutureExt, StreamExt};
use log::{debug, error, warn};
use std::{collections::HashMap, time};
Expand Down
6 changes: 4 additions & 2 deletions consensus/src/backup/saver.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::io::Write;

use aleph_bft_types::Terminator;
use codec::Encode;
use futures::{FutureExt, StreamExt};
use log::{debug, error};

use crate::{
alerts::AlertData, backup::BackupItem, units::UncheckedSignedUnit, Data, Hasher, MultiKeychain,
Receiver, Sender, Terminator,
Receiver, Sender,
};

const LOG_TARGET: &str = "AlephBFT-backup-saver";
Expand Down Expand Up @@ -108,12 +109,13 @@ mod tests {
};

use aleph_bft_mock::{Data, Hasher64, Keychain, Saver, Signature};
use aleph_bft_types::Terminator;

use crate::{
alerts::{Alert, AlertData},
backup::BackupSaver,
units::{creator_set, preunit_to_unchecked_signed_unit, UncheckedSignedUnit},
NodeCount, NodeIndex, Terminator,
NodeCount, NodeIndex,
};

type TestBackupSaver = BackupSaver<Hasher64, Data, Keychain, Saver>;
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/consensus.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aleph_bft_types::{handle_task_termination, Terminator};
use futures::{
channel::{mpsc, oneshot},
future::pending,
Expand All @@ -9,10 +10,9 @@ use crate::{
config::Config,
creation,
extender::Extender,
handle_task_termination,
runway::{NotificationIn, NotificationOut},
terminal::Terminal,
Hasher, Receiver, Round, Sender, SpawnHandle, Terminator,
Hasher, Receiver, Round, Sender, SpawnHandle,
};

pub(crate) async fn run<H: Hasher + 'static>(
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/creation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use crate::{
config::{Config as GeneralConfig, DelaySchedule},
runway::NotificationOut,
units::{PreUnit, Unit},
Hasher, NodeCount, NodeIndex, Receiver, Round, Sender, Terminator,
Hasher, NodeCount, NodeIndex, Receiver, Round, Sender,
};
use aleph_bft_types::Terminator;
use futures::{
channel::{
mpsc::{SendError, TrySendError},
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/extender.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use futures::{FutureExt, StreamExt};
use std::collections::{HashMap, VecDeque};

use aleph_bft_types::Terminator;
use log::{debug, warn};

use crate::{Hasher, NodeCount, NodeIndex, NodeMap, Receiver, Round, Sender, Terminator};
use crate::{Hasher, NodeCount, NodeIndex, NodeMap, Receiver, Round, Sender};

pub(crate) struct ExtenderUnit<H: Hasher> {
creator: NodeIndex,
Expand Down
2 changes: 0 additions & 2 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mod member;
mod network;
mod runway;
mod terminal;
mod terminator;
mod units;

mod backup;
Expand All @@ -30,7 +29,6 @@ pub use config::{
};
pub use member::{run_session, LocalIO};
pub use network::NetworkData;
pub use terminator::{handle_task_termination, Terminator};

type Receiver<T> = futures::channel::mpsc::UnboundedReceiver<T>;
type Sender<T> = futures::channel::mpsc::UnboundedSender<T>;
5 changes: 2 additions & 3 deletions consensus/src/member.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{
handle_task_termination,
member::Task::{CoordRequest, ParentsRequest, RequestNewest, UnitBroadcast},
network,
runway::{
Expand All @@ -9,9 +8,9 @@ use crate::{
task_queue::TaskQueue,
units::{UncheckedSignedUnit, UnitCoord},
Config, Data, DataProvider, FinalizationHandler, Hasher, MultiKeychain, Network, NodeIndex,
Receiver, Recipient, Round, Sender, Signature, SpawnHandle, Terminator, UncheckedSigned,
Receiver, Recipient, Round, Sender, Signature, SpawnHandle, UncheckedSigned,
};
use aleph_bft_types::NodeMap;
use aleph_bft_types::{handle_task_termination, NodeMap, Terminator};
use codec::{Decode, Encode};
use futures::{channel::mpsc, pin_mut, FutureExt, StreamExt};
use futures_timer::Delay;
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
alerts::AlertMessage, member::UnitMessage, Data, Hasher, Network, PartialMultisignature,
Receiver, Recipient, Sender, Signature, Terminator,
Receiver, Recipient, Sender, Signature,
};
use aleph_bft_types::Terminator;
use codec::{Decode, Encode};
use futures::{FutureExt, StreamExt};
use log::{debug, error, warn};
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/runway/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::{
alerts::{Alert, ForkProof, ForkingNotification, NetworkMessage},
consensus, handle_task_termination,
consensus,
member::UnitMessage,
units::{
ControlHash, PreUnit, SignedUnit, UncheckedSignedUnit, Unit, UnitCoord, UnitStore,
UnitStoreStatus, Validator,
},
Config, Data, DataProvider, FinalizationHandler, Hasher, Index, Keychain, MultiKeychain,
NodeCount, NodeIndex, NodeMap, Receiver, Round, Sender, Signature, Signed, SpawnHandle,
Terminator, UncheckedSigned,
UncheckedSigned,
};
use aleph_bft_types::Recipient;
use aleph_bft_types::{handle_task_termination, Recipient, Terminator};
use futures::{
channel::{mpsc, oneshot},
pin_mut, Future, FutureExt, StreamExt,
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/runway/packer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
units::{FullUnit, PreUnit, SignedUnit},
Data, DataProvider, Hasher, MultiKeychain, NodeIndex, Receiver, Sender, SessionId, Signed,
Terminator,
};
use aleph_bft_types::Terminator;
use futures::{pin_mut, FutureExt, StreamExt};
use log::{debug, error};
use std::marker::PhantomData;
Expand Down Expand Up @@ -100,10 +100,10 @@ mod tests {
use super::Packer;
use crate::{
units::{ControlHash, PreUnit, SignedUnit},
NodeCount, NodeIndex, Receiver, Sender, SessionId, Terminator,
NodeCount, NodeIndex, Receiver, Sender, SessionId,
};
use aleph_bft_mock::{Data, DataProvider, Hasher64, Keychain, StalledDataProvider};
use aleph_bft_types::NodeMap;
use aleph_bft_types::{NodeMap, Terminator};
use futures::{
channel::{mpsc, oneshot},
pin_mut, FutureExt, StreamExt,
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use crate::{
extender::ExtenderUnit,
runway::{NotificationIn, NotificationOut},
units::{ControlHash, Unit, UnitCoord},
Hasher, NodeCount, NodeIndex, NodeMap, Receiver, Round, Sender, Terminator,
Hasher, NodeCount, NodeIndex, NodeMap, Receiver, Round, Sender,
};
use aleph_bft_types::Terminator;
use codec::{Decode, Encode};
use log::{debug, trace, warn};

Expand Down
3 changes: 2 additions & 1 deletion consensus/src/testing/alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use crate::{
alerts::{Alert, AlertMessage, ForkProof, ForkingNotification, Handler, Service},
units::{ControlHash, FullUnit, PreUnit},
Index, Indexed, Keychain as _, NodeCount, NodeIndex, NodeMap, Recipient, Round, Signable,
Signed, Terminator, UncheckedSigned,
Signed, UncheckedSigned,
};
use aleph_bft_mock::{Data, Hasher64, Keychain, PartialMultisignature, Signature};
use aleph_bft_rmc::Message as RmcMessage;
use aleph_bft_types::Terminator;
use futures::{
channel::{mpsc, oneshot},
FutureExt, StreamExt,
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/testing/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use crate::{
runway::{NotificationIn, NotificationOut},
testing::{complete_oneshot, gen_config, gen_delay_config, init_log},
units::{ControlHash, PreUnit, Unit, UnitCoord},
Hasher, NodeIndex, SpawnHandle, Terminator,
Hasher, NodeIndex, SpawnHandle,
};
use aleph_bft_mock::{Hasher64, Spawner};
use aleph_bft_types::Terminator;
use codec::Encode;
use futures::{
channel::{
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/testing/creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use crate::{
runway::NotificationOut as GenericNotificationOut,
testing::{gen_config, gen_delay_config},
units::{FullUnit as GenericFullUnit, PreUnit as GenericPreUnit, Unit as GenericUnit},
NodeCount, Receiver, Round, Sender, Terminator,
NodeCount, Receiver, Round, Sender,
};
use aleph_bft_mock::{Data, Hasher64};
use aleph_bft_types::Terminator;
use futures::{
channel::{mpsc, oneshot},
FutureExt, StreamExt,
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/testing/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use crate::{
runway::{NotificationIn, NotificationOut},
testing::{complete_oneshot, gen_config, gen_delay_config},
units::{ControlHash, PreUnit, Unit},
NodeCount, NodeIndex, NodeMap, NodeSubset, Receiver, Round, Sender, SpawnHandle, Terminator,
NodeCount, NodeIndex, NodeMap, NodeSubset, Receiver, Round, Sender, SpawnHandle,
};
use aleph_bft_mock::{Hash64, Hasher64, Spawner};
use aleph_bft_types::Terminator;
use futures::{
channel::{mpsc, oneshot},
stream::StreamExt,
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ mod unreliable;

use crate::{
create_config, run_session, Config, DelayConfig, LocalIO, Network as NetworkT, NodeCount,
NodeIndex, SpawnHandle, TaskHandle, Terminator,
NodeIndex, SpawnHandle, TaskHandle,
};
use aleph_bft_mock::{
Data, DataProvider, FinalizationHandler, Hasher64, Keychain, Loader, Network as MockNetwork,
PartialMultisignature, ReconnectSender as ReconnectSenderGeneric, Saver, Signature, Spawner,
};
use aleph_bft_types::Terminator;
use futures::channel::{mpsc::UnboundedReceiver, oneshot};
use parking_lot::Mutex;
use std::{sync::Arc, time::Duration};
Expand Down
1 change: 1 addition & 0 deletions examples/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ publish = false
[dependencies]
aleph-bft = { path = "../../consensus", version = "*" }
aleph-bft-mock = { path = "../../mock", version = "*" }
aleph-bft-types = { path = "../../types", version = "*" }
async-trait = "0.1"
clap = { version = "4", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] }
Expand Down
3 changes: 2 additions & 1 deletion examples/blockchain/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{network::NetworkData, DataStore};
use aleph_bft::{NodeIndex, Terminator};
use aleph_bft::NodeIndex;
use aleph_bft_types::Terminator;
use codec::{Decode, Encode};
use futures::{
channel::mpsc::{UnboundedReceiver, UnboundedSender},
Expand Down
3 changes: 2 additions & 1 deletion examples/blockchain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use futures::{channel::oneshot, StreamExt};
use log::{debug, error, info};
use time::{macros::format_description, OffsetDateTime};

use aleph_bft::{run_session, NodeIndex, Terminator};
use aleph_bft::{run_session, NodeIndex};
use aleph_bft_mock::{FinalizationHandler, Keychain, Loader, Saver, Spawner};
use aleph_bft_types::Terminator;
use chain::{run_blockchain, Block, BlockNum, ChainConfig};
use data::{Data, DataProvider, DataStore};
use network::{Address, NetworkData, NetworkManager};
Expand Down
3 changes: 2 additions & 1 deletion examples/blockchain/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{Block, Data};
use aleph_bft::{NodeIndex, Recipient, Terminator};
use aleph_bft::{NodeIndex, Recipient};
use aleph_bft_mock::{Hasher64, PartialMultisignature, Signature};
use aleph_bft_types::Terminator;
use codec::{Decode, Encode};
use futures::{
channel::mpsc::{self, UnboundedReceiver, UnboundedSender},
Expand Down
3 changes: 2 additions & 1 deletion examples/ordering/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
mod dataio;
mod network;

use aleph_bft::{run_session, NodeIndex, Terminator};
use aleph_bft::{run_session, NodeIndex};
use aleph_bft_mock::{Keychain, Spawner};
use aleph_bft_types::Terminator;
use clap::Parser;
use dataio::{Data, DataProvider, FinalizationHandler};
use futures::{channel::oneshot, StreamExt};
Expand Down
1 change: 1 addition & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cargo-fuzz = true
[dependencies]
aleph-bft = { path = "../consensus", version = "*" }
aleph-bft-mock = { path = "../mock", version = "*" }
aleph-bft-types = { path = "../types", version = "*" }
async-trait = "0.1"
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive", "std"] }
env_logger = "0.10"
Expand Down
3 changes: 2 additions & 1 deletion fuzz/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use aleph_bft::{
create_config, run_session, Config, DelayConfig, LocalIO, Network as NetworkT, NetworkData,
NodeCount, NodeIndex, Recipient, SpawnHandle, TaskHandle, Terminator,
NodeCount, NodeIndex, Recipient, SpawnHandle, TaskHandle,
};
use aleph_bft_mock::{
Data, DataProvider, FinalizationHandler, Hasher64, Keychain, Loader, NetworkHook,
PartialMultisignature, Router, Saver, Signature,
};
use aleph_bft_types::Terminator;
use codec::{Decode, Encode, IoReader};
use futures::{
channel::{oneshot, oneshot::Receiver},
Expand Down
4 changes: 4 additions & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ aleph-bft-crypto = { path = "../crypto", version = "0.7" }
async-trait = "0.1"
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] }
futures = "0.3"
log = "0.4"

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread", "time"] }
2 changes: 2 additions & 0 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod dataio;
mod network;
mod tasks;
mod terminator;

pub use aleph_bft_crypto::{
IncompleteMultisignatureError, Index, Indexed, Keychain, MultiKeychain, Multisigned, NodeCount,
Expand All @@ -12,6 +13,7 @@ pub use aleph_bft_crypto::{
pub use dataio::{DataProvider, FinalizationHandler};
pub use network::{Network, Recipient};
pub use tasks::{SpawnHandle, TaskHandle};
pub use terminator::{handle_task_termination, Terminator};

use codec::Codec;
use std::{fmt::Debug, hash::Hash as StdHash};
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/terminator.rs → types/src/terminator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aleph_bft_crypto::NodeIndex;
use futures::{
channel::oneshot::{channel, Receiver, Sender},
future::FusedFuture,
Expand Down Expand Up @@ -170,7 +171,7 @@ pub async fn handle_task_termination<T>(
task_handle: T,
target: &'static str,
name: &'static str,
index: aleph_bft_types::NodeIndex,
index: NodeIndex,
) where
T: FusedFuture<Output = Result<(), ()>>,
{
Expand Down

0 comments on commit 480a542

Please sign in to comment.