Merge pull request #1022 from TheBlueMatt/2021-07-to-remote-reorg
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Wed, 4 Aug 2021 03:08:53 +0000 (03:08 +0000)
committerGitHub <noreply@github.com>
Wed, 4 Aug 2021 03:08:53 +0000 (03:08 +0000)
Fix to_remote SpendableOutputs generation in rare reorg cases

1  2 
lightning/src/chain/channelmonitor.rs

index e3485e7a7bf40f42ffd7adf9058f4726df3dca4e,525718c71f5c928e7ca76158f4a017482e906795..6e2ac3fcf512ed3364fd19af3912bbf350de2c68
@@@ -53,7 -53,7 +53,7 @@@ use util::events::Event
  
  use prelude::*;
  use core::{cmp, mem};
 -use std::io::Error;
 +use io::{self, Error};
  use core::ops::Deref;
  use sync::Mutex;
  
@@@ -88,7 -88,7 +88,7 @@@ pub struct ChannelMonitorUpdate 
  pub const CLOSED_CHANNEL_UPDATE_ID: u64 = core::u64::MAX;
  
  impl Writeable for ChannelMonitorUpdate {
 -      fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
 +      fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
                write_ver_prefix!(w, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
                self.update_id.write(w)?;
                (self.updates.len() as u64).write(w)?;
        }
  }
  impl Readable for ChannelMonitorUpdate {
 -      fn read<R: ::std::io::Read>(r: &mut R) -> Result<Self, DecodeError> {
 +      fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
                let _ver = read_ver_prefix!(r, SERIALIZATION_VERSION);
                let update_id: u64 = Readable::read(r)?;
                let len: u64 = Readable::read(r)?;
@@@ -293,7 -293,7 +293,7 @@@ struct CounterpartyCommitmentTransactio
  }
  
  impl Writeable for CounterpartyCommitmentTransaction {
 -      fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
 +      fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
                w.write_all(&byte_utils::be64_to_array(self.per_htlc.len() as u64))?;
                for (ref txid, ref htlcs) in self.per_htlc.iter() {
                        w.write_all(&txid[..])?;
        }
  }
  impl Readable for CounterpartyCommitmentTransaction {
 -      fn read<R: ::std::io::Read>(r: &mut R) -> Result<Self, DecodeError> {
 +      fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
                let counterparty_commitment_transaction = {
                        let per_htlc_len: u64 = Readable::read(r)?;
                        let mut per_htlc = HashMap::with_capacity(cmp::min(per_htlc_len as usize, MAX_ALLOC_SIZE / 64));
@@@ -2451,7 -2451,8 +2451,8 @@@ impl<Signer: Sign> ChannelMonitorImpl<S
                                        output: outp.clone(),
                                });
                                break;
-                       } else if let Some(ref broadcasted_holder_revokable_script) = self.broadcasted_holder_revokable_script {
+                       }
+                       if let Some(ref broadcasted_holder_revokable_script) = self.broadcasted_holder_revokable_script {
                                if broadcasted_holder_revokable_script.0 == outp.script_pubkey {
                                        spendable_output =  Some(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor {
                                                outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
                                        }));
                                        break;
                                }
-                       } else if self.counterparty_payment_script == outp.script_pubkey {
+                       }
+                       if self.counterparty_payment_script == outp.script_pubkey {
                                spendable_output = Some(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor {
                                        outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
                                        output: outp.clone(),
                                        channel_value_satoshis: self.channel_value_satoshis,
                                }));
                                break;
-                       } else if outp.script_pubkey == self.shutdown_script {
+                       }
+                       if outp.script_pubkey == self.shutdown_script {
                                spendable_output = Some(SpendableOutputDescriptor::StaticOutput {
                                        outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
                                        output: outp.clone(),
                                });
+                               break;
                        }
                }
                if let Some(spendable_output) = spendable_output {
@@@ -2581,7 -2585,7 +2585,7 @@@ const MAX_ALLOC_SIZE: usize = 64*1024
  
  impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
                for (BlockHash, ChannelMonitor<Signer>) {
 -      fn read<R: ::std::io::Read>(reader: &mut R, keys_manager: &'a K) -> Result<Self, DecodeError> {
 +      fn read<R: io::Read>(reader: &mut R, keys_manager: &'a K) -> Result<Self, DecodeError> {
                macro_rules! unwrap_obj {
                        ($key: expr) => {
                                match $key {