Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract warp sync strategy from ChainSync #2467

Merged
merged 60 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b9b543b
Make `warpSync` a self-contained syncing strategy
dmitry-markin Nov 16, 2023
4b4c880
Cleanup warp sync leftovers in `ChainSync`
dmitry-markin Nov 20, 2023
1c45b93
Introduce `SyncingStrategy` proxy enum
dmitry-markin Nov 21, 2023
efd0511
Plug `SyncingStrategy` into `SyncingEngine`
dmitry-markin Nov 22, 2023
fc5f074
Resolve borrowing issues in `WarpSync`
dmitry-markin Nov 23, 2023
abff720
Report `WarpSyncProgress` during gap sync
dmitry-markin Nov 23, 2023
f913b65
Actualize docs
dmitry-markin Nov 23, 2023
d2a7bbd
Merge remote-tracking branch 'origin/master' into dm-warp-sync-strategy
dmitry-markin Nov 23, 2023
9c5884d
Fix: stop state requests once state sync is over
dmitry-markin Nov 23, 2023
1ace10f
Pass connected peers to `ChainSync` upon construction
dmitry-markin Nov 23, 2023
124ea31
Fix: warp sync should be considered major syncing
dmitry-markin Nov 23, 2023
c7be20b
Fall back to full sync if warp sync has failed
dmitry-markin Nov 24, 2023
cf46bce
Incapsulate strategy switching in `SyncingStrategy`
dmitry-markin Nov 27, 2023
982069d
minor: remove unused structs in `WarpSync`
dmitry-markin Nov 28, 2023
54607ef
Extract state sync strategy from warp sync strategy
dmitry-markin Nov 28, 2023
3fcfa13
minor: revert useless change in `types.rs`
dmitry-markin Nov 28, 2023
a61401b
Apply suggestions from code review
dmitry-markin Nov 29, 2023
d6969bb
Merge remote-tracking branch 'origin/master' into dm-warp-sync-strategy
dmitry-markin Nov 29, 2023
0b07b36
Apply review suggestions
dmitry-markin Nov 29, 2023
fab9cd2
Apply more review suggestions
dmitry-markin Nov 29, 2023
cfde130
Define `LOG_TARGET` in crate root and get rid of hardcoded targets
dmitry-markin Nov 29, 2023
8e704e1
Fix tests compilation
dmitry-markin Nov 29, 2023
37c79ae
Fix best block update in `ChainSync::on_validated_block_announce`
dmitry-markin Nov 30, 2023
8bd7e39
Fix zombienet warp sync tests
dmitry-markin Nov 30, 2023
de33eca
Move `ChainSync` metrics reporting to `ChainSync`
dmitry-markin Nov 30, 2023
4d0d13c
Cleanup next peer selection
dmitry-markin Nov 30, 2023
5db9500
Simplify target block processing in `StateStrategy`
dmitry-markin Dec 1, 2023
e37c000
Shutdown greacefully in case of `ChainSync` initialization failure
dmitry-markin Dec 1, 2023
36db215
minor: comment
dmitry-markin Dec 1, 2023
7f5a407
minor: update comments re warp sync test
dmitry-markin Dec 4, 2023
3ad88a4
Add test for warp sync failover to full sync
dmitry-markin Dec 5, 2023
55e53db
Rework directory structure
dmitry-markin Dec 5, 2023
f6fb4d2
Merge remote-tracking branch 'origin/master' into dm-warp-sync-strategy
dmitry-markin Dec 5, 2023
17895cf
Remove unneded trait bound of `Client` in `WarpSync`
dmitry-markin Dec 6, 2023
1795194
Introduce some warp sync tests
dmitry-markin Dec 6, 2023
9b164b8
Add more warp sync startegy tests
dmitry-markin Dec 7, 2023
0bab827
Add more tests
dmitry-markin Dec 7, 2023
cadb861
Merge remote-tracking branch 'origin/master' into dm-warp-sync-strategy
dmitry-markin Dec 8, 2023
dfa0168
Add more warp sync tests
dmitry-markin Dec 8, 2023
74e3179
Initial `StateStrategy` tests
dmitry-markin Dec 11, 2023
edd28b2
Add more `StateStrategy` tests
dmitry-markin Dec 11, 2023
242f09f
minor: make clippy happy
dmitry-markin Dec 11, 2023
465cd52
Introduce `StateSyncProvider` trait
dmitry-markin Dec 12, 2023
6a082bf
Add more `StateStrategy` tests
dmitry-markin Dec 12, 2023
20dd76d
Add PRdoc
dmitry-markin Dec 12, 2023
14fdbb8
Improve PRdoc
dmitry-markin Dec 12, 2023
ec42a7e
Merge remote-tracking branch 'origin/master' into dm-warp-sync-strategy
dmitry-markin Dec 13, 2023
c0115cf
Add test for failed block import in `StateStrategy`
dmitry-markin Dec 13, 2023
fc3da77
minor: comment
dmitry-markin Dec 13, 2023
aded4c5
minor: remove unused import
dmitry-markin Dec 13, 2023
43454d7
minor: put strategy module into `strategy.rs`
dmitry-markin Dec 18, 2023
7a242a4
minor: formatting
dmitry-markin Dec 20, 2023
dd70e6c
Apply suggestions from code review
dmitry-markin Jan 9, 2024
0c9d09c
Add comment re skipping proofs in state sync
dmitry-markin Jan 9, 2024
eeb14c3
Fix issue with slow target block download during warp sync
dmitry-markin Jan 9, 2024
3825565
Merge remote-tracking branch 'origin/master' into dm-warp-sync-strategy
dmitry-markin Jan 11, 2024
3d50db2
Apply review suggestions
dmitry-markin Jan 11, 2024
180e582
Don't log state sync result twice
dmitry-markin Jan 12, 2024
e72c559
Print nicer informant messages during state sync
dmitry-markin Jan 12, 2024
398c8b6
Update warp sync zombienet tests
dmitry-markin Jan 12, 2024
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
2 changes: 1 addition & 1 deletion polkadot/node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ pub fn new_full<OverseerGenerator: OverseerGen>(
}: NewFullParams<OverseerGenerator>,
) -> Result<NewFull, Error> {
use polkadot_node_network_protocol::request_response::IncomingRequest;
use sc_network_sync::warp::WarpSyncParams;
use sc_network_sync::WarpSyncParams;

let is_offchain_indexing_enabled = config.offchain_worker.indexing_enabled;
let role = config.role.clone();
Expand Down
15 changes: 15 additions & 0 deletions prdoc/pr_2467.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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: Extract warp sync strategy from `ChainSync`

doc:
- audience: Node Dev
description: |
`WarpSync`, and `StateSync` as the logical part of warp sync, are extracted from `ChainSync`
as independent syncing strategies. `SyncingStrategy` enum is introduced as a proxy between
`SyncingEngine` and specific strategies. `SyncingStrategy` may be replaced by a trait in a
follow-up PRs.

crates:
- name: sc-network-sync
2 changes: 1 addition & 1 deletion substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use node_primitives::Block;
use sc_client_api::{Backend, BlockBackend};
use sc_consensus_babe::{self, SlotProportion};
use sc_network::{event::Event, NetworkEventStream, NetworkService};
use sc_network_sync::{warp::WarpSyncParams, SyncingService};
use sc_network_sync::{strategy::warp::WarpSyncParams, SyncingService};
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
use sc_statement_store::Store as StatementStore;
use sc_telemetry::{Telemetry, TelemetryWorker};
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/consensus/grandpa/src/warp_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
BlockNumberOps, GrandpaJustification, SharedAuthoritySet,
};
use sc_client_api::Backend as ClientBackend;
use sc_network_sync::warp::{EncodedProof, VerificationResult, WarpSyncProvider};
use sc_network_sync::strategy::warp::{EncodedProof, VerificationResult, WarpSyncProvider};
use sp_blockchain::{Backend as BlockchainBackend, HeaderBackend};
use sp_consensus_grandpa::{AuthorityList, SetId, GRANDPA_ENGINE_ID};
use sp_runtime::{
Expand Down
5 changes: 1 addition & 4 deletions substrate/client/informant/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ use ansi_term::Colour;
use log::info;
use sc_client_api::ClientInfo;
use sc_network::NetworkStatus;
use sc_network_sync::{
warp::{WarpSyncPhase, WarpSyncProgress},
SyncState, SyncStatus,
};
use sc_network_sync::{SyncState, SyncStatus, WarpSyncPhase, WarpSyncProgress};
use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Saturating, Zero};
use std::{fmt, time::Instant};

Expand Down
2 changes: 1 addition & 1 deletion substrate/client/network/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sp-consensus-grandpa = { path = "../../../primitives/consensus/grandpa" }
sp-runtime = { path = "../../../primitives/runtime" }

[dev-dependencies]
tokio = { version = "1.22.0", features = ["macros"] }
mockall = "0.11.3"
quickcheck = { version = "1.0.3", default-features = false }
sc-block-builder = { path = "../../block-builder" }
sp-test-primitives = { path = "../../../primitives/test-primitives" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! [`BlockAnnounceValidator`] is responsible for async validation of block announcements.
//! [`Stream`] implemented by [`BlockAnnounceValidator`] never terminates.

use crate::futures_stream::FuturesStream;
use crate::{futures_stream::FuturesStream, LOG_TARGET};
use futures::{stream::FusedStream, Future, FutureExt, Stream, StreamExt};
use libp2p::PeerId;
use log::{debug, error, trace, warn};
Expand All @@ -33,9 +33,6 @@ use std::{
task::{Context, Poll},
};

/// Log target for this file.
const LOG_TARGET: &str = "sync";

/// Maximum number of concurrent block announce validations.
///
/// If the queue reaches the maximum, we drop any new block
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/network/sync/src/block_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
BlockResponse as BlockResponseSchema, BlockResponse, Direction,
},
service::network::NetworkServiceHandle,
LOG_TARGET,
};

use codec::{Decode, DecodeAll, Encode};
Expand Down Expand Up @@ -56,7 +57,6 @@ use std::{
/// Maximum blocks per response.
pub(crate) const MAX_BLOCKS_IN_RESPONSE: usize = 128;

const LOG_TARGET: &str = "sync";
const MAX_BODY_BYTES: usize = 8 * 1024 * 1024;
const MAX_NUMBER_OF_SAME_REQUESTS_PER_PEER: usize = 2;

Expand Down
13 changes: 7 additions & 6 deletions substrate/client/network/sync/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::LOG_TARGET;
use libp2p::PeerId;
use log::trace;
use sc_network_common::sync::message;
Expand Down Expand Up @@ -87,10 +88,10 @@ impl<B: BlockT> BlockCollection<B> {

match self.blocks.get(&start) {
Some(&BlockRangeState::Downloading { .. }) => {
trace!(target: "sync", "Inserting block data still marked as being downloaded: {}", start);
trace!(target: LOG_TARGET, "Inserting block data still marked as being downloaded: {}", start);
},
Some(BlockRangeState::Complete(existing)) if existing.len() >= blocks.len() => {
trace!(target: "sync", "Ignored block data already downloaded: {}", start);
trace!(target: LOG_TARGET, "Ignored block data already downloaded: {}", start);
return
},
_ => (),
Expand Down Expand Up @@ -162,7 +163,7 @@ impl<B: BlockT> BlockCollection<B> {
};
// crop to peers best
if range.start > peer_best {
trace!(target: "sync", "Out of range for peer {} ({} vs {})", who, range.start, peer_best);
trace!(target: LOG_TARGET, "Out of range for peer {} ({} vs {})", who, range.start, peer_best);
return None
}
range.end = cmp::min(peer_best + One::one(), range.end);
Expand All @@ -173,7 +174,7 @@ impl<B: BlockT> BlockCollection<B> {
.next()
.map_or(false, |(n, _)| range.start > *n + max_ahead.into())
{
trace!(target: "sync", "Too far ahead for peer {} ({})", who, range.start);
trace!(target: LOG_TARGET, "Too far ahead for peer {} ({})", who, range.start);
return None
}

Expand Down Expand Up @@ -224,7 +225,7 @@ impl<B: BlockT> BlockCollection<B> {
};
*range_data = BlockRangeState::Queued { len };
}
trace!(target: "sync", "{} blocks ready for import", ready.len());
trace!(target: LOG_TARGET, "{} blocks ready for import", ready.len());
ready
}

Expand All @@ -235,7 +236,7 @@ impl<B: BlockT> BlockCollection<B> {
self.blocks.remove(&block_num);
block_num += One::one();
}
trace!(target: "sync", "Cleared blocks from {:?} to {:?}", from, to);
trace!(target: LOG_TARGET, "Cleared blocks from {:?} to {:?}", from, to);
}
}

Expand Down
Loading