@@ -42,10 +42,12 @@ use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpd
42
42
use ln:: features:: { InitFeatures , NodeFeatures } ;
43
43
use routing:: router:: { Route , RouteHop } ;
44
44
use ln:: msgs;
45
+ use ln:: msgs:: NetAddress ;
45
46
use ln:: onion_utils;
46
47
use ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError , OptionalField } ;
47
48
use chain:: keysinterface:: { ChannelKeys , KeysInterface , KeysManager , InMemoryChannelKeys } ;
48
49
use util:: config:: UserConfig ;
50
+ use util:: events:: { Event , EventsProvider , MessageSendEvent , MessageSendEventsProvider } ;
49
51
use util:: { byte_utils, events} ;
50
52
use util:: ser:: { Readable , ReadableArgs , MaybeReadable , Writeable , Writer } ;
51
53
use util:: chacha20:: { ChaCha20 , ChaChaReader } ;
@@ -312,7 +314,7 @@ pub(super) struct ChannelHolder<ChanSigner: ChannelKeys> {
312
314
claimable_htlcs : HashMap < ( PaymentHash , Option < PaymentSecret > ) , Vec < ClaimableHTLC > > ,
313
315
/// Messages to send to peers - pushed to in the same lock that they are generated in (except
314
316
/// for broadcast messages, where ordering isn't as strict).
315
- pub ( super ) pending_msg_events : Vec < events :: MessageSendEvent > ,
317
+ pub ( super ) pending_msg_events : Vec < MessageSendEvent > ,
316
318
}
317
319
318
320
/// State we hold per-peer. In the future we should put channels in here, but for now we only hold
@@ -1484,7 +1486,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1484
1486
// be absurd. We ensure this by checking that at least 500 (our stated public contract on when
1485
1487
// broadcast_node_announcement panics) of the maximum-length addresses would fit in a 64KB
1486
1488
// message...
1487
- const HALF_MESSAGE_IS_ADDRS : u32 = :: std:: u16:: MAX as u32 / ( msgs :: NetAddress :: MAX_LEN as u32 + 1 ) / 2 ;
1489
+ const HALF_MESSAGE_IS_ADDRS : u32 = :: std:: u16:: MAX as u32 / ( NetAddress :: MAX_LEN as u32 + 1 ) / 2 ;
1488
1490
#[ deny( const_err) ]
1489
1491
#[ allow( dead_code) ]
1490
1492
// ...by failing to compile if the number of addresses that would be half of a message is
@@ -1504,7 +1506,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
1504
1506
/// only Tor Onion addresses.
1505
1507
///
1506
1508
/// Panics if addresses is absurdly large (more than 500).
1507
- pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : Vec < msgs :: NetAddress > ) {
1509
+ pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : Vec < NetAddress > ) {
1508
1510
let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
1509
1511
1510
1512
if addresses. len ( ) > 500 {
@@ -3011,14 +3013,14 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
3011
3013
}
3012
3014
}
3013
3015
3014
- impl < ChanSigner : ChannelKeys , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > events :: MessageSendEventsProvider for ChannelManager < ChanSigner , M , T , K , F , L >
3016
+ impl < ChanSigner : ChannelKeys , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > MessageSendEventsProvider for ChannelManager < ChanSigner , M , T , K , F , L >
3015
3017
where M :: Target : ManyChannelMonitor < Keys =ChanSigner > ,
3016
3018
T :: Target : BroadcasterInterface ,
3017
3019
K :: Target : KeysInterface < ChanKeySigner = ChanSigner > ,
3018
3020
F :: Target : FeeEstimator ,
3019
3021
L :: Target : Logger ,
3020
3022
{
3021
- fn get_and_clear_pending_msg_events ( & self ) -> Vec < events :: MessageSendEvent > {
3023
+ fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
3022
3024
//TODO: This behavior should be documented. It's non-intuitive that we query
3023
3025
// ChannelMonitors when clearing other events.
3024
3026
self . process_pending_monitor_events ( ) ;
@@ -3030,14 +3032,14 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
3030
3032
}
3031
3033
}
3032
3034
3033
- impl < ChanSigner : ChannelKeys , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > events :: EventsProvider for ChannelManager < ChanSigner , M , T , K , F , L >
3035
+ impl < ChanSigner : ChannelKeys , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref > EventsProvider for ChannelManager < ChanSigner , M , T , K , F , L >
3034
3036
where M :: Target : ManyChannelMonitor < Keys =ChanSigner > ,
3035
3037
T :: Target : BroadcasterInterface ,
3036
3038
K :: Target : KeysInterface < ChanKeySigner = ChanSigner > ,
3037
3039
F :: Target : FeeEstimator ,
3038
3040
L :: Target : Logger ,
3039
3041
{
3040
- fn get_and_clear_pending_events ( & self ) -> Vec < events :: Event > {
3042
+ fn get_and_clear_pending_events ( & self ) -> Vec < Event > {
3041
3043
//TODO: This behavior should be documented. It's non-intuitive that we query
3042
3044
// ChannelMonitors when clearing other events.
3043
3045
self . process_pending_monitor_events ( ) ;
@@ -3774,7 +3776,27 @@ pub struct ChannelManagerReadArgs<'a, ChanSigner: 'a + ChannelKeys, M: Deref, T:
3774
3776
///
3775
3777
/// In such cases the latest local transactions will be sent to the tx_broadcaster included in
3776
3778
/// this struct.
3777
- pub channel_monitors : & ' a mut HashMap < OutPoint , & ' a mut ChannelMonitor < ChanSigner > > ,
3779
+ pub channel_monitors : HashMap < OutPoint , & ' a mut ChannelMonitor < ChanSigner > > ,
3780
+ }
3781
+
3782
+ impl < ' a , ChanSigner : ' a + ChannelKeys , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
3783
+ ChannelManagerReadArgs < ' a , ChanSigner , M , T , K , F , L >
3784
+ where M :: Target : ManyChannelMonitor < Keys =ChanSigner > ,
3785
+ T :: Target : BroadcasterInterface ,
3786
+ K :: Target : KeysInterface < ChanKeySigner = ChanSigner > ,
3787
+ F :: Target : FeeEstimator ,
3788
+ L :: Target : Logger ,
3789
+ {
3790
+ /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor
3791
+ /// HashMap for you. This is primarily useful for C bindings where it is not practical to
3792
+ /// populate a HashMap directly from C.
3793
+ pub fn new ( keys_manager : K , fee_estimator : F , monitor : M , tx_broadcaster : T , logger : L , default_config : UserConfig ,
3794
+ mut channel_monitors : Vec < & ' a mut ChannelMonitor < ChanSigner > > ) -> Self {
3795
+ Self {
3796
+ keys_manager, fee_estimator, monitor, tx_broadcaster, logger, default_config,
3797
+ channel_monitors : channel_monitors. drain ( ..) . map ( |monitor| { ( monitor. get_funding_txo ( ) . 0 , monitor) } ) . collect ( )
3798
+ }
3799
+ }
3778
3800
}
3779
3801
3780
3802
// Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the
@@ -3801,7 +3823,7 @@ impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: De
3801
3823
F :: Target : FeeEstimator ,
3802
3824
L :: Target : Logger ,
3803
3825
{
3804
- fn read < R : :: std:: io:: Read > ( reader : & mut R , args : ChannelManagerReadArgs < ' a , ChanSigner , M , T , K , F , L > ) -> Result < Self , DecodeError > {
3826
+ fn read < R : :: std:: io:: Read > ( reader : & mut R , mut args : ChannelManagerReadArgs < ' a , ChanSigner , M , T , K , F , L > ) -> Result < Self , DecodeError > {
3805
3827
let _ver: u8 = Readable :: read ( reader) ?;
3806
3828
let min_ver: u8 = Readable :: read ( reader) ?;
3807
3829
if min_ver > SERIALIZATION_VERSION {
0 commit comments