@@ -19,6 +19,7 @@ use ln::msgs;
19
19
use ln:: msgs:: { HandleError , ChannelMessageHandler , MsgEncodable , MsgDecodable } ;
20
20
use util:: { byte_utils, events, internal_traits, rng} ;
21
21
use util:: sha2:: Sha256 ;
22
+ use util:: logger:: Logger ;
22
23
23
24
use crypto;
24
25
use crypto:: mac:: { Mac , MacResult } ;
@@ -166,6 +167,8 @@ pub struct ChannelManager {
166
167
our_network_key : SecretKey ,
167
168
168
169
pending_events : Mutex < Vec < events:: Event > > ,
170
+
171
+ logger : Arc < Logger > ,
169
172
}
170
173
171
174
const CLTV_EXPIRY_DELTA : u16 = 6 * 24 * 2 ; //TODO?
@@ -211,7 +214,7 @@ impl ChannelManager {
211
214
/// fee_proportional_millionths is an optional fee to charge any payments routed through us.
212
215
/// Non-proportional fees are fixed according to our risk using the provided fee estimator.
213
216
/// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
214
- pub fn new ( our_network_key : SecretKey , fee_proportional_millionths : u32 , announce_channels_publicly : bool , network : Network , feeest : Arc < FeeEstimator > , monitor : Arc < ManyChannelMonitor > , chain_monitor : Arc < ChainWatchInterface > , tx_broadcaster : Arc < BroadcasterInterface > ) -> Result < Arc < ChannelManager > , secp256k1:: Error > {
217
+ pub fn new ( our_network_key : SecretKey , fee_proportional_millionths : u32 , announce_channels_publicly : bool , network : Network , feeest : Arc < FeeEstimator > , monitor : Arc < ManyChannelMonitor > , chain_monitor : Arc < ChainWatchInterface > , tx_broadcaster : Arc < BroadcasterInterface > , logger : Arc < Logger > ) -> Result < Arc < ChannelManager > , secp256k1:: Error > {
215
218
let secp_ctx = Secp256k1 :: new ( ) ;
216
219
217
220
let res = Arc :: new ( ChannelManager {
@@ -236,6 +239,8 @@ impl ChannelManager {
236
239
our_network_key,
237
240
238
241
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
242
+
243
+ logger,
239
244
} ) ;
240
245
let weak_res = Arc :: downgrade ( & res) ;
241
246
res. chain_monitor . register_listener ( weak_res) ;
@@ -270,7 +275,7 @@ impl ChannelManager {
270
275
}
271
276
} ;
272
277
273
- let channel = Channel :: new_outbound ( & * self . fee_estimator , chan_keys, their_network_key, channel_value_satoshis, self . announce_channels_publicly , user_id) ;
278
+ let channel = Channel :: new_outbound ( & * self . fee_estimator , chan_keys, their_network_key, channel_value_satoshis, self . announce_channels_publicly , user_id, Arc :: clone ( & self . logger ) ) ;
274
279
let res = channel. get_open_channel ( self . genesis_hash . clone ( ) , & * self . fee_estimator ) ?;
275
280
let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
276
281
match channel_state. by_id . insert ( channel. channel_id ( ) , channel) {
@@ -766,6 +771,7 @@ impl ChannelManager {
766
771
/// Call this upon creation of a funding transaction for the given channel.
767
772
/// Panics if a funding transaction has already been provided for this channel.
768
773
pub fn funding_transaction_generated ( & self , temporary_channel_id : & [ u8 ; 32 ] , funding_txo : OutPoint ) {
774
+
769
775
macro_rules! add_pending_event {
770
776
( $event: expr) => {
771
777
{
@@ -1286,7 +1292,7 @@ impl ChannelMessageHandler for ChannelManager {
1286
1292
}
1287
1293
} ;
1288
1294
1289
- let channel = Channel :: new_from_req ( & * self . fee_estimator , chan_keys, their_node_id. clone ( ) , msg, 0 , false , self . announce_channels_publicly ) ?;
1295
+ let channel = Channel :: new_from_req ( & * self . fee_estimator , chan_keys, their_node_id. clone ( ) , msg, 0 , false , self . announce_channels_publicly , Arc :: clone ( & self . logger ) ) ?;
1290
1296
let accept_msg = channel. get_accept_channel ( ) ?;
1291
1297
channel_state. by_id . insert ( channel. channel_id ( ) , channel) ;
1292
1298
Ok ( accept_msg)
@@ -1972,6 +1978,7 @@ mod tests {
1972
1978
use ln:: msgs:: { MsgEncodable , ChannelMessageHandler , RoutingMessageHandler } ;
1973
1979
use util:: test_utils;
1974
1980
use util:: events:: { Event , EventsProvider } ;
1981
+ use util:: logger:: Logger ;
1975
1982
1976
1983
use bitcoin:: util:: hash:: Sha256dHash ;
1977
1984
use bitcoin:: blockdata:: block:: { Block , BlockHeader } ;
@@ -2686,19 +2693,20 @@ mod tests {
2686
2693
let mut nodes = Vec :: new ( ) ;
2687
2694
let mut rng = thread_rng ( ) ;
2688
2695
let secp_ctx = Secp256k1 :: new ( ) ;
2696
+ let logger: Arc < Logger > = Arc :: new ( test_utils:: TestLogger :: new ( ) ) ;
2689
2697
2690
2698
for _ in 0 ..node_count {
2691
2699
let feeest = Arc :: new ( test_utils:: TestFeeEstimator { sat_per_kw : 253 } ) ;
2692
- let chain_monitor = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( ) ) ;
2700
+ let chain_monitor = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( Arc :: clone ( & logger ) ) ) ;
2693
2701
let tx_broadcaster = Arc :: new ( test_utils:: TestBroadcaster { txn_broadcasted : Mutex :: new ( Vec :: new ( ) ) } ) ;
2694
2702
let chan_monitor = Arc :: new ( test_utils:: TestChannelMonitor :: new ( chain_monitor. clone ( ) , tx_broadcaster. clone ( ) ) ) ;
2695
2703
let node_id = {
2696
2704
let mut key_slice = [ 0 ; 32 ] ;
2697
2705
rng. fill_bytes ( & mut key_slice) ;
2698
2706
SecretKey :: from_slice ( & secp_ctx, & key_slice) . unwrap ( )
2699
2707
} ;
2700
- let node = ChannelManager :: new ( node_id. clone ( ) , 0 , true , Network :: Testnet , feeest. clone ( ) , chan_monitor. clone ( ) , chain_monitor. clone ( ) , tx_broadcaster. clone ( ) ) . unwrap ( ) ;
2701
- let router = Router :: new ( PublicKey :: from_secret_key ( & secp_ctx, & node_id) . unwrap ( ) ) ;
2708
+ let node = ChannelManager :: new ( node_id. clone ( ) , 0 , true , Network :: Testnet , feeest. clone ( ) , chan_monitor. clone ( ) , chain_monitor. clone ( ) , tx_broadcaster. clone ( ) , Arc :: clone ( & logger ) ) . unwrap ( ) ;
2709
+ let router = Router :: new ( PublicKey :: from_secret_key ( & secp_ctx, & node_id) . unwrap ( ) , Arc :: clone ( & logger ) ) ;
2702
2710
nodes. push ( Node { feeest, chain_monitor, tx_broadcaster, chan_monitor, node_id, node, router } ) ;
2703
2711
}
2704
2712
0 commit comments