Skip to content

Commit

Permalink
fix(engine): run pruner after saving blocks (#11927)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo authored Oct 22, 2024
1 parent e820593 commit cab76f2
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions crates/engine/tree/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,22 @@ impl<N: ProviderNodeTypes> PersistenceService<N> {
}
PersistenceAction::SaveBlocks(blocks, sender) => {
let result = self.on_save_blocks(blocks)?;
if let Some(ref num_hash) = result {
let result_number = result.map(|r| r.number);

// we ignore the error because the caller may or may not care about the result
let _ = sender.send(result);

if let Some(block_number) = result_number {
// send new sync metrics based on saved blocks
let _ = self
.sync_metrics_tx
.send(MetricEvent::SyncHeight { height: num_hash.number });
}
// we ignore the error because the caller may or may not care about the result
let _ = sender.send(result);
}
PersistenceAction::PruneBefore(block_num, sender) => {
let res = self.prune_before(block_num)?;
.send(MetricEvent::SyncHeight { height: block_number });

// we ignore the error because the caller may or may not care about the result
let _ = sender.send(res);
if self.pruner.is_pruning_needed(block_number) {
// We log `PrunerOutput` inside the `Pruner`
let _ = self.prune_before(block_number)?;
}
}
}
PersistenceAction::SaveFinalizedBlock(finalized_block) => {
let provider = self.provider.database_provider_rw()?;
Expand Down Expand Up @@ -175,10 +177,6 @@ pub enum PersistenceAction {
/// static files.
RemoveBlocksAbove(u64, oneshot::Sender<Option<BlockNumHash>>),

/// Prune associated block data before the given block number, according to already-configured
/// prune modes.
PruneBefore(u64, oneshot::Sender<PrunerOutput>),

/// Update the persisted finalized block on disk
SaveFinalizedBlock(u64),

Expand Down Expand Up @@ -279,18 +277,6 @@ impl PersistenceHandle {
) -> Result<(), SendError<PersistenceAction>> {
self.send_action(PersistenceAction::RemoveBlocksAbove(block_num, tx))
}

/// Tells the persistence service to remove block data before the given hash, according to the
/// configured prune config.
///
/// The resulting [`PrunerOutput`] is returned in the receiver end of the sender argument.
pub fn prune_before(
&self,
block_num: u64,
tx: oneshot::Sender<PrunerOutput>,
) -> Result<(), SendError<PersistenceAction>> {
self.send_action(PersistenceAction::PruneBefore(block_num, tx))
}
}

#[cfg(test)]
Expand Down

0 comments on commit cab76f2

Please sign in to comment.