From 61401b16f0e59967e665998440d1aee0ebf253e8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 31 Jan 2021 20:12:50 -0500 Subject: [PATCH] Make ChannelMonitor clonable again In general, we'd been moving away from ChannelMonitor being clonable, XXXXXXXXXXXXXXXXXXXx --- lightning/src/chain/channelmonitor.rs | 15 +++++++++++---- lightning/src/chain/onchaintx.rs | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index e79e50172..a12662eac 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -263,7 +263,7 @@ impl_writeable_tlv_based!(HolderSignedTx, { /// We use this to track static counterparty commitment transaction data and to generate any /// justice or 2nd-stage preimage/timeout transactions. -#[derive(PartialEq)] +#[derive(Clone, PartialEq)] struct CounterpartyCommitmentParameters { counterparty_delayed_payment_base_key: PublicKey, counterparty_htlc_base_key: PublicKey, @@ -317,7 +317,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)] +#[derive(Clone, PartialEq)] struct OnchainEventEntry { txid: Txid, height: u32, @@ -359,7 +359,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)] +#[derive(Clone, PartialEq)] 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 @@ -617,7 +617,7 @@ pub enum Balance { } /// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY. -#[derive(PartialEq)] +#[derive(Clone, PartialEq)] struct IrrevocablyResolvedHTLC { commitment_tx_output_idx: Option, /// The txid of the transaction which resolved the HTLC, this may be a commitment (if the HTLC @@ -685,6 +685,13 @@ pub struct ChannelMonitor { inner: Mutex>, } +impl Clone for ChannelMonitor { + fn clone(&self) -> Self { + Self { inner: Mutex::new(self.inner.lock().unwrap().clone()) } + } +} + +#[derive(Clone)] pub(crate) struct ChannelMonitorImpl { latest_update_id: u64, commitment_transaction_number_obscure_factor: u64, diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index 0f2edff5e..0f8ebd5dc 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -46,7 +46,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)] +#[derive(Clone, PartialEq)] struct OnchainEventEntry { txid: Txid, height: u32, @@ -65,7 +65,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)] +#[derive(Clone, PartialEq)] enum OnchainEvent { /// Outpoint under claim process by our own tx, once this one get enough confirmations, we remove it from /// bump-txn candidate buffer. @@ -165,6 +165,7 @@ impl Writeable for Option>> { /// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and /// do RBF bumping if possible. +#[derive(Clone)] pub struct OnchainTxHandler { destination_script: Script, holder_commitment: HolderCommitmentTransaction, -- 2.39.5