Skip to content

Commit 1b289ed

Browse files
committed
Separate Clone from Sign
Clone requires Sized, which prevents Sign from being a dyn object.
1 parent 4c58f98 commit 1b289ed

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

lightning-persister/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl FilesystemPersister {
143143
}
144144
}
145145

146-
impl<ChannelSigner: Sign + Send + Sync> channelmonitor::Persist<ChannelSigner> for FilesystemPersister {
146+
impl<ChannelSigner: Sign> channelmonitor::Persist<ChannelSigner> for FilesystemPersister {
147147
fn persist_new_channel(&self, funding_txo: OutPoint, monitor: &ChannelMonitor<ChannelSigner>) -> Result<(), ChannelMonitorUpdateErr> {
148148
let filename = format!("{}_{}", funding_txo.txid.to_hex(), funding_txo.index);
149149
util::write_to_file(self.path_to_monitor_data(), filename, monitor)

lightning/src/chain/keysinterface.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl Readable for SpendableOutputDescriptor {
226226
/// of LN security model, orthogonal of key management issues.
227227
// TODO: We should remove Clone by instead requesting a new Sign copy when we create
228228
// ChannelMonitors instead of expecting to clone the one out of the Channel into the monitors.
229-
pub trait Sign : Send+Clone + Writeable {
229+
pub trait BaseSign : Send + Writeable {
230230
/// Gets the per-commitment point for a specific commitment number
231231
///
232232
/// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
@@ -344,6 +344,14 @@ pub trait Sign : Send+Clone + Writeable {
344344
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters);
345345
}
346346

347+
/// A cloneable signer.
348+
///
349+
/// Although we require signers to be cloneable, it may be useful for developers to be able to use
350+
/// signers in an un-sized way, for example as `dyn BaseSign`. Therefore we separate the Clone trait,
351+
/// which implies Sized, into this derived trait.
352+
pub trait Sign: BaseSign + Clone {
353+
}
354+
347355
/// A trait to describe an object which can get user secrets and key material.
348356
pub trait KeysInterface: Send + Sync {
349357
/// A type which implements Sign which will be returned by get_channel_signer.
@@ -549,7 +557,7 @@ impl InMemorySigner {
549557
}
550558
}
551559

552-
impl Sign for InMemorySigner {
560+
impl BaseSign for InMemorySigner {
553561
fn get_per_commitment_point(&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> PublicKey {
554562
let commitment_secret = SecretKey::from_slice(&chan_utils::build_commitment_secret(&self.commitment_seed, idx)).unwrap();
555563
PublicKey::from_secret_key(secp_ctx, &commitment_secret)
@@ -682,6 +690,8 @@ impl Sign for InMemorySigner {
682690
}
683691
}
684692

693+
impl Sign for InMemorySigner {}
694+
685695
impl Writeable for InMemorySigner {
686696
fn write(&self, writer: &mut Writer) -> Result<(), Error> {
687697
self.funding_key.write(writer)?;

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,14 +4792,14 @@ mod tests {
47924792
use bitcoin::hashes::hex::FromHex;
47934793
use hex;
47944794
use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
4795-
use ln::channel::{Channel,Sign,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,HTLCCandidate,HTLCInitiator,TxCreationKeys};
4795+
use ln::channel::{Channel,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,HTLCCandidate,HTLCInitiator,TxCreationKeys};
47964796
use ln::channel::MAX_FUNDING_SATOSHIS;
47974797
use ln::features::InitFeatures;
47984798
use ln::msgs::{ChannelUpdate, DataLossProtect, DecodeError, OptionalField, UnsignedChannelUpdate};
47994799
use ln::chan_utils;
48004800
use ln::chan_utils::{ChannelPublicKeys, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT};
48014801
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
4802-
use chain::keysinterface::{InMemorySigner, KeysInterface};
4802+
use chain::keysinterface::{InMemorySigner, KeysInterface, BaseSign};
48034803
use chain::transaction::OutPoint;
48044804
use util::config::UserConfig;
48054805
use util::enforcing_trait_impls::EnforcingSigner;

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use chain::Watch;
1616
use chain::channelmonitor;
1717
use chain::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
1818
use chain::transaction::OutPoint;
19-
use chain::keysinterface::{Sign, KeysInterface};
19+
use chain::keysinterface::{KeysInterface, BaseSign};
2020
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
2121
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure, BREAKDOWN_TIMEOUT};
2222
use ln::channel::{Channel, ChannelError};

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, HolderCommitmentTransaction, CommitmentTransaction, ChannelTransactionParameters, TrustedCommitmentTransaction};
1111
use ln::{chan_utils, msgs};
12-
use chain::keysinterface::{Sign, InMemorySigner};
12+
use chain::keysinterface::{Sign, InMemorySigner, BaseSign};
1313

1414
use std::cmp;
1515
use std::sync::{Mutex, Arc};
@@ -74,7 +74,7 @@ impl EnforcingSigner {
7474
}
7575
}
7676

77-
impl Sign for EnforcingSigner {
77+
impl BaseSign for EnforcingSigner {
7878
fn get_per_commitment_point(&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> PublicKey {
7979
self.inner.get_per_commitment_point(idx, secp_ctx)
8080
}
@@ -161,6 +161,7 @@ impl Sign for EnforcingSigner {
161161
}
162162
}
163163

164+
impl Sign for EnforcingSigner {}
164165

165166
impl Writeable for EnforcingSigner {
166167
fn write(&self, writer: &mut Writer) -> Result<(), Error> {

0 commit comments

Comments
 (0)