- if self.funding_txo.is_some() {
- // We should be able to compare the entire funding_txo, but in fuzztarget its trivially
- // easy to collide the funding_txo hash and have a different scriptPubKey.
- if other.funding_txo.is_some() && other.funding_txo.as_ref().unwrap().0 != self.funding_txo.as_ref().unwrap().0 {
- return Err(MonitorUpdateError("Funding transaction outputs are not identical!"));
- }
- } else {
- self.funding_txo = other.funding_txo.take();
- }
+
+ self.key_storage = match self.key_storage {
+ 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, .. } => {
+
+ macro_rules! new_storage_local {
+ ($funding_info: expr) => {
+ Storage::Local {
+ revocation_base_key: *revocation_base_key,
+ htlc_base_key: *htlc_base_key,
+ delayed_payment_base_key: *delayed_payment_base_key,
+ payment_base_key: *payment_base_key,
+ shutdown_pubkey: *shutdown_pubkey,
+ prev_latest_per_commitment_point: *prev_latest_per_commitment_point,
+ latest_per_commitment_point: *latest_per_commitment_point,
+ funding_info: $funding_info,
+ }
+ }
+ }
+
+ let our_funding_info = funding_info;
+ if let Storage::Local { ref mut funding_info, .. } = other.key_storage {
+ if our_funding_info.is_some() {
+ // We should be able to compare the entire funding_txo, but in fuzztarget its trivially
+ // easy to collide the funding_txo hash and have a different scriptPubKey.
+ if funding_info.is_some() && our_funding_info.is_some() && funding_info.as_ref().unwrap().0 != our_funding_info.as_ref().unwrap().0 {
+ return Err(MonitorUpdateError("Funding transaction outputs are not identical!"));
+ } else {
+ new_storage_local!(our_funding_info.take())
+ }
+ } else {
+ return Err(MonitorUpdateError("Try to combine a Local monitor without funding_info"));
+ }
+ } else {
+ return Err(MonitorUpdateError("Try to combine a Local monitor with a Watchtower one !"));
+ }
+ },
+ Storage::Watchtower { .. } => {
+ if let Storage::Watchtower { ref revocation_base_key, ref htlc_base_key, ref mut sigs } = other.key_storage {
+ Storage::Watchtower {
+ revocation_base_key: *revocation_base_key,
+ htlc_base_key: *htlc_base_key,
+ sigs: sigs.drain().collect(),
+ }
+ } else {
+ return Err(MonitorUpdateError("Try to combine a Watchtower monitor with a Local one !"));
+ }
+ },
+ };