Make ChannelMonitor clonable again
authorMatt Corallo <git@bluematt.me>
Mon, 1 Feb 2021 01:12:50 +0000 (20:12 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 27 Oct 2022 23:16:50 +0000 (23:16 +0000)
In general, we'd been moving away from ChannelMonitor being clonable,
   XXXXXXXXXXXXXXXXXXXx

lightning/src/chain/channelmonitor.rs
lightning/src/chain/onchaintx.rs

index 79d589c6521b0d0268d8a897d6950cdd97db0a96..8e31b4c6f0888ba589f41f7417bc7de0be5883f5 100644 (file)
@@ -282,7 +282,7 @@ impl HolderSignedTx {
 
 /// We use this to track static counterparty commitment transaction data and to generate any
 /// justice or 2nd-stage preimage/timeout transactions.
-#[derive(PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq)]
 struct CounterpartyCommitmentParameters {
        counterparty_delayed_payment_base_key: PublicKey,
        counterparty_htlc_base_key: PublicKey,
@@ -336,7 +336,7 @@ impl Readable for CounterpartyCommitmentParameters {
 /// transaction causing it.
 ///
 /// Used to determine when the on-chain event can be considered safe from a chain reorganization.
-#[derive(PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq)]
 struct OnchainEventEntry {
        txid: Txid,
        height: u32,
@@ -378,7 +378,7 @@ type CommitmentTxCounterpartyOutputInfo = Option<(u32, u64)>;
 
 /// Upon discovering of some classes of onchain tx by ChannelMonitor, we may have to take actions on it
 /// once they mature to enough confirmations (ANTI_REORG_DELAY)
-#[derive(PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq)]
 enum OnchainEvent {
        /// An outbound HTLC failing after a transaction is confirmed. Used
        ///  * when an outbound HTLC output is spent by us after the HTLC timed out
@@ -636,7 +636,7 @@ pub enum Balance {
 }
 
 /// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY.
-#[derive(PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq)]
 struct IrrevocablyResolvedHTLC {
        commitment_tx_output_idx: Option<u32>,
        /// The txid of the transaction which resolved the HTLC, this may be a commitment (if the HTLC
@@ -704,6 +704,13 @@ pub struct ChannelMonitor<Signer: Sign> {
        inner: Mutex<ChannelMonitorImpl<Signer>>,
 }
 
+impl<Signer: Sign> Clone for ChannelMonitor<Signer> {
+       fn clone(&self) -> Self {
+               Self { inner: Mutex::new(self.inner.lock().unwrap().clone()) }
+       }
+}
+
+#[derive(Clone)]
 pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
        latest_update_id: u64,
        commitment_transaction_number_obscure_factor: u64,
index 18679f0aacd5cd34fead7952fc91be997ad4e57b..9424b1ef07050da0c7b9cbf1366afa2ca93a21fc 100644 (file)
@@ -54,7 +54,7 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
 /// transaction causing it.
 ///
 /// Used to determine when the on-chain event can be considered safe from a chain reorganization.
-#[derive(PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq)]
 struct OnchainEventEntry {
        txid: Txid,
        height: u32,
@@ -73,7 +73,7 @@ impl OnchainEventEntry {
 
 /// Upon discovering of some classes of onchain tx by ChannelMonitor, we may have to take actions on it
 /// once they mature to enough confirmations (ANTI_REORG_DELAY)
-#[derive(PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq)]
 enum OnchainEvent {
        /// Outpoint under claim process by our own tx, once this one get enough confirmations, we remove it from
        /// bump-txn candidate buffer.
@@ -196,6 +196,7 @@ pub(crate) enum OnchainClaim {
 
 /// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and
 /// do RBF bumping if possible.
+#[derive(Clone)]
 pub struct OnchainTxHandler<ChannelSigner: Sign> {
        destination_script: Script,
        holder_commitment: HolderCommitmentTransaction,