async fn check_trusted_header(
        &self,
        trusted_header: &SignedHeader<Chain::Commit, Chain::Header>,
        trust_options: &TrustOptions,
    ) -> Result<(), error::Error> {
        debug!(
            chain.id = %self.chain.id(),
            "restoring trusted state from store",
        );

        let primary_hash = match trust_options.height.cmp(&trusted_header.header().height()) {
            Ordering::Greater => {
                debug!(
                    chain.id = %self.chain.id(),
                    trust_options.height,
                    trusted_header.height = trusted_header.header().height(),
                    "trusted options height is greater than trusted header height",
                );

                self.chain
                    .requester()
                    .signed_header(trust_options.height)
                    .await
                    .map_err(|e| error::Kind::Rpc.context(e))?
                    .header()
                    .hash()
            }
            Ordering::Equal => {
                debug!(
                    chain.id = %self.chain.id(),
                    trust_options.height,
                    trusted_header.height = trusted_header.header().height(),
                    "trusted options height is equal to trusted header height",
                );

                trust_options.hash
            }
            Ordering::Less => {
                debug!(
                    chain.id = %self.chain.id(),
                    trust_options.height,
                    trusted_header.height = trusted_header.header().height(),
                    "trusted options height is lesser than trusted header height",
                );

                info!(
                    chain.id = %self.chain.id(),
                    old = %trust_options.height,
                    trusted_header.height = %trusted_header.header().height(),
                    trusted_header.hash = %trusted_header.header().hash(),
                    "client initialized with old header (trusted header is more recent)",
                );

                // TODO: Rollback: Remove all headers in (trust_options.height, trusted_header.height]

                trust_options.hash
            }
        };

        debug!(
            chain.id = %self.chain.id(),
            primary.hash = %primary_hash,
            trusted_header.hash = %trusted_header.header().hash(),
            "comparing trusted_header.hash against primary.hash",
        );

        if primary_hash != trusted_header.header().hash() {
            // TODO: Implement cleanup

            warn!(
                chain.id = %self.chain.id(),
                primary.hash = %primary_hash,
                trusted_header.hash = %trusted_header.header().hash(),
                "trusted header hash and primary header hash do not match, rolling back (TODO)",
            );
        } else {
            debug!(
                chain.id = %self.chain.id(),
                primary.hash = %primary_hash,
                trusted_header.hash = %trusted_header.header().hash(),
                "trusted header hash and primary header hash match",
            );
        }

        Ok(())
    }
/// Check that the given trusted state corresponding to the given
/// trust options is valid.
///
/// TODO: Improve doc
/// TODO: Impement rollback
/// TODO: Implement cleanup
Check that the given trusted state corresponding to the given
trust options is valid.

Improve doc
TODO: Impement rollback
TODO: Implement cleanup
Check that the given trusted state corresponding to the given trust options is valid . Improve doc TODO : Impement rollback TODO : Implement cleanup
async fn check_trusted_header(
        &self,
        trusted_header: &SignedHeader<Chain::Commit, Chain::Header>,
        trust_options: &TrustOptions,
    ) -> Result<(), error::Error> {
        debug!(
            chain.id = %self.chain.id(),
            "restoring trusted state from store",
        );
        let primary_hash = match trust_options.height.cmp(&trusted_header.header().height()) {
            Ordering::Greater => {
                debug!(
                    chain.id = %self.chain.id(),
                    trust_options.height,
                    trusted_header.height = trusted_header.header().height(),
                    "trusted options height is greater than trusted header height",
                );
                self.chain
                    .requester()
                    .signed_header(trust_options.height)
                    .await
                    .map_err(|e| error::Kind::Rpc.context(e))?
                    .header()
                    .hash()
            }
            Ordering::Equal => {
                debug!(
                    chain.id = %self.chain.id(),
                    trust_options.height,
                    trusted_header.height = trusted_header.header().height(),
                    "trusted options height is equal to trusted header height",
                );
                trust_options.hash
            }
            Ordering::Less => {
                debug!(
                    chain.id = %self.chain.id(),
                    trust_options.height,
                    trusted_header.height = trusted_header.header().height(),
                    "trusted options height is lesser than trusted header height",
                );
                info!(
                    chain.id = %self.chain.id(),
                    old = %trust_options.height,
                    trusted_header.height = %trusted_header.header().height(),
                    trusted_header.hash = %trusted_header.header().hash(),
                    "client initialized with old header (trusted header is more recent)",
                );
                // TODO: Rollback: Remove all headers in (trust_options.height, trusted_header.height]
                trust_options.hash
            }
        };
        debug!(
            chain.id = %self.chain.id(),
            primary.hash = %primary_hash,
            trusted_header.hash = %trusted_header.header().hash(),
            "comparing trusted_header.hash against primary.hash",
        );
        if primary_hash != trusted_header.header().hash() {
            // TODO: Implement cleanup
            warn!(
                chain.id = %self.chain.id(),
                primary.hash = %primary_hash,
                trusted_header.hash = %trusted_header.header().hash(),
                "trusted header hash and primary header hash do not match, rolling back (TODO)",
            );
        } else {
            debug!(
                chain.id = %self.chain.id(),
                primary.hash = %primary_hash,
                trusted_header.hash = %trusted_header.header().hash(),
                "trusted header hash and primary header hash match",
            );
        }
        Ok(())
    }
async fn check_trusted_header ( & self , trusted_header : & SignedHeader < Chain :: Commit , Chain :: Header > , trust_options : & TrustOptions , ) -> Result < ( ) , error :: Error > { debug ! ( chain id self chain id ( ) " " ) ; let primary_hash = match trust_options . height . cmp ( & trusted_header . header ( ) . height ( ) ) { Ordering :: Greater => { debug ! ( chain id self chain id ( ) trust_options height trusted_header height trusted_header header ( ) height ( ) " " ) ; self . chain . requester ( ) . signed_header ( trust_options . height ) . await . map_err ( | e | error :: Kind :: Rpc . context ( e ) ) ? . header ( ) . hash ( ) } Ordering :: Equal => { debug ! ( chain id self chain id ( ) trust_options height trusted_header height trusted_header header ( ) height ( ) " " ) ; trust_options . hash } Ordering :: Less => { debug ! ( chain id self chain id ( ) trust_options height trusted_header height trusted_header header ( ) height ( ) " " ) ; info ! ( chain id self chain id ( ) old trust_options height trusted_header height trusted_header header ( ) height ( ) trusted_header hash trusted_header header ( ) hash ( ) " " ) ; // TODO: Rollback: Remove all headers in (trust_options.height, trusted_header.height] trust_options . hash } } ; debug ! ( chain id self chain id ( ) primary hash primary_hash trusted_header hash trusted_header header ( ) hash ( ) " " ) ; if primary_hash != trusted_header . header ( ) . hash ( ) { // TODO: Implement cleanup warn ! ( chain id self chain id ( ) primary hash primary_hash trusted_header hash trusted_header header ( ) hash ( ) " " ) ; } else { debug ! ( chain id self chain id ( ) primary hash primary_hash trusted_header hash trusted_header header ( ) hash ( ) " " ) ; } Ok ( ( ) ) }
Check that the given trusted state corresponding to the given
trust options is valid.
Check that the given trusted state corresponding to the given trust options is valid .
&self
trusted_header
&SignedHeader<Chain::Commit, Chain::Header>
trust_options
&TrustOptions
&self
trusted_header
&SignedHeader<Chain::Commit, Chain::Header>
trust_options
&TrustOptions