From 485f5b36cea9e862dc8486eb011f29d1eccdf13f Mon Sep 17 00:00:00 2001 From: bigbear <155267841+aso20455@users.noreply.github.com> Date: Tue, 6 Jan 2026 15:16:22 +0200 Subject: [PATCH] fix(transaction-pool): finalized block number should never decrease (#20781) --- crates/transaction-pool/src/maintain.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 89d81e4037..c58a5151da 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -604,10 +604,10 @@ impl FinalizedBlockTracker { /// Updates the tracked finalized block and returns the new finalized block if it changed fn update(&mut self, finalized_block: Option) -> Option { let finalized = finalized_block?; - self.last_finalized_block - .replace(finalized) - .is_none_or(|last| last < finalized) - .then_some(finalized) + self.last_finalized_block.is_none_or(|last| last < finalized).then(|| { + self.last_finalized_block = Some(finalized); + finalized + }) } } @@ -934,7 +934,8 @@ mod tests { fn test_update_with_lower_finalized_block() { let mut tracker = FinalizedBlockTracker::new(Some(20)); assert_eq!(tracker.update(Some(15)), None); - assert_eq!(tracker.last_finalized_block, Some(15)); + // finalized block should NOT go backwards + assert_eq!(tracker.last_finalized_block, Some(20)); } #[test]