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

Extract syncing protocol from sc-network #12828

Merged
merged 47 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7a76b40
Move import queue out of `sc-network`
altonen Nov 21, 2022
1d1b955
Move stuff to SyncingEngine
altonen Nov 22, 2022
bd8f6a2
Move `ChainSync` instanation to `SyncingEngine`
altonen Nov 22, 2022
9569593
Move peer hashmap to `SyncingEngine`
altonen Nov 22, 2022
befeac3
Let `SyncingEngine` to implement `ChainSyncInterface`
altonen Nov 23, 2022
c642a33
Introduce `SyncStatusProvider`
altonen Nov 23, 2022
badfbf3
Move `sync_peer_(connected|disconnected)` to `SyncingEngine`
altonen Nov 23, 2022
755b47c
Implement `SyncEventStream`
altonen Nov 25, 2022
0b11339
Introduce `ChainSyncInterface`
altonen Nov 25, 2022
6f4ac98
Move event stream polling to `SyncingEngine`
altonen Nov 26, 2022
e2ea277
Make `SyncingEngine` into an asynchronous runner
altonen Nov 26, 2022
caf54b4
Fix warnings
altonen Nov 27, 2022
a920a7e
Code refactoring
altonen Nov 27, 2022
5dd14e3
Use `SyncingService` for BEEFY
altonen Nov 28, 2022
83509c9
Use `SyncingService` for GRANDPA
altonen Nov 28, 2022
bb005b6
Remove call delegation from `NetworkService`
altonen Nov 28, 2022
e5d6c49
Remove `ChainSyncService`
altonen Nov 29, 2022
a4f5403
Remove `ChainSync` service tests
altonen Nov 29, 2022
f485d89
Merge remote-tracking branch 'origin/master' into import-queue-refact…
altonen Dec 1, 2022
2acb775
Refactor code
altonen Nov 29, 2022
b01586a
Merge branch 'import-queue-refactoring' into extract-syncing-from-sc-…
altonen Dec 1, 2022
0085220
Refactor code
altonen Dec 2, 2022
da14feb
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Dec 12, 2022
ee39f7b
Merge remote-tracking branch 'origin/master' into extract-syncing
altonen Dec 30, 2022
a55a44d
Update client/finality-grandpa/src/communication/tests.rs
altonen Dec 30, 2022
9882a76
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Feb 7, 2023
49240a2
Fix warnings
altonen Feb 8, 2023
e8c017d
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Feb 17, 2023
17b6872
Apply review comments
altonen Feb 20, 2023
721cc49
Fix docs
altonen Feb 20, 2023
6851852
Fix test
altonen Feb 20, 2023
8eaa4cb
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Feb 20, 2023
d84be72
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Feb 21, 2023
4f7cf6e
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Feb 22, 2023
e50fda8
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Feb 28, 2023
d8461c4
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Mar 1, 2023
e105fe5
cargo-fmt
altonen Mar 2, 2023
2f0d7d2
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Mar 2, 2023
1f8d399
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Mar 2, 2023
d21fffc
Update client/network/sync/src/engine.rs
altonen Mar 5, 2023
198a695
Update client/network/sync/src/engine.rs
altonen Mar 5, 2023
7c4babc
Add missing docs
altonen Mar 5, 2023
d028177
Refactor code
altonen Mar 5, 2023
efa7716
Merge remote-tracking branch 'origin/extract-syncing-from-sc-network'…
altonen Mar 5, 2023
800b4ae
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Mar 5, 2023
242ee09
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Mar 6, 2023
4f295d4
Merge remote-tracking branch 'origin/master' into extract-syncing-fro…
altonen Mar 6, 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
11 changes: 10 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
Vec::default(),
));

let (network, system_rpc_tx, tx_handler_controller, network_starter) =
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
Expand Down Expand Up @@ -240,6 +240,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
backend,
system_rpc_tx,
tx_handler_controller,
sync_service: sync_service.clone(),
config,
telemetry: telemetry.as_mut(),
})?;
Expand Down Expand Up @@ -276,8 +277,8 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
force_authoring,
backoff_authoring_blocks,
keystore: keystore_container.sync_keystore(),
sync_oracle: network.clone(),
justification_sync_link: network.clone(),
sync_oracle: sync_service.clone(),
justification_sync_link: sync_service.clone(),
block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32),
max_block_proposal_slot_portion: None,
telemetry: telemetry.as_ref().map(|x| x.handle()),
Expand Down Expand Up @@ -320,6 +321,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
config: grandpa_config,
link: grandpa_link,
network,
sync: Arc::new(sync_service),
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
shared_voter_state: SharedVoterState::empty(),
Expand Down
1 change: 1 addition & 0 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ sc-transaction-pool = { version = "4.0.0-dev", path = "../../../client/transacti
sc-transaction-pool-api = { version = "4.0.0-dev", path = "../../../client/transaction-pool/api" }
sc-network = { version = "0.10.0-dev", path = "../../../client/network" }
sc-network-common = { version = "0.10.0-dev", path = "../../../client/network/common" }
sc-network-sync = { version = "0.10.0-dev", path = "../../../client/network/sync" }
sc-consensus-slots = { version = "0.10.0-dev", path = "../../../client/consensus/slots" }
sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" }
sc-consensus-uncles = { version = "0.10.0-dev", path = "../../../client/consensus/uncles" }
Expand Down
3 changes: 2 additions & 1 deletion bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,13 @@ pub(crate) mod tests {
sp_tracing::try_init_simple();

sc_service_test::connectivity(integration_test_config_with_two_authorities(), |config| {
let NewFullBase { task_manager, client, network, transaction_pool, .. } =
let NewFullBase { task_manager, client, network, sync, transaction_pool, .. } =
new_full_base(config, false, |_, _| ())?;
Ok(sc_service_test::TestNetComponents::new(
task_manager,
client,
network,
sync,
transaction_pool,
))
});
Expand Down
26 changes: 20 additions & 6 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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_sync::SyncingService;
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -302,6 +303,8 @@ pub struct NewFullBase {
pub client: Arc<FullClient>,
/// The networking service of the node.
pub network: Arc<NetworkService<Block, <Block as BlockT>::Hash>>,
/// The syncing service of the node.
pub sync: Arc<SyncingService<Block>>,
/// The transaction pool of the node.
pub transaction_pool: Arc<TransactionPool>,
/// The rpc handlers of the node.
Expand Down Expand Up @@ -354,7 +357,7 @@ pub fn new_full_base(
Vec::default(),
));

let (network, system_rpc_tx, tx_handler_controller, network_starter) =
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
Expand Down Expand Up @@ -393,6 +396,7 @@ pub fn new_full_base(
task_manager: &mut task_manager,
system_rpc_tx,
tx_handler_controller,
sync_service: sync_service.clone(),
telemetry: telemetry.as_mut(),
})?;

Expand Down Expand Up @@ -430,8 +434,8 @@ pub fn new_full_base(
select_chain,
env: proposer,
block_import,
sync_oracle: network.clone(),
justification_sync_link: network.clone(),
sync_oracle: sync_service.clone(),
justification_sync_link: sync_service.clone(),
create_inherent_data_providers: move |parent, ()| {
let client_clone = client_clone.clone();
async move {
Expand Down Expand Up @@ -532,6 +536,7 @@ pub fn new_full_base(
config,
link: grandpa_link,
network: network.clone(),
sync: Arc::new(sync_service.clone()),
telemetry: telemetry.as_ref().map(|x| x.handle()),
voting_rule: grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
Expand All @@ -548,7 +553,14 @@ pub fn new_full_base(
}

network_starter.start_network();
Ok(NewFullBase { task_manager, client, network, transaction_pool, rpc_handlers })
Ok(NewFullBase {
task_manager,
client,
network,
sync: sync_service,
transaction_pool,
rpc_handlers,
})
}

/// Builds a new service for a full client.
Expand Down Expand Up @@ -621,7 +633,7 @@ mod tests {
chain_spec,
|config| {
let mut setup_handles = None;
let NewFullBase { task_manager, client, network, transaction_pool, .. } =
let NewFullBase { task_manager, client, network, sync, transaction_pool, .. } =
new_full_base(
config,
false,
Expand All @@ -635,6 +647,7 @@ mod tests {
task_manager,
client,
network,
sync,
transaction_pool,
);
Ok((node, setup_handles.unwrap()))
Expand Down Expand Up @@ -800,12 +813,13 @@ mod tests {
sc_service_test::consensus(
crate::chain_spec::tests::integration_test_config_with_two_authorities(),
|config| {
let NewFullBase { task_manager, client, network, transaction_pool, .. } =
let NewFullBase { task_manager, client, network, sync, transaction_pool, .. } =
new_full_base(config, false, |_, _| ())?;
Ok(sc_service_test::TestNetComponents::new(
task_manager,
client,
network,
sync,
transaction_pool,
))
},
Expand Down
1 change: 1 addition & 0 deletions client/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sc-keystore = { version = "4.0.0-dev", path = "../keystore" }
sc-network = { version = "0.10.0-dev", path = "../network" }
sc-network-common = { version = "0.10.0-dev", path = "../network/common" }
sc-network-gossip = { version = "0.10.0-dev", path = "../network-gossip" }
sc-network-sync = { version = "0.10.0-dev", path = "../network/sync" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
sp-api = { version = "4.0.0-dev", path = "../../primitives/api" }
sp-application-crypto = { version = "7.0.0", path = "../../primitives/application-crypto" }
Expand Down
30 changes: 20 additions & 10 deletions client/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use sc_client_api::{Backend, BlockBackend, BlockchainEvents, FinalityNotificatio
use sc_consensus::BlockImport;
use sc_network::ProtocolName;
use sc_network_common::service::NetworkRequest;
use sc_network_gossip::{GossipEngine, Network as GossipNetwork};
use sc_network_gossip::{GossipEngine, Network as GossipNetwork, Syncing as GossipSyncing};
use sp_api::{HeaderT, NumberFor, ProvideRuntimeApi};
use sp_blockchain::{
Backend as BlockchainBackend, Error as ClientError, HeaderBackend, Result as ClientResult,
Expand Down Expand Up @@ -165,9 +165,11 @@ where
}

/// BEEFY gadget network parameters.
pub struct BeefyNetworkParams<B: Block, N> {
pub struct BeefyNetworkParams<B: Block, N, S> {
/// Network implementing gossip, requests and sync-oracle.
pub network: Arc<N>,
/// Syncing service implementing a sync oracle and an event stream for peers.
pub sync: Arc<S>,
/// Chain specific BEEFY gossip protocol name. See
/// [`communication::beefy_protocol_name::gossip_protocol_name`].
pub gossip_protocol_name: ProtocolName,
Expand All @@ -179,7 +181,7 @@ pub struct BeefyNetworkParams<B: Block, N> {
}

/// BEEFY gadget initialization parameters.
pub struct BeefyParams<B: Block, BE, C, N, P, R> {
pub struct BeefyParams<B: Block, BE, C, N, P, R, S> {
/// BEEFY client
pub client: Arc<C>,
/// Client Backend
Expand All @@ -191,7 +193,7 @@ pub struct BeefyParams<B: Block, BE, C, N, P, R> {
/// Local key store
pub key_store: Option<SyncCryptoStorePtr>,
/// BEEFY voter network params
pub network_params: BeefyNetworkParams<B, N>,
pub network_params: BeefyNetworkParams<B, N, S>,
/// Minimal delta between blocks, BEEFY should vote for
pub min_block_delta: u32,
/// Prometheus metric registry
Expand All @@ -205,15 +207,17 @@ pub struct BeefyParams<B: Block, BE, C, N, P, R> {
/// Start the BEEFY gadget.
///
/// This is a thin shim around running and awaiting a BEEFY worker.
pub async fn start_beefy_gadget<B, BE, C, N, P, R>(beefy_params: BeefyParams<B, BE, C, N, P, R>)
where
pub async fn start_beefy_gadget<B, BE, C, N, P, R, S>(
beefy_params: BeefyParams<B, BE, C, N, P, R, S>,
) where
B: Block,
BE: Backend<B>,
C: Client<B, BE> + BlockBackend<B>,
P: PayloadProvider<B>,
R: ProvideRuntimeApi<B>,
R::Api: BeefyApi<B> + MmrApi<B, MmrRootHash, NumberFor<B>>,
N: GossipNetwork<B> + NetworkRequest + SyncOracle + Send + Sync + 'static,
N: GossipNetwork<B> + NetworkRequest + Send + Sync + 'static,
S: GossipSyncing<B> + SyncOracle + 'static,
{
let BeefyParams {
client,
Expand All @@ -228,14 +232,20 @@ where
on_demand_justifications_handler,
} = beefy_params;

let BeefyNetworkParams { network, gossip_protocol_name, justifications_protocol_name, .. } =
network_params;
let BeefyNetworkParams {
network,
sync,
gossip_protocol_name,
justifications_protocol_name,
..
} = network_params;

let known_peers = Arc::new(Mutex::new(KnownPeers::new()));
let gossip_validator =
Arc::new(communication::gossip::GossipValidator::new(known_peers.clone()));
let mut gossip_engine = sc_network_gossip::GossipEngine::new(
network.clone(),
sync.clone(),
gossip_protocol_name,
gossip_validator.clone(),
None,
Expand Down Expand Up @@ -284,7 +294,7 @@ where
let worker_params = worker::WorkerParams {
backend,
payload_provider,
network,
sync,
key_store: key_store.into(),
gossip_engine,
gossip_validator,
Expand Down
8 changes: 7 additions & 1 deletion client/beefy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ impl TestNetFactory for BeefyTestNet {
&self.peers
}

fn peers_mut(&mut self) -> &mut Vec<BeefyPeer> {
&mut self.peers
}

fn mut_peers<F: FnOnce(&mut Vec<BeefyPeer>)>(&mut self, closure: F) {
closure(&mut self.peers);
}
Expand Down Expand Up @@ -325,6 +329,7 @@ fn voter_init_setup(
Arc::new(crate::communication::gossip::GossipValidator::new(known_peers));
let mut gossip_engine = sc_network_gossip::GossipEngine::new(
net.peer(0).network_service().clone(),
net.peer(0).sync_service().clone(),
"/beefy/whatever",
gossip_validator,
None,
Expand Down Expand Up @@ -363,6 +368,7 @@ where

let network_params = crate::BeefyNetworkParams {
network: peer.network_service().clone(),
sync: peer.sync_service().clone(),
gossip_protocol_name: beefy_gossip_proto_name(),
justifications_protocol_name: on_demand_justif_handler.protocol_name(),
_phantom: PhantomData,
Expand All @@ -381,7 +387,7 @@ where
prometheus_registry: None,
on_demand_justifications_handler: on_demand_justif_handler,
};
let task = crate::start_beefy_gadget::<_, _, _, _, _, _>(beefy_params);
let task = crate::start_beefy_gadget::<_, _, _, _, _, _, _>(beefy_params);

fn assert_send<T: Send>(_: &T) {}
assert_send(&task);
Expand Down
Loading