Skip to content

Commit

Permalink
chore: add send_action method to persistence task (#9233)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Jul 2, 2024
1 parent 82770b0 commit 95f2281
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions crates/engine/tree/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,31 @@ where
match action {
PersistenceAction::RemoveBlocksAbove((new_tip_num, sender)) => {
let output = self.remove_blocks_above(new_tip_num);
sender.send(output).unwrap();

// we ignore the error because the caller may or may not care about the result
let _ = sender.send(output);
}
PersistenceAction::SaveBlocks((blocks, sender)) => {
if blocks.is_empty() {
todo!("return error or something");
}
let last_block_hash = blocks.last().unwrap().block().hash();
self.write(blocks).unwrap();
sender.send(last_block_hash).unwrap();

// we ignore the error because the caller may or may not care about the result
let _ = sender.send(last_block_hash);
}
PersistenceAction::PruneBefore((block_hash, sender)) => {
self.prune_before(block_hash);
sender.send(()).unwrap();

// we ignore the error because the caller may or may not care about the result
let _ = sender.send(());
}
PersistenceAction::CleanStaticFileDuplicates(sender) => {
self.clean_static_file_duplicates();
sender.send(()).unwrap();

// we ignore the error because the caller may or may not care about the result
let _ = sender.send(());
}
}
}
Expand Down Expand Up @@ -203,6 +211,12 @@ impl PersistenceHandle {
Self { sender }
}

/// Sends a specific [`PersistenceAction`] in the contained channel. The caller is responsible
/// for creating any channels for the given action.
pub fn send_action(&self, action: PersistenceAction) {
self.sender.send(action).expect("should be able to send");
}

/// Tells the persistence task to save a certain list of finalized blocks. The blocks are
/// assumed to be ordered by block number.
///
Expand Down

0 comments on commit 95f2281

Please sign in to comment.