removes use of sc_client::Client from sc_finality_grandpa (#5030)

* removes use of sc_client::Client from sc_finality_grandpa

* code formatting

* code formatting

* removes use of sc_client::Client from sc_finality_grandpa
This commit is contained in:
Seun Lanlege
2020-02-27 12:19:07 +01:00
committed by GitHub
parent bad9647af9
commit 5907b0d902
13 changed files with 333 additions and 309 deletions
+56 -34
View File
@@ -66,7 +66,7 @@ pub use sc_client_api::{
backend::{
self, BlockImportOperation, PrunableStateChangesTrieStorage,
ClientImportOperation, Finalizer, ImportSummary, NewBlockState,
changes_tries_state_at_block,
LockImportRun, changes_tries_state_at_block,
},
client::{
ImportNotifications, FinalityNotification, FinalityNotifications, BlockImportNotification,
@@ -218,6 +218,61 @@ impl<B, E, Block, RA> BlockOf for Client<B, E, Block, RA> where
type Type = Block;
}
impl<B, E, Block, RA> LockImportRun<Block, B> for Client<B, E, Block, RA>
where
B: backend::Backend<Block>,
E: CallExecutor<Block>,
Block: BlockT,
{
fn lock_import_and_run<R, Err, F>(&self, f: F) -> Result<R, Err>
where
F: FnOnce(&mut ClientImportOperation<Block, B>) -> Result<R, Err>,
Err: From<sp_blockchain::Error>,
{
let inner = || {
let _import_lock = self.backend.get_import_lock().write();
let mut op = ClientImportOperation {
op: self.backend.begin_operation()?,
notify_imported: None,
notify_finalized: Vec::new(),
};
let r = f(&mut op)?;
let ClientImportOperation { op, notify_imported, notify_finalized } = op;
self.backend.commit_operation(op)?;
self.notify_finalized(notify_finalized)?;
if let Some(notify_imported) = notify_imported {
self.notify_imported(notify_imported)?;
}
Ok(r)
};
let result = inner();
*self.importing_block.write() = None;
result
}
}
impl<B, E, Block, RA> LockImportRun<Block, B> for &Client<B, E, Block, RA>
where
Block: BlockT,
B: backend::Backend<Block>,
E: CallExecutor<Block>,
{
fn lock_import_and_run<R, Err, F>(&self, f: F) -> Result<R, Err>
where
F: FnOnce(&mut ClientImportOperation<Block, B>) -> Result<R, Err>,
Err: From<sp_blockchain::Error>,
{
(**self).lock_import_and_run(f)
}
}
impl<B, E, Block, RA> Client<B, E, Block, RA> where
B: backend::Backend<Block>,
E: CallExecutor<Block>,
@@ -835,39 +890,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
)
}
/// Lock the import lock, and run operations inside.
pub fn lock_import_and_run<R, Err, F>(&self, f: F) -> Result<R, Err> where
F: FnOnce(&mut ClientImportOperation<Block, B>) -> Result<R, Err>,
Err: From<sp_blockchain::Error>,
{
let inner = || {
let _import_lock = self.backend.get_import_lock().write();
let mut op = ClientImportOperation {
op: self.backend.begin_operation()?,
notify_imported: None,
notify_finalized: Vec::new(),
};
let r = f(&mut op)?;
let ClientImportOperation { op, notify_imported, notify_finalized } = op;
self.backend.commit_operation(op)?;
self.notify_finalized(notify_finalized)?;
if let Some(notify_imported) = notify_imported {
self.notify_imported(notify_imported)?;
}
Ok(r)
};
let result = inner();
*self.importing_block.write() = None;
result
}
/// Apply a checked and validated block to an operation. If a justification is provided
/// then `finalized` *must* be true.
fn apply_block(
+1 -1
View File
@@ -98,7 +98,7 @@ pub use crate::{
client::{
new_with_backend,
new_in_mem,
BlockBody, ImportNotifications, FinalityNotifications, BlockchainEvents,
BlockBody, ImportNotifications, FinalityNotifications, BlockchainEvents, LockImportRun,
BlockImportNotification, Client, ClientInfo, ExecutionStrategies, FinalityNotification,
LongestChain, BlockOf, ProvideUncles, BadBlocks, ForkBlocks, apply_aux,
},