Skip to content

Commit

Permalink
Expose more syncing types to enable custom syncing strategy (#6163)
Browse files Browse the repository at this point in the history
This PR exposes additional syncing types to facilitate the development
of a custom syncing strategy based on the existing Polkadot syncing
strategy. Specifically, my goal is to isolate the state sync and chain
sync components, allowing the state to be downloaded from the P2P
network without running a full regular Substrate node. I also need to
intercept the state responses during the state sync process.

The newly exposed types are necessary to implement this custom syncing
strategy.
  • Loading branch information
liuchengxu authored Nov 7, 2024
1 parent c4e94d3 commit 0e09ad4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
13 changes: 13 additions & 0 deletions prdoc/pr_6163.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Expose more syncing types to enable custom syncing strategy

doc:
- audience: Node Dev
description: |
Exposes additional syncing types to facilitate the development of a custom syncing strategy.

crates:
- name: sc-network-sync
bump: patch
1 change: 1 addition & 0 deletions substrate/client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

//! Blockchain syncing implementation in Substrate.

pub use schema::v1::*;
pub use service::syncing_service::SyncingService;
pub use strategy::warp::{WarpSyncConfig, WarpSyncPhase, WarpSyncProgress};
pub use types::{SyncEvent, SyncEventStream, SyncState, SyncStatus, SyncStatusProvider};
Expand Down
5 changes: 3 additions & 2 deletions substrate/client/network/sync/src/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
pub mod chain_sync;
mod disconnected_peers;
pub mod polkadot;
mod state;
pub mod state;
pub mod state_sync;
pub mod warp;

Expand Down Expand Up @@ -177,7 +177,8 @@ pub enum SyncingAction<B: BlockT> {
}

impl<B: BlockT> SyncingAction<B> {
fn is_finished(&self) -> bool {
/// Returns `true` if the syncing action has completed.
pub fn is_finished(&self) -> bool {
matches!(self, SyncingAction::Finished)
}

Expand Down
11 changes: 6 additions & 5 deletions substrate/client/network/sync/src/strategy/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ impl<B: BlockT> StateStrategy<B> {
}
}

// Create a new instance with a custom state sync provider.
// Used in tests.
#[cfg(test)]
fn new_with_provider(
/// Create a new instance with a custom state sync provider.
///
/// Note: In most cases, users should use [`StateStrategy::new`].
/// This method is intended for custom sync strategies and advanced use cases.
pub fn new_with_provider(
state_sync_provider: Box<dyn StateSyncProvider<B>>,
initial_peers: impl Iterator<Item = (PeerId, NumberFor<B>)>,
protocol_name: ProtocolName,
Expand Down Expand Up @@ -348,7 +349,7 @@ impl<B: BlockT> StateStrategy<B> {
}
}

/// Get actions that should be performed by the owner on [`WarpSync`]'s behalf
/// Get actions that should be performed.
#[must_use]
pub fn actions(
&mut self,
Expand Down

0 comments on commit 0e09ad4

Please sign in to comment.