@@ -438,8 +438,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
438
438
}
439
439
440
440
// Constructors:
441
- pub fn new_outbound < K : Deref > ( fee_estimator : & FeeEstimator , keys_provider : & K , their_node_id : PublicKey , channel_value_satoshis : u64 , push_msat : u64 , user_id : u64 , logger : Arc < Logger > , config : & UserConfig ) -> Result < Channel < ChanSigner > , APIError >
442
- where K :: Target : KeysInterface < ChanKeySigner = ChanSigner >
441
+ pub fn new_outbound < K : Deref , F : Deref > ( fee_estimator : & F , keys_provider : & K , their_node_id : PublicKey , channel_value_satoshis : u64 , push_msat : u64 , user_id : u64 , logger : Arc < Logger > , config : & UserConfig ) -> Result < Channel < ChanSigner > , APIError >
442
+ where K :: Target : KeysInterface < ChanKeySigner = ChanSigner > ,
443
+ F :: Target : FeeEstimator ,
443
444
{
444
445
let chan_keys = keys_provider. get_channel_keys ( false , channel_value_satoshis) ;
445
446
@@ -541,7 +542,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
541
542
} )
542
543
}
543
544
544
- fn check_remote_fee ( fee_estimator : & FeeEstimator , feerate_per_kw : u32 ) -> Result < ( ) , ChannelError > {
545
+ fn check_remote_fee < F : Deref > ( fee_estimator : & F , feerate_per_kw : u32 ) -> Result < ( ) , ChannelError >
546
+ where F :: Target : FeeEstimator
547
+ {
545
548
if ( feerate_per_kw as u64 ) < fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) {
546
549
return Err ( ChannelError :: Close ( "Peer's feerate much too low" ) ) ;
547
550
}
@@ -553,8 +556,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
553
556
554
557
/// Creates a new channel from a remote sides' request for one.
555
558
/// Assumes chain_hash has already been checked and corresponds with what we expect!
556
- pub fn new_from_req < K : Deref > ( fee_estimator : & FeeEstimator , keys_provider : & K , their_node_id : PublicKey , their_features : InitFeatures , msg : & msgs:: OpenChannel , user_id : u64 , logger : Arc < Logger > , config : & UserConfig ) -> Result < Channel < ChanSigner > , ChannelError >
557
- where K :: Target : KeysInterface < ChanKeySigner = ChanSigner >
559
+ pub fn new_from_req < K : Deref , F : Deref > ( fee_estimator : & F , keys_provider : & K , their_node_id : PublicKey , their_features : InitFeatures , msg : & msgs:: OpenChannel , user_id : u64 , logger : Arc < Logger > , config : & UserConfig ) -> Result < Channel < ChanSigner > , ChannelError >
560
+ where K :: Target : KeysInterface < ChanKeySigner = ChanSigner > ,
561
+ F :: Target : FeeEstimator
558
562
{
559
563
let mut chan_keys = keys_provider. get_channel_keys ( true , msg. funding_satoshis ) ;
560
564
let their_pubkeys = ChannelPublicKeys {
@@ -1777,7 +1781,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1777
1781
Ok ( ( ) )
1778
1782
}
1779
1783
1780
- pub fn commitment_signed ( & mut self , msg : & msgs:: CommitmentSigned , fee_estimator : & FeeEstimator ) -> Result < ( msgs:: RevokeAndACK , Option < msgs:: CommitmentSigned > , Option < msgs:: ClosingSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) > {
1784
+ pub fn commitment_signed < F : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , fee_estimator : & F ) -> Result < ( msgs:: RevokeAndACK , Option < msgs:: CommitmentSigned > , Option < msgs:: ClosingSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) > where F :: Target : FeeEstimator {
1781
1785
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
1782
1786
return Err ( ( None , ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" ) ) ) ;
1783
1787
}
@@ -2065,7 +2069,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2065
2069
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
2066
2070
/// generating an appropriate error *after* the channel state has been updated based on the
2067
2071
/// revoke_and_ack message.
2068
- pub fn revoke_and_ack ( & mut self , msg : & msgs:: RevokeAndACK , fee_estimator : & FeeEstimator ) -> Result < ( Option < msgs:: CommitmentUpdate > , Vec < ( PendingHTLCInfo , u64 ) > , Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > , Option < msgs:: ClosingSigned > , ChannelMonitorUpdate ) , ChannelError > {
2072
+ pub fn revoke_and_ack < F : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , fee_estimator : & F ) -> Result < ( Option < msgs:: CommitmentUpdate > , Vec < ( PendingHTLCInfo , u64 ) > , Vec < ( HTLCSource , PaymentHash , HTLCFailReason ) > , Option < msgs:: ClosingSigned > , ChannelMonitorUpdate ) , ChannelError >
2073
+ where F :: Target : FeeEstimator
2074
+ {
2069
2075
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2070
2076
return Err ( ChannelError :: Close ( "Got revoke/ACK message when channel was not in an operational state" ) ) ;
2071
2077
}
@@ -2463,7 +2469,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2463
2469
( raa, commitment_update, order, forwards, failures, needs_broadcast_safe, funding_locked)
2464
2470
}
2465
2471
2466
- pub fn update_fee ( & mut self , fee_estimator : & FeeEstimator , msg : & msgs:: UpdateFee ) -> Result < ( ) , ChannelError > {
2472
+ pub fn update_fee < F : Deref > ( & mut self , fee_estimator : & F , msg : & msgs:: UpdateFee ) -> Result < ( ) , ChannelError >
2473
+ where F :: Target : FeeEstimator
2474
+ {
2467
2475
if self . channel_outbound {
2468
2476
return Err ( ChannelError :: Close ( "Non-funding remote tried to update channel fee" ) ) ;
2469
2477
}
@@ -2684,7 +2692,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2684
2692
}
2685
2693
}
2686
2694
2687
- fn maybe_propose_first_closing_signed ( & mut self , fee_estimator : & FeeEstimator ) -> Option < msgs:: ClosingSigned > {
2695
+ fn maybe_propose_first_closing_signed < F : Deref > ( & mut self , fee_estimator : & F ) -> Option < msgs:: ClosingSigned >
2696
+ where F :: Target : FeeEstimator
2697
+ {
2688
2698
if !self . channel_outbound || !self . pending_inbound_htlcs . is_empty ( ) || !self . pending_outbound_htlcs . is_empty ( ) ||
2689
2699
self . channel_state & ( BOTH_SIDES_SHUTDOWN_MASK | ChannelState :: AwaitingRemoteRevoke as u32 ) != BOTH_SIDES_SHUTDOWN_MASK ||
2690
2700
self . last_sent_closing_fee . is_some ( ) || self . pending_update_fee . is_some ( ) {
@@ -2712,7 +2722,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2712
2722
} )
2713
2723
}
2714
2724
2715
- pub fn shutdown ( & mut self , fee_estimator : & FeeEstimator , msg : & msgs:: Shutdown ) -> Result < ( Option < msgs:: Shutdown > , Option < msgs:: ClosingSigned > , Vec < ( HTLCSource , PaymentHash ) > ) , ChannelError > {
2725
+ pub fn shutdown < F : Deref > ( & mut self , fee_estimator : & F , msg : & msgs:: Shutdown ) -> Result < ( Option < msgs:: Shutdown > , Option < msgs:: ClosingSigned > , Vec < ( HTLCSource , PaymentHash ) > ) , ChannelError >
2726
+ where F :: Target : FeeEstimator
2727
+ {
2716
2728
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
2717
2729
return Err ( ChannelError :: Close ( "Peer sent shutdown when we needed a channel_reestablish" ) ) ;
2718
2730
}
@@ -2808,7 +2820,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2808
2820
tx. input [ 0 ] . witness . push ( self . get_funding_redeemscript ( ) . into_bytes ( ) ) ;
2809
2821
}
2810
2822
2811
- pub fn closing_signed ( & mut self , fee_estimator : & FeeEstimator , msg : & msgs:: ClosingSigned ) -> Result < ( Option < msgs:: ClosingSigned > , Option < Transaction > ) , ChannelError > {
2823
+ pub fn closing_signed < F : Deref > ( & mut self , fee_estimator : & F , msg : & msgs:: ClosingSigned ) -> Result < ( Option < msgs:: ClosingSigned > , Option < Transaction > ) , ChannelError >
2824
+ where F :: Target : FeeEstimator
2825
+ {
2812
2826
if self . channel_state & BOTH_SIDES_SHUTDOWN_MASK != BOTH_SIDES_SHUTDOWN_MASK {
2813
2827
return Err ( ChannelError :: Close ( "Remote end sent us a closing_signed before both sides provided a shutdown" ) ) ;
2814
2828
}
@@ -3026,7 +3040,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3026
3040
3027
3041
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
3028
3042
/// Allowed in any state (including after shutdown)
3029
- pub fn get_our_fee_base_msat ( & self , fee_estimator : & FeeEstimator ) -> u32 {
3043
+ pub fn get_our_fee_base_msat < F : Deref > ( & self , fee_estimator : & F ) -> u32
3044
+ where F :: Target : FeeEstimator
3045
+ {
3030
3046
// For lack of a better metric, we calculate what it would cost to consolidate the new HTLC
3031
3047
// output value back into a transaction with the regular channel output:
3032
3048
@@ -3230,7 +3246,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3230
3246
// Methods to get unprompted messages to send to the remote end (or where we already returned
3231
3247
// something in the handler for the message that prompted this message):
3232
3248
3233
- pub fn get_open_channel ( & self , chain_hash : Sha256dHash , fee_estimator : & FeeEstimator ) -> msgs:: OpenChannel {
3249
+ pub fn get_open_channel < F : Deref > ( & self , chain_hash : Sha256dHash , fee_estimator : & F ) -> msgs:: OpenChannel
3250
+ where F :: Target : FeeEstimator
3251
+ {
3234
3252
if !self . channel_outbound {
3235
3253
panic ! ( "Tried to open a channel for an inbound channel?" ) ;
3236
3254
}
@@ -4338,12 +4356,12 @@ mod tests {
4338
4356
4339
4357
assert_eq ! ( PublicKey :: from_secret_key( & secp_ctx, chan_keys. funding_key( ) ) . serialize( ) [ ..] ,
4340
4358
hex:: decode( "023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb" ) . unwrap( ) [ ..] ) ;
4341
- let keys_provider: Arc < KeysInterface < ChanKeySigner = InMemoryChannelKeys > > = Arc :: new ( Keys { chan_keys } ) ;
4359
+ let keys_provider = Keys { chan_keys } ;
4342
4360
4343
4361
let their_node_id = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
4344
4362
let mut config = UserConfig :: default ( ) ;
4345
4363
config. channel_options . announced_channel = false ;
4346
- let mut chan = Channel :: < InMemoryChannelKeys > :: new_outbound ( & feeest, & keys_provider, their_node_id, 10000000 , 100000 , 42 , Arc :: clone ( & logger) , & config) . unwrap ( ) ; // Nothing uses their network key in this test
4364
+ let mut chan = Channel :: < InMemoryChannelKeys > :: new_outbound ( & & feeest, & & keys_provider, their_node_id, 10000000 , 100000 , 42 , Arc :: clone ( & logger) , & config) . unwrap ( ) ; // Nothing uses their network key in this test
4347
4365
chan. their_to_self_delay = 144 ;
4348
4366
chan. our_dust_limit_satoshis = 546 ;
4349
4367
0 commit comments