aleph-bft 0.45.4

AlephBFT is an asynchronous and Byzantine fault tolerant consensus protocol aimed at ordering arbitrary messages (transactions). It has been designed to continuously operate even in the harshest conditions: with no bounds on message-delivery delays and in the presence of malicious actors. This makes it an excellent fit for blockchain-related applications.
Documentation
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
//! Converts units from the network into ones that are in the Dag, in the correct order.
use std::collections::HashMap;

use crate::{
    alerts::{Alert, ForkingNotification},
    units::{
        SignedUnit, UncheckedSignedUnit, Unit, UnitStore, Validator as UnitValidator, WrappedUnit,
    },
    Data, Hasher, MultiKeychain,
};
use log::{debug, trace, warn};

mod reconstruction;
mod validation;

pub use reconstruction::{ReconstructedUnit, Request};
use reconstruction::{Reconstruction, ReconstructionResult};
pub use validation::ValidatorStatus as DagStatus;
use validation::{Error as ValidationError, Validator};

const LOG_TARGET: &str = "AlephBFT-dag";

pub type DagUnit<H, D, MK> = ReconstructedUnit<SignedUnit<H, D, MK>>;

/// The result of sending some information to the Dag.
pub struct DagResult<H: Hasher, D: Data, MK: MultiKeychain> {
    /// Units added to the dag.
    pub units: Vec<DagUnit<H, D, MK>>,
    /// Requests for more information.
    pub requests: Vec<Request<H>>,
    /// Alerts raised due to encountered forks.
    pub alerts: Vec<Alert<H, D, MK::Signature>>,
}

impl<H: Hasher, D: Data, MK: MultiKeychain> DagResult<H, D, MK> {
    fn empty() -> Self {
        DagResult {
            units: Vec::new(),
            requests: Vec::new(),
            alerts: Vec::new(),
        }
    }

    fn alert(alert: Alert<H, D, MK::Signature>) -> Self {
        DagResult {
            units: Vec::new(),
            requests: Vec::new(),
            alerts: vec![alert],
        }
    }

    fn add_alert(&mut self, alert: Alert<H, D, MK::Signature>) {
        self.alerts.push(alert);
    }

    fn accumulate(&mut self, other: DagResult<H, D, MK>) {
        let DagResult {
            mut units,
            mut requests,
            mut alerts,
        } = other;
        self.units.append(&mut units);
        self.requests.append(&mut requests);
        self.alerts.append(&mut alerts);
    }
}

impl<H: Hasher, D: Data, MK: MultiKeychain> From<ReconstructionResult<SignedUnit<H, D, MK>>>
    for DagResult<H, D, MK>
{
    fn from(other: ReconstructionResult<SignedUnit<H, D, MK>>) -> Self {
        let ReconstructionResult { units, requests } = other;
        DagResult {
            units,
            requests,
            alerts: Vec::new(),
        }
    }
}

/// The Dag ensuring that all units from the network get returned reconstructed in the correct order.
pub struct Dag<H: Hasher, D: Data, MK: MultiKeychain> {
    validator: Validator<H, D, MK>,
    reconstruction: Reconstruction<SignedUnit<H, D, MK>>,
}

impl<H: Hasher, D: Data, MK: MultiKeychain> Dag<H, D, MK> {
    /// A new dag using the provided unit validator under the hood.
    pub fn new(unit_validator: UnitValidator<MK>) -> Self {
        Dag {
            validator: Validator::new(unit_validator),
            reconstruction: Reconstruction::new(),
        }
    }

    fn handle_validation_error(error: ValidationError<H, D, MK>) -> DagResult<H, D, MK> {
        use ValidationError::*;
        match error {
            Invalid(e) => {
                warn!(target: LOG_TARGET, "Received unit failing validation: {}", e);
                DagResult::empty()
            }
            Duplicate(unit) => {
                trace!(target: LOG_TARGET, "Received unit with hash {:?} again.", unit.hash());
                DagResult::empty()
            }
            Uncommitted(unit) => {
                debug!(target: LOG_TARGET, "Received unit with hash {:?} created by known forker {:?} for which we don't have a commitment, discarding.", unit.hash(), unit.creator());
                DagResult::empty()
            }
            NewForker(alert) => {
                warn!(target: LOG_TARGET, "New forker detected.");
                trace!(target: LOG_TARGET, "Created alert: {:?}.", alert);
                DagResult::alert(*alert)
            }
        }
    }

    /// Add a unit to the Dag.
    pub fn add_unit<U: WrappedUnit<H, Wrapped = SignedUnit<H, D, MK>>>(
        &mut self,
        unit: UncheckedSignedUnit<H, D, MK::Signature>,
        store: &UnitStore<U>,
    ) -> DagResult<H, D, MK> {
        match self.validator.validate(unit, store) {
            Ok(unit) => self.reconstruction.add_unit(unit).into(),
            Err(e) => Self::handle_validation_error(e),
        }
    }

    /// Add parents of a unit to the Dag.
    pub fn add_parents<U: WrappedUnit<H, Wrapped = SignedUnit<H, D, MK>>>(
        &mut self,
        unit_hash: H::Hash,
        parents: Vec<UncheckedSignedUnit<H, D, MK::Signature>>,
        store: &UnitStore<U>,
    ) -> DagResult<H, D, MK> {
        use ValidationError::*;
        let mut result = DagResult::empty();
        let mut parent_hashes = HashMap::new();
        for unit in parents {
            let unit = match self.validator.validate(unit, store) {
                Ok(unit) => {
                    result.accumulate(self.reconstruction.add_unit(unit.clone()).into());
                    unit
                }
                Err(Invalid(e)) => {
                    warn!(target: LOG_TARGET, "Received parent failing validation: {}", e);
                    return result;
                }
                Err(Duplicate(unit)) => {
                    trace!(target: LOG_TARGET, "Received parent with hash {:?} again.", unit.hash());
                    unit
                }
                Err(Uncommitted(unit)) => {
                    debug!(target: LOG_TARGET, "Received uncommitted parent {:?}, we should get the commitment soon.", unit.hash());
                    unit
                }
                Err(NewForker(alert)) => {
                    warn!(target: LOG_TARGET, "New forker detected.");
                    trace!(target: LOG_TARGET, "Created alert: {:?}.", alert);
                    result.add_alert(*alert);
                    // technically this was a correct unit, so we could have passed it on,
                    // but this will happen at most once and we will receive the parent
                    // response again, so we just discard it now
                    return result;
                }
            };
            parent_hashes.insert(unit.coord(), unit.hash());
        }
        result.accumulate(
            self.reconstruction
                .add_parents(unit_hash, parent_hashes)
                .into(),
        );
        result
    }

    /// Process a forking notification, potentially returning a lot of unit processing results.
    pub fn process_forking_notification<U: WrappedUnit<H, Wrapped = SignedUnit<H, D, MK>>>(
        &mut self,
        notification: ForkingNotification<H, D, MK::Signature>,
        store: &UnitStore<U>,
    ) -> DagResult<H, D, MK> {
        use ForkingNotification::*;
        let mut result = DagResult::empty();
        match notification {
            Forker((unit, other_unit)) => {
                // Just treat them as normal incoming units, if they are a forking proof
                // this will either trigger a new forker or we already knew about this one.
                result.accumulate(self.add_unit(unit, store));
                result.accumulate(self.add_unit(other_unit, store));
            }
            Units(units) => {
                for unit in units {
                    result.accumulate(match self.validator.validate_committed(unit, store) {
                        Ok(unit) => self.reconstruction.add_unit(unit).into(),
                        Err(e) => Self::handle_validation_error(e),
                    })
                }
            }
        }
        result
    }

    /// The store of units currently being processed by this dag.
    pub fn processing_units(&self) -> &UnitStore<SignedUnit<H, D, MK>> {
        self.validator.processing_units()
    }

    /// Notify the dag that a unit has finished processing and can be cleared from the cache.
    pub fn finished_processing(&mut self, hash: &H::Hash) {
        self.validator.finished_processing(hash);
    }

    pub fn status(&self) -> DagStatus {
        self.validator.status()
    }
}

#[cfg(test)]
mod test {
    use crate::{
        alerts::ForkingNotification,
        dag::{Dag, DagResult, Request},
        units::{
            random_full_parent_units_up_to, random_unit_with_parents, Unit, UnitStore,
            Validator as UnitValidator, WrappedSignedUnit,
        },
        NodeCount, NodeIndex, Signed,
    };
    use aleph_bft_mock::Keychain;

    #[test]
    fn accepts_initial_units() {
        let node_count = NodeCount(4);
        let node_id = NodeIndex(0);
        let session_id = 43;
        let max_round = 2137;
        let keychains: Vec<_> = node_count
            .into_iterator()
            .map(|node_id| Keychain::new(node_count, node_id))
            .collect();
        let store = UnitStore::<WrappedSignedUnit>::new(node_count);
        let validator = UnitValidator::new(session_id, keychains[node_id.0], max_round);
        let mut dag = Dag::new(validator);
        for unit in random_full_parent_units_up_to(0, node_count, session_id)
            .into_iter()
            .flatten()
            .map(|unit| {
                let keychain = keychains
                    .get(unit.creator().0)
                    .expect("we have the keychains");
                Signed::sign(unit, keychain)
            })
        {
            let DagResult {
                units,
                requests,
                alerts,
            } = dag.add_unit(unit.into(), &store);
            assert_eq!(units.len(), 1);
            assert!(requests.is_empty());
            assert!(alerts.is_empty());
        }
    }

    #[test]
    fn accepts_units_in_order() {
        let node_count = NodeCount(4);
        let node_id = NodeIndex(0);
        let session_id = 43;
        let max_round = 2137;
        let keychains: Vec<_> = node_count
            .into_iterator()
            .map(|node_id| Keychain::new(node_count, node_id))
            .collect();
        let store = UnitStore::<WrappedSignedUnit>::new(node_count);
        let validator = UnitValidator::new(session_id, keychains[node_id.0], max_round);
        let mut dag = Dag::new(validator);
        for unit in random_full_parent_units_up_to(13, node_count, session_id)
            .into_iter()
            .flatten()
            .map(|unit| {
                let keychain = keychains
                    .get(unit.creator().0)
                    .expect("we have the keychains");
                Signed::sign(unit, keychain)
            })
        {
            let DagResult {
                units,
                requests,
                alerts,
            } = dag.add_unit(unit.into(), &store);
            assert_eq!(units.len(), 1);
            assert!(requests.is_empty());
            assert!(alerts.is_empty());
        }
    }

    #[test]
    fn accepts_units_in_reverse_order() {
        let node_count = NodeCount(4);
        let node_id = NodeIndex(0);
        let session_id = 43;
        let max_round = 2137;
        let total_rounds = 13;
        let keychains: Vec<_> = node_count
            .into_iterator()
            .map(|node_id| Keychain::new(node_count, node_id))
            .collect();
        let store = UnitStore::<WrappedSignedUnit>::new(node_count);
        let validator = UnitValidator::new(session_id, keychains[node_id.0], max_round);
        let mut dag = Dag::new(validator);
        for unit in random_full_parent_units_up_to(total_rounds, node_count, session_id)
            .into_iter()
            .flatten()
            .rev()
            .map(|unit| {
                let keychain = keychains
                    .get(unit.creator().0)
                    .expect("we have the keychains");
                Signed::sign(unit, keychain)
            })
        {
            let unit_round = unit.round();
            let unit_creator = unit.creator();
            let DagResult {
                units,
                requests,
                alerts,
            } = dag.add_unit(unit.into(), &store);
            assert!(alerts.is_empty());
            match unit_round {
                0 => match unit_creator {
                    NodeIndex(0) => {
                        assert_eq!(units.len(), (total_rounds * 4 + 1).into());
                        assert!(requests.is_empty());
                    }
                    _ => {
                        assert_eq!(units.len(), 1);
                        assert!(requests.is_empty());
                    }
                },
                _ => {
                    assert_eq!(requests.len(), 4);
                    assert!(units.is_empty());
                }
            }
        }
    }

    #[test]
    fn alerts_on_fork() {
        let node_count = NodeCount(4);
        let node_id = NodeIndex(0);
        let session_id = 43;
        let max_round = 2137;
        let keychains: Vec<_> = node_count
            .into_iterator()
            .map(|node_id| Keychain::new(node_count, node_id))
            .collect();
        let mut store = UnitStore::new(node_count);
        let validator = UnitValidator::new(session_id, keychains[node_id.0], max_round);
        let mut dag = Dag::new(validator);
        let forker_id = NodeIndex(3);
        let keychain = keychains.get(forker_id.0).expect("we have the keychain");
        let unit = random_full_parent_units_up_to(0, node_count, session_id)
            .first()
            .expect("we have initial units")
            .get(forker_id.0)
            .expect("We have the forker")
            .clone();
        let unit = Signed::sign(unit, keychain);
        let mut fork = random_full_parent_units_up_to(0, node_count, session_id)
            .first()
            .expect("we have initial units")
            .get(forker_id.0)
            .expect("We have the forker")
            .clone();
        // we might have randomly created an identical "fork"
        while fork.hash() == unit.hash() {
            fork = random_full_parent_units_up_to(0, node_count, session_id)
                .first()
                .expect("we have initial units")
                .get(forker_id.0)
                .expect("We have the forker")
                .clone();
        }
        let fork = Signed::sign(fork, keychain);
        let DagResult {
            mut units,
            requests,
            alerts,
        } = dag.add_unit(unit.into(), &store);
        assert_eq!(units.len(), 1);
        assert!(requests.is_empty());
        assert!(alerts.is_empty());
        store.insert(units.pop().expect("just checked"));
        let DagResult {
            units,
            requests,
            alerts,
        } = dag.add_unit(fork.into(), &store);
        assert!(units.is_empty());
        assert!(requests.is_empty());
        assert_eq!(alerts.len(), 1);
    }

    #[test]
    fn detects_fork_through_notification() {
        let node_count = NodeCount(7);
        let node_id = NodeIndex(0);
        let forker_id = NodeIndex(3);
        let session_id = 0;
        let max_round = 2137;
        let keychains: Vec<_> = node_count
            .into_iterator()
            .map(|node_id| Keychain::new(node_count, node_id))
            .collect();
        let store = UnitStore::<WrappedSignedUnit>::new(node_count);
        let validator = UnitValidator::new(session_id, keychains[node_id.0], max_round);
        let mut dag = Dag::new(validator);
        let unit = random_full_parent_units_up_to(2, node_count, session_id)
            .get(2)
            .expect("we have the requested round")
            .get(forker_id.0)
            .expect("we have the unit for the forker")
            .clone();
        let unit = Signed::sign(unit, &keychains[forker_id.0]);
        let fork = random_full_parent_units_up_to(2, node_count, session_id)
            .get(2)
            .expect("we have the requested round")
            .get(forker_id.0)
            .expect("we have the unit for the forker")
            .clone();
        let fork = Signed::sign(fork, &keychains[forker_id.0]);
        let DagResult {
            units,
            requests,
            alerts,
        } = dag.process_forking_notification(
            ForkingNotification::Forker((unit.clone().into(), fork.into())),
            &store,
        );
        // parents were not passed, so the correct unit does not yet get returned
        assert!(units.is_empty());
        assert_eq!(requests.len(), node_count.0);
        assert_eq!(alerts.len(), 1);
    }

    #[test]
    fn accepts_committed() {
        let node_count = NodeCount(7);
        let node_id = NodeIndex(0);
        let forker_id = NodeIndex(3);
        let session_id = 0;
        let max_round = 2137;
        let produced_round = 4;
        let keychains: Vec<_> = node_count
            .into_iterator()
            .map(|node_id| Keychain::new(node_count, node_id))
            .collect();
        let store = UnitStore::<WrappedSignedUnit>::new(node_count);
        let validator = UnitValidator::new(session_id, keychains[node_id.0], max_round);
        let mut dag = Dag::new(validator);
        let units = random_full_parent_units_up_to(produced_round, node_count, session_id);
        let fork_parents = units
            .get(2)
            .expect("we have the requested round")
            .iter()
            .take(5)
            .cloned()
            .collect();
        let fork = random_unit_with_parents(forker_id, &fork_parents, 3);
        let fork = Signed::sign(fork, &keychains[forker_id.0]);
        let unit = units
            .get(3)
            .expect("we have the requested round")
            .get(forker_id.0)
            .expect("we have the forker's unit")
            .clone();
        let unit = Signed::sign(unit, &keychains[forker_id.0]);
        let DagResult {
            units: reconstructed_units,
            requests,
            alerts,
        } = dag.process_forking_notification(
            ForkingNotification::Forker((unit.clone().into(), fork.clone().into())),
            &store,
        );
        assert!(reconstructed_units.is_empty());
        assert_eq!(requests.len(), node_count.0);
        assert_eq!(alerts.len(), 1);
        // normally adding forker units should no longer work now, so trying to add all units only adds initial units of non-forkers
        let mut units_added = 0;
        for unit in units.iter().flatten().map(|unit| {
            let keychain = keychains
                .get(unit.creator().0)
                .expect("we have the keychains");
            Signed::sign(unit.clone(), keychain)
        }) {
            let DagResult {
                units,
                requests: _,
                alerts,
            } = dag.add_unit(unit.into(), &store);
            units_added += units.len();
            assert!(alerts.is_empty());
        }
        assert_eq!(units_added, node_count.0 - 1);
        let committed_units = units
            .iter()
            .take(3)
            .map(|units| {
                units
                    .get(forker_id.0)
                    .expect("we have the forker's unit")
                    .clone()
            })
            .map(|unit| Signed::sign(unit, &keychains[forker_id.0]))
            .chain(Some(fork))
            .map(|unit| unit.into())
            .collect();
        let DagResult {
            units: reconstructed_units,
            requests,
            alerts,
        } = dag.process_forking_notification(ForkingNotification::Units(committed_units), &store);
        assert!(alerts.is_empty());
        // the non-fork unit was added first in the forking notif, so all units reconstruct successfully
        assert!(requests.is_empty());
        assert_eq!(reconstructed_units.len(), node_count.0 * 4 + 1);
    }

    #[test]
    fn handles_explicit_parents() {
        let node_count = NodeCount(7);
        let node_id = NodeIndex(0);
        let forker_id = NodeIndex(3);
        let session_id = 0;
        let max_round = 2137;
        let produced_round = 4;
        let keychains: Vec<_> = node_count
            .into_iterator()
            .map(|node_id| Keychain::new(node_count, node_id))
            .collect();
        let store = UnitStore::<WrappedSignedUnit>::new(node_count);
        let validator = UnitValidator::new(session_id, keychains[node_id.0], max_round);
        let mut dag = Dag::new(validator);
        let units = random_full_parent_units_up_to(produced_round, node_count, session_id);
        let fork_parents = units
            .get(2)
            .expect("we have the requested round")
            .iter()
            .take(5)
            .cloned()
            .collect();
        let fork = random_unit_with_parents(forker_id, &fork_parents, 3);
        let fork = Signed::sign(fork, &keychains[forker_id.0]);
        let unit = units
            .get(3)
            .expect("we have the requested round")
            .get(forker_id.0)
            .expect("we have the forker's unit")
            .clone();
        let unit = Signed::sign(unit, &keychains[forker_id.0]);
        let DagResult {
            units: reconstructed_units,
            requests,
            alerts,
        } = dag.process_forking_notification(
            // note the reverse order, to create parent requests later
            ForkingNotification::Forker((fork.clone().into(), unit.clone().into())),
            &store,
        );
        assert!(reconstructed_units.is_empty());
        // the fork only has 5 parents
        assert_eq!(requests.len(), 5);
        assert_eq!(alerts.len(), 1);
        let mut units_added = 0;
        let mut all_requests = Vec::new();
        for unit in units.iter().flatten().map(|unit| {
            let keychain = keychains
                .get(unit.creator().0)
                .expect("we have the keychains");
            Signed::sign(unit.clone(), keychain)
        }) {
            let DagResult {
                units,
                mut requests,
                alerts,
            } = dag.add_unit(unit.into(), &store);
            units_added += units.len();
            all_requests.append(&mut requests);
            assert!(alerts.is_empty());
        }
        assert_eq!(units_added, node_count.0 - 1);
        let mut parent_requests: Vec<_> = all_requests
            .into_iter()
            .filter_map(|request| match request {
                Request::Coord(_) => None,
                Request::ParentsOf(hash) => Some(hash),
            })
            .collect();
        // all the round 4 non-forker units should be confused
        assert_eq!(parent_requests.len(), node_count.0 - 1);
        let committed_units = units
            .iter()
            .take(3)
            .map(|units| {
                units
                    .get(forker_id.0)
                    .expect("we have the forker's unit")
                    .clone()
            })
            .map(|unit| Signed::sign(unit, &keychains[forker_id.0]))
            .chain(Some(fork))
            .map(|unit| unit.into())
            .collect();
        let DagResult {
            units: reconstructed_units,
            requests,
            alerts,
        } = dag.process_forking_notification(ForkingNotification::Units(committed_units), &store);
        assert!(alerts.is_empty());
        // we already got the requests earlier, in parent_requests
        assert!(requests.is_empty());
        assert!(!reconstructed_units.is_empty());
        // gotta also commit to the correct unit, so that it can get imported
        let committed_units = units
            .iter()
            .take(4)
            .map(|units| {
                units
                    .get(forker_id.0)
                    .expect("we have the forker's unit")
                    .clone()
            })
            .map(|unit| Signed::sign(unit, &keychains[forker_id.0]).into())
            .collect();
        let DagResult {
            units: reconstructed_units,
            requests,
            alerts,
        } = dag.process_forking_notification(ForkingNotification::Units(committed_units), &store);
        assert!(alerts.is_empty());
        assert!(requests.is_empty());
        assert_eq!(reconstructed_units.len(), 1);
        let confused_unit = parent_requests.pop().expect("we chacked it's not empty");
        let parents = units
            .get(3)
            .expect("we have round 3 units")
            .iter()
            .map(|unit| Signed::sign(unit.clone(), &keychains[unit.creator().0]))
            .map(|unit| unit.into())
            .collect();
        let DagResult {
            units: reconstructed_units,
            requests,
            alerts,
        } = dag.add_parents(confused_unit, parents, &store);
        assert!(alerts.is_empty());
        assert!(requests.is_empty());
        assert_eq!(reconstructed_units.len(), 1);
        assert_eq!(reconstructed_units[0].hash(), confused_unit);
    }
}