Skip to content

Commit

Permalink
Update fast-sync API
Browse files Browse the repository at this point in the history
  • Loading branch information
shamil-gadelshin committed May 29, 2024
1 parent 4ffa45a commit 57fea75
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion substrate/client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<Block: BlockT> blockchain::Backend<Block> for Blockchain<Block> {
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.")
}
}
Expand Down
9 changes: 8 additions & 1 deletion substrate/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,16 @@ impl<Block: BlockT> sc_client_api::blockchain::Backend<Block> for BlockchainDb<B
}
}

fn clear_block_gap(&self) {
fn clear_block_gap(&self) -> 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(())
}
}

Expand Down
20 changes: 2 additions & 18 deletions substrate/client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,10 @@ where
B: backend::Backend<Block>,
E: CallExecutor<Block> + Send + Sync,
Block: BlockT,
Client<B, E, Block, RA>: ProvideRuntimeApi<Block>,
<Client<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api: CoreApi<Block> + ApiExt<Block>,
RA: Sync + Send,
{
/// Apply a checked and validated block to an operation.
fn apply_block(
&self,
operation: &mut ClientImportOperation<Block, B>,
import_block: BlockImportParams<Block>,
storage_changes: Option<sc_consensus::StorageChanges<Block>>,
) -> sp_blockchain::Result<ImportResult>
where
Self: ProvideRuntimeApi<Block>,
<Self as ProvideRuntimeApi<Block>>::Api: CoreApi<Block> + ApiExt<Block>,
{
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()
}
}

Expand Down
13 changes: 2 additions & 11 deletions substrate/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -102,15 +100,8 @@ pub struct RpcHandlers(Arc<RpcModule<()>>);

/// Provides extended functions for `Client` to enable fast-sync.
pub trait ClientExt<Block: BlockT, B: backend::Backend<Block>> {
/// Apply a checked and validated block to an operation.
fn apply_block(
&self,
operation: &mut ClientImportOperation<Block, B>,
import_block: BlockImportParams<Block>,
storage_changes: Option<sc_consensus::StorageChanges<Block>>,
) -> sp_blockchain::Result<sc_consensus::ImportResult>;
/// Clear block gap after initial block insertion.
fn clear_block_gap(&self);
fn clear_block_gap(&self) -> sp_blockchain::Result<()>;
}

impl RpcHandlers {
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/blockchain/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub trait Backend<Block: BlockT>:
fn block_indexed_body(&self, hash: Block::Hash) -> Result<Option<Vec<Vec<u8>>>>;

/// Clears the block gap from DB after the fast-sync.
fn clear_block_gap(&self);
fn clear_block_gap(&self) -> Result<()>;
}

/// Blockchain info
Expand Down

0 comments on commit 57fea75

Please sign in to comment.