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
use std::collections::BTreeSet;

use serde::{de::DeserializeOwned, Serialize};

use super::{SenderQueueableConsensusProtocol, SenderQueueableMessage, SenderQueueableOutput};
use crate::honey_badger::{Batch, HoneyBadger, Message};
use crate::{Contribution, Epoched, NodeIdT};

impl<C, N> SenderQueueableOutput<N, u64> for Batch<C, N>
where
    C: Contribution,
    N: NodeIdT,
{
    fn participant_change(&self) -> Option<BTreeSet<N>> {
        None
    }

    fn output_epoch(&self) -> u64 {
        self.epoch
    }
}

impl<N> SenderQueueableMessage for Message<N> {
    type Epoch = u64;

    fn is_premature(&self, them: u64, max_future_epochs: u64) -> bool {
        self.epoch() > them + max_future_epochs
    }

    fn is_obsolete(&self, them: u64) -> bool {
        self.epoch() < them
    }

    fn first_epoch(&self) -> u64 {
        self.epoch()
    }
}

impl<C, N> Epoched for HoneyBadger<C, N>
where
    C: Contribution + Serialize + DeserializeOwned,
    N: NodeIdT,
{
    type Epoch = u64;

    fn epoch(&self) -> u64 {
        self.next_epoch()
    }
}

impl<C, N> SenderQueueableConsensusProtocol for HoneyBadger<C, N>
where
    C: Contribution + Serialize + DeserializeOwned,
    N: NodeIdT,
{
    fn max_future_epochs(&self) -> u64 {
        self.max_future_epochs()
    }
}