[][src]Struct lightning::chain::channelmonitor::ChannelMonitor

pub struct ChannelMonitor<ChanSigner: ChannelKeys> { /* fields omitted */ }

A ChannelMonitor handles chain events (blocks connected and disconnected) and generates on-chain transactions to ensure no loss of funds occurs.

You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date information and are actively monitoring the chain.

Pending Events or updated HTLCs which have not yet been read out by get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events gotten are fully handled before re-serializing the new state.

Implementations

impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner>[src]

pub fn serialize_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), Error>[src]

Writes this monitor into the given writer, suitable for writing to disk.

Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along the "reorg path" (ie disconnecting blocks until you find a common ancestor from both the returned block hash and the the current chain and then reconnecting blocks to get to the best chain) upon deserializing the object!

impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner>[src]

pub fn update_monitor<B: Deref, F: Deref, L: Deref>(
    &mut self,
    updates: &ChannelMonitorUpdate,
    broadcaster: &B,
    fee_estimator: &F,
    logger: &L
) -> Result<(), MonitorUpdateError> where
    B::Target: BroadcasterInterface,
    F::Target: FeeEstimator,
    L::Target: Logger
[src]

Updates a ChannelMonitor on the basis of some new information provided by the Channel itself.

panics if the given update is not the next update by update_id.

pub fn get_latest_update_id(&self) -> u64[src]

Gets the update_id from the latest ChannelMonitorUpdate which was applied to this ChannelMonitor.

pub fn get_funding_txo(&self) -> &(OutPoint, Script)[src]

Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.

pub fn get_outputs_to_watch(&self) -> &HashMap<Txid, Vec<(u32, Script)>>[src]

Gets a list of txids, with their output scripts (in the order they appear in the transaction), which we must learn about spends of via block_connected().

(C-not exported) because we have no HashMap bindings

pub fn get_and_clear_pending_monitor_events(&mut self) -> Vec<MonitorEvent>[src]

Get the list of HTLCs who's status has been updated on chain. This should be called by ChannelManager via chain::Watch::release_pending_monitor_events.

pub fn get_and_clear_pending_events(&mut self) -> Vec<Event>[src]

Gets the list of pending events which were generated by previous actions, clearing the list in the process.

This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do no internal locking in ChannelMonitors.

pub fn get_latest_holder_commitment_txn<L: Deref>(
    &mut self,
    logger: &L
) -> Vec<Transaction> where
    L::Target: Logger
[src]

Used by ChannelManager deserialization to broadcast the latest holder state if its copy of the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows a higher revocation secret than the holder commitment number we are aware of. Broadcasting these transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to broadcast them if counterparty don't close channel with his higher commitment transaction after a substantial amount of time (a month or even a year) to get back funds. Best may be to contact out-of-band the other node operator to coordinate with him if option is available to you. In any-case, choice is up to the user.

pub fn block_connected<B: Deref, F: Deref, L: Deref>(
    &mut self,
    header: &BlockHeader,
    txdata: &TransactionData<'_>,
    height: u32,
    broadcaster: B,
    fee_estimator: F,
    logger: L
) -> Vec<(Txid, Vec<(u32, TxOut)>)> where
    B::Target: BroadcasterInterface,
    F::Target: FeeEstimator,
    L::Target: Logger
[src]

Processes transactions in a newly connected block, which may result in any of the following:

  • update the monitor's state against resolved HTLCs
  • punish the counterparty in the case of seeing a revoked commitment transaction
  • force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
  • detect settled outputs for later spending
  • schedule and bump any in-flight claims

Returns any new outputs to watch from txdata; after called, these are also included in get_outputs_to_watch.

pub fn block_disconnected<B: Deref, F: Deref, L: Deref>(
    &mut self,
    header: &BlockHeader,
    height: u32,
    broadcaster: B,
    fee_estimator: F,
    logger: L
) where
    B::Target: BroadcasterInterface,
    F::Target: FeeEstimator,
    L::Target: Logger
[src]

Determines if the disconnected block contained any transactions of interest and updates appropriately.

Auto Trait Implementations

impl<ChanSigner> RefUnwindSafe for ChannelMonitor<ChanSigner> where
    ChanSigner: RefUnwindSafe

impl<ChanSigner> Send for ChannelMonitor<ChanSigner>

impl<ChanSigner> Sync for ChannelMonitor<ChanSigner> where
    ChanSigner: Sync

impl<ChanSigner> Unpin for ChannelMonitor<ChanSigner> where
    ChanSigner: Unpin

impl<ChanSigner> UnwindSafe for ChannelMonitor<ChanSigner> where
    ChanSigner: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.