Skip to content

Commit

Permalink
feat(chain-state): notify about new safe/finalized only if modified
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Oct 1, 2024
1 parent 86f12b7 commit e028b70
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions crates/chain-state/src/chain_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() != Some(&header) {
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() != Some(&header) {
let _ = current_header.replace(header);
return true
}

false
});
}

Expand Down

0 comments on commit e028b70

Please sign in to comment.