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)
30    }
31
32    pub fn peer_synced_through(&self) -> Result<Option<ChainPoint>, Error> {
33        self.archive()?.peer_synced_through()
34    }
35
36    pub fn omitting_peers(&self) -> Result<Vec<String>, Error> {
37        self.archive()?.omitting_peers()
38    }
39
40    pub fn peer_omissions(&self) -> Result<Vec<Omission>, Error> {
41        self.archive()?.peer_omissions()
42    }
43
44    /// The `limit` highest selected omissions, ascending; bounded in SQL.
45    pub fn peer_omissions_latest(&self, limit: u32) -> Result<Vec<Omission>, Error> {
46        self.archive()?.peer_omissions_latest(limit)
47    }
48
49    /// Chain peers the source holds now; 0 without a source (offline).
50    pub fn chain_peers(&self) -> Result<u64, Error> {
51        match &self.source {
52            Some(source) => source.chain_peers(),
53            None => Ok(0),
54        }
55    }
56}