Skip to main content

urma_node/
engine_sync.rs

1//! Peer synchronization bookkeeping. Coverage is a local claim about which
2//! peer listings were fully admitted; full-block scans remain the audit.
3use crate::{
4    Error,
5    engine::Engine,
6    model::{ChainPoint, Omission},
7};
8
9impl Engine {
10    /// Record that `peer` (its PeerId string) listed every placement in
11    /// selected [from, to] and each listed placement was admitted, already
12    /// held, or answered Missing (listed-only).
13    /// `generation` is the one observed before fetching; a reorg since is Stale.
14    /// admit_record keeps multipart children even in Pruned mode, so synced
15    /// components stay until cache maintenance evicts them.
16    pub fn record_peer_coverage(
17        &self,
18        peer: &str,
19        from: u64,
20        to: u64,
21        generation: u64,
22    ) -> Result<(), Error> {
23        self.archive()?
24            .record_peer_coverage(peer, from, to, generation)
25    }
26
27    /// First height after the peer's contiguous coverage from app start.
28    pub fn peer_cursor(&self, peer: &str) -> Result<u64, Error> {
29        self.archive()?.peer_cursor(peer, 0)
30    }
31
32    /// As `peer_cursor`, starting at the peer's own scan floor when that is
33    /// above app start: heights below it are never asked of this peer.
34    pub fn peer_cursor_from(&self, peer: &str, floor: u64) -> Result<u64, Error> {
35        self.archive()?.peer_cursor(peer, floor)
36    }
37
38    pub fn peer_synced_through(&self) -> Result<Option<ChainPoint>, Error> {
39        self.archive()?.peer_synced_through()
40    }
41
42    pub fn omitting_peers(&self) -> Result<Vec<String>, Error> {
43        self.archive()?.omitting_peers()
44    }
45
46    pub fn peer_omissions(&self) -> Result<Vec<Omission>, Error> {
47        self.archive()?.peer_omissions()
48    }
49
50    /// The `limit` highest selected omissions, ascending; bounded in SQL.
51    pub fn peer_omissions_latest(&self, limit: u32) -> Result<Vec<Omission>, Error> {
52        self.archive()?.peer_omissions_latest(limit)
53    }
54
55    /// Chain peers the source holds now; 0 without a source (offline).
56    pub fn chain_peers(&self) -> Result<u64, Error> {
57        match &self.source {
58            Some(source) => source.chain_peers(),
59            None => Ok(0),
60        }
61    }
62
63    /// Absolute header-sync target; `None` while unknown or offline.
64    pub fn chain_target(&self) -> Option<u64> {
65        self.source
66            .as_ref()
67            .and_then(|source| source.chain_target())
68    }
69}