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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::result;
use crate::crypto::PublicKey;
use rand::distributions::{Distribution, Standard};
use rand::Rng;
use serde::{de::DeserializeOwned, Serialize};
use super::{Error, SenderQueue, SenderQueueableConsensusProtocol};
use crate::queueing_honey_badger::{Change, Error as QhbError, QueueingHoneyBadger};
use crate::transaction_queue::TransactionQueue;
use crate::{Contribution, CpStep, Epoched, NodeIdT};
impl<T, N, Q> Epoched for QueueingHoneyBadger<T, N, Q>
where
T: Contribution + Serialize + DeserializeOwned + Clone,
N: NodeIdT + Serialize + DeserializeOwned,
Q: TransactionQueue<T>,
Standard: Distribution<N>,
{
type Epoch = (u64, u64);
fn epoch(&self) -> (u64, u64) {
self.dyn_hb().epoch()
}
}
impl<T, N, Q> SenderQueueableConsensusProtocol for QueueingHoneyBadger<T, N, Q>
where
T: Contribution + Serialize + DeserializeOwned + Clone,
N: NodeIdT + Serialize + DeserializeOwned,
Q: TransactionQueue<T>,
Standard: Distribution<N>,
{
fn max_future_epochs(&self) -> u64 {
self.dyn_hb().max_future_epochs()
}
}
type Result<T, N, Q> =
result::Result<CpStep<SenderQueue<QueueingHoneyBadger<T, N, Q>>>, Error<QhbError>>;
impl<T, N, Q> SenderQueue<QueueingHoneyBadger<T, N, Q>>
where
T: Contribution + Serialize + DeserializeOwned + Clone,
N: NodeIdT + Serialize + DeserializeOwned,
Q: TransactionQueue<T>,
Standard: Distribution<N>,
{
pub fn push_transaction<R: Rng>(&mut self, tx: T, rng: &mut R) -> Result<T, N, Q> {
self.apply(|algo| algo.push_transaction(tx, rng))
}
pub fn vote_for<R: Rng>(&mut self, change: Change<N>, rng: &mut R) -> Result<T, N, Q> {
self.apply(|algo| algo.vote_for(change, rng))
}
pub fn vote_to_add<R: Rng>(
&mut self,
node_id: N,
pub_key: PublicKey,
rng: &mut R,
) -> Result<T, N, Q> {
self.apply(|algo| algo.vote_to_add(node_id, pub_key, rng))
}
pub fn vote_to_remove<R: Rng>(&mut self, node_id: &N, rng: &mut R) -> Result<T, N, Q> {
self.apply(|algo| algo.vote_to_remove(node_id, rng))
}
}