Skip to content

Commit 90d2ca3

Browse files
committed
Simplify insert_combine by unimplemented!()ing unimplemented things
1 parent e86e10b commit 90d2ca3

File tree

1 file changed

+10
-36
lines changed

1 file changed

+10
-36
lines changed

src/ln/channelmonitor.rs

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ enum Storage {
243243
Watchtower {
244244
revocation_base_key: PublicKey,
245245
htlc_base_key: PublicKey,
246-
sigs: HashMap<Sha256dHash, Signature>,
247246
}
248247
}
249248

@@ -545,54 +544,29 @@ impl ChannelMonitor {
545544
/// After a successful call this ChannelMonitor is up-to-date and is safe to use to monitor the
546545
/// chain for new blocks/transactions.
547546
pub fn insert_combine(&mut self, mut other: ChannelMonitor) -> Result<(), MonitorUpdateError> {
548-
549-
self.key_storage = match self.key_storage {
550-
Storage::Local { ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref payment_base_key, ref shutdown_pubkey, ref prev_latest_per_commitment_point, ref latest_per_commitment_point, ref mut funding_info, .. } => {
551-
552-
macro_rules! new_storage_local {
553-
($funding_info: expr) => {
554-
Storage::Local {
555-
revocation_base_key: *revocation_base_key,
556-
htlc_base_key: *htlc_base_key,
557-
delayed_payment_base_key: *delayed_payment_base_key,
558-
payment_base_key: *payment_base_key,
559-
shutdown_pubkey: *shutdown_pubkey,
560-
prev_latest_per_commitment_point: *prev_latest_per_commitment_point,
561-
latest_per_commitment_point: *latest_per_commitment_point,
562-
funding_info: $funding_info,
563-
}
564-
}
565-
}
566-
547+
match self.key_storage {
548+
Storage::Local { ref funding_info, .. } => {
549+
if funding_info.is_none() { return Err(MonitorUpdateError("Try to combine a Local monitor without funding_info")); }
567550
let our_funding_info = funding_info;
568-
if let Storage::Local { ref mut funding_info, .. } = other.key_storage {
569-
if our_funding_info.is_some() {
551+
if let Storage::Local { ref funding_info, .. } = other.key_storage {
552+
if funding_info.is_none() { return Err(MonitorUpdateError("Try to combine a Local monitor without funding_info")); }
570553
// We should be able to compare the entire funding_txo, but in fuzztarget its trivially
571554
// easy to collide the funding_txo hash and have a different scriptPubKey.
572-
if funding_info.is_some() && our_funding_info.is_some() && funding_info.as_ref().unwrap().0 != our_funding_info.as_ref().unwrap().0 {
573-
return Err(MonitorUpdateError("Funding transaction outputs are not identical!"));
574-
} else {
575-
new_storage_local!(our_funding_info.take())
576-
}
577-
} else {
578-
return Err(MonitorUpdateError("Try to combine a Local monitor without funding_info"));
555+
if funding_info.as_ref().unwrap().0 != our_funding_info.as_ref().unwrap().0 {
556+
return Err(MonitorUpdateError("Funding transaction outputs are not identical!"));
579557
}
580558
} else {
581559
return Err(MonitorUpdateError("Try to combine a Local monitor with a Watchtower one !"));
582560
}
583561
},
584562
Storage::Watchtower { .. } => {
585-
if let Storage::Watchtower { ref revocation_base_key, ref htlc_base_key, ref mut sigs } = other.key_storage {
586-
Storage::Watchtower {
587-
revocation_base_key: *revocation_base_key,
588-
htlc_base_key: *htlc_base_key,
589-
sigs: sigs.drain().collect(),
590-
}
563+
if let Storage::Watchtower { .. } = other.key_storage {
564+
unimplemented!();
591565
} else {
592566
return Err(MonitorUpdateError("Try to combine a Watchtower monitor with a Local one !"));
593567
}
594568
},
595-
};
569+
}
596570
let other_min_secret = other.get_min_seen_secret();
597571
let our_min_secret = self.get_min_seen_secret();
598572
if our_min_secret > other_min_secret {

0 commit comments

Comments
 (0)