pub(crate) fn add_valid_unit(&mut self, swunit: SignedWireUnit<C>) {
        let wunit = swunit.wire_unit();
        let hash = swunit.hash();
        if self.has_unit(&hash) {
            warn!(%hash, "called add_valid_unit twice");
            return;
        }
        let instance_id = wunit.instance_id;
        let fork_choice = self.fork_choice(&wunit.panorama).cloned();
        let (unit, maybe_value) = Unit::new(swunit, fork_choice.as_ref(), self);
        if let Some(value) = maybe_value {
            let block = Block::new(fork_choice, value, self);
            self.blocks.insert(hash, block);
        }
        self.add_ping(unit.creator, unit.timestamp);
        self.units.insert(hash, unit);

        // Update the panorama.
        let unit = self.unit(&hash);
        let creator = unit.creator;
        let new_obs = match (&self.panorama[creator], &unit.panorama[creator]) {
            (Observation::Faulty, _) => Observation::Faulty,
            (obs0, obs1) if obs0 == obs1 => Observation::Correct(hash),
            (Observation::None, _) => panic!("missing creator's previous unit"),
            (Observation::Correct(hash0), _) => {
                // We have all dependencies of unit, but it does not cite hash0 as its predecessor,
                // which is our latest known unit by the creator. It must therefore cite an older
                // unit and so its sequence number must be at most the same as hash0. Hence it is
                // an equivocation, and to prove that, we only need to provide the other unit with
                // the same sequence number.
                let prev0 = self.find_in_swimlane(hash0, unit.seq_number).unwrap();
                let wunit0 = self.wire_unit(prev0, instance_id).unwrap();
                let wunit1 = self.wire_unit(&hash, instance_id).unwrap();
                self.add_evidence(Evidence::Equivocation(wunit0, wunit1));
                Observation::Faulty
            }
        };
        self.panorama[creator] = new_obs;
    }
/// Adds the unit to the protocol state.
///
/// The unit must be valid (see `validate_unit`), and its dependencies satisfied.
Adds the unit to the protocol state.
The unit must be valid , and its dependencies satisfied.
Adds the unit to the protocol state . The unit must be valid and its dependencies satisfied .
pub(crate) fn add_valid_unit(&mut self, swunit: SignedWireUnit<C>) {
        let wunit = swunit.wire_unit();
        let hash = swunit.hash();
        if self.has_unit(&hash) {
            warn!(%hash, "called add_valid_unit twice");
            return;
        }
        let instance_id = wunit.instance_id;
        let fork_choice = self.fork_choice(&wunit.panorama).cloned();
        let (unit, maybe_value) = Unit::new(swunit, fork_choice.as_ref(), self);
        if let Some(value) = maybe_value {
            let block = Block::new(fork_choice, value, self);
            self.blocks.insert(hash, block);
        }
        self.add_ping(unit.creator, unit.timestamp);
        self.units.insert(hash, unit);
        // Update the panorama.
        let unit = self.unit(&hash);
        let creator = unit.creator;
        let new_obs = match (&self.panorama[creator], &unit.panorama[creator]) {
            (Observation::Faulty, _) => Observation::Faulty,
            (obs0, obs1) if obs0 == obs1 => Observation::Correct(hash),
            (Observation::None, _) => panic!("missing creator's previous unit"),
            (Observation::Correct(hash0), _) => {
                // We have all dependencies of unit, but it does not cite hash0 as its predecessor,
                // which is our latest known unit by the creator. It must therefore cite an older
                // unit and so its sequence number must be at most the same as hash0. Hence it is
                // an equivocation, and to prove that, we only need to provide the other unit with
                // the same sequence number.
                let prev0 = self.find_in_swimlane(hash0, unit.seq_number).unwrap();
                let wunit0 = self.wire_unit(prev0, instance_id).unwrap();
                let wunit1 = self.wire_unit(&hash, instance_id).unwrap();
                self.add_evidence(Evidence::Equivocation(wunit0, wunit1));
                Observation::Faulty
            }
        };
        self.panorama[creator] = new_obs;
    }
pub ( crate ) fn add_valid_unit ( & mut self , swunit : SignedWireUnit < C > ) { let wunit = swunit . wire_unit ( ) ; let hash = swunit . hash ( ) ; if self . has_unit ( & hash ) { warn ! ( hash " " ) ; return ; } let instance_id = wunit . instance_id ; let fork_choice = self . fork_choice ( & wunit . panorama ) . cloned ( ) ; let ( unit , maybe_value ) = Unit :: new ( swunit , fork_choice . as_ref ( ) , self ) ; if let Some ( value ) = maybe_value { let block = Block :: new ( fork_choice , value , self ) ; self . blocks . insert ( hash , block ) ; } self . add_ping ( unit . creator , unit . timestamp ) ; self . units . insert ( hash , unit ) ; // Update the panorama. let unit = self . unit ( & hash ) ; let creator = unit . creator ; let new_obs = match ( & self . panorama [ creator ] , & unit . panorama [ creator ] ) { ( Observation :: Faulty , _ ) => Observation :: Faulty , ( obs0 , obs1 ) if obs0 == obs1 => Observation :: Correct ( hash ) , ( Observation :: None , _ ) => panic ! ( " " ) , ( Observation :: Correct ( hash0 ) , _ ) => { // We have all dependencies of unit, but it does not cite hash0 as its predecessor, // which is our latest known unit by the creator. It must therefore cite an older // unit and so its sequence number must be at most the same as hash0. Hence it is // an equivocation, and to prove that, we only need to provide the other unit with // the same sequence number. let prev0 = self . find_in_swimlane ( hash0 , unit . seq_number ) . unwrap ( ) ; let wunit0 = self . wire_unit ( prev0 , instance_id ) . unwrap ( ) ; let wunit1 = self . wire_unit ( & hash , instance_id ) . unwrap ( ) ; self . add_evidence ( Evidence :: Equivocation ( wunit0 , wunit1 ) ) ; Observation :: Faulty } } ; self . panorama [ creator ] = new_obs ; }
Adds the unit to the protocol state.
Adds the unit to the protocol state .
&mut self
swunit
SignedWireUnit<C>
&mut self
swunit
SignedWireUnit<C>