From a6f6346ffe07dedd579a7e843ba9bad0bdb65260 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 23 Jul 2024 19:36:24 +0200 Subject: [PATCH] feat: emit chain notifications (#9732) --- crates/chain-state/src/in_memory.rs | 9 ++++++++- crates/engine/tree/src/tree/mod.rs | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index 65120ee7e9..1e6184d180 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -1,6 +1,8 @@ //! Types for tracking the canonical chain state in memory. -use crate::{CanonStateNotificationSender, CanonStateNotifications, ChainInfoTracker}; +use crate::{ + CanonStateNotification, CanonStateNotificationSender, CanonStateNotifications, ChainInfoTracker, +}; use parking_lot::RwLock; use reth_chainspec::ChainInfo; use reth_execution_types::ExecutionOutcome; @@ -251,6 +253,11 @@ impl CanonicalInMemoryState { pub fn subscribe_canon_state(&self) -> CanonStateNotifications { self.inner.canon_state_notification_sender.subscribe() } + + /// Attempts to send a new [`CanonStateNotification`] to all active Receiver handles. + pub fn notify_canon_state(&self, event: CanonStateNotification) { + self.inner.canon_state_notification_sender.send(event).ok(); + } } /// State after applying the given block. diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index a895a04ad7..d8eadd68e6 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -1380,7 +1380,9 @@ where // TODO // update inmemory state // update trackers - // emit notification + + // sends an event to all active listeners about the new canonical chain + self.canonical_in_memory_state.notify_canon_state(update.to_chain_notification()); if let Some(attr) = attrs { let updated = self.process_payload_attributes(attr, &update.tip().header, state);