X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fchannelmonitor.rs;h=6daab991922f160be0d4062f5cb392545f69789e;hb=b5902fecd40574fe4017a5b173fd2576b0d595f9;hp=f91af7cc66cd3c9a3ea70b07c9cb5aef82bcca86;hpb=a491200f96760315fa420e433d0e60c4e6503a97;p=rust-lightning diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index f91af7cc..6daab991 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -256,7 +256,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, @@ -310,7 +310,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, @@ -346,7 +346,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 { /// An outbound HTLC failing after a transaction is confirmed. Used /// * when an outbound HTLC output is spent by us after the HTLC timed out @@ -566,7 +566,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: u32, /// Only set if the HTLC claim was ours using a payment preimage @@ -601,6 +601,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, @@ -965,6 +972,13 @@ impl Writeable for ChannelMonitorImpl { } impl ChannelMonitor { + /// For lockorder enforcement purposes, we need to have a single site which constructs the + /// `inner` mutex, otherwise cases where we lock two monitors at the same time (eg in our + /// PartialEq implementation) we may decide a lockorder violation has occurred. + fn from_impl(imp: ChannelMonitorImpl) -> Self { + ChannelMonitor { inner: Mutex::new(imp) } + } + pub(crate) fn new(secp_ctx: Secp256k1, keys: Signer, shutdown_script: Option