@@ -23,11 +23,13 @@ use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
2323use chain:: transaction:: OutPoint ;
2424use util:: { transaction_utils, rng} ;
2525use util:: sha2:: Sha256 ;
26+ use util:: logger:: { Logger , Record } ;
2627
2728use std;
2829use std:: default:: Default ;
2930use std:: { cmp, mem} ;
3031use std:: time:: Instant ;
32+ use std:: sync:: { Arc } ;
3133
3234pub struct ChannelKeys {
3335 pub funding_key : SecretKey ,
@@ -303,6 +305,8 @@ pub struct Channel {
303305 their_shutdown_scriptpubkey : Option < Script > ,
304306
305307 channel_monitor : ChannelMonitor ,
308+
309+ logger : Arc < Logger > ,
306310}
307311
308312const OUR_MAX_HTLCS : u16 = 5 ; //TODO
@@ -361,7 +365,7 @@ impl Channel {
361365 // Constructors:
362366
363367 /// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`
364- pub fn new_outbound ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , channel_value_satoshis : u64 , announce_publicly : bool , user_id : u64 ) -> Channel {
368+ pub fn new_outbound ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , channel_value_satoshis : u64 , announce_publicly : bool , user_id : u64 , logger : Arc < Logger > ) -> Channel {
365369 if channel_value_satoshis >= MAX_FUNDING_SATOSHIS {
366370 panic ! ( "funding value > 2^24" ) ;
367371 }
@@ -429,6 +433,8 @@ impl Channel {
429433 their_shutdown_scriptpubkey : None ,
430434
431435 channel_monitor : channel_monitor,
436+
437+ logger,
432438 }
433439 }
434440
@@ -446,7 +452,7 @@ impl Channel {
446452 /// Assumes chain_hash has already been checked and corresponds with what we expect!
447453 /// Generally prefers to take the DisconnectPeer action on failure, as a notice to the sender
448454 /// that we're rejecting the new channel.
449- pub fn new_from_req ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , msg : & msgs:: OpenChannel , user_id : u64 , require_announce : bool , allow_announce : bool ) -> Result < Channel , HandleError > {
455+ pub fn new_from_req ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , msg : & msgs:: OpenChannel , user_id : u64 , require_announce : bool , allow_announce : bool , logger : Arc < Logger > ) -> Result < Channel , HandleError > {
450456 // Check sanity of message fields:
451457 if msg. funding_satoshis >= MAX_FUNDING_SATOSHIS {
452458 return Err ( HandleError { err : "funding value > 2^24" , action : Some ( msgs:: ErrorAction :: DisconnectPeer { msg : None } ) } ) ;
@@ -548,6 +554,8 @@ impl Channel {
548554 their_shutdown_scriptpubkey : None ,
549555
550556 channel_monitor : channel_monitor,
557+
558+ logger,
551559 } ;
552560
553561 let obscure_factor = chan. get_commitment_transaction_number_obscure_factor ( ) ;
@@ -1748,7 +1756,7 @@ impl Channel {
17481756
17491757 match self . secp_ctx . verify ( & sighash, & msg. signature , & self . their_funding_pubkey ) {
17501758 Ok ( _) => { } ,
1751- Err ( _ ) => {
1759+ Err ( _e ) => {
17521760 // The remote end may have decided to revoke their output due to inconsistent dust
17531761 // limits, so check for that case by re-checking the signature here.
17541762 closing_tx = self . build_closing_transaction ( msg. fee_satoshis , true ) . 0 ;
@@ -2111,6 +2119,7 @@ impl Channel {
21112119 let ( our_signature, commitment_tx) = match self . get_outbound_funding_created_signature ( ) {
21122120 Ok ( res) => res,
21132121 Err ( e) => {
2122+ log_error ! ( self , "Got bad signatures: {}!" , e. err) ;
21142123 self . channel_monitor . unset_funding_info ( ) ;
21152124 return Err ( e) ;
21162125 }
@@ -2409,10 +2418,13 @@ mod tests {
24092418 use ln:: chan_utils;
24102419 use chain:: chaininterface:: { FeeEstimator , ConfirmationTarget } ;
24112420 use chain:: transaction:: OutPoint ;
2421+ use util:: test_utils;
2422+ use util:: logger:: Logger ;
24122423 use secp256k1:: { Secp256k1 , Message , Signature } ;
24132424 use secp256k1:: key:: { SecretKey , PublicKey } ;
24142425 use crypto:: sha2:: Sha256 ;
24152426 use crypto:: digest:: Digest ;
2427+ use std:: sync:: Arc ;
24162428
24172429 struct TestFeeEstimator {
24182430 fee_est : u64
@@ -2433,6 +2445,7 @@ mod tests {
24332445 fn outbound_commitment_test ( ) {
24342446 // Test vectors from BOLT 3 Appendix C:
24352447 let feeest = TestFeeEstimator { fee_est : 15000 } ;
2448+ let logger : Arc < Logger > = Arc :: new ( test_utils:: TestLogger :: new ( ) ) ;
24362449 let secp_ctx = Secp256k1 :: new ( ) ;
24372450
24382451 let chan_keys = ChannelKeys {
@@ -2450,7 +2463,7 @@ mod tests {
24502463 assert_eq ! ( PublicKey :: from_secret_key( & secp_ctx, & chan_keys. funding_key) . unwrap( ) . serialize( ) [ ..] ,
24512464 hex:: decode( "023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb" ) . unwrap( ) [ ..] ) ;
24522465
2453- let mut chan = Channel :: new_outbound ( & feeest, chan_keys, PublicKey :: new ( ) , 10000000 , false , 42 ) ; // Nothing uses their network key in this test
2466+ let mut chan = Channel :: new_outbound ( & feeest, chan_keys, PublicKey :: new ( ) , 10000000 , false , 42 , Arc :: clone ( & logger ) ) ; // Nothing uses their network key in this test
24542467 chan. their_to_self_delay = 144 ;
24552468 chan. our_dust_limit_satoshis = 546 ;
24562469
0 commit comments