pub struct InitialSync { /* private fields */ }Expand description
Initial sync manager
Implementations§
Source§impl InitialSync
impl InitialSync
Sourcepub fn new(config: ConsensusConfig) -> Self
pub fn new(config: ConsensusConfig) -> Self
Create a new initial sync manager
Sourcepub fn with_spam_filter(
config: ConsensusConfig,
spam_filter_config: SpamFilterConfig,
) -> Self
pub fn with_spam_filter( config: ConsensusConfig, spam_filter_config: SpamFilterConfig, ) -> Self
Create a new initial sync manager with custom spam filter config
Sourcepub async fn execute_initial_sync<C: UtxoCommitmentsNetworkClient>(
&self,
peers: &[(PeerInfo, String)],
header_chain: &[BlockHeader],
network_client: &C,
) -> UtxoCommitmentResult<UtxoCommitment>
pub async fn execute_initial_sync<C: UtxoCommitmentsNetworkClient>( &self, peers: &[(PeerInfo, String)], header_chain: &[BlockHeader], network_client: &C, ) -> UtxoCommitmentResult<UtxoCommitment>
Execute initial sync algorithm
Performs the complete initial sync process:
- Discover diverse peers
- Determine checkpoint height
- Request UTXO sets
- Find consensus
- Verify against headers
- Return verified UTXO commitment
Sourcepub async fn complete_sync_from_checkpoint<C, F, Fut>(
&self,
utxo_tree: &mut UtxoMerkleTree,
checkpoint_height: Natural,
current_tip: Natural,
network_client: &C,
get_block_hash: F,
peer_id: &str,
network: Network,
network_time: u64,
recent_headers: Option<&[BlockHeader]>,
checkpoint_utxo_set: Option<UtxoSet>,
) -> UtxoCommitmentResult<()>where
C: UtxoCommitmentsNetworkClient,
F: Fn(Natural) -> Fut,
Fut: Future<Output = UtxoCommitmentResult<HashType>>,
pub async fn complete_sync_from_checkpoint<C, F, Fut>(
&self,
utxo_tree: &mut UtxoMerkleTree,
checkpoint_height: Natural,
current_tip: Natural,
network_client: &C,
get_block_hash: F,
peer_id: &str,
network: Network,
network_time: u64,
recent_headers: Option<&[BlockHeader]>,
checkpoint_utxo_set: Option<UtxoSet>,
) -> UtxoCommitmentResult<()>where
C: UtxoCommitmentsNetworkClient,
F: Fn(Natural) -> Fut,
Fut: Future<Output = UtxoCommitmentResult<HashType>>,
Complete sync from checkpoint to current tip
Syncs forward from checkpoint using FULL blocks with complete validation. Fully validates all transactions (signatures, scripts) before updating UTXO set.
§Arguments
utxo_tree- UTXO Merkle tree to update incrementallycheckpoint_height- Starting height (checkpoint)current_tip- Ending height (current chain tip)network_client- Network client for requesting blocksget_block_hash- Function to get block hash for a given heightpeer_id- Peer ID to request blocks fromnetwork- Network type (Mainnet, Testnet, Regtest)network_time- Current network time (Unix timestamp)recent_headers- Recent block headers for median time-past calculationcheckpoint_utxo_set- Full UTXO set at checkpoint (required for validation) If None, starts with empty set (cannot verify checkpoint commitment until end)
§Implementation
- Requests FULL blocks from checkpoint+1 to tip
- For each full block:
- Fully validates block with connect_block() (signatures, scripts, all consensus rules)
- Updates UTXO set from validated result
- Updates UTXO tree from validated UTXO set
- Verifies commitment matches computed root
- Updates UTXO tree incrementally after validation
Security: All transactions are cryptographically verified before UTXO set update.
Sourcepub fn process_filtered_block(
&self,
utxo_tree: &mut UtxoMerkleTree,
block_height: Natural,
block_transactions: &[Transaction],
) -> UtxoCommitmentResult<(SpamSummary, HashType)>
pub fn process_filtered_block( &self, utxo_tree: &mut UtxoMerkleTree, block_height: Natural, block_transactions: &[Transaction], ) -> UtxoCommitmentResult<(SpamSummary, HashType)>
Process a filtered block and update UTXO set
Takes a block with transactions (already filtered or to be filtered), applies spam filter, updates UTXO set, and verifies commitment.
Critical: This function processes ALL transactions to remove spent inputs, but only adds non-spam outputs to the UTXO tree. This ensures UTXO set consistency:
- Spam transactions that spend non-spam inputs will still remove those inputs
- Only non-spam outputs are added to the tree (bandwidth savings)
- UTXO set remains consistent with actual blockchain state
Note: This function applies transactions to the UTXO tree for commitment purposes. Full signature verification should be done during block validation before calling this function. This function assumes transactions are already validated.
Auto Trait Implementations§
impl Freeze for InitialSync
impl RefUnwindSafe for InitialSync
impl Send for InitialSync
impl Sync for InitialSync
impl Unpin for InitialSync
impl UnsafeUnpin for InitialSync
impl UnwindSafe for InitialSync
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more