pub struct SyncManager { /* private fields */ }Expand description
The sync manager drives chain synchronization.
It processes peer events, manages the block index, and coordinates header/block downloads across multiple peers.
Implementations§
Source§impl SyncManager
impl SyncManager
Sourcepub fn new(block_index: Arc<RwLock<BlockIndex>>) -> Self
pub fn new(block_index: Arc<RwLock<BlockIndex>>) -> Self
Create a new sync manager with the given block index.
Sourcepub fn blocks_remaining(&self) -> usize
pub fn blocks_remaining(&self) -> usize
Get the number of blocks remaining to download.
Sourcepub async fn on_peer_event(
&mut self,
event: PeerEvent,
peer_manager: &dyn PeerManager,
block_store: &dyn BlockStore,
chain_state: &dyn ChainStateStore,
mempool: &dyn MempoolPort,
) -> Result<Vec<SyncAction>, Box<dyn Error + Send + Sync>>
pub async fn on_peer_event( &mut self, event: PeerEvent, peer_manager: &dyn PeerManager, block_store: &dyn BlockStore, chain_state: &dyn ChainStateStore, mempool: &dyn MempoolPort, ) -> Result<Vec<SyncAction>, Box<dyn Error + Send + Sync>>
Process a peer event. Returns a list of actions the caller should take (send messages, store blocks, etc.).
Sourcepub async fn on_getdata_with_mempool(
&mut self,
peer_id: u64,
items: Vec<InventoryItem>,
block_store: &dyn BlockStore,
mempool: &dyn MempoolPort,
) -> Result<Vec<SyncAction>, Box<dyn Error + Send + Sync>>
pub async fn on_getdata_with_mempool( &mut self, peer_id: u64, items: Vec<InventoryItem>, block_store: &dyn BlockStore, mempool: &dyn MempoolPort, ) -> Result<Vec<SyncAction>, Box<dyn Error + Send + Sync>>
Process a getdata request that may include transactions.
This is the full version that also serves transactions from the mempool.
Sourcepub async fn announce_block(
&self,
block_hash: BlockHash,
from_peer: Option<u64>,
peer_manager: &dyn PeerManager,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn announce_block( &self, block_hash: BlockHash, from_peer: Option<u64>, peer_manager: &dyn PeerManager, ) -> Result<(), Box<dyn Error + Send + Sync>>
Announce a newly connected block to all connected peers.
Sends an inv message with the block hash to every peer except
the one that sent it to us (if known).
Sourcepub async fn announce_transaction(
&self,
txid: Txid,
from_peer: Option<u64>,
peer_manager: &dyn PeerManager,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn announce_transaction( &self, txid: Txid, from_peer: Option<u64>, peer_manager: &dyn PeerManager, ) -> Result<(), Box<dyn Error + Send + Sync>>
Announce a new transaction to all connected peers.
Sends an inv message with the txid to every peer except
the one that sent it to us (if known). This is called when a
transaction is accepted into the mempool.
Sourcepub fn known_address_count(&self) -> usize
pub fn known_address_count(&self) -> usize
Get the number of known peer addresses.
Sourcepub fn is_banned(&self, addr: &SocketAddr) -> bool
pub fn is_banned(&self, addr: &SocketAddr) -> bool
Check whether a given address is currently banned.
Sourcepub fn peer_ban_score(&self, peer_id: u64) -> i32
pub fn peer_ban_score(&self, peer_id: u64) -> i32
Get the ban score for a connected peer.
Sourcepub fn orphan_tx_count(&self) -> usize
pub fn orphan_tx_count(&self) -> usize
Get the number of orphan transactions currently held.