1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
crate::ix!();

pub trait TipMayBeStale {

    fn tip_may_be_stale(self: Arc<Self>) -> bool;
}

impl TipMayBeStale for PeerManager {
    
    #[EXCLUSIVE_LOCKS_REQUIRED(CS_MAIN)]
    fn tip_may_be_stale(self: Arc<Self>) -> bool {
        
        assert_lock_held!(CS_MAIN);

        let consensus_params: Arc<ChainConsensusParams> 
        = self.chainparams.get_consensus();

        if self.last_tip_update.load(atomic::Ordering::Relaxed).is_none() {
            self.last_tip_update.store(Some(get_datetime()), atomic::Ordering::Relaxed);
        }

        let last_tip_update = self.last_tip_update.load(atomic::Ordering::Relaxed);

        let inner = self.inner.lock();
        let mbif = inner.map_blocks_in_flight.lock();

        last_tip_update < OffsetDateTime::from_unix_timestamp(get_datetime().unix_timestamp() - consensus_params.n_pow_target_spacing * 3).ok()
        && mbif.is_empty()
    }
}