@@ -23,11 +23,13 @@ use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
23
23
use chain:: transaction:: OutPoint ;
24
24
use util:: { transaction_utils, rng} ;
25
25
use util:: sha2:: Sha256 ;
26
+ use util:: logger:: { Logger , Record } ;
26
27
27
28
use std;
28
29
use std:: default:: Default ;
29
30
use std:: { cmp, mem} ;
30
31
use std:: time:: Instant ;
32
+ use std:: sync:: { Arc } ;
31
33
32
34
pub struct ChannelKeys {
33
35
pub funding_key : SecretKey ,
@@ -303,6 +305,8 @@ pub struct Channel {
303
305
their_shutdown_scriptpubkey : Option < Script > ,
304
306
305
307
channel_monitor : ChannelMonitor ,
308
+
309
+ logger : Arc < Logger > ,
306
310
}
307
311
308
312
const OUR_MAX_HTLCS : u16 = 5 ; //TODO
@@ -361,7 +365,7 @@ impl Channel {
361
365
// Constructors:
362
366
363
367
/// 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 {
365
369
if channel_value_satoshis >= MAX_FUNDING_SATOSHIS {
366
370
panic ! ( "funding value > 2^24" ) ;
367
371
}
@@ -429,6 +433,8 @@ impl Channel {
429
433
their_shutdown_scriptpubkey : None ,
430
434
431
435
channel_monitor : channel_monitor,
436
+
437
+ logger,
432
438
}
433
439
}
434
440
@@ -446,7 +452,7 @@ impl Channel {
446
452
/// Assumes chain_hash has already been checked and corresponds with what we expect!
447
453
/// Generally prefers to take the DisconnectPeer action on failure, as a notice to the sender
448
454
/// 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 > {
450
456
// Check sanity of message fields:
451
457
if msg. funding_satoshis >= MAX_FUNDING_SATOSHIS {
452
458
return Err ( HandleError { err : "funding value > 2^24" , action : Some ( msgs:: ErrorAction :: DisconnectPeer { msg : None } ) } ) ;
@@ -548,6 +554,8 @@ impl Channel {
548
554
their_shutdown_scriptpubkey : None ,
549
555
550
556
channel_monitor : channel_monitor,
557
+
558
+ logger,
551
559
} ;
552
560
553
561
let obscure_factor = chan. get_commitment_transaction_number_obscure_factor ( ) ;
@@ -1748,7 +1756,7 @@ impl Channel {
1748
1756
1749
1757
match self . secp_ctx . verify ( & sighash, & msg. signature , & self . their_funding_pubkey ) {
1750
1758
Ok ( _) => { } ,
1751
- Err ( _ ) => {
1759
+ Err ( _e ) => {
1752
1760
// The remote end may have decided to revoke their output due to inconsistent dust
1753
1761
// limits, so check for that case by re-checking the signature here.
1754
1762
closing_tx = self . build_closing_transaction ( msg. fee_satoshis , true ) . 0 ;
@@ -2111,6 +2119,7 @@ impl Channel {
2111
2119
let ( our_signature, commitment_tx) = match self . get_outbound_funding_created_signature ( ) {
2112
2120
Ok ( res) => res,
2113
2121
Err ( e) => {
2122
+ log_error ! ( self , "Got bad signatures: {}!" , e. err) ;
2114
2123
self . channel_monitor . unset_funding_info ( ) ;
2115
2124
return Err ( e) ;
2116
2125
}
@@ -2409,10 +2418,13 @@ mod tests {
2409
2418
use ln:: chan_utils;
2410
2419
use chain:: chaininterface:: { FeeEstimator , ConfirmationTarget } ;
2411
2420
use chain:: transaction:: OutPoint ;
2421
+ use util:: test_utils;
2422
+ use util:: logger:: Logger ;
2412
2423
use secp256k1:: { Secp256k1 , Message , Signature } ;
2413
2424
use secp256k1:: key:: { SecretKey , PublicKey } ;
2414
2425
use crypto:: sha2:: Sha256 ;
2415
2426
use crypto:: digest:: Digest ;
2427
+ use std:: sync:: Arc ;
2416
2428
2417
2429
struct TestFeeEstimator {
2418
2430
fee_est : u64
@@ -2433,6 +2445,7 @@ mod tests {
2433
2445
fn outbound_commitment_test ( ) {
2434
2446
// Test vectors from BOLT 3 Appendix C:
2435
2447
let feeest = TestFeeEstimator { fee_est : 15000 } ;
2448
+ let logger : Arc < Logger > = Arc :: new ( test_utils:: TestLogger :: new ( ) ) ;
2436
2449
let secp_ctx = Secp256k1 :: new ( ) ;
2437
2450
2438
2451
let chan_keys = ChannelKeys {
@@ -2450,7 +2463,7 @@ mod tests {
2450
2463
assert_eq ! ( PublicKey :: from_secret_key( & secp_ctx, & chan_keys. funding_key) . unwrap( ) . serialize( ) [ ..] ,
2451
2464
hex:: decode( "023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb" ) . unwrap( ) [ ..] ) ;
2452
2465
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
2454
2467
chan. their_to_self_delay = 144 ;
2455
2468
chan. our_dust_limit_satoshis = 546 ;
2456
2469
0 commit comments