vls_frontend/
lib.rs

1#![crate_name = "vls_frontend"]
2#![forbid(unsafe_code)]
3#![allow(bare_trait_objects)]
4#![allow(ellipsis_inclusive_range_patterns)]
5
6use std::sync::Arc;
7
8use async_trait::async_trait;
9
10use bitcoin::blockdata::block::Header as BlockHeader;
11use bitcoin::secp256k1::PublicKey;
12use bitcoin::{BlockHash, Network, OutPoint, Txid};
13use lightning_signer::bitcoin;
14use lightning_signer::chain::tracker::Headers;
15use lightning_signer::node::SignedHeartbeat;
16use lightning_signer::txoo::proof::TxoProof;
17
18mod chain_follower;
19pub mod external_persist;
20pub mod frontend;
21pub mod heartbeat;
22
23pub use self::frontend::Frontend;
24pub use self::heartbeat::HeartbeatMonitor;
25
26/// Provides ChainTracks for nodes in a signer
27#[async_trait]
28pub trait ChainTrackDirectory: Sync + Send {
29    /// Return a ChainTrack for a specific node
30    fn tracker(&self, node_id: &PublicKey) -> Arc<dyn ChainTrack>;
31
32    /// Return ChainTracks for all nodes
33    async fn trackers(&self) -> Vec<Arc<dyn ChainTrack>>;
34}
35
36/// ChainTracker interface
37#[async_trait]
38pub trait ChainTrack: Sync + Send {
39    /// Identity string for the log
40    fn log_prefix(&self) -> String;
41
42    /// Full identity
43    async fn id(&self) -> Vec<u8>;
44
45    /// The heartbeat public key
46    async fn heartbeat_pubkey(&self) -> PublicKey;
47
48    /// Returns the network
49    fn network(&self) -> Network;
50
51    /// Return the block height and hash of specified node's chaintracker tip
52    async fn tip_info(&self) -> (u32, BlockHash);
53
54    /// Returns all Txid and OutPoints to watch for in future blocks
55    async fn forward_watches(&self) -> (Vec<Txid>, Vec<OutPoint>);
56
57    /// Returns all Txid and OutPoint watches used for prior blocks (used when removing)
58    async fn reverse_watches(&self) -> (Vec<Txid>, Vec<OutPoint>);
59
60    /// Add a block to the tracker
61    async fn add_block(&self, header: BlockHeader, proof: TxoProof);
62
63    /// Remove block at tip due to reorg
64    async fn remove_block(&self, proof: TxoProof, prev_headers: Headers);
65
66    /// Produce a signed heartbeat for the signer node
67    async fn beat(&self) -> SignedHeartbeat;
68}