fn should_restart_sync(e: BlockDownloadVerifyError) -> bool {
        match e {
            // Structural matches
            BlockDownloadVerifyError::Invalid(VerifyChainError::Checkpoint(
                VerifyCheckpointError::AlreadyVerified { .. },
            )) => {
                tracing::debug!(error = ?e, "block was already verified, possibly from a previous sync run, continuing");
                false
            }
            BlockDownloadVerifyError::Invalid(VerifyChainError::Block(
                VerifyBlockError::Block {
                    source: BlockError::AlreadyInChain(_, _),
                },
            )) => {
                tracing::debug!(error = ?e, "block is already in chain, possibly from a previous sync run, continuing");
                false
            }
            BlockDownloadVerifyError::CancelledDuringDownload
            | BlockDownloadVerifyError::CancelledDuringVerification => {
                tracing::debug!(error = ?e, "block verification was cancelled, continuing");
                false
            }

            // String matches
            BlockDownloadVerifyError::Invalid(VerifyChainError::Block(
                VerifyBlockError::Commit(ref source),
            )) if format!("{:?}", source).contains("block is already committed to the state") => {
                // TODO: improve this by checking the type (#2908)
                tracing::debug!(error = ?e, "block is already committed, possibly from a previous sync run, continuing");
                false
            }
            BlockDownloadVerifyError::DownloadFailed(ref source)
                if format!("{:?}", source).contains("NotFound") =>
            {
                // TODO: improve this by checking the type (#2908)
                //       restart after a certain number of NotFound errors?
                tracing::debug!(error = ?e, "block was not found, possibly from a peer that doesn't have the block yet, continuing");
                false
            }

            _ => {
                // download_and_verify downcasts errors from the block verifier
                // into VerifyChainError, and puts the result inside one of the
                // BlockDownloadVerifyError enumerations. This downcast could
                // become incorrect e.g. after some refactoring, and it is difficult
                // to write a test to check it. The test below is a best-effort
                // attempt to catch if that happens and log it.
                // TODO: add a proper test and remove this
                // https://github.com/ZcashFoundation/zebra/issues/2909
                let err_str = format!("{:?}", e);
                if err_str.contains("AlreadyVerified")
                    || err_str.contains("AlreadyInChain")
                    || err_str.contains("Cancelled")
                    || err_str.contains("block is already committed to the state")
                    || err_str.contains("NotFound")
                {
                    tracing::error!(?e,
                        "a BlockDownloadVerifyError that should have been filtered out was detected, \
                        which possibly indicates a programming error in the downcast inside \
                        zebrad::components::sync::downloads::Downloads::download_and_verify"
                    )
                }

                tracing::warn!(?e, "error downloading and verifying block");
                true
            }
        }
    }
/// Return if the sync should be restarted based on the given error
/// from the block downloader and verifier stream.
Return if the sync should be restarted based on the given error
from the block downloader and verifier stream.
Return if the sync should be restarted based on the given error from the block downloader and verifier stream .
fn should_restart_sync(e: BlockDownloadVerifyError) -> bool {
        match e {
            // Structural matches
            BlockDownloadVerifyError::Invalid(VerifyChainError::Checkpoint(
                VerifyCheckpointError::AlreadyVerified { .. },
            )) => {
                tracing::debug!(error = ?e, "block was already verified, possibly from a previous sync run, continuing");
                false
            }
            BlockDownloadVerifyError::Invalid(VerifyChainError::Block(
                VerifyBlockError::Block {
                    source: BlockError::AlreadyInChain(_, _),
                },
            )) => {
                tracing::debug!(error = ?e, "block is already in chain, possibly from a previous sync run, continuing");
                false
            }
            BlockDownloadVerifyError::CancelledDuringDownload
            | BlockDownloadVerifyError::CancelledDuringVerification => {
                tracing::debug!(error = ?e, "block verification was cancelled, continuing");
                false
            }
            // String matches
            BlockDownloadVerifyError::Invalid(VerifyChainError::Block(
                VerifyBlockError::Commit(ref source),
            )) if format!("{:?}", source).contains("block is already committed to the state") => {
                // TODO: improve this by checking the type (#2908)
                tracing::debug!(error = ?e, "block is already committed, possibly from a previous sync run, continuing");
                false
            }
            BlockDownloadVerifyError::DownloadFailed(ref source)
                if format!("{:?}", source).contains("NotFound") =>
            {
                // TODO: improve this by checking the type (#2908)
                //       restart after a certain number of NotFound errors?
                tracing::debug!(error = ?e, "block was not found, possibly from a peer that doesn't have the block yet, continuing");
                false
            }
            _ => {
                // download_and_verify downcasts errors from the block verifier
                // into VerifyChainError, and puts the result inside one of the
                // BlockDownloadVerifyError enumerations. This downcast could
                // become incorrect e.g. after some refactoring, and it is difficult
                // to write a test to check it. The test below is a best-effort
                // attempt to catch if that happens and log it.
                // TODO: add a proper test and remove this
                // https://github.com/ZcashFoundation/zebra/issues/2909
                let err_str = format!("{:?}", e);
                if err_str.contains("AlreadyVerified")
                    || err_str.contains("AlreadyInChain")
                    || err_str.contains("Cancelled")
                    || err_str.contains("block is already committed to the state")
                    || err_str.contains("NotFound")
                {
                    tracing::error!(?e,
                        "a BlockDownloadVerifyError that should have been filtered out was detected, \
                        which possibly indicates a programming error in the downcast inside \
                        zebrad::components::sync::downloads::Downloads::download_and_verify"
                    )
                }
                tracing::warn!(?e, "error downloading and verifying block");
                true
            }
        }
    }
fn should_restart_sync ( e : BlockDownloadVerifyError ) -> bool { match e { // Structural matches BlockDownloadVerifyError :: Invalid ( VerifyChainError :: Checkpoint ( VerifyCheckpointError :: AlreadyVerified { .. } , ) ) => { tracing :: debug ! ( error e " " ) ; false } BlockDownloadVerifyError :: Invalid ( VerifyChainError :: Block ( VerifyBlockError :: Block { source : BlockError :: AlreadyInChain ( _ , _ ) , } , ) ) => { tracing :: debug ! ( error e " " ) ; false } BlockDownloadVerifyError :: CancelledDuringDownload | BlockDownloadVerifyError :: CancelledDuringVerification => { tracing :: debug ! ( error e " " ) ; false } // String matches BlockDownloadVerifyError :: Invalid ( VerifyChainError :: Block ( VerifyBlockError :: Commit ( ref source ) , ) ) if format ! ( " " source ) . contains ( " " ) => { // TODO: improve this by checking the type (#2908) tracing :: debug ! ( error e " " ) ; false } BlockDownloadVerifyError :: DownloadFailed ( ref source ) if format ! ( " " source ) . contains ( " " ) => { // TODO: improve this by checking the type (#2908) //       restart after a certain number of NotFound errors? tracing :: debug ! ( error e " " ) ; false } _ => { // download_and_verify downcasts errors from the block verifier // into VerifyChainError, and puts the result inside one of the // BlockDownloadVerifyError enumerations. This downcast could // become incorrect e.g. after some refactoring, and it is difficult // to write a test to check it. The test below is a best-effort // attempt to catch if that happens and log it. // TODO: add a proper test and remove this // https://github.com/ZcashFoundation/zebra/issues/2909 let err_str = format ! ( " " e ) ; if err_str . contains ( " " ) || err_str . contains ( " " ) || err_str . contains ( " " ) || err_str . contains ( " " ) || err_str . contains ( " " ) { tracing :: error ! ( e " \
 \
 " ) } tracing :: warn ! ( e " " ) ; true } } }
Return if the sync should be restarted based on the given error
from the block downloader and verifier stream.
Return if the sync should be restarted based on the given error from the block downloader and verifier stream .
e
BlockDownloadVerifyError