Skip to content

Commit d026259

Browse files
benthecarmanTheBlueMatt
authored andcommitted
Impl clone for ChannelMonitor
This gives people more freedom with the channel monitors. For Mutiny this would be nice for us to be able to create copies of them and pass aorund in memory without having to serialize until we actually want to. Originally by benthecarman <[email protected]> Small bugfix from Matt Corallo <[email protected]>
1 parent e13ff10 commit d026259

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lightning/src/chain/channelmonitor.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl HolderSignedTx {
280280

281281
/// We use this to track static counterparty commitment transaction data and to generate any
282282
/// justice or 2nd-stage preimage/timeout transactions.
283-
#[derive(PartialEq, Eq)]
283+
#[derive(Clone, PartialEq, Eq)]
284284
struct CounterpartyCommitmentParameters {
285285
counterparty_delayed_payment_base_key: PublicKey,
286286
counterparty_htlc_base_key: PublicKey,
@@ -334,7 +334,7 @@ impl Readable for CounterpartyCommitmentParameters {
334334
/// observed, as well as the transaction causing it.
335335
///
336336
/// Used to determine when the on-chain event can be considered safe from a chain reorganization.
337-
#[derive(PartialEq, Eq)]
337+
#[derive(Clone, PartialEq, Eq)]
338338
struct OnchainEventEntry {
339339
txid: Txid,
340340
height: u32,
@@ -377,7 +377,7 @@ type CommitmentTxCounterpartyOutputInfo = Option<(u32, u64)>;
377377

378378
/// Upon discovering of some classes of onchain tx by ChannelMonitor, we may have to take actions on it
379379
/// once they mature to enough confirmations (ANTI_REORG_DELAY)
380-
#[derive(PartialEq, Eq)]
380+
#[derive(Clone, PartialEq, Eq)]
381381
enum OnchainEvent {
382382
/// An outbound HTLC failing after a transaction is confirmed. Used
383383
/// * when an outbound HTLC output is spent by us after the HTLC timed out
@@ -682,7 +682,7 @@ impl Balance {
682682
}
683683

684684
/// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY.
685-
#[derive(PartialEq, Eq)]
685+
#[derive(Clone, PartialEq, Eq)]
686686
struct IrrevocablyResolvedHTLC {
687687
commitment_tx_output_idx: Option<u32>,
688688
/// The txid of the transaction which resolved the HTLC, this may be a commitment (if the HTLC
@@ -750,7 +750,14 @@ pub struct ChannelMonitor<Signer: WriteableEcdsaChannelSigner> {
750750
pub(super) inner: Mutex<ChannelMonitorImpl<Signer>>,
751751
}
752752

753-
#[derive(PartialEq)]
753+
impl<Signer: WriteableEcdsaChannelSigner> Clone for ChannelMonitor<Signer> where Signer: Clone {
754+
fn clone(&self) -> Self {
755+
let inner = self.inner.lock().unwrap().clone();
756+
ChannelMonitor::from_impl(inner)
757+
}
758+
}
759+
760+
#[derive(Clone, PartialEq)]
754761
pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
755762
latest_update_id: u64,
756763
commitment_transaction_number_obscure_factor: u64,

lightning/src/chain/onchaintx.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
5050
/// transaction causing it.
5151
///
5252
/// Used to determine when the on-chain event can be considered safe from a chain reorganization.
53-
#[derive(PartialEq, Eq)]
53+
#[derive(Clone, PartialEq, Eq)]
5454
struct OnchainEventEntry {
5555
txid: Txid,
5656
height: u32,
@@ -70,7 +70,7 @@ impl OnchainEventEntry {
7070

7171
/// Events for claims the [`OnchainTxHandler`] has generated. Once the events are considered safe
7272
/// from a chain reorg, the [`OnchainTxHandler`] will act accordingly.
73-
#[derive(PartialEq, Eq)]
73+
#[derive(Clone, PartialEq, Eq)]
7474
enum OnchainEvent {
7575
/// A pending request has been claimed by a transaction spending the exact same set of outpoints
7676
/// as the request. This claim can either be ours or from the counterparty. Once the claiming
@@ -172,6 +172,7 @@ impl Writeable for Option<Vec<Option<(usize, Signature)>>> {
172172
}
173173

174174
/// The claim commonly referred to as the pre-signed second-stage HTLC transaction.
175+
#[derive(Clone, PartialEq, Eq)]
175176
pub(crate) struct ExternalHTLCClaim {
176177
pub(crate) commitment_txid: Txid,
177178
pub(crate) per_commitment_number: u64,
@@ -182,6 +183,7 @@ pub(crate) struct ExternalHTLCClaim {
182183

183184
// Represents the different types of claims for which events are yielded externally to satisfy said
184185
// claims.
186+
#[derive(Clone, PartialEq, Eq)]
185187
pub(crate) enum ClaimEvent {
186188
/// Event yielded to signal that the commitment transaction fee must be bumped to claim any
187189
/// encumbered funds and proceed to HTLC resolution, if any HTLCs exist.
@@ -211,6 +213,7 @@ pub(crate) enum OnchainClaim {
211213

212214
/// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and
213215
/// do RBF bumping if possible.
216+
#[derive(Clone)]
214217
pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
215218
destination_script: Script,
216219
holder_commitment: HolderCommitmentTransaction,

0 commit comments

Comments
 (0)