fn batch_request(
        &self,
        rng: &mut NodeRng,
        vid: ValidatorIndex,
        our_next_seq: u64,
        their_next_seq: u64,
    ) -> Vec<HighwayMessage<C>> {
        let state = self.highway.state();
        if our_next_seq == their_next_seq {
            return vec![];
        }
        if our_next_seq < their_next_seq {
            // We're behind. Request missing vertices.
            (our_next_seq..their_next_seq)
                .take(self.config.max_request_batch_size)
                .map(|unit_seq_number| {
                    let uuid = rng.next_u64();
                    debug!(?uuid, ?vid, ?unit_seq_number, "requesting dependency");
                    HighwayMessage::RequestDependencyByHeight {
                        uuid,
                        vid,
                        unit_seq_number,
                    }
                })
                .into_iter()
                .collect()
        } else {
            // We're ahead.
            match state.panorama().get(vid) {
                None => {
                    warn!(?vid, "received a request for non-existing validator");
                    vec![]
                }
                Some(observation) => match observation {
                    Observation::None => {
                        warn!(
                            ?vid,
                            our_next_seq,
                            ?observation,
                            "expected unit for validator but found none"
                        );
                        vec![]
                    }
                    Observation::Faulty => {
                        let ev = match state.maybe_evidence(vid) {
                            Some(ev) => ev.clone(),
                            None => {
                                warn!(
                                    ?vid, instance_id=?self.highway.instance_id(),
                                    "panorama marked validator as faulty but no evidence was found"
                                );
                                return vec![];
                            }
                        };
                        vec![HighwayMessage::NewVertex(Vertex::Evidence(ev))]
                    }
                    Observation::Correct(hash) => (their_next_seq..our_next_seq)
                        .take(self.config.max_request_batch_size)
                        .filter_map(|seq_num| {
                            let unit = state.find_in_swimlane(hash, seq_num).unwrap();
                            state
                                .wire_unit(unit, *self.highway.instance_id())
                                .map(|swu| HighwayMessage::NewVertex(Vertex::Unit(swu)))
                        })
                        .into_iter()
                        .collect(),
                },
            }
        }
    }
/// Creates a batch of dependency requests if the peer has more units by the validator `vidx`
/// than we do; otherwise sends a batch of missing units to the peer.
Creates a batch of dependency requests if the peer has more units by the validator `vidx`
than we do; otherwise sends a batch of missing units to the peer.
Creates a batch of dependency requests if the peer has more units by the validator ` vidx ` than we do ; otherwise sends a batch of missing units to the peer .
fn batch_request(
        &self,
        rng: &mut NodeRng,
        vid: ValidatorIndex,
        our_next_seq: u64,
        their_next_seq: u64,
    ) -> Vec<HighwayMessage<C>> {
        let state = self.highway.state();
        if our_next_seq == their_next_seq {
            return vec![];
        }
        if our_next_seq < their_next_seq {
            // We're behind. Request missing vertices.
            (our_next_seq..their_next_seq)
                .take(self.config.max_request_batch_size)
                .map(|unit_seq_number| {
                    let uuid = rng.next_u64();
                    debug!(?uuid, ?vid, ?unit_seq_number, "requesting dependency");
                    HighwayMessage::RequestDependencyByHeight {
                        uuid,
                        vid,
                        unit_seq_number,
                    }
                })
                .into_iter()
                .collect()
        } else {
            // We're ahead.
            match state.panorama().get(vid) {
                None => {
                    warn!(?vid, "received a request for non-existing validator");
                    vec![]
                }
                Some(observation) => match observation {
                    Observation::None => {
                        warn!(
                            ?vid,
                            our_next_seq,
                            ?observation,
                            "expected unit for validator but found none"
                        );
                        vec![]
                    }
                    Observation::Faulty => {
                        let ev = match state.maybe_evidence(vid) {
                            Some(ev) => ev.clone(),
                            None => {
                                warn!(
                                    ?vid, instance_id=?self.highway.instance_id(),
                                    "panorama marked validator as faulty but no evidence was found"
                                );
                                return vec![];
                            }
                        };
                        vec![HighwayMessage::NewVertex(Vertex::Evidence(ev))]
                    }
                    Observation::Correct(hash) => (their_next_seq..our_next_seq)
                        .take(self.config.max_request_batch_size)
                        .filter_map(|seq_num| {
                            let unit = state.find_in_swimlane(hash, seq_num).unwrap();
                            state
                                .wire_unit(unit, *self.highway.instance_id())
                                .map(|swu| HighwayMessage::NewVertex(Vertex::Unit(swu)))
                        })
                        .into_iter()
                        .collect(),
                },
            }
        }
    }
fn batch_request ( & self , rng : & mut NodeRng , vid : ValidatorIndex , our_next_seq : u64 , their_next_seq : u64 , ) -> Vec < HighwayMessage < C > > { let state = self . highway . state ( ) ; if our_next_seq == their_next_seq { return vec ! [ ] ; } if our_next_seq < their_next_seq { // We're behind. Request missing vertices. ( our_next_seq .. their_next_seq ) . take ( self . config . max_request_batch_size ) . map ( | unit_seq_number | { let uuid = rng . next_u64 ( ) ; debug ! ( uuid vid unit_seq_number " " ) ; HighwayMessage :: RequestDependencyByHeight { uuid , vid , unit_seq_number , } } ) . into_iter ( ) . collect ( ) } else { // We're ahead. match state . panorama ( ) . get ( vid ) { None => { warn ! ( vid " " ) ; vec ! [ ] } Some ( observation ) => match observation { Observation :: None => { warn ! ( vid our_next_seq observation " " ) ; vec ! [ ] } Observation :: Faulty => { let ev = match state . maybe_evidence ( vid ) { Some ( ev ) => ev . clone ( ) , None => { warn ! ( vid instance_id self highway instance_id ( ) " " ) ; return vec ! [ ] ; } } ; vec ! [ HighwayMessage NewVertex ( Vertex Evidence ( ev ) ) ] } Observation :: Correct ( hash ) => ( their_next_seq .. our_next_seq ) . take ( self . config . max_request_batch_size ) . filter_map ( | seq_num | { let unit = state . find_in_swimlane ( hash , seq_num ) . unwrap ( ) ; state . wire_unit ( unit , * self . highway . instance_id ( ) ) . map ( | swu | HighwayMessage :: NewVertex ( Vertex :: Unit ( swu ) ) ) } ) . into_iter ( ) . collect ( ) , } , } } }
Creates a batch of dependency requests if the peer has more units by the validator `vidx`
than we do; otherwise sends a batch of missing units to the peer.
Creates a batch of dependency requests if the peer has more units by the validator ` vidx ` than we do ; otherwise sends a batch of missing units to the peer .
&self
rng
&mut NodeRng
vid
ValidatorIndex
our_next_seq
u64
their_next_seq
u64
&self
rng
&mut NodeRng
vid
ValidatorIndex
our_next_seq
u64
their_next_seq
u64