Skip to content

Commit a15628d

Browse files
author
Antoine Riard
committed
Add key_storage selection in ChannelMonitor insert_combine
Based on commitment_number
1 parent ef3a6e8 commit a15628d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/ln/channelmonitor.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,15 @@ impl ChannelMonitor {
550550
if our_min_secret > other_min_secret {
551551
self.provide_secret(other_min_secret, other.get_secret(other_min_secret).unwrap())?;
552552
}
553+
if let Some(ref local_tx) = self.current_local_signed_commitment_tx {
554+
if let Some(ref other_local_tx) = other.current_local_signed_commitment_tx {
555+
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);
556+
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);
557+
if our_commitment_number >= other_commitment_number {
558+
self.key_storage = other.key_storage;
559+
}
560+
}
561+
}
553562
// TODO: We should use current_remote_commitment_number and the commitment number out of
554563
// local transactions to decide how to merge
555564
if our_min_secret >= other_min_secret {
@@ -565,6 +574,7 @@ impl ChannelMonitor {
565574
}
566575
self.payment_preimages = other.payment_preimages;
567576
}
577+
568578
self.current_remote_commitment_number = cmp::min(self.current_remote_commitment_number, other.current_remote_commitment_number);
569579
Ok(())
570580
}

0 commit comments

Comments
 (0)