From 95f228155f143ffc6cd1995bdb9a74d49a196190 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:08:54 -0400 Subject: [PATCH] chore: add send_action method to persistence task (#9233) --- crates/engine/tree/src/persistence.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/engine/tree/src/persistence.rs b/crates/engine/tree/src/persistence.rs index 6b1afe94d3..989ed5f76b 100644 --- a/crates/engine/tree/src/persistence.rs +++ b/crates/engine/tree/src/persistence.rs @@ -148,7 +148,9 @@ 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() { @@ -156,15 +158,21 @@ where } 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(()); } } } @@ -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. ///