@@ -9253,53 +9253,51 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9253
9253
let per_peer_state = self.per_peer_state.read().unwrap();
9254
9254
9255
9255
let mut cursor = io::Cursor::new(decrypted);
9256
- match <PeerStorageMonitorHolderList as Readable>::read(&mut cursor) {
9257
- Ok(mon_list) => {
9258
- for mon_holder in mon_list.monitors.iter() {
9259
- let peer_state_mutex =
9260
- match per_peer_state.get(&mon_holder.counterparty_node_id) {
9261
- Some(mutex) => mutex,
9262
- None => {
9263
- log_debug!(
9264
- logger,
9265
- "Not able to find peer_state for the counterparty {}, channelId {}",
9266
- log_pubkey!(mon_holder.counterparty_node_id),
9267
- mon_holder.channel_id
9268
- );
9269
- continue;
9270
- },
9271
- };
9256
+ let mon_list = <PeerStorageMonitorHolderList as Readable>::read(&mut cursor).unwrap_or_else(|e| {
9257
+ // This should NEVER happen.
9258
+ log_debug!(self.logger, "Unable to unpack the retrieved peer storage {:?}", e);
9259
+ PeerStorageMonitorHolderList { monitors: Vec::new() }
9260
+ });
9272
9261
9273
- let peer_state_lock = peer_state_mutex.lock().unwrap();
9274
- let peer_state = &*peer_state_lock;
9262
+ for mon_holder in mon_list.monitors.iter() {
9263
+ let peer_state_mutex =
9264
+ match per_peer_state.get(&mon_holder.counterparty_node_id) {
9265
+ Some(mutex) => mutex,
9266
+ None => {
9267
+ log_debug!(
9268
+ logger,
9269
+ "Not able to find peer_state for the counterparty {}, channelId {}",
9270
+ log_pubkey!(mon_holder.counterparty_node_id),
9271
+ mon_holder.channel_id
9272
+ );
9273
+ continue;
9274
+ },
9275
+ };
9275
9276
9276
- match peer_state.channel_by_id.get(&mon_holder.channel_id) {
9277
- Some(chan) => {
9278
- if let Some(funded_chan) = chan.as_funded() {
9279
- if funded_chan
9280
- .get_revoked_counterparty_commitment_transaction_number()
9281
- > mon_holder.min_seen_secret
9282
- {
9283
- panic!(
9284
- "Lost channel state for channel {}.
9285
- Received peer storage with a more recent state than what our node had.
9286
- Use the FundRecoverer to initiate a force close and sweep the funds.",
9287
- &mon_holder.channel_id
9288
- );
9289
- }
9290
- }
9291
- },
9292
- None => {
9293
- // TODO: Figure out if this channel is so old that we have forgotten about it.
9294
- panic!("Lost a channel {}", &mon_holder.channel_id);
9295
- },
9296
- }
9297
- }
9298
- },
9277
+ let peer_state_lock = peer_state_mutex.lock().unwrap();
9278
+ let peer_state = &*peer_state_lock;
9299
9279
9300
- Err(e) => {
9301
- panic!("Wrong serialisation of PeerStorageMonitorHolderList: {}", e);
9302
- },
9280
+ match peer_state.channel_by_id.get(&mon_holder.channel_id) {
9281
+ Some(chan) => {
9282
+ if let Some(funded_chan) = chan.as_funded() {
9283
+ if funded_chan
9284
+ .get_revoked_counterparty_commitment_transaction_number()
9285
+ > mon_holder.min_seen_secret
9286
+ {
9287
+ panic!(
9288
+ "Lost channel state for channel {}.
9289
+ Received peer storage with a more recent state than what our node had.
9290
+ Use the FundRecoverer to initiate a force close and sweep the funds.",
9291
+ &mon_holder.channel_id
9292
+ );
9293
+ }
9294
+ }
9295
+ },
9296
+ None => {
9297
+ // TODO: Figure out if this channel is so old that we have forgotten about it.
9298
+ panic!("Lost a channel {}", &mon_holder.channel_id);
9299
+ },
9300
+ }
9303
9301
}
9304
9302
Ok(())
9305
9303
}
0 commit comments