Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

add warp to target block for parachains #12761

Merged
merged 51 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9db3468
add warp to target block for parachains
samelamin Nov 22, 2022
f46d68b
fix for failing tests
samelamin Nov 23, 2022
5b814bc
format using `Cargo +nightly fmt`
samelamin Nov 23, 2022
c12da89
Remove blocking based on PR comments and create new `WarpSync` on poll
samelamin Nov 28, 2022
57cc090
remove method from trait
samelamin Dec 1, 2022
a3205b4
add tests for wait for target
samelamin Dec 7, 2022
e57569e
Update client/network/common/src/sync/warp.rs
samelamin Dec 7, 2022
1864722
Update client/network/common/src/sync/warp.rs
samelamin Dec 7, 2022
6d5eef8
Update client/network/test/src/sync.rs
samelamin Dec 7, 2022
02e5885
Update client/network/test/src/sync.rs
samelamin Dec 7, 2022
2a9f68a
Update client/network/test/src/lib.rs
samelamin Dec 7, 2022
9c2f8f5
Update client/network/test/src/sync.rs
samelamin Dec 7, 2022
f36c215
Update client/network/test/src/sync.rs
samelamin Dec 7, 2022
709608e
code refactor based on pr comments
samelamin Dec 7, 2022
0adecb9
Second round of PR comments
samelamin Dec 12, 2022
db0a3a4
Third round of pr comments
samelamin Dec 13, 2022
fdbe062
add comments to explain logic
samelamin Dec 13, 2022
958fe3f
Update client/network/sync/src/lib.rs
samelamin Dec 14, 2022
1eac0da
Update client/network/sync/src/lib.rs
samelamin Dec 14, 2022
312ed8c
Update client/network/sync/src/warp.rs
samelamin Dec 14, 2022
aae4229
Update client/network/sync/src/warp.rs
samelamin Dec 14, 2022
eaa6be3
Update client/network/sync/src/warp.rs
samelamin Dec 14, 2022
c4602b2
Update client/network/sync/src/lib.rs
samelamin Dec 14, 2022
a692ca3
code refactor based on last PR comments
samelamin Dec 14, 2022
a198aff
move warp sync polling before `process_outbound_requests`
samelamin Dec 14, 2022
c7112bc
Update client/network/sync/src/warp.rs
samelamin Dec 15, 2022
226c894
Update client/network/sync/src/lib.rs
samelamin Dec 15, 2022
b5dac79
Update client/network/sync/src/warp.rs
samelamin Dec 15, 2022
06cdb67
fmt after code suggestions
samelamin Dec 15, 2022
de29579
rebase changes
samelamin Dec 20, 2022
c0ecb22
Bring down the node if the target block fails to return
samelamin Jan 13, 2023
5ed2e51
Revert "Bring down the node if the target block fails to return"
samelamin Jan 20, 2023
2dadb0d
Update client/network/common/src/sync/warp.rs
samelamin Jan 24, 2023
fac9214
Update client/network/common/src/sync/warp.rs
samelamin Jan 24, 2023
c6390a1
use matching on polling to avoid calling poll more than once
samelamin Jan 26, 2023
7941ee6
Update client/network/sync/src/warp.rs
samelamin Jan 27, 2023
fcc7216
Update client/network/sync/src/warp.rs
samelamin Jan 27, 2023
da38da3
Update client/network/sync/src/warp.rs
samelamin Jan 27, 2023
d7d16ba
fix typo on comment
samelamin Jan 27, 2023
f960907
update snapshot with new folder structure
samelamin Feb 6, 2023
ba4e7e6
Upload snapshot
skunert Feb 7, 2023
5f24b3e
Bump zombienet
skunert Feb 7, 2023
be94536
bump zombienet again
samelamin Feb 13, 2023
d973272
Merge branch 'master' into warp_sync_parachain
samelamin Feb 13, 2023
de75501
Improve test
skunert Feb 13, 2023
501c4f4
Update client/network/test/src/sync.rs
samelamin Feb 14, 2023
4cc074e
Update client/network/test/src/sync.rs
samelamin Feb 14, 2023
03a3b72
fix tests
samelamin Feb 14, 2023
3d8ecac
dummy commit to restart builds
samelamin Feb 14, 2023
f12c16a
Converted the target block to an optional value that is set to `None`…
samelamin Feb 14, 2023
10e248f
dummy commit to restart builds
samelamin Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
pub use sc_executor::NativeElseWasmExecutor;
use sc_finality_grandpa::SharedVoterState;
use sc_keystore::LocalKeystore;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -200,7 +200,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
spawn_handle: task_manager.spawn_handle(),
import_queue,
block_announce_validator_builder: None,
warp_sync: Some(warp_sync),
warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)),
})?;

if config.offchain_worker.enabled {
Expand Down
6 changes: 4 additions & 2 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ use sc_client_api::BlockBackend;
use sc_consensus_babe::{self, SlotProportion};
use sc_executor::NativeElseWasmExecutor;
use sc_network::NetworkService;
use sc_network_common::{protocol::event::Event, service::NetworkEventStream};
use sc_network_common::{
protocol::event::Event, service::NetworkEventStream, sync::warp::WarpSyncParams,
};
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -362,7 +364,7 @@ pub fn new_full_base(
spawn_handle: task_manager.spawn_handle(),
import_queue,
block_announce_validator_builder: None,
warp_sync: Some(warp_sync),
warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)),
})?;

if config.offchain_worker.enabled {
Expand Down
5 changes: 5 additions & 0 deletions client/informant/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ impl<B: BlockT> InformantDisplay<B> {
_,
Some(WarpSyncProgress { phase: WarpSyncPhase::DownloadingBlocks(n), .. }),
) => ("⏩", "Block history".into(), format!(", #{}", n)),
(
_,
_,
Some(WarpSyncProgress { phase: WarpSyncPhase::AwaitingTargetBlock, .. }),
) => ("⏩", "Waiting for pending target block".into(), "".into()),
(_, _, Some(warp)) => (
"⏩",
"Warping".into(),
Expand Down
16 changes: 15 additions & 1 deletion client/network/common/src/sync/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use codec::{Decode, Encode};
use futures::channel::oneshot;
pub use sp_finality_grandpa::{AuthorityList, SetId};
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::fmt;
use std::{fmt, sync::Arc};

/// Scale-encoded warp sync proof response.
pub struct EncodedProof(pub Vec<u8>);
Expand All @@ -29,6 +30,16 @@ pub struct WarpProofRequest<B: BlockT> {
pub begin: B::Hash,
}

/// The different types of warp syncing.
pub enum WarpSyncParams<Block: BlockT> {
/// Standard warp sync for the relay chain
WithProvider(Arc<dyn WarpSyncProvider<Block>>),
/// Skip downloading proofs and wait for a header of the state that should be downloaded.
///
/// It is expected that the header provider ensures that the header is trusted.
WaitForTarget(oneshot::Receiver<<Block as BlockT>::Header>),
}

/// Proof verification result.
pub enum VerificationResult<Block: BlockT> {
/// Proof is valid, but the target was not reached.
Expand Down Expand Up @@ -62,6 +73,8 @@ pub trait WarpSyncProvider<Block: BlockT>: Send + Sync {
pub enum WarpSyncPhase<Block: BlockT> {
/// Waiting for peers to connect.
AwaitingPeers,
/// Waiting for target block to be received
samelamin marked this conversation as resolved.
Show resolved Hide resolved
AwaitingTargetBlock,
/// Downloading and verifying grandpa warp proofs.
DownloadingWarpProofs,
/// Downloading target block.
Expand All @@ -78,6 +91,7 @@ impl<Block: BlockT> fmt::Display for WarpSyncPhase<Block> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::AwaitingPeers => write!(f, "Waiting for peers"),
Self::AwaitingTargetBlock => write!(f, "Waiting for target block to be reached"),
samelamin marked this conversation as resolved.
Show resolved Hide resolved
Self::DownloadingWarpProofs => write!(f, "Downloading finality proofs"),
Self::DownloadingTargetBlock => write!(f, "Downloading target block"),
Self::DownloadingState => write!(f, "Downloading state"),
Expand Down
28 changes: 18 additions & 10 deletions client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use sc_network_common::{
BlockAnnounce, BlockAnnouncesHandshake, BlockAttributes, BlockData, BlockRequest,
BlockResponse, Direction, FromBlock,
},
warp::{EncodedProof, WarpProofRequest, WarpSyncPhase, WarpSyncProgress, WarpSyncProvider},
warp::{EncodedProof, WarpProofRequest, WarpSyncParams, WarpSyncPhase, WarpSyncProgress},
BadPeer, ChainSync as ChainSyncT, ImportResult, Metrics, OnBlockData, OnBlockJustification,
OnStateData, OpaqueBlockRequest, OpaqueBlockResponse, OpaqueStateRequest,
OpaqueStateResponse, PeerInfo, PeerRequest, PollBlockAnnounceValidation, SyncMode,
Expand Down Expand Up @@ -318,8 +318,10 @@ pub struct ChainSync<B: BlockT, Client> {
state_sync: Option<StateSync<B, Client>>,
/// Warp sync in progress, if any.
warp_sync: Option<WarpSync<B, Client>>,
/// Warp sync provider.
warp_sync_provider: Option<Arc<dyn WarpSyncProvider<B>>>,
/// Warp sync params.
///
/// Will be `None` after `self.warp_sync` is `Some(_)`.
warp_sync_params: Option<WarpSyncParams<B>>,
/// Enable importing existing blocks. This is used used after the state download to
/// catch up to the latest state while re-importing blocks.
import_existing: bool,
Expand Down Expand Up @@ -565,6 +567,7 @@ where
info!("💔 New peer with unknown genesis hash {} ({}).", best_hash, best_number);
return Err(BadPeer(who, rep::GENESIS_MISMATCH))
}

// If there are more than `MAJOR_SYNC_BLOCKS` in the import queue then we have
// enough to do in the import queue that it's not worth kicking off
// an ancestor search, which is what we do in the next match case below.
Expand Down Expand Up @@ -630,17 +633,15 @@ where
},
);

if let SyncMode::Warp = &self.mode {
if let SyncMode::Warp = self.mode {
if self.peers.len() >= MIN_PEERS_TO_START_WARP_SYNC && self.warp_sync.is_none()
{
log::debug!(target: "sync", "Starting warp state sync.");
if let Some(provider) = &self.warp_sync_provider {
self.warp_sync =
Some(WarpSync::new(self.client.clone(), provider.clone()));
if let Some(params) = self.warp_sync_params.take() {
self.warp_sync = Some(WarpSync::new(self.client.clone(), params));
}
}
}

Ok(req)
},
Ok(BlockStatus::Queued) |
Expand Down Expand Up @@ -1359,6 +1360,13 @@ where
},
}
}

// Should be called before `process_outbound_requests` to ensure
// that a potential target block is directly leading to requests.
if let Some(warp_sync) = &mut self.warp_sync {
samelamin marked this conversation as resolved.
Show resolved Hide resolved
let _ = warp_sync.poll(cx);
samelamin marked this conversation as resolved.
Show resolved Hide resolved
}

self.process_outbound_requests();

while let Poll::Ready(result) = self.poll_pending_responses(cx) {
Expand Down Expand Up @@ -1427,7 +1435,7 @@ where
roles: Roles,
block_announce_validator: Box<dyn BlockAnnounceValidator<B> + Send>,
max_parallel_downloads: u32,
warp_sync_provider: Option<Arc<dyn WarpSyncProvider<B>>>,
warp_sync_params: Option<WarpSyncParams<B>>,
metrics_registry: Option<&Registry>,
network_service: service::network::NetworkServiceHandle,
import_queue: Box<dyn ImportQueueService<B>>,
Expand Down Expand Up @@ -1467,13 +1475,13 @@ where
block_announce_validation_per_peer_stats: Default::default(),
state_sync: None,
warp_sync: None,
warp_sync_provider,
import_existing: false,
gap_sync: None,
service_rx,
network_service,
block_request_protocol_name,
state_request_protocol_name,
warp_sync_params,
warp_sync_protocol_name,
block_announce_protocol_name: block_announce_config
.notifications_protocol
Expand Down
Loading