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

Commit

Permalink
format using Cargo +nightly fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
samelamin committed Nov 23, 2022
1 parent 1185a68 commit 35d282c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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_network_common::sync::warp::WarpSyncParams;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::{sync::Arc, time::Duration};
Expand Down
4 changes: 3 additions & 1 deletion 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, sync::warp::WarpSyncParams};
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
2 changes: 1 addition & 1 deletion client/network/common/src/sync/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +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, sync::Arc};
use futures::channel::oneshot;

/// Scale-encoded warp sync proof response.
pub struct EncodedProof(pub Vec<u8>);
Expand Down
1 change: 0 additions & 1 deletion client/network/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ prost-build = "0.11"
[dependencies]
array-bytes = "4.1"
async-trait = "0.1.58"
async-std = { version = "1.11.0", default-features = false }
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
futures = "0.3.21"
libp2p = "0.49.0"
Expand Down
31 changes: 19 additions & 12 deletions client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,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 @@ -601,18 +602,24 @@ where
if let SyncMode::Warp = &self.mode {
if self.peers.len() >= MIN_PEERS_TO_START_WARP_SYNC && self.warp_sync.is_none()
{
match self.warp_sync_params.as_mut().unwrap() {
WarpSyncParams::WithProvider(warp_with_provider) => {
log::debug!(target: "sync", "Starting warp state sync.");
self.warp_sync = Some(WarpSync::new(self.client.clone(), warp_with_provider.clone()));
}
WarpSyncParams::WaitForTarget(header) => {
log::debug!(target: "sync", "Waiting for target block.");
async_std::task::block_on(async {
self.warp_sync = Some(WarpSync::new_with_target_block(self.client.clone(), header.await.unwrap()));
});
}
}
match self.warp_sync_params.as_mut().unwrap() {
WarpSyncParams::WithProvider(warp_with_provider) => {
log::debug!(target: "sync", "Starting warp state sync.");
self.warp_sync = Some(WarpSync::new(
self.client.clone(),
warp_with_provider.clone(),
));
},
WarpSyncParams::WaitForTarget(header) => {
log::debug!(target: "sync", "Waiting for target block.");
futures::executor::block_on(async {
self.warp_sync = Some(WarpSync::new_with_target_block(
self.client.clone(),
header.await.unwrap(),
));
});
},
}
}
}
Ok(req)
Expand Down
14 changes: 9 additions & 5 deletions client/network/sync/src/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ use sp_runtime::traits::{Block as BlockT, Header, NumberFor, Zero};
use std::sync::Arc;

enum Phase<B: BlockT, Client> {
WarpProof { set_id: SetId, authorities: AuthorityList, last_hash: B::Hash, warp_sync_provider: Arc<dyn WarpSyncProvider<B>> },
WarpProof {
set_id: SetId,
authorities: AuthorityList,
last_hash: B::Hash,
warp_sync_provider: Arc<dyn WarpSyncProvider<B>>,
},
TargetBlock(B::Header),
State(StateSync<B, Client>),
}
Expand Down Expand Up @@ -76,7 +81,7 @@ where
set_id: 0,
authorities: warp_sync_provider.current_authorities(),
last_hash,
warp_sync_provider
warp_sync_provider,
};
Self { client, phase, total_proof_bytes: 0 }
}
Expand Down Expand Up @@ -104,7 +109,7 @@ where
log::debug!(target: "sync", "Unexpected warp proof response");
WarpProofImportResult::BadResponse
},
Phase::WarpProof { set_id, authorities, last_hash, warp_sync_provider } => {
Phase::WarpProof { set_id, authorities, last_hash, warp_sync_provider } =>
match warp_sync_provider.verify(&response, *set_id, authorities.clone()) {
Err(e) => {
log::debug!(target: "sync", "Bad warp proof response: {}", e);
Expand All @@ -124,8 +129,7 @@ where
self.phase = Phase::TargetBlock(header);
WarpProofImportResult::Success
},
}
},
},
}
}

Expand Down
4 changes: 3 additions & 1 deletion client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ use sc_network_common::{
},
protocol::{role::Roles, ProtocolName},
service::{NetworkBlock, NetworkStateInfo, NetworkSyncForkRequest},
sync::warp::{AuthorityList, EncodedProof, SetId, VerificationResult, WarpSyncParams, WarpSyncProvider},
sync::warp::{
AuthorityList, EncodedProof, SetId, VerificationResult, WarpSyncParams, WarpSyncProvider,
},
};
use sc_network_light::light_client_requests::handler::LightClientRequestHandler;
use sc_network_sync::{
Expand Down
9 changes: 6 additions & 3 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,13 +832,16 @@ where
config.chain_spec.fork_id(),
provider.clone(),
);
spawn_handle.spawn("warp-sync-request-handler", Some("networking"), handler.run());
spawn_handle.spawn(
"warp-sync-request-handler",
Some("networking"),
handler.run(),
);
(Some(provider), Some(protocol_config))
})
.unwrap_or_default();
},
_ => {
}
_ => {},
}

let light_client_request_protocol_config = {
Expand Down

0 comments on commit 35d282c

Please sign in to comment.