pub(crate) fn update(&mut self, headers: Vec<NewHeader>) {
        if let Some(first_height) = headers.first().map(|h| h.height) {
            for (hash, _header) in self.headers.drain(first_height..) {
                assert!(self.heights.remove(&hash).is_some());
            }
            for (h, height) in headers.into_iter().zip(first_height..) {
                assert_eq!(h.height, height);
                assert_eq!(h.hash, h.header.block_hash());
                assert!(self.heights.insert(h.hash, h.height).is_none());
                self.headers.push((h.hash, h.header));
            }
            info!(
                "chain updated: tip={}, height={}",
                self.headers.last().unwrap().0,
                self.headers.len() - 1
            );
        }
    }
/// Update the chain with a list of new headers (possibly a reorg)
Update the chain with a list of new headers (possibly a reorg)
Update the chain with a list of new headers ( possibly a reorg )
pub(crate) fn update(&mut self, headers: Vec<NewHeader>) {
        if let Some(first_height) = headers.first().map(|h| h.height) {
            for (hash, _header) in self.headers.drain(first_height..) {
                assert!(self.heights.remove(&hash).is_some());
            }
            for (h, height) in headers.into_iter().zip(first_height..) {
                assert_eq!(h.height, height);
                assert_eq!(h.hash, h.header.block_hash());
                assert!(self.heights.insert(h.hash, h.height).is_none());
                self.headers.push((h.hash, h.header));
            }
            info!(
                "chain updated: tip={}, height={}",
                self.headers.last().unwrap().0,
                self.headers.len() - 1
            );
        }
    }
pub ( crate ) fn update ( & mut self , headers : Vec < NewHeader > ) { if let Some ( first_height ) = headers . first ( ) . map ( | h | h . height ) { for ( hash , _header ) in self . headers . drain ( first_height .. ) { assert ! ( self heights remove ( hash ) is_some ( ) ) ; } for ( h , height ) in headers . into_iter ( ) . zip ( first_height .. ) { assert_eq ! ( h height height ) ; assert_eq ! ( h hash h header block_hash ( ) ) ; assert ! ( self heights insert ( h hash h height ) is_none ( ) ) ; self . headers . push ( ( h . hash , h . header ) ) ; } info ! ( " " self headers last ( ) unwrap ( ) 0 self headers len ( ) 1 ) ; } }
Update the chain with a list of new headers (possibly a reorg)
Update the chain with a list of new headers ( possibly a reorg )
&mut self
headers
Vec<NewHeader>
&mut self
headers
Vec<NewHeader>