Make ChannelMonitor clonable again 2021-03-java-bindings-base-out-of-tree
authorMatt Corallo <git@bluematt.me>
Mon, 1 Feb 2021 01:12:50 +0000 (20:12 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 2 Jul 2021 20:27:30 +0000 (20:27 +0000)
In general, we'd been moving away from ChannelMonitor being clonable,
   XXXXXXXXXXXXXXXXXXXx

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

index 9ce18e8e102d312c225d40112efa5fe9b432db4d..5f6257bf98e4b5c6efaf2e627fa848cff5fc8c2c 100644 (file)
@@ -284,7 +284,7 @@ impl_writeable_tlv_based!(HolderSignedTx, {
 
 /// We use this to track counterparty commitment transactions and htlcs outputs and
 /// use it to generate any justice or 2nd-stage preimage/timeout transactions.
-#[derive(PartialEq)]
+#[derive(Clone, PartialEq)]
 struct CounterpartyCommitmentTransaction {
        counterparty_delayed_payment_base_key: PublicKey,
        counterparty_htlc_base_key: PublicKey,
@@ -350,7 +350,7 @@ impl Readable for CounterpartyCommitmentTransaction {
 /// 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,
@@ -377,7 +377,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 {
        /// HTLC output getting solved by a timeout, at maturation we pass upstream payment source information to solve
        /// inbound HTLC in backward channel. Note, in case of preimage, we pass info to upstream without delay as we can
@@ -482,6 +482,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 cd28314651057d3659ee64dc5f2141935595b96b..8fca682ee1ebd02b8b4879903e2e922bb8d74837 100644 (file)
@@ -44,7 +44,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,
@@ -63,7 +63,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.
@@ -140,6 +140,7 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
 
 /// 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,