Skip to main content

forest/message_pool/msgpool/
events.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4//! Event types published by the pending pool.
5
6use crate::message::SignedMessage;
7use tokio::sync::broadcast;
8
9pub(in crate::message_pool) const MPOOL_UPDATE_CHANNEL_CAPACITY: usize = 256;
10
11/// A change to the pending pool.
12#[derive(Clone, Debug)]
13pub enum MpoolUpdate {
14    Add(SignedMessage),
15    #[allow(dead_code)]
16    Remove(SignedMessage),
17}
18
19/// Subscribe-only handle to the pending pool's [`MpoolUpdate`] broadcast bus.
20///
21/// Hands out independent receivers via [`subscribe`](Self::subscribe), each with
22/// its own cursor.
23#[derive(Debug)]
24pub struct MpoolSubscriber(broadcast::Sender<MpoolUpdate>);
25
26impl MpoolSubscriber {
27    /// Wrap the pending pool's broadcast `Sender`.
28    pub(crate) fn new(events: broadcast::Sender<MpoolUpdate>) -> Self {
29        Self(events)
30    }
31
32    /// A detached handle with no producer behind it, its receivers never observe
33    /// any event.
34    #[cfg(test)]
35    pub(crate) fn dummy() -> Self {
36        Self(broadcast::channel(1).0)
37    }
38
39    /// Open a fresh receiver that observes every [`MpoolUpdate`] published from
40    /// this point on.
41    pub(crate) fn subscribe(&self) -> broadcast::Receiver<MpoolUpdate> {
42        self.0.subscribe()
43    }
44}