Skip to content

Commit 492983f

Browse files
committed
Fail to deserialize ChannelManager if it is ahead of any monitor(s)
If any monitors are out of sync with the Channel, we previously closed the channel, but we should really only do that if the monitor is ahead of the channel, opting to call the whole thing invalid if the channel is ahead of the monitor.
1 parent 7df042b commit 492983f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,10 +3470,17 @@ impl<'a, ChanSigner: ChannelKeys + Readable, M: Deref, T: Deref, K: Deref, F: De
34703470
let funding_txo = channel.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
34713471
funding_txo_set.insert(funding_txo.clone());
34723472
if let Some(ref mut monitor) = args.channel_monitors.get_mut(&funding_txo) {
3473-
if channel.get_cur_local_commitment_transaction_number() != monitor.get_cur_local_commitment_number() ||
3474-
channel.get_revoked_remote_commitment_transaction_number() != monitor.get_min_seen_secret() ||
3475-
channel.get_cur_remote_commitment_transaction_number() != monitor.get_cur_remote_commitment_number() ||
3476-
channel.get_latest_monitor_update_id() != monitor.get_latest_update_id() {
3473+
if channel.get_cur_local_commitment_transaction_number() < monitor.get_cur_local_commitment_number() ||
3474+
channel.get_revoked_remote_commitment_transaction_number() < monitor.get_min_seen_secret() ||
3475+
channel.get_cur_remote_commitment_transaction_number() < monitor.get_cur_remote_commitment_number() ||
3476+
channel.get_latest_monitor_update_id() > monitor.get_latest_update_id() {
3477+
// If the channel is ahead of the monitor, return InvalidValue:
3478+
return Err(DecodeError::InvalidValue);
3479+
} else if channel.get_cur_local_commitment_transaction_number() > monitor.get_cur_local_commitment_number() ||
3480+
channel.get_revoked_remote_commitment_transaction_number() > monitor.get_min_seen_secret() ||
3481+
channel.get_cur_remote_commitment_transaction_number() > monitor.get_cur_remote_commitment_number() ||
3482+
channel.get_latest_monitor_update_id() < monitor.get_latest_update_id() {
3483+
// But if the channel is behind of the monitor, close the channel:
34773484
let (_, _, mut new_failed_htlcs) = channel.force_shutdown(true);
34783485
failed_htlcs.append(&mut new_failed_htlcs);
34793486
monitor.broadcast_latest_local_commitment_txn(&args.tx_broadcaster);

0 commit comments

Comments
 (0)