From 394b11c7b55a5a98e0b46aa22ca914693aa2df45 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Tue, 6 Nov 2018 03:23:22 +0000 Subject: [PATCH] Add key_storage selection in ChannelMonitor insert_combine Based on commitment_number --- src/ln/channelmonitor.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 8b209c1e..7f584aeb 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -552,6 +552,15 @@ impl ChannelMonitor { if our_min_secret > other_min_secret { self.provide_secret(other_min_secret, other.get_secret(other_min_secret).unwrap())?; } + if let Some(ref local_tx) = self.current_local_signed_commitment_tx { + if let Some(ref other_local_tx) = other.current_local_signed_commitment_tx { + let our_commitment_number = 0xffffffffffff - ((((local_tx.tx.input[0].sequence as u64 & 0xffffff) << 3*8) | (local_tx.tx.lock_time as u64 & 0xffffff)) ^ self.commitment_transaction_number_obscure_factor); + let other_commitment_number = 0xffffffffffff - ((((other_local_tx.tx.input[0].sequence as u64 & 0xffffff) << 3*8) | (other_local_tx.tx.lock_time as u64 & 0xffffff)) ^ other.commitment_transaction_number_obscure_factor); + if our_commitment_number >= other_commitment_number { + self.key_storage = other.key_storage; + } + } + } // TODO: We should use current_remote_commitment_number and the commitment number out of // local transactions to decide how to merge if our_min_secret >= other_min_secret { @@ -567,6 +576,7 @@ impl ChannelMonitor { } self.payment_preimages = other.payment_preimages; } + self.current_remote_commitment_number = cmp::min(self.current_remote_commitment_number, other.current_remote_commitment_number); Ok(()) } -- 2.30.2