chore: add CanonStateSubscriptions to NoopTree (#7828)

This commit is contained in:
Matthias Seitz
2024-04-23 23:17:36 +02:00
committed by GitHub
parent a75d6cd753
commit 0f9145b728

View File

@ -22,7 +22,10 @@ use std::collections::{BTreeMap, HashSet};
/// Caution: this is only intended for testing purposes, or for wiring components together.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct NoopBlockchainTree {}
pub struct NoopBlockchainTree {
/// Broadcast channel for canon state changes notifications.
pub canon_state_notification_sender: Option<CanonStateNotificationSender>,
}
impl BlockchainTreeEngine for NoopBlockchainTree {
fn buffer_block(&self, _block: SealedBlockWithSenders) -> Result<(), InsertBlockError> {
@ -127,6 +130,9 @@ impl BlockchainTreePendingStateProvider for NoopBlockchainTree {
impl CanonStateSubscriptions for NoopBlockchainTree {
fn subscribe_to_canonical_state(&self) -> CanonStateNotifications {
CanonStateNotificationSender::new(1).subscribe()
self.canon_state_notification_sender
.as_ref()
.map(|sender| sender.subscribe())
.unwrap_or_else(|| CanonStateNotificationSender::new(1).subscribe())
}
}