@@ -284,11 +284,16 @@ impl ChannelManager {
284
284
/// pending HTLCs, the channel will be closed on chain.
285
285
pub fn close_channel ( & self , channel_id : & Uint256 ) -> Result < msgs:: Shutdown , HandleError > {
286
286
let res = {
287
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
287
+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
288
+ let channel_state = channel_state_lock. borrow_parts ( ) ;
289
+
288
290
match channel_state. by_id . entry ( channel_id. clone ( ) ) {
289
291
hash_map:: Entry :: Occupied ( mut chan_entry) => {
290
292
let res = chan_entry. get_mut ( ) . get_shutdown ( ) ?;
291
293
if chan_entry. get ( ) . is_shutdown ( ) {
294
+ if let Some ( short_id) = chan_entry. get ( ) . get_short_channel_id ( ) {
295
+ channel_state. short_to_id . remove ( & short_id) ;
296
+ }
292
297
chan_entry. remove_entry ( ) ;
293
298
}
294
299
res
@@ -1140,7 +1145,8 @@ impl ChannelMessageHandler for ChannelManager {
1140
1145
1141
1146
fn handle_shutdown ( & self , their_node_id : & PublicKey , msg : & msgs:: Shutdown ) -> Result < ( Option < msgs:: Shutdown > , Option < msgs:: ClosingSigned > ) , HandleError > {
1142
1147
let res = {
1143
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1148
+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
1149
+ let channel_state = channel_state_lock. borrow_parts ( ) ;
1144
1150
1145
1151
match channel_state. by_id . entry ( msg. channel_id . clone ( ) ) {
1146
1152
hash_map:: Entry :: Occupied ( mut chan_entry) => {
@@ -1149,6 +1155,9 @@ impl ChannelMessageHandler for ChannelManager {
1149
1155
}
1150
1156
let res = chan_entry. get_mut ( ) . shutdown ( & * self . fee_estimator , & msg) ?;
1151
1157
if chan_entry. get ( ) . is_shutdown ( ) {
1158
+ if let Some ( short_id) = chan_entry. get ( ) . get_short_channel_id ( ) {
1159
+ channel_state. short_to_id . remove ( & short_id) ;
1160
+ }
1152
1161
chan_entry. remove_entry ( ) ;
1153
1162
}
1154
1163
res
@@ -1165,7 +1174,8 @@ impl ChannelMessageHandler for ChannelManager {
1165
1174
1166
1175
fn handle_closing_signed ( & self , their_node_id : & PublicKey , msg : & msgs:: ClosingSigned ) -> Result < Option < msgs:: ClosingSigned > , HandleError > {
1167
1176
let res = {
1168
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1177
+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
1178
+ let channel_state = channel_state_lock. borrow_parts ( ) ;
1169
1179
match channel_state. by_id . entry ( msg. channel_id . clone ( ) ) {
1170
1180
hash_map:: Entry :: Occupied ( mut chan_entry) => {
1171
1181
if chan_entry. get ( ) . get_their_node_id ( ) != * their_node_id {
@@ -1178,6 +1188,9 @@ impl ChannelMessageHandler for ChannelManager {
1178
1188
// also implies there are no pending HTLCs left on the channel, so we can
1179
1189
// fully delete it from tracking (the channel monitor is still around to
1180
1190
// watch for old state broadcasts)!
1191
+ if let Some ( short_id) = chan_entry. get ( ) . get_short_channel_id ( ) {
1192
+ channel_state. short_to_id . remove ( & short_id) ;
1193
+ }
1181
1194
chan_entry. remove_entry ( ) ;
1182
1195
}
1183
1196
res
@@ -1657,11 +1670,8 @@ impl ChannelMessageHandler for ChannelManager {
1657
1670
if no_connection_possible {
1658
1671
channel_state. by_id . retain ( move |_, chan| {
1659
1672
if chan. get_their_node_id ( ) == * their_node_id {
1660
- match chan. get_short_channel_id ( ) {
1661
- Some ( short_id) => {
1662
- short_to_id. remove ( & short_id) ;
1663
- } ,
1664
- None => { } ,
1673
+ if let Some ( short_id) = chan. get_short_channel_id ( ) {
1674
+ short_to_id. remove ( & short_id) ;
1665
1675
}
1666
1676
//TODO: get the latest commitment tx, any HTLC txn built on top of it, etc out
1667
1677
//of the channel and throw those into the announcement blackhole.
0 commit comments