1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use config::WorkerId;
use fastcrypto::Hash;
use store::Store;
use tokio::{sync::watch, task::JoinHandle};
use types::{
error::DagError,
metered_channel::{Receiver, Sender},
Batch, BatchDigest, ReconfigureNotification, WorkerPrimaryMessage,
};
#[cfg(test)]
#[path = "tests/processor_tests.rs"]
pub mod processor_tests;
pub struct Processor;
impl Processor {
#[must_use]
pub fn spawn(
id: WorkerId,
store: Store<BatchDigest, Batch>,
mut rx_reconfigure: watch::Receiver<ReconfigureNotification>,
mut rx_batch: Receiver<Batch>,
tx_digest: Sender<WorkerPrimaryMessage>,
own_digest: bool,
) -> JoinHandle<()> {
tokio::spawn(async move {
loop {
tokio::select! {
Some(batch) = rx_batch.recv() => {
let digest = batch.digest();
store.write(digest, batch).await;
let message = match own_digest {
true => WorkerPrimaryMessage::OurBatch(digest, id),
false => WorkerPrimaryMessage::OthersBatch(digest, id),
};
if tx_digest
.send(message)
.await
.is_err() {
tracing::debug!("{}", DagError::ShuttingDown);
};
},
result = rx_reconfigure.changed() => {
result.expect("Committee channel dropped");
let message = rx_reconfigure.borrow().clone();
if let ReconfigureNotification::Shutdown = message {
return;
}
}
}
}
})
}
}