@@ -155,6 +155,23 @@ impl MsgHandleErrInternal {
155
155
needs_channel_force_close : true ,
156
156
}
157
157
}
158
+
159
+ #[ inline]
160
+ fn disconnect_peer_with_err_msg ( err : & ' static str , channel_id : [ u8 ; 32 ] ) -> Self {
161
+ Self {
162
+ err : HandleError {
163
+ err,
164
+ action : Some ( msgs:: ErrorAction :: DisconnectPeer {
165
+ msg : Some ( msgs:: ErrorMessage {
166
+ channel_id,
167
+ data : err. to_string ( )
168
+ } ) ,
169
+ } ) ,
170
+ } ,
171
+ needs_channel_force_close : true ,
172
+ }
173
+ }
174
+
158
175
#[ inline]
159
176
fn from_maybe_close ( err : msgs:: HandleError ) -> Self {
160
177
Self { err, needs_channel_force_close : true }
@@ -1439,6 +1456,30 @@ impl ChannelManager {
1439
1456
Ok ( accept_msg)
1440
1457
}
1441
1458
1459
+ fn internal_accept_channel ( & self , their_node_id : & PublicKey , msg : & msgs:: AcceptChannel ) -> Result < ( ) , MsgHandleErrInternal > {
1460
+ let ( value, output_script, user_id) = {
1461
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1462
+ match channel_state. by_id . get_mut ( & msg. temporary_channel_id ) {
1463
+ Some ( chan) => {
1464
+ if chan. get_their_node_id ( ) != * their_node_id {
1465
+ return Err ( MsgHandleErrInternal :: disconnect_peer_with_err_msg ( "Got a message for a channel from the wrong node!" , msg. temporary_channel_id . clone ( ) ) ) ;
1466
+ }
1467
+ chan. accept_channel ( & msg) . map_err ( |e| MsgHandleErrInternal :: from_maybe_close ( e) ) ?;
1468
+ ( chan. get_value_satoshis ( ) , chan. get_funding_redeemscript ( ) . to_v0_p2wsh ( ) , chan. get_user_id ( ) )
1469
+ } ,
1470
+ None => return Err ( MsgHandleErrInternal :: from_no_close ( HandleError { err : "Failed to find corresponding channel" , action : Some ( msgs:: ErrorAction :: IgnoreError ) } ) )
1471
+ }
1472
+ } ;
1473
+ let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
1474
+ pending_events. push ( events:: Event :: FundingGenerationReady {
1475
+ temporary_channel_id : msg. temporary_channel_id ,
1476
+ channel_value_satoshis : value,
1477
+ output_script : output_script,
1478
+ user_channel_id : user_id,
1479
+ } ) ;
1480
+ Ok ( ( ) )
1481
+ }
1482
+
1442
1483
fn internal_announcement_signatures ( & self , their_node_id : & PublicKey , msg : & msgs:: AnnouncementSignatures ) -> Result < ( ) , MsgHandleErrInternal > {
1443
1484
let ( chan_announcement, chan_update) = {
1444
1485
let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -1645,27 +1686,7 @@ impl ChannelMessageHandler for ChannelManager {
1645
1686
}
1646
1687
1647
1688
fn handle_accept_channel ( & self , their_node_id : & PublicKey , msg : & msgs:: AcceptChannel ) -> Result < ( ) , HandleError > {
1648
- let ( value, output_script, user_id) = {
1649
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1650
- match channel_state. by_id . get_mut ( & msg. temporary_channel_id ) {
1651
- Some ( chan) => {
1652
- if chan. get_their_node_id ( ) != * their_node_id {
1653
- return Err ( HandleError { err : "Got a message for a channel from the wrong node!" , action : None } )
1654
- }
1655
- chan. accept_channel ( & msg) ?;
1656
- ( chan. get_value_satoshis ( ) , chan. get_funding_redeemscript ( ) . to_v0_p2wsh ( ) , chan. get_user_id ( ) )
1657
- } ,
1658
- None => return Err ( HandleError { err : "Failed to find corresponding channel" , action : None } )
1659
- }
1660
- } ;
1661
- let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
1662
- pending_events. push ( events:: Event :: FundingGenerationReady {
1663
- temporary_channel_id : msg. temporary_channel_id ,
1664
- channel_value_satoshis : value,
1665
- output_script : output_script,
1666
- user_channel_id : user_id,
1667
- } ) ;
1668
- Ok ( ( ) )
1689
+ handle_error ! ( self , self . internal_accept_channel( their_node_id, msg) , their_node_id)
1669
1690
}
1670
1691
1671
1692
fn handle_funding_created ( & self , their_node_id : & PublicKey , msg : & msgs:: FundingCreated ) -> Result < msgs:: FundingSigned , HandleError > {
0 commit comments