Merge ChainMonitor impl blocks
[rust-lightning] / lightning / src / ln / onchaintx.rs
index 7aced598ecbb4f39c9a4d30dada413021c9e0bb9..dbe86c869ce4ddfa720a4f8c94d43e405305661c 100644 (file)
@@ -25,7 +25,7 @@ use ln::msgs::DecodeError;
 use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMaterial, ClaimRequest};
 use ln::channelmanager::PaymentPreimage;
 use ln::chan_utils;
-use ln::chan_utils::{TxCreationKeys, LocalCommitmentTransaction};
+use ln::chan_utils::{TxCreationKeys, HolderCommitmentTransaction};
 use chain::chaininterface::{FeeEstimator, BroadcasterInterface, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT};
 use chain::keysinterface::ChannelKeys;
 use util::logger::Logger;
@@ -241,13 +241,13 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
 /// do RBF bumping if possible.
 pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
        destination_script: Script,
-       holder_commitment: Option<LocalCommitmentTransaction>,
+       holder_commitment: Option<HolderCommitmentTransaction>,
        // holder_htlc_sigs and prev_holder_htlc_sigs are in the order as they appear in the commitment
        // transaction outputs (hence the Option<>s inside the Vec). The first usize is the index in
-       // the set of HTLCs in the LocalCommitmentTransaction (including those which do not appear in
+       // the set of HTLCs in the HolderCommitmentTransaction (including those which do not appear in
        // the commitment transaction).
        holder_htlc_sigs: Option<Vec<Option<(usize, Signature)>>>,
-       prev_holder_commitment: Option<LocalCommitmentTransaction>,
+       prev_holder_commitment: Option<HolderCommitmentTransaction>,
        prev_holder_htlc_sigs: Option<Vec<Option<(usize, Signature)>>>,
        on_holder_tx_csv: u16,
 
@@ -657,7 +657,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
                None
        }
 
-       pub(super) fn block_connected<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], claimable_outpoints: Vec<ClaimRequest>, height: u32, broadcaster: B, fee_estimator: F, logger: L)
+       pub(crate) fn block_connected<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], claimable_outpoints: Vec<ClaimRequest>, height: u32, broadcaster: B, fee_estimator: F, logger: L)
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator,
                                        L::Target: Logger,
@@ -877,18 +877,9 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
                }
        }
 
-       pub(super) fn provide_latest_holder_tx(&mut self, tx: LocalCommitmentTransaction) -> Result<(), ()> {
-               // To prevent any unsafe state discrepancy between offchain and onchain, once holder
-               // commitment transaction has been signed due to an event (either block height for
-               // HTLC-timeout or channel force-closure), don't allow any further update of holder
-               // commitment transaction view to avoid delivery of revocation secret to counterparty
-               // for the aformentionned signed transaction.
-               if self.holder_htlc_sigs.is_some() || self.prev_holder_htlc_sigs.is_some() {
-                       return Err(());
-               }
+       pub(super) fn provide_latest_holder_tx(&mut self, tx: HolderCommitmentTransaction) {
                self.prev_holder_commitment = self.holder_commitment.take();
                self.holder_commitment = Some(tx);
-               Ok(())
        }
 
        fn sign_latest_holder_htlcs(&mut self) {
@@ -931,7 +922,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
        pub(super) fn get_fully_signed_holder_tx(&mut self, funding_redeemscript: &Script) -> Option<Transaction> {
                if let Some(ref mut holder_commitment) = self.holder_commitment {
                        match self.key_storage.sign_holder_commitment(holder_commitment, &self.secp_ctx) {
-                               Ok(sig) => Some(holder_commitment.add_local_sig(funding_redeemscript, sig)),
+                               Ok(sig) => Some(holder_commitment.add_holder_sig(funding_redeemscript, sig)),
                                Err(_) => return None,
                        }
                } else {
@@ -944,7 +935,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
                if let Some(ref mut holder_commitment) = self.holder_commitment {
                        let holder_commitment = holder_commitment.clone();
                        match self.key_storage.sign_holder_commitment(&holder_commitment, &self.secp_ctx) {
-                               Ok(sig) => Some(holder_commitment.add_local_sig(funding_redeemscript, sig)),
+                               Ok(sig) => Some(holder_commitment.add_holder_sig(funding_redeemscript, sig)),
                                Err(_) => return None,
                        }
                } else {