mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 00:11:01 +00:00
Chain-selection subsystem data revert (#5350)
* Chain-selection subsystem data revert * Cargo fmt * Better code comments * Remove unwraps * Document public method * Remove duplicated 'ChainSelectionSubsystem' impl block * Fix typos * Nitpicks * Revert returns a service Error * Removed superflous error handling * Apply suggestions from code review * Rename tree 'revert' to 'revert_to' Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
This commit is contained in:
@@ -315,6 +315,17 @@ impl ChainSelectionSubsystem {
|
||||
pub fn new(config: Config, db: Arc<dyn Database>) -> Self {
|
||||
ChainSelectionSubsystem { config, db }
|
||||
}
|
||||
|
||||
/// Revert to the block corresponding to the specified `hash`.
|
||||
/// The revert is not allowed for blocks older than the last finalized one.
|
||||
pub fn revert(&self, hash: Hash) -> Result<(), Error> {
|
||||
let backend_config = db_backend::v1::Config { col_data: self.config.col_data };
|
||||
let mut backend = db_backend::v1::DbBackend::new(self.db.clone(), backend_config);
|
||||
|
||||
let ops = tree::revert_to(&backend, hash)?.into_write_ops();
|
||||
|
||||
backend.write(ops)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Context> overseer::Subsystem<Context, SubsystemError> for ChainSelectionSubsystem
|
||||
@@ -323,9 +334,9 @@ where
|
||||
Context: overseer::SubsystemContext<Message = ChainSelectionMessage>,
|
||||
{
|
||||
fn start(self, ctx: Context) -> SpawnedSubsystem {
|
||||
let backend = crate::db_backend::v1::DbBackend::new(
|
||||
let backend = db_backend::v1::DbBackend::new(
|
||||
self.db,
|
||||
crate::db_backend::v1::Config { col_data: self.config.col_data },
|
||||
db_backend::v1::Config { col_data: self.config.col_data },
|
||||
);
|
||||
|
||||
SpawnedSubsystem {
|
||||
@@ -412,7 +423,7 @@ where
|
||||
let _ = tx.send(leaves);
|
||||
}
|
||||
ChainSelectionMessage::BestLeafContaining(required, tx) => {
|
||||
let best_containing = crate::backend::find_best_leaf_containing(
|
||||
let best_containing = backend::find_best_leaf_containing(
|
||||
&*backend,
|
||||
required,
|
||||
)?;
|
||||
@@ -549,7 +560,7 @@ async fn handle_active_leaf(
|
||||
};
|
||||
|
||||
let reversion_logs = extract_reversion_logs(&header);
|
||||
crate::tree::import_block(
|
||||
tree::import_block(
|
||||
&mut overlay,
|
||||
hash,
|
||||
header.number,
|
||||
@@ -612,8 +623,7 @@ fn handle_finalized_block(
|
||||
finalized_hash: Hash,
|
||||
finalized_number: BlockNumber,
|
||||
) -> Result<(), Error> {
|
||||
let ops =
|
||||
crate::tree::finalize_block(&*backend, finalized_hash, finalized_number)?.into_write_ops();
|
||||
let ops = tree::finalize_block(&*backend, finalized_hash, finalized_number)?.into_write_ops();
|
||||
|
||||
backend.write(ops)
|
||||
}
|
||||
@@ -623,7 +633,7 @@ fn handle_approved_block(backend: &mut impl Backend, approved_block: Hash) -> Re
|
||||
let ops = {
|
||||
let mut overlay = OverlayedBackend::new(&*backend);
|
||||
|
||||
crate::tree::approve_block(&mut overlay, approved_block)?;
|
||||
tree::approve_block(&mut overlay, approved_block)?;
|
||||
|
||||
overlay.into_write_ops()
|
||||
};
|
||||
@@ -633,7 +643,7 @@ fn handle_approved_block(backend: &mut impl Backend, approved_block: Hash) -> Re
|
||||
|
||||
fn detect_stagnant(backend: &mut impl Backend, now: Timestamp) -> Result<(), Error> {
|
||||
let ops = {
|
||||
let overlay = crate::tree::detect_stagnant(&*backend, now)?;
|
||||
let overlay = tree::detect_stagnant(&*backend, now)?;
|
||||
|
||||
overlay.into_write_ops()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user