This repository was archived by the owner on Feb 3, 2025. It is now read-only.
File tree 5 files changed +40
-6
lines changed
5 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,9 @@ pub enum MutinyError {
95
95
/// A channel could not be opened.
96
96
#[ error( "Failed to create channel." ) ]
97
97
ChannelCreationFailed ,
98
+ /// A channel could not be opened.
99
+ #[ error( "Failed to create channel. {0}" ) ]
100
+ ChannelCreationFailedWithReason ( String ) ,
98
101
/// A channel could not be closed.
99
102
#[ error( "Failed to close channel." ) ]
100
103
ChannelClosingFailed ,
@@ -237,6 +240,10 @@ impl PartialEq for MutinyError {
237
240
( Self :: RoutingFailed , Self :: RoutingFailed ) => true ,
238
241
( Self :: PeerInfoParseFailed , Self :: PeerInfoParseFailed ) => true ,
239
242
( Self :: ChannelCreationFailed , Self :: ChannelCreationFailed ) => true ,
243
+ (
244
+ Self :: ChannelCreationFailedWithReason ( x) ,
245
+ Self :: ChannelCreationFailedWithReason ( y) ,
246
+ ) => x == y,
240
247
( Self :: ChannelClosingFailed , Self :: ChannelClosingFailed ) => true ,
241
248
( Self :: PersistenceFailed { source } , Self :: PersistenceFailed { source : source2 } ) => {
242
249
source == source2
Original file line number Diff line number Diff line change @@ -524,8 +524,19 @@ impl<S: MutinyStorage> EventHandler<S> {
524
524
} => {
525
525
// if we still have channel open params, then it was just a failed channel open
526
526
// we should not persist this as a closed channel and just delete the channel open params
527
- if let Ok ( Some ( _) ) = self . persister . get_channel_open_params ( user_channel_id) {
528
- let _ = self . persister . delete_channel_open_params ( user_channel_id) ;
527
+ if let Ok ( Some ( mut params) ) =
528
+ self . persister . get_channel_open_params ( user_channel_id)
529
+ {
530
+ // Remove the LDK fluff from the error message
531
+ let reason_str = reason. to_string ( ) . replace (
532
+ "Channel closed because counterparty force-closed with message: " ,
533
+ "" ,
534
+ ) ;
535
+
536
+ params. failure_reason = Some ( reason_str) ;
537
+ let _ = self
538
+ . persister
539
+ . persist_channel_open_params ( user_channel_id, params) ;
529
540
return ;
530
541
} ;
531
542
Original file line number Diff line number Diff line change @@ -550,6 +550,8 @@ pub(crate) struct ChannelOpenParams {
550
550
pub ( crate ) labels : Option < Vec < String > > ,
551
551
#[ serde( skip_serializing_if = "Option::is_none" ) ]
552
552
pub ( crate ) opening_tx : Option < Transaction > ,
553
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
554
+ pub ( crate ) failure_reason : Option < String > ,
553
555
}
554
556
555
557
impl ChannelOpenParams {
@@ -560,6 +562,7 @@ impl ChannelOpenParams {
560
562
utxos : None ,
561
563
labels : None ,
562
564
opening_tx : None ,
565
+ failure_reason : None ,
563
566
}
564
567
}
565
568
@@ -574,6 +577,7 @@ impl ChannelOpenParams {
574
577
utxos : Some ( utxos) ,
575
578
labels : None ,
576
579
opening_tx : None ,
580
+ failure_reason : None ,
577
581
}
578
582
}
579
583
}
Original file line number Diff line number Diff line change @@ -1874,10 +1874,16 @@ impl<S: MutinyStorage> Node<S> {
1874
1874
return Err ( MutinyError :: NotRunning ) ;
1875
1875
}
1876
1876
1877
- // We will get a channel closure event if the peer rejects the channel
1878
- // todo return closure reason to user
1879
- if let Ok ( Some ( _closure) ) = self . persister . get_channel_closure ( user_channel_id) {
1880
- return Err ( MutinyError :: ChannelCreationFailed ) ;
1877
+ // We'll set failure reason if the peer rejects the channel
1878
+ if let Some ( failure_reason) = self
1879
+ . persister
1880
+ . get_channel_open_params ( user_channel_id) ?
1881
+ . and_then ( |p| p. failure_reason )
1882
+ {
1883
+ log_error ! ( self . logger, "Channel funding tx failed: {failure_reason}" ) ;
1884
+ // can now safely delete the channel open params
1885
+ let _ = self . persister . delete_channel_open_params ( user_channel_id) ;
1886
+ return Err ( MutinyError :: ChannelCreationFailedWithReason ( failure_reason) ) ;
1881
1887
}
1882
1888
1883
1889
let channels = self . channel_manager . list_channels_with_counterparty ( pubkey) ;
Original file line number Diff line number Diff line change @@ -86,6 +86,9 @@ pub enum MutinyJsError {
86
86
/// A channel could not be opened.
87
87
#[ error( "Failed to create channel." ) ]
88
88
ChannelCreationFailed ,
89
+ /// A channel could not be opened.
90
+ #[ error( "Failed to create channel. {0}" ) ]
91
+ ChannelCreationFailedWithReason ( String ) ,
89
92
/// A channel could not be closed.
90
93
#[ error( "Failed to close channel." ) ]
91
94
ChannelClosingFailed ,
@@ -203,6 +206,9 @@ impl From<MutinyError> for MutinyJsError {
203
206
MutinyError :: RoutingFailed => MutinyJsError :: RoutingFailed ,
204
207
MutinyError :: PeerInfoParseFailed => MutinyJsError :: PeerInfoParseFailed ,
205
208
MutinyError :: ChannelCreationFailed => MutinyJsError :: ChannelCreationFailed ,
209
+ MutinyError :: ChannelCreationFailedWithReason ( x) => {
210
+ MutinyJsError :: ChannelCreationFailedWithReason ( x)
211
+ }
206
212
MutinyError :: ChannelClosingFailed => MutinyJsError :: ChannelClosingFailed ,
207
213
MutinyError :: PersistenceFailed { source : _ } => MutinyJsError :: PersistenceFailed ,
208
214
MutinyError :: ReadError { source : _ } => MutinyJsError :: ReadError ,
You can’t perform that action at this time.
0 commit comments