Merge pull request #1434 from TheBlueMatt/2022-04-robust-payment-claims
[rust-lightning] / lightning / src / chain / channelmonitor.rs
index 62dc48607f6a17ecb96ccf7ba268903e7d16c7a5..5128600163a42854f0be6c2bb5f27f79608050e6 100644 (file)
@@ -655,6 +655,10 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
        // deserialization
        current_holder_commitment_number: u64,
 
+       /// The set of payment hashes from inbound payments for which we know the preimage. Payment
+       /// preimages that are not included in any unrevoked local commitment transaction or unrevoked
+       /// remote commitment transactions are automatically removed when commitment transactions are
+       /// revoked.
        payment_preimages: HashMap<PaymentHash, PaymentPreimage>,
 
        // Note that `MonitorEvent`s MUST NOT be generated during update processing, only generated
@@ -1085,7 +1089,8 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
                self.inner.lock().unwrap().provide_latest_holder_commitment_tx(holder_commitment_tx, htlc_outputs).map_err(|_| ())
        }
 
-       #[cfg(test)]
+       /// This is used to provide payment preimage(s) out-of-band during startup without updating the
+       /// off-chain state with a new commitment transaction.
        pub(crate) fn provide_payment_preimage<B: Deref, F: Deref, L: Deref>(
                &self,
                payment_hash: &PaymentHash,
@@ -1632,6 +1637,10 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
 
                res
        }
+
+       pub(crate) fn get_stored_preimages(&self) -> HashMap<PaymentHash, PaymentPreimage> {
+               self.inner.lock().unwrap().payment_preimages.clone()
+       }
 }
 
 /// Compares a broadcasted commitment transaction's HTLCs with those in the latest state,