Skip to main content

InitialSync

Struct InitialSync 

Source
pub struct InitialSync { /* private fields */ }
Expand description

Initial sync manager

Implementations§

Source§

impl InitialSync

Source

pub fn new(config: ConsensusConfig) -> Self

Create a new initial sync manager

Source

pub fn with_spam_filter( config: ConsensusConfig, spam_filter_config: SpamFilterConfig, ) -> Self

Create a new initial sync manager with custom spam filter config

Source

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:

  1. Discover diverse peers
  2. Determine checkpoint height
  3. Request UTXO sets
  4. Find consensus
  5. Verify against headers
  6. Return verified UTXO commitment
Source

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<()>

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 incrementally
  • checkpoint_height - Starting height (checkpoint)
  • current_tip - Ending height (current chain tip)
  • network_client - Network client for requesting blocks
  • get_block_hash - Function to get block hash for a given height
  • peer_id - Peer ID to request blocks from
  • network - Network type (Mainnet, Testnet, Regtest)
  • network_time - Current network time (Unix timestamp)
  • recent_headers - Recent block headers for median time-past calculation
  • checkpoint_utxo_set - Full UTXO set at checkpoint (required for validation) If None, starts with empty set (cannot verify checkpoint commitment until end)
§Implementation
  1. Requests FULL blocks from checkpoint+1 to tip
  2. 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
  3. Updates UTXO tree incrementally after validation

Security: All transactions are cryptographically verified before UTXO set update.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more