From: Antoine Riard Date: Tue, 6 Nov 2018 03:23:22 +0000 (+0000) Subject: Add key_storage selection in ChannelMonitor insert_combine X-Git-Tag: v0.0.12~271^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=394b11c7b55a5a98e0b46aa22ca914693aa2df45;p=rust-lightning Add key_storage selection in ChannelMonitor insert_combine Based on commitment_number --- diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 8b209c1e7..7f584aeba 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(()) }