From b44fff4dd0889f050df62957c752b24f140e96f9 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Wed, 2 Oct 2024 14:51:41 +0300 Subject: [PATCH] feat(chain-state): notify about new safe/finalized only if modified (#11383) --- crates/chain-state/src/chain_info.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/chain-state/src/chain_info.rs b/crates/chain-state/src/chain_info.rs index f01d472719..d9e2c03e27 100644 --- a/crates/chain-state/src/chain_info.rs +++ b/crates/chain-state/src/chain_info.rs @@ -112,15 +112,25 @@ impl ChainInfoTracker { /// Sets the safe header of the chain. pub fn set_safe(&self, header: SealedHeader) { - self.inner.safe_block.send_modify(|h| { - let _ = h.replace(header); + self.inner.safe_block.send_if_modified(|current_header| { + if current_header.as_ref().map(SealedHeader::hash) != Some(header.hash()) { + let _ = current_header.replace(header); + return true + } + + false }); } /// Sets the finalized header of the chain. pub fn set_finalized(&self, header: SealedHeader) { - self.inner.finalized_block.send_modify(|h| { - let _ = h.replace(header); + self.inner.finalized_block.send_if_modified(|current_header| { + if current_header.as_ref().map(SealedHeader::hash) != Some(header.hash()) { + let _ = current_header.replace(header); + return true + } + + false }); }