From 4ffa45aa683286e69f1e4ec99c0c18bee96da057 Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Wed, 29 May 2024 14:35:59 +0700 Subject: [PATCH 1/2] Revert "Introduce connected_peers() API" This reverts commit 88831de21c3770c4ff6c95445a0f38dae0d3624a. --- substrate/client/network/src/service.rs | 30 ------------------------- 1 file changed, 30 deletions(-) diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 0ac8ca1ecd27..47e23337633b 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -743,21 +743,6 @@ impl NetworkService { rx.await.map_err(|_| ()) } - /// Returns a collection of currently connected (open) peers. - pub async fn connected_peers(&self) -> Result, ()> { - let (tx, rx) = oneshot::channel(); - - let _ = self - .to_worker - .unbounded_send(ServiceToWorkerMsg::ConnectedPeers { pending_response: tx }); - - match rx.await { - Ok(v) => Ok(v), - // The channel can only be closed if the network worker no longer exists. - Err(_) => Err(()), - } - } - /// Utility function to extract `PeerId` from each `Multiaddr` for peer set updates. /// /// Returns an `Err` if one of the given addresses is invalid or contains an @@ -1188,9 +1173,6 @@ enum ServiceToWorkerMsg { NetworkState { pending_response: oneshot::Sender>, }, - ConnectedPeers { - pending_response: oneshot::Sender>, - }, DisconnectPeer(PeerId, ProtocolName), } @@ -1333,21 +1315,9 @@ where .behaviour_mut() .user_protocol_mut() .disconnect_peer(&who, protocol_name), - ServiceToWorkerMsg::ConnectedPeers { pending_response } => { - let _ = pending_response.send(self.connected_peers()); - }, } } - fn connected_peers(&self) -> Vec { - self.network_service - .behaviour() - .user_protocol() - .open_peers() - .cloned() - .collect::>() - } - /// Process the next event coming from `Swarm`. fn handle_swarm_event(&mut self, event: SwarmEvent>>) { match event { From 57fea752a0c8c071bfca94c2ca96832f9b1903d0 Mon Sep 17 00:00:00 2001 From: Shamil Gadelshin Date: Wed, 29 May 2024 21:05:13 +0700 Subject: [PATCH 2/2] Update fast-sync API --- substrate/client/api/src/in_mem.rs | 2 +- substrate/client/db/src/lib.rs | 9 ++++++++- substrate/client/service/src/client/client.rs | 20 ++----------------- substrate/client/service/src/lib.rs | 13 ++---------- .../primitives/blockchain/src/backend.rs | 2 +- 5 files changed, 14 insertions(+), 32 deletions(-) diff --git a/substrate/client/api/src/in_mem.rs b/substrate/client/api/src/in_mem.rs index 0238343f250f..2679aa3b5dd4 100644 --- a/substrate/client/api/src/in_mem.rs +++ b/substrate/client/api/src/in_mem.rs @@ -448,7 +448,7 @@ impl blockchain::Backend for Blockchain { unimplemented!("Not supported by the in-mem backend.") } - fn clear_block_gap(&self) { + fn clear_block_gap(&self) -> sp_blockchain::Result<()> { unimplemented!("Not supported by the in-mem backend.") } } diff --git a/substrate/client/db/src/lib.rs b/substrate/client/db/src/lib.rs index 6a2a0975ed60..165ea302bdb7 100644 --- a/substrate/client/db/src/lib.rs +++ b/substrate/client/db/src/lib.rs @@ -804,9 +804,16 @@ impl sc_client_api::blockchain::Backend for BlockchainDb ClientResult<()> { debug!(target: "sync", "Clear block gap."); + + let mut transaction = Transaction::new(); + transaction.remove(columns::META, meta_keys::BLOCK_GAP); + self.db.commit(transaction)?; + self.update_block_gap(None); + + Ok(()) } } diff --git a/substrate/client/service/src/client/client.rs b/substrate/client/service/src/client/client.rs index 0ff858e7d941..e3f44c5b2ac5 100644 --- a/substrate/client/service/src/client/client.rs +++ b/substrate/client/service/src/client/client.rs @@ -123,26 +123,10 @@ where B: backend::Backend, E: CallExecutor + Send + Sync, Block: BlockT, - Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: CoreApi + ApiExt, RA: Sync + Send, { - /// Apply a checked and validated block to an operation. - fn apply_block( - &self, - operation: &mut ClientImportOperation, - import_block: BlockImportParams, - storage_changes: Option>, - ) -> sp_blockchain::Result - where - Self: ProvideRuntimeApi, - >::Api: CoreApi + ApiExt, - { - self.apply_block(operation, import_block, storage_changes) - } - - fn clear_block_gap(&self) { - self.backend.blockchain().clear_block_gap(); + fn clear_block_gap(&self) -> sp_blockchain::Result<()> { + self.backend.blockchain().clear_block_gap() } } diff --git a/substrate/client/service/src/lib.rs b/substrate/client/service/src/lib.rs index a3a70f1b69b1..ed6a324ffa67 100644 --- a/substrate/client/service/src/lib.rs +++ b/substrate/client/service/src/lib.rs @@ -41,8 +41,7 @@ use futures::{pin_mut, FutureExt, StreamExt}; use jsonrpsee::RpcModule; use log::{debug, error, warn}; use sc_client_api::{ - backend, blockchain::HeaderBackend, BlockBackend, BlockchainEvents, ClientImportOperation, - ProofProvider, + backend, blockchain::HeaderBackend, BlockBackend, BlockchainEvents, ProofProvider, }; use sc_network::{ config::MultiaddrWithPeerId, NetworkBlock, NetworkPeers, NetworkStateInfo, PeerId, @@ -78,7 +77,6 @@ pub use sc_chain_spec::{ Properties, RuntimeGenesis, }; -use sc_consensus::BlockImportParams; pub use sc_consensus::ImportQueue; pub use sc_executor::NativeExecutionDispatch; pub use sc_network_sync::WarpSyncParams; @@ -102,15 +100,8 @@ pub struct RpcHandlers(Arc>); /// Provides extended functions for `Client` to enable fast-sync. pub trait ClientExt> { - /// Apply a checked and validated block to an operation. - fn apply_block( - &self, - operation: &mut ClientImportOperation, - import_block: BlockImportParams, - storage_changes: Option>, - ) -> sp_blockchain::Result; /// Clear block gap after initial block insertion. - fn clear_block_gap(&self); + fn clear_block_gap(&self) -> sp_blockchain::Result<()>; } impl RpcHandlers { diff --git a/substrate/primitives/blockchain/src/backend.rs b/substrate/primitives/blockchain/src/backend.rs index 363c71fdb75a..2131d7f9c26b 100644 --- a/substrate/primitives/blockchain/src/backend.rs +++ b/substrate/primitives/blockchain/src/backend.rs @@ -257,7 +257,7 @@ pub trait Backend: fn block_indexed_body(&self, hash: Block::Hash) -> Result>>>; /// Clears the block gap from DB after the fast-sync. - fn clear_block_gap(&self); + fn clear_block_gap(&self) -> Result<()>; } /// Blockchain info