@@ -374,6 +374,14 @@ const B_OUTPUT_PLUS_SPENDING_INPUT_WEIGHT: u64 = 104; // prevout: 40, nSequence:
374
374
/// it's 2^24.
375
375
pub const MAX_FUNDING_SATOSHIS : u64 = ( 1 << 24 ) ;
376
376
377
+ /// Used to return a simple Error back to ChannelManager. Will get converted to a
378
+ /// msgs::ErrorAction::SendErrorMessage or msgs::ErrorAction::IgnoreError as appropriate with our
379
+ /// channel_id in ChannelManager.
380
+ pub ( super ) enum ChannelError {
381
+ Ignore ( & ' static str ) ,
382
+ Close ( & ' static str ) ,
383
+ }
384
+
377
385
macro_rules! secp_call {
378
386
( $res: expr, $err: expr, $chan_id: expr ) => {
379
387
match $res {
@@ -506,95 +514,85 @@ impl Channel {
506
514
} )
507
515
}
508
516
509
- fn check_remote_fee ( fee_estimator : & FeeEstimator , feerate_per_kw : u32 ) -> Result < ( ) , HandleError > {
517
+ fn check_remote_fee ( fee_estimator : & FeeEstimator , feerate_per_kw : u32 ) -> Result < ( ) , ChannelError > {
510
518
if ( feerate_per_kw as u64 ) < fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) {
511
- return Err ( HandleError { err : "Peer's feerate much too low" , action : Some ( msgs :: ErrorAction :: DisconnectPeer { msg : None } ) } ) ;
519
+ return Err ( ChannelError :: Close ( "Peer's feerate much too low" ) ) ;
512
520
}
513
521
if ( feerate_per_kw as u64 ) > fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * 2 {
514
- return Err ( HandleError { err : "Peer's feerate much too high" , action : Some ( msgs :: ErrorAction :: DisconnectPeer { msg : None } ) } ) ;
522
+ return Err ( ChannelError :: Close ( "Peer's feerate much too high" ) ) ;
515
523
}
516
524
Ok ( ( ) )
517
525
}
518
526
519
527
/// Creates a new channel from a remote sides' request for one.
520
528
/// Assumes chain_hash has already been checked and corresponds with what we expect!
521
- /// Generally prefers to take the DisconnectPeer action on failure, as a notice to the sender
522
- /// that we're rejecting the new channel.
523
- 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 > {
524
- macro_rules! return_error_message {
525
- ( $msg: expr ) => {
526
- return Err ( HandleError { err: $msg, action: Some ( msgs:: ErrorAction :: SendErrorMessage { msg: msgs:: ErrorMessage { channel_id: msg. temporary_channel_id, data: $msg. to_string( ) } } ) } ) ;
527
- }
528
- }
529
-
529
+ 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 , ChannelError > {
530
530
// Check sanity of message fields:
531
531
if msg. funding_satoshis >= MAX_FUNDING_SATOSHIS {
532
- return_error_message ! ( "funding value > 2^24" ) ;
532
+ return Err ( ChannelError :: Close ( "funding value > 2^24" ) ) ;
533
533
}
534
534
if msg. channel_reserve_satoshis > msg. funding_satoshis {
535
- return_error_message ! ( "Bogus channel_reserve_satoshis" ) ;
535
+ return Err ( ChannelError :: Close ( "Bogus channel_reserve_satoshis" ) ) ;
536
536
}
537
537
if msg. push_msat > ( msg. funding_satoshis - msg. channel_reserve_satoshis ) * 1000 {
538
- return_error_message ! ( "push_msat larger than funding value" ) ;
538
+ return Err ( ChannelError :: Close ( "push_msat larger than funding value" ) ) ;
539
539
}
540
540
if msg. dust_limit_satoshis > msg. funding_satoshis {
541
- return_error_message ! ( "Peer never wants payout outputs?" ) ;
541
+ return Err ( ChannelError :: Close ( "Peer never wants payout outputs?" ) ) ;
542
542
}
543
543
if msg. dust_limit_satoshis > msg. channel_reserve_satoshis {
544
- return_error_message ! ( "Bogus; channel reserve is less than dust limit" ) ;
544
+ return Err ( ChannelError :: Close ( "Bogus; channel reserve is less than dust limit" ) ) ;
545
545
}
546
546
if msg. htlc_minimum_msat >= ( msg. funding_satoshis - msg. channel_reserve_satoshis ) * 1000 {
547
- return_error_message ! ( "Miminum htlc value is full channel value" ) ;
547
+ return Err ( ChannelError :: Close ( "Miminum htlc value is full channel value" ) ) ;
548
548
}
549
- Channel :: check_remote_fee ( fee_estimator, msg. feerate_per_kw ) . map_err ( |e|
550
- HandleError { err : e. err , action : Some ( msgs:: ErrorAction :: SendErrorMessage { msg : msgs:: ErrorMessage { channel_id : msg. temporary_channel_id , data : e. err . to_string ( ) } } ) }
551
- ) ?;
549
+ Channel :: check_remote_fee ( fee_estimator, msg. feerate_per_kw ) ?;
552
550
553
551
if msg. to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
554
- return_error_message ! ( "They wanted our payments to be delayed by a needlessly long period" ) ;
552
+ return Err ( ChannelError :: Close ( "They wanted our payments to be delayed by a needlessly long period" ) ) ;
555
553
}
556
554
if msg. max_accepted_htlcs < 1 {
557
- return_error_message ! ( "0 max_accpted_htlcs makes for a useless channel" ) ;
555
+ return Err ( ChannelError :: Close ( "0 max_accpted_htlcs makes for a useless channel" ) ) ;
558
556
}
559
557
if msg. max_accepted_htlcs > 483 {
560
- return_error_message ! ( "max_accpted_htlcs > 483" ) ;
558
+ return Err ( ChannelError :: Close ( "max_accpted_htlcs > 483" ) ) ;
561
559
}
562
560
563
561
// Convert things into internal flags and prep our state:
564
562
565
563
let their_announce = if ( msg. channel_flags & 1 ) == 1 { true } else { false } ;
566
564
if require_announce && !their_announce {
567
- return_error_message ! ( "Peer tried to open unannounced channel, but we require public ones" ) ;
565
+ return Err ( ChannelError :: Close ( "Peer tried to open unannounced channel, but we require public ones" ) ) ;
568
566
}
569
567
if !allow_announce && their_announce {
570
- return_error_message ! ( "Peer tried to open announced channel, but we require private ones" ) ;
568
+ return Err ( ChannelError :: Close ( "Peer tried to open announced channel, but we require private ones" ) ) ;
571
569
}
572
570
573
571
let background_feerate = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
574
572
575
573
let our_dust_limit_satoshis = Channel :: derive_our_dust_limit_satoshis ( background_feerate) ;
576
574
let our_channel_reserve_satoshis = Channel :: get_our_channel_reserve_satoshis ( msg. funding_satoshis ) ;
577
575
if our_channel_reserve_satoshis < our_dust_limit_satoshis {
578
- return_error_message ! ( "Suitalbe channel reserve not found. aborting" ) ;
576
+ return Err ( ChannelError :: Close ( "Suitalbe channel reserve not found. aborting" ) ) ;
579
577
}
580
578
if msg. channel_reserve_satoshis < our_dust_limit_satoshis {
581
- return_error_message ! ( "channel_reserve_satoshis too small" ) ;
579
+ return Err ( ChannelError :: Close ( "channel_reserve_satoshis too small" ) ) ;
582
580
}
583
581
if our_channel_reserve_satoshis < msg. dust_limit_satoshis {
584
- return_error_message ! ( "Dust limit too high for our channel reserve" ) ;
582
+ return Err ( ChannelError :: Close ( "Dust limit too high for our channel reserve" ) ) ;
585
583
}
586
584
587
585
// check if the funder's amount for the initial commitment tx is sufficient
588
586
// for full fee payment
589
587
let funders_amount_msat = msg. funding_satoshis * 1000 - msg. push_msat ;
590
588
if funders_amount_msat < background_feerate * COMMITMENT_TX_BASE_WEIGHT {
591
- return_error_message ! ( "Insufficient funding amount for initial commitment" ) ;
589
+ return Err ( ChannelError :: Close ( "Insufficient funding amount for initial commitment" ) ) ;
592
590
}
593
591
594
592
let to_local_msat = msg. push_msat ;
595
593
let to_remote_msat = funders_amount_msat - background_feerate * COMMITMENT_TX_BASE_WEIGHT ;
596
594
if to_local_msat <= msg. channel_reserve_satoshis * 1000 && to_remote_msat <= our_channel_reserve_satoshis * 1000 {
597
- return_error_message ! ( "Insufficient funding amount for initial commitment" ) ;
595
+ return Err ( ChannelError :: Close ( "Insufficient funding amount for initial commitment" ) ) ;
598
596
}
599
597
600
598
let secp_ctx = Secp256k1 :: new ( ) ;
@@ -2005,12 +2003,12 @@ impl Channel {
2005
2003
outbound_drops
2006
2004
}
2007
2005
2008
- pub fn update_fee ( & mut self , fee_estimator : & FeeEstimator , msg : & msgs:: UpdateFee ) -> Result < ( ) , HandleError > {
2006
+ pub fn update_fee ( & mut self , fee_estimator : & FeeEstimator , msg : & msgs:: UpdateFee ) -> Result < ( ) , ChannelError > {
2009
2007
if self . channel_outbound {
2010
- return Err ( HandleError { err : "Non-funding remote tried to update channel fee" , action : None } ) ;
2008
+ return Err ( ChannelError :: Close ( "Non-funding remote tried to update channel fee" ) ) ;
2011
2009
}
2012
2010
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
2013
- return Err ( HandleError { err : "Peer sent update_fee when we needed a channel_reestablish" , action : Some ( msgs :: ErrorAction :: SendErrorMessage { msg : msgs :: ErrorMessage { data : "Peer sent update_fee when we needed a channel_reestablish" . to_string ( ) , channel_id : msg . channel_id } } ) } ) ;
2011
+ return Err ( ChannelError :: Close ( "Peer sent update_fee when we needed a channel_reestablish" ) ) ;
2014
2012
}
2015
2013
Channel :: check_remote_fee ( fee_estimator, msg. feerate_per_kw ) ?;
2016
2014
0 commit comments