Skip to content

Commit cbe1153

Browse files
committed
Create creator outside of creation
1 parent 0426c16 commit cbe1153

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

consensus/src/consensus/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use crate::{
66
handler::Consensus,
77
service::{Service, IO as ConsensusIO},
88
},
9-
creation, handle_task_termination,
9+
creation::{run as run_creation, Creator, IO as CreationIO},
10+
handle_task_termination,
1011
interface::LocalIO,
1112
network::{Hub as NetworkHub, NetworkData},
1213
units::Validator,
@@ -97,14 +98,16 @@ pub async fn run_session<
9798
let (starting_round_for_creator, starting_round_from_collection) = oneshot::channel();
9899

99100
debug!(target: LOG_TARGET, "Spawning creator.");
101+
let creator = Creator::new(index, config.n_members());
100102
let creator_terminator = terminator.add_offspring_connection("creator");
101103
let creator_config = config.clone();
102104
let creator_keychain = keychain.clone();
103105
let creator_handle = spawn_handle
104106
.spawn_essential("consensus/creator", async move {
105-
creation::run(
107+
run_creation(
108+
creator,
106109
creator_config,
107-
creation::IO {
110+
CreationIO {
108111
outgoing_units: new_units_for_service,
109112
incoming_parents: parents_from_service,
110113
data_provider,

consensus/src/creation/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ async fn keep_processing_units_until<U: Unit>(
109109
/// We refer to the documentation https://cardinal-cryptography.github.io/AlephBFT/internals.html
110110
/// Section 5.1 for a discussion of this component.
111111
pub async fn run<U: Unit, MK: MultiKeychain, DP: DataProvider>(
112+
creator: Creator<U::Hasher>,
112113
conf: Config,
113114
mut io: IO<U, MK, DP>,
114115
keychain: MK,
115116
mut starting_round: oneshot::Receiver<Option<Round>>,
116117
mut terminator: Terminator,
117118
) {
118119
futures::select! {
119-
_ = read_starting_round_and_run_creator(conf, &mut io, keychain, &mut starting_round).fuse() =>
120+
_ = read_starting_round_and_run_creator(creator, conf, &mut io, keychain, &mut starting_round).fuse() =>
120121
debug!(target: LOG_TARGET, "Creator is about to finish."),
121122
_ = terminator.get_exit().fuse() =>
122123
debug!(target: LOG_TARGET, "Received an exit signal."),
@@ -126,6 +127,7 @@ pub async fn run<U: Unit, MK: MultiKeychain, DP: DataProvider>(
126127
}
127128

128129
async fn read_starting_round_and_run_creator<U: Unit, MK: MultiKeychain, DP: DataProvider>(
130+
creator: Creator<U::Hasher>,
129131
conf: Config,
130132
io: &mut IO<U, MK, DP>,
131133
keychain: MK,
@@ -144,7 +146,7 @@ async fn read_starting_round_and_run_creator<U: Unit, MK: MultiKeychain, DP: Dat
144146
}
145147
};
146148

147-
if let Err(err) = run_creator(conf, io, keychain, starting_round).await {
149+
if let Err(err) = run_creator(creator, conf, io, keychain, starting_round).await {
148150
match err {
149151
CreatorError::OutChannelClosed(e) => {
150152
warn!(target: LOG_TARGET, "Notification send error: {}. Exiting.", e)
@@ -157,17 +159,15 @@ async fn read_starting_round_and_run_creator<U: Unit, MK: MultiKeychain, DP: Dat
157159
}
158160

159161
async fn run_creator<U: Unit, MK: MultiKeychain, DP: DataProvider>(
162+
mut creator: Creator<U::Hasher>,
160163
conf: Config,
161164
io: &mut IO<U, MK, DP>,
162165
keychain: MK,
163166
starting_round: Round,
164167
) -> anyhow::Result<(), CreatorError> {
165-
let node_id = conf.node_ix();
166-
let n_members = conf.n_members();
167168
let create_delay = conf.delay_config().unit_creation_delay.clone();
168169
let max_round = conf.max_round();
169170
let session_id = conf.session_id();
170-
let mut creator = Creator::new(node_id, n_members);
171171
let packer = Packer::new(keychain, session_id);
172172
let incoming_parents = &mut io.incoming_parents;
173173
let outgoing_units = &io.outgoing_units;

consensus/src/testing/creation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
creation::{run, IO},
2+
creation::{run, Creator, IO},
33
testing::{gen_config, gen_delay_config},
44
units::{SignedUnit as GenericSignedUnit, Unit as GenericUnit},
55
NodeCount, Receiver, Round, Sender, Terminator,
@@ -77,6 +77,7 @@ fn setup_test(n_members: NodeCount) -> TestSetup {
7777
data_provider: DataProvider::new(),
7878
};
7979
let config = gen_config(node_ix, n_members, gen_delay_config());
80+
let creator = Creator::new(node_ix, n_members);
8081
let (starting_round_for_consensus, starting_round) = oneshot::channel();
8182

8283
units_for_creators.push(parents_for_creator);
@@ -87,6 +88,7 @@ fn setup_test(n_members: NodeCount) -> TestSetup {
8788

8889
let handle = tokio::spawn(async move {
8990
run(
91+
creator,
9092
config,
9193
io,
9294
keychain,

0 commit comments

Comments
 (0)