@@ -449,7 +449,10 @@ impl ChannelManager {
449
449
let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
450
450
let mut res = Vec :: with_capacity ( channel_state. by_id . len ( ) ) ;
451
451
for ( channel_id, channel) in channel_state. by_id . iter ( ) {
452
- if channel. is_usable ( ) {
452
+ // Note we use is_live here instead of usable which leads to somewhat confused
453
+ // internal/external nomenclature, but that's ok cause that's probably what the user
454
+ // really wanted anyway.
455
+ if channel. is_live ( ) {
453
456
res. push ( ChannelDetails {
454
457
channel_id : ( * channel_id) . clone ( ) ,
455
458
short_channel_id : channel. get_short_channel_id ( ) ,
@@ -997,7 +1000,7 @@ impl ChannelManager {
997
1000
} ;
998
1001
999
1002
let msg_hash = Sha256dHash :: from_data ( & unsigned. encode ( ) [ ..] ) ;
1000
- let sig = self . secp_ctx . sign ( & Message :: from_slice ( & msg_hash[ ..] ) . unwrap ( ) , & self . our_network_key ) ; //TODO Can we unwrap here?
1003
+ let sig = self . secp_ctx . sign ( & Message :: from_slice ( & msg_hash[ ..] ) . unwrap ( ) , & self . our_network_key ) ;
1001
1004
1002
1005
Ok ( msgs:: ChannelUpdate {
1003
1006
signature : sig,
@@ -1050,7 +1053,7 @@ impl ChannelManager {
1050
1053
let channel_state = channel_state_lock. borrow_parts ( ) ;
1051
1054
1052
1055
let id = match channel_state. short_to_id . get ( & route. hops . first ( ) . unwrap ( ) . short_channel_id ) {
1053
- None => return Err ( APIError :: RouteError { err : "No channel available with first hop!" } ) ,
1056
+ None => return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" } ) ,
1054
1057
Some ( id) => id. clone ( ) ,
1055
1058
} ;
1056
1059
@@ -1060,12 +1063,12 @@ impl ChannelManager {
1060
1063
return Err ( APIError :: RouteError { err : "Node ID mismatch on first hop!" } ) ;
1061
1064
}
1062
1065
if !chan. is_live ( ) {
1063
- return Err ( APIError :: RouteError { err : "Peer for first hop currently disconnected!" } ) ;
1066
+ return Err ( APIError :: ChannelUnavailable { err : "Peer for first hop currently disconnected!" } ) ;
1064
1067
}
1065
1068
chan. send_htlc_and_commit ( htlc_msat, payment_hash. clone ( ) , htlc_cltv, HTLCSource :: OutboundRoute {
1066
1069
route : route. clone ( ) ,
1067
1070
session_priv : session_priv. clone ( ) ,
1068
- } , onion_packet) . map_err ( |he| APIError :: RouteError { err : he. err } ) ?
1071
+ } , onion_packet) . map_err ( |he| APIError :: ChannelUnavailable { err : he. err } ) ?
1069
1072
} ;
1070
1073
1071
1074
let first_hop_node_id = route. hops . first ( ) . unwrap ( ) . pubkey ;
@@ -1102,7 +1105,6 @@ impl ChannelManager {
1102
1105
/// May panic if the funding_txo is duplicative with some other channel (note that this should
1103
1106
/// be trivially prevented by using unique funding transaction keys per-channel).
1104
1107
pub fn funding_transaction_generated ( & self , temporary_channel_id : & [ u8 ; 32 ] , funding_txo : OutPoint ) {
1105
-
1106
1108
macro_rules! add_pending_event {
1107
1109
( $event: expr) => {
1108
1110
{
@@ -1998,12 +2000,12 @@ impl ChannelManager {
1998
2000
match channel_state. by_id . get_mut ( & channel_id) {
1999
2001
None => return Err ( APIError :: APIMisuseError { err : "Failed to find corresponding channel" } ) ,
2000
2002
Some ( chan) => {
2001
- if !chan. is_usable ( ) {
2002
- return Err ( APIError :: APIMisuseError { err : "Channel is not in usuable state" } ) ;
2003
- }
2004
2003
if !chan. is_outbound ( ) {
2005
2004
return Err ( APIError :: APIMisuseError { err : "update_fee cannot be sent for an inbound channel" } ) ;
2006
2005
}
2006
+ if !chan. is_live ( ) {
2007
+ return Err ( APIError :: ChannelUnavailable { err : "Channel is either not yet fully established or peer is currently disconnected" } ) ;
2008
+ }
2007
2009
if let Some ( ( update_fee, commitment_signed, chan_monitor) ) = chan. send_update_fee_and_commit ( feerate_per_kw) . map_err ( |e| APIError :: APIMisuseError { err : e. err } ) ? {
2008
2010
if let Err ( _e) = self . monitor . add_update_monitor ( chan_monitor. get_funding_txo ( ) . unwrap ( ) , chan_monitor) {
2009
2011
unimplemented ! ( ) ;
@@ -3025,7 +3027,7 @@ mod tests {
3025
3027
3026
3028
let err = origin_node. node . send_payment ( route, our_payment_hash) . err ( ) . unwrap ( ) ;
3027
3029
match err {
3028
- APIError :: RouteError { err} => assert_eq ! ( err, "Cannot send value that would put us over our max HTLC value in flight" ) ,
3030
+ APIError :: ChannelUnavailable { err} => assert_eq ! ( err, "Cannot send value that would put us over our max HTLC value in flight" ) ,
3029
3031
_ => panic ! ( "Unknown error variants" ) ,
3030
3032
} ;
3031
3033
}
@@ -3989,7 +3991,7 @@ mod tests {
3989
3991
assert ! ( route. hops. iter( ) . rev( ) . skip( 1 ) . all( |h| h. fee_msat == feemsat) ) ;
3990
3992
let err = nodes[ 0 ] . node . send_payment ( route, our_payment_hash) . err ( ) . unwrap ( ) ;
3991
3993
match err {
3992
- APIError :: RouteError { err} => assert_eq ! ( err, "Cannot send value that would put us over our max HTLC value in flight" ) ,
3994
+ APIError :: ChannelUnavailable { err} => assert_eq ! ( err, "Cannot send value that would put us over our max HTLC value in flight" ) ,
3993
3995
_ => panic ! ( "Unknown error variants" ) ,
3994
3996
}
3995
3997
}
@@ -4025,7 +4027,7 @@ mod tests {
4025
4027
let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( recv_value + 1 ) ;
4026
4028
let err = nodes[ 0 ] . node . send_payment ( route. clone ( ) , our_payment_hash) . err ( ) . unwrap ( ) ;
4027
4029
match err {
4028
- APIError :: RouteError { err} => assert_eq ! ( err, "Cannot send value that would put us over our reserve value" ) ,
4030
+ APIError :: ChannelUnavailable { err} => assert_eq ! ( err, "Cannot send value that would put us over our reserve value" ) ,
4029
4031
_ => panic ! ( "Unknown error variants" ) ,
4030
4032
}
4031
4033
}
@@ -4050,7 +4052,7 @@ mod tests {
4050
4052
{
4051
4053
let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( recv_value_2 + 1 ) ;
4052
4054
match nodes[ 0 ] . node . send_payment ( route, our_payment_hash) . err ( ) . unwrap ( ) {
4053
- APIError :: RouteError { err} => assert_eq ! ( err, "Cannot send value that would put us over our reserve value" ) ,
4055
+ APIError :: ChannelUnavailable { err} => assert_eq ! ( err, "Cannot send value that would put us over our reserve value" ) ,
4054
4056
_ => panic ! ( "Unknown error variants" ) ,
4055
4057
}
4056
4058
}
@@ -4106,7 +4108,7 @@ mod tests {
4106
4108
{
4107
4109
let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( recv_value_22+1 ) ;
4108
4110
match nodes[ 0 ] . node . send_payment ( route, our_payment_hash) . err ( ) . unwrap ( ) {
4109
- APIError :: RouteError { err} => assert_eq ! ( err, "Cannot send value that would put us over our reserve value" ) ,
4111
+ APIError :: ChannelUnavailable { err} => assert_eq ! ( err, "Cannot send value that would put us over our reserve value" ) ,
4110
4112
_ => panic ! ( "Unknown error variants" ) ,
4111
4113
}
4112
4114
}
@@ -4935,6 +4937,10 @@ mod tests {
4935
4937
_ => panic ! ( "Unexpected event" ) ,
4936
4938
} ;
4937
4939
4940
+ nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
4941
+ nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
4942
+ reconnect_nodes ( & nodes[ 0 ] , & nodes[ 1 ] , false , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
4943
+
4938
4944
nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . next_forward = Instant :: now ( ) ;
4939
4945
nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
4940
4946
@@ -5029,6 +5035,10 @@ mod tests {
5029
5035
reconnect_nodes ( & nodes[ 0 ] , & nodes[ 1 ] , false , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
5030
5036
}
5031
5037
5038
+ nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
5039
+ nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
5040
+ reconnect_nodes ( & nodes[ 0 ] , & nodes[ 1 ] , false , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
5041
+
5032
5042
// Channel should still work fine...
5033
5043
let payment_preimage_2 = send_along_route ( & nodes[ 0 ] , route, & [ & nodes[ 1 ] ] , 1000000 ) . 0 ;
5034
5044
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage_2) ;
@@ -5079,6 +5089,9 @@ mod tests {
5079
5089
_ => panic ! ( "Unexpected event" ) ,
5080
5090
}
5081
5091
5092
+ reconnect_nodes ( & nodes[ 0 ] , & nodes[ 1 ] , true , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
5093
+ nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
5094
+ nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
5082
5095
reconnect_nodes ( & nodes[ 0 ] , & nodes[ 1 ] , true , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
5083
5096
5084
5097
// TODO: We shouldn't need to manually pass list_usable_chanels here once we support
0 commit comments