pub struct ChainMonitor<ChannelSigner, C, T, F, L, P>
where ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, <C as Deref>::Target: Filter, <T as Deref>::Target: BroadcasterInterface, <F as Deref>::Target: FeeEstimator, <L as Deref>::Target: Logger, <P as Deref>::Target: Persist<ChannelSigner>,
{ /* private fields */ }
Expand description

An implementation of chain::Watch for monitoring channels.

Connected and disconnected blocks must be provided to ChainMonitor as documented by chain::Watch. May be used in conjunction with ChannelManager to monitor channels locally or used independently to monitor channels remotely. See the module-level documentation for details.

Note that ChainMonitor should regularly trigger rebroadcasts/fee bumps of pending claims from a force-closed channel. This is crucial in preventing certain classes of pinning attacks, detecting substantial mempool feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend invoking this every 30 seconds, or lower if running in an environment with spotty connections, like on mobile.

Implementations§

§

impl<ChannelSigner, C, T, F, L, P> ChainMonitor<ChannelSigner, C, T, F, L, P>
where ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, <C as Deref>::Target: Filter, <T as Deref>::Target: BroadcasterInterface, <F as Deref>::Target: FeeEstimator, <L as Deref>::Target: Logger, <P as Deref>::Target: Persist<ChannelSigner>,

pub fn new( chain_source: Option<C>, broadcaster: T, logger: L, feeest: F, persister: P, ) -> ChainMonitor<ChannelSigner, C, T, F, L, P>

Creates a new ChainMonitor used to watch on-chain activity pertaining to channels.

When an optional chain source implementing chain::Filter is provided, the chain monitor will call back to it indicating transactions and outputs of interest. This allows clients to pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may always need to fetch full blocks absent another means for determining which blocks contain transactions relevant to the watched channels.

pub fn get_claimable_balances( &self, ignored_channels: &[&ChannelDetails], ) -> Vec<Balance>

Gets the balances in the contained ChannelMonitors which are claimable on-chain or claims which are awaiting confirmation.

Includes the balances from each ChannelMonitor except those included in ignored_channels, allowing you to filter out balances from channels which are still open (and whose balance should likely be pulled from the ChannelDetails).

See ChannelMonitor::get_claimable_balances for more details on the exact criteria for inclusion in the return value.

pub fn get_monitor( &self, funding_txo: OutPoint, ) -> Result<LockedChannelMonitor<'_, ChannelSigner>, ()>

Gets the LockedChannelMonitor for a given funding outpoint, returning an Err if no such ChannelMonitor is currently being monitored for.

Note that the result holds a mutex over our monitor set, and should not be held indefinitely.

pub fn list_monitors(&self) -> Vec<OutPoint>

Lists the funding outpoint of each ChannelMonitor being monitored.

Note that ChannelMonitors are not removed when a channel is closed as they are always monitoring for on-chain state resolutions.

pub fn list_pending_monitor_updates( &self, ) -> HashMap<OutPoint, Vec<MonitorUpdateId>>

Lists the pending updates for each ChannelMonitor (by OutPoint being monitored).

pub fn channel_monitor_updated( &self, funding_txo: OutPoint, completed_update_id: MonitorUpdateId, ) -> Result<(), APIError>

Indicates the persistence of a ChannelMonitor has completed after ChannelMonitorUpdateStatus::InProgress was returned from an update operation.

Thus, the anticipated use is, at a high level:

  1. This ChainMonitor calls Persist::update_persisted_channel which stores the update to disk and begins updating any remote (e.g. watchtower/backup) copies, returning ChannelMonitorUpdateStatus::InProgress,
  2. once all remote copies are updated, you call this function with the completed_update_id that completed, and once all pending updates have completed the channel will be re-enabled.

Returns an APIError::APIMisuseError if funding_txo does not match any currently registered ChannelMonitors.

pub fn get_and_clear_pending_events(&self) -> Vec<Event>

pub async fn process_pending_events_async<Future, H>(&self, handler: H)
where Future: Future, H: Fn(Event) -> Future,

Processes any events asynchronously in the order they were generated since the last call using the given event handler.

See the trait-level documentation of EventsProvider for requirements.

pub fn get_update_future(&self) -> Future

Gets a Future that completes when an event is available either via chain::Watch::release_pending_monitor_events or EventsProvider::process_pending_events.

Note that callbacks registered on the Future MUST NOT call back into this ChainMonitor and should instead register actions to be taken later.

pub fn rebroadcast_pending_claims(&self)

Triggers rebroadcasts/fee-bumps of pending claims from a force-closed channel. This is crucial in preventing certain classes of pinning attacks, detecting substantial mempool feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend invoking this every 30 seconds, or lower if running in an environment with spotty connections, like on mobile.

Trait Implementations§

§

impl<ChannelSigner, C, T, F, L, P> Confirm for ChainMonitor<ChannelSigner, C, T, F, L, P>
where ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, <C as Deref>::Target: Filter, <T as Deref>::Target: BroadcasterInterface, <F as Deref>::Target: FeeEstimator, <L as Deref>::Target: Logger, <P as Deref>::Target: Persist<ChannelSigner>,

§

fn transactions_confirmed( &self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32, )

Notifies LDK of transactions confirmed in a block with a given header and height. Read more
§

fn transaction_unconfirmed(&self, txid: &Txid)

Notifies LDK of a transaction that is no longer confirmed as result of a chain reorganization. Read more
§

fn best_block_updated(&self, header: &BlockHeader, height: u32)

Notifies LDK of an update to the best header connected at the given height. Read more
§

fn get_relevant_txids(&self) -> Vec<(Txid, Option<BlockHash>)>

Returns transactions that must be monitored for reorganization out of the chain along with the hash of the block as part of which it had been previously confirmed. Read more
§

impl<ChannelSigner, C, T, F, L, P> EventsProvider for ChainMonitor<ChannelSigner, C, T, F, L, P>
where ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, <C as Deref>::Target: Filter, <T as Deref>::Target: BroadcasterInterface, <F as Deref>::Target: FeeEstimator, <L as Deref>::Target: Logger, <P as Deref>::Target: Persist<ChannelSigner>,

§

fn process_pending_events<H>(&self, handler: H)
where H: Deref, <H as Deref>::Target: EventHandler,

Processes SpendableOutputs events produced from each ChannelMonitor upon maturity.

For channels featuring anchor outputs, this method will also process BumpTransaction events produced from each ChannelMonitor while there is a balance to claim onchain within each channel. As the confirmation of a commitment transaction may be critical to the safety of funds, we recommend invoking this every 30 seconds, or lower if running in an environment with spotty connections, like on mobile.

An EventHandler may safely call back to the provider, though this shouldn’t be needed in order to handle these events.

§

impl<ChannelSigner, C, T, F, L, P> Listen for ChainMonitor<ChannelSigner, C, T, F, L, P>
where ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, <C as Deref>::Target: Filter, <T as Deref>::Target: BroadcasterInterface, <F as Deref>::Target: FeeEstimator, <L as Deref>::Target: Logger, <P as Deref>::Target: Persist<ChannelSigner>,

§

fn filtered_block_connected( &self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32, )

Notifies the listener that a block was added at the given height, with the transaction data possibly filtered.
§

fn block_disconnected(&self, header: &BlockHeader, height: u32)

Notifies the listener that a block was removed at the given height.
§

fn block_connected(&self, block: &Block, height: u32)

Notifies the listener that a block was added at the given height.
§

impl<ChannelSigner, C, T, F, L, P> Watch<ChannelSigner> for ChainMonitor<ChannelSigner, C, T, F, L, P>
where ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, <C as Deref>::Target: Filter, <T as Deref>::Target: BroadcasterInterface, <F as Deref>::Target: FeeEstimator, <L as Deref>::Target: Logger, <P as Deref>::Target: Persist<ChannelSigner>,

§

fn watch_channel( &self, funding_outpoint: OutPoint, monitor: ChannelMonitor<ChannelSigner>, ) -> Result<ChannelMonitorUpdateStatus, ()>

Watches a channel identified by funding_txo using monitor. Read more
§

fn update_channel( &self, funding_txo: OutPoint, update: &ChannelMonitorUpdate, ) -> ChannelMonitorUpdateStatus

Updates a channel identified by funding_txo by applying update to its monitor. Read more
§

fn release_pending_monitor_events( &self, ) -> Vec<(OutPoint, Vec<MonitorEvent>, Option<PublicKey>)>

Returns any monitor events since the last call. Subsequent calls must only return new events. Read more

Auto Trait Implementations§

§

impl<ChannelSigner, C, T, F, L, P> !Freeze for ChainMonitor<ChannelSigner, C, T, F, L, P>

§

impl<ChannelSigner, C, T, F, L, P> RefUnwindSafe for ChainMonitor<ChannelSigner, C, T, F, L, P>

§

impl<ChannelSigner, C, T, F, L, P> Send for ChainMonitor<ChannelSigner, C, T, F, L, P>
where T: Send, L: Send, F: Send, P: Send, C: Send, ChannelSigner: Send,

§

impl<ChannelSigner, C, T, F, L, P> Sync for ChainMonitor<ChannelSigner, C, T, F, L, P>
where T: Sync, L: Sync, F: Sync, P: Sync, C: Sync, ChannelSigner: Send,

§

impl<ChannelSigner, C, T, F, L, P> Unpin for ChainMonitor<ChannelSigner, C, T, F, L, P>
where T: Unpin, L: Unpin, F: Unpin, P: Unpin, C: Unpin, ChannelSigner: Unpin,

§

impl<ChannelSigner, C, T, F, L, P> UnwindSafe for ChainMonitor<ChannelSigner, C, T, F, L, P>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

§

impl<T> AsAny for T
where T: Any,

§

fn as_any(&self) -> &(dyn Any + 'static)

§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

§

fn type_name(&self) -> &'static str

Gets the type name of self
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: AsAny + ?Sized,

§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DartSafe for T