@@ -31,6 +31,7 @@ use crate::chain::{ChannelMonitorUpdateStatus, Filter, WatchedOutput};
31
31
use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
32
32
use crate :: chain:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdate , Balance , MonitorEvent , TransactionOutputs , WithChannelMonitor , LATENCY_GRACE_PERIOD_BLOCKS } ;
33
33
use crate :: chain:: transaction:: { OutPoint , TransactionData } ;
34
+ use crate :: ln:: ChannelId ;
34
35
use crate :: sign:: ecdsa:: WriteableEcdsaChannelSigner ;
35
36
use crate :: events;
36
37
use crate :: events:: { Event , EventHandler } ;
@@ -158,7 +159,7 @@ pub trait Persist<ChannelSigner: WriteableEcdsaChannelSigner> {
158
159
///
159
160
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
160
161
/// [`Writeable::write`]: crate::util::ser::Writeable::write
161
- fn persist_new_channel ( & self , channel_id : OutPoint , data : & ChannelMonitor < ChannelSigner > , update_id : MonitorUpdateId ) -> ChannelMonitorUpdateStatus ;
162
+ fn persist_new_channel ( & self , channel_funding_outpoint : OutPoint , data : & ChannelMonitor < ChannelSigner > , update_id : MonitorUpdateId ) -> ChannelMonitorUpdateStatus ;
162
163
163
164
/// Update one channel's data. The provided [`ChannelMonitor`] has already applied the given
164
165
/// update.
@@ -193,7 +194,7 @@ pub trait Persist<ChannelSigner: WriteableEcdsaChannelSigner> {
193
194
/// [`ChannelMonitorUpdateStatus`] for requirements when returning errors.
194
195
///
195
196
/// [`Writeable::write`]: crate::util::ser::Writeable::write
196
- fn update_persisted_channel ( & self , channel_id : OutPoint , update : Option < & ChannelMonitorUpdate > , data : & ChannelMonitor < ChannelSigner > , update_id : MonitorUpdateId ) -> ChannelMonitorUpdateStatus ;
197
+ fn update_persisted_channel ( & self , channel_funding_outpoint : OutPoint , update : Option < & ChannelMonitorUpdate > , data : & ChannelMonitor < ChannelSigner > , update_id : MonitorUpdateId ) -> ChannelMonitorUpdateStatus ;
197
198
}
198
199
199
200
struct MonitorHolder < ChannelSigner : WriteableEcdsaChannelSigner > {
@@ -287,7 +288,7 @@ pub struct ChainMonitor<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T:
287
288
persister : P ,
288
289
/// "User-provided" (ie persistence-completion/-failed) [`MonitorEvent`]s. These came directly
289
290
/// from the user and not from a [`ChannelMonitor`].
290
- pending_monitor_events : Mutex < Vec < ( OutPoint , Vec < MonitorEvent > , Option < PublicKey > ) > > ,
291
+ pending_monitor_events : Mutex < Vec < ( OutPoint , ChannelId , Vec < MonitorEvent > , Option < PublicKey > ) > > ,
291
292
/// The best block height seen, used as a proxy for the passage of time.
292
293
highest_chain_height : AtomicUsize ,
293
294
@@ -471,12 +472,15 @@ where C::Target: chain::Filter,
471
472
}
472
473
}
473
474
474
- /// Lists the funding outpoint of each [`ChannelMonitor`] being monitored.
475
+ /// Lists the funding outpoint and channel ID of each [`ChannelMonitor`] being monitored.
475
476
///
476
477
/// Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always
477
478
/// monitoring for on-chain state resolutions.
478
- pub fn list_monitors ( & self ) -> Vec < OutPoint > {
479
- self . monitors . read ( ) . unwrap ( ) . keys ( ) . map ( |outpoint| * outpoint) . collect ( )
479
+ pub fn list_monitors ( & self ) -> Vec < ( OutPoint , ChannelId ) > {
480
+ self . monitors . read ( ) . unwrap ( ) . iter ( ) . map ( |( outpoint, monitor_holder) | {
481
+ let channel_id = monitor_holder. monitor . channel_id ( ) ;
482
+ ( * outpoint, channel_id)
483
+ } ) . collect ( )
480
484
}
481
485
482
486
#[ cfg( not( c_bindings) ) ]
@@ -542,8 +546,9 @@ where C::Target: chain::Filter,
542
546
// Completed event.
543
547
return Ok ( ( ) ) ;
544
548
}
545
- self . pending_monitor_events . lock ( ) . unwrap ( ) . push ( ( funding_txo, vec ! [ MonitorEvent :: Completed {
546
- funding_txo,
549
+ let channel_id = monitor_data. monitor . channel_id ( ) ;
550
+ self . pending_monitor_events . lock ( ) . unwrap ( ) . push ( ( funding_txo, channel_id, vec ! [ MonitorEvent :: Completed {
551
+ funding_txo, channel_id,
547
552
monitor_update_id: monitor_data. monitor. get_latest_update_id( ) ,
548
553
} ] , monitor_data. monitor . get_counterparty_node_id ( ) ) ) ;
549
554
} ,
@@ -565,9 +570,14 @@ where C::Target: chain::Filter,
565
570
#[ cfg( any( test, fuzzing) ) ]
566
571
pub fn force_channel_monitor_updated ( & self , funding_txo : OutPoint , monitor_update_id : u64 ) {
567
572
let monitors = self . monitors . read ( ) . unwrap ( ) ;
568
- let counterparty_node_id = monitors. get ( & funding_txo) . and_then ( |m| m. monitor . get_counterparty_node_id ( ) ) ;
569
- self . pending_monitor_events . lock ( ) . unwrap ( ) . push ( ( funding_txo, vec ! [ MonitorEvent :: Completed {
573
+ let ( counterparty_node_id, channel_id) = if let Some ( m) = monitors. get ( & funding_txo) {
574
+ ( m. monitor . get_counterparty_node_id ( ) , m. monitor . channel_id ( ) )
575
+ } else {
576
+ ( None , ChannelId :: v1_from_funding_outpoint ( funding_txo) )
577
+ } ;
578
+ self . pending_monitor_events . lock ( ) . unwrap ( ) . push ( ( funding_txo, channel_id, vec ! [ MonitorEvent :: Completed {
570
579
funding_txo,
580
+ channel_id,
571
581
monitor_update_id,
572
582
} ] , counterparty_node_id) ) ;
573
583
self . event_notifier . notify ( ) ;
@@ -753,11 +763,14 @@ where C::Target: chain::Filter,
753
763
}
754
764
755
765
fn update_channel ( & self , funding_txo : OutPoint , update : & ChannelMonitorUpdate ) -> ChannelMonitorUpdateStatus {
766
+ // `ChannelMonitorUpdate`'s `channel_id` is `None` prior to 0.0.121 and all channels in those
767
+ // versions are V1-established. For 0.0.121+ the `channel_id` fields is always `Some`.
768
+ let channel_id = update. channel_id . unwrap_or ( ChannelId :: v1_from_funding_outpoint ( funding_txo) ) ;
756
769
// Update the monitor that watches the channel referred to by the given outpoint.
757
770
let monitors = self . monitors . read ( ) . unwrap ( ) ;
758
771
match monitors. get ( & funding_txo) {
759
772
None => {
760
- let logger = WithContext :: from ( & self . logger , update. counterparty_node_id , Some ( funding_txo . to_channel_id ( ) ) ) ;
773
+ let logger = WithContext :: from ( & self . logger , update. counterparty_node_id , Some ( channel_id ) ) ;
761
774
log_error ! ( logger, "Failed to update channel monitor: no such monitor registered" ) ;
762
775
763
776
// We should never ever trigger this from within ChannelManager. Technically a
@@ -815,7 +828,7 @@ where C::Target: chain::Filter,
815
828
}
816
829
}
817
830
818
- fn release_pending_monitor_events ( & self ) -> Vec < ( OutPoint , Vec < MonitorEvent > , Option < PublicKey > ) > {
831
+ fn release_pending_monitor_events ( & self ) -> Vec < ( OutPoint , ChannelId , Vec < MonitorEvent > , Option < PublicKey > ) > {
819
832
let mut pending_monitor_events = self . pending_monitor_events . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
820
833
for monitor_state in self . monitors . read ( ) . unwrap ( ) . values ( ) {
821
834
let logger = WithChannelMonitor :: from ( & self . logger , & monitor_state. monitor ) ;
@@ -829,8 +842,9 @@ where C::Target: chain::Filter,
829
842
let monitor_events = monitor_state. monitor . get_and_clear_pending_monitor_events ( ) ;
830
843
if monitor_events. len ( ) > 0 {
831
844
let monitor_outpoint = monitor_state. monitor . get_funding_txo ( ) . 0 ;
845
+ let monitor_channel_id = monitor_state. monitor . channel_id ( ) ;
832
846
let counterparty_node_id = monitor_state. monitor . get_counterparty_node_id ( ) ;
833
- pending_monitor_events. push ( ( monitor_outpoint, monitor_events, counterparty_node_id) ) ;
847
+ pending_monitor_events. push ( ( monitor_outpoint, monitor_channel_id , monitor_events, counterparty_node_id) ) ;
834
848
}
835
849
}
836
850
}
0 commit comments