Skip to content

Commit ff9bc05

Browse files
committed
Introduce BaseSign
1 parent 4d20627 commit ff9bc05

File tree

10 files changed

+55
-48
lines changed

10 files changed

+55
-48
lines changed

background-processor/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl BackgroundProcessor {
6464
/// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable
6565
/// [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager
6666
pub fn start<PM, Signer, M, T, K, F, L>(persist_manager: PM, manager: Arc<ChannelManager<Signer, Arc<M>, Arc<T>, Arc<K>, Arc<F>, Arc<L>>>, logger: Arc<L>) -> Self
67-
where Signer: 'static + Sign+Clone,
67+
where Signer: 'static + Sign,
6868
M: 'static + chain::Watch<Signer>,
6969
T: 'static + BroadcasterInterface,
7070
K: 'static + KeysInterface<Signer=Signer>,
@@ -291,7 +291,7 @@ mod tests {
291291
fn test_persist_error() {
292292
// Test that if we encounter an error during manager persistence, the thread panics.
293293
fn persist_manager<Signer, M, T, K, F, L>(_data: &ChannelManager<Signer, Arc<M>, Arc<T>, Arc<K>, Arc<F>, Arc<L>>) -> Result<(), std::io::Error>
294-
where Signer: 'static + Sign+Clone,
294+
where Signer: 'static + Sign,
295295
M: 'static + chain::Watch<Signer>,
296296
T: 'static + BroadcasterInterface,
297297
K: 'static + KeysInterface<Signer=Signer>,

lightning-persister/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ pub struct FilesystemPersister {
5353
path_to_channel_data: String,
5454
}
5555

56-
impl<Signer: Sign+Clone> DiskWriteable for ChannelMonitor<Signer> {
56+
impl<Signer: Sign> DiskWriteable for ChannelMonitor<Signer> {
5757
fn write_to_file(&self, file: &mut fs::File) -> Result<(), Error> {
5858
file.write_all(self.encode().as_slice())
5959
}
6060
}
6161

62-
impl<Signer: Sign+Clone, M, T, K, F, L> DiskWriteable for ChannelManager<Signer, Arc<M>, Arc<T>, Arc<K>, Arc<F>, Arc<L>>
62+
impl<Signer: Sign, M, T, K, F, L> DiskWriteable for ChannelManager<Signer, Arc<M>, Arc<T>, Arc<K>, Arc<F>, Arc<L>>
6363
where M: chain::Watch<Signer>,
6464
T: BroadcasterInterface,
6565
K: KeysInterface<Signer=Signer>,
@@ -97,7 +97,7 @@ impl FilesystemPersister {
9797
data_dir: String,
9898
manager: &ChannelManager<Signer, Arc<M>, Arc<T>, Arc<K>, Arc<F>, Arc<L>>
9999
) -> Result<(), std::io::Error>
100-
where Signer: Sign+Clone,
100+
where Signer: Sign,
101101
M: chain::Watch<Signer>,
102102
T: BroadcasterInterface,
103103
K: KeysInterface<Signer=Signer>,
@@ -143,7 +143,7 @@ impl FilesystemPersister {
143143
}
144144
}
145145

146-
impl<ChannelSigner: Sign+Clone> 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/chainmonitor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use std::ops::Deref;
4949
///
5050
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
5151
/// [module-level documentation]: crate::chain::chainmonitor
52-
pub struct ChainMonitor<ChannelSigner: Sign+Clone, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
52+
pub struct ChainMonitor<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
5353
where C::Target: chain::Filter,
5454
T::Target: BroadcasterInterface,
5555
F::Target: FeeEstimator,
@@ -65,7 +65,7 @@ pub struct ChainMonitor<ChannelSigner: Sign+Clone, C: Deref, T: Deref, F: Deref,
6565
persister: P,
6666
}
6767

68-
impl<ChannelSigner: Sign+Clone, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> ChainMonitor<ChannelSigner, C, T, F, L, P>
68+
impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> ChainMonitor<ChannelSigner, C, T, F, L, P>
6969
where C::Target: chain::Filter,
7070
T::Target: BroadcasterInterface,
7171
F::Target: FeeEstimator,
@@ -147,7 +147,7 @@ where C::Target: chain::Filter,
147147
}
148148
}
149149

150-
impl<ChannelSigner: Sign+Clone, C: Deref + Send + Sync, T: Deref + Send + Sync, F: Deref + Send + Sync, L: Deref + Send + Sync, P: Deref + Send + Sync>
150+
impl<ChannelSigner: Sign, C: Deref + Send + Sync, T: Deref + Send + Sync, F: Deref + Send + Sync, L: Deref + Send + Sync, P: Deref + Send + Sync>
151151
chain::Listen for ChainMonitor<ChannelSigner, C, T, F, L, P>
152152
where
153153
ChannelSigner: Sign,
@@ -167,7 +167,7 @@ where
167167
}
168168
}
169169

170-
impl<ChannelSigner: Sign+Clone, C: Deref + Sync + Send, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send, P: Deref + Sync + Send>
170+
impl<ChannelSigner: Sign, C: Deref + Sync + Send, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send, P: Deref + Sync + Send>
171171
chain::Watch<ChannelSigner> for ChainMonitor<ChannelSigner, C, T, F, L, P>
172172
where C::Target: chain::Filter,
173173
T::Target: BroadcasterInterface,
@@ -252,7 +252,7 @@ where C::Target: chain::Filter,
252252
}
253253
}
254254

255-
impl<ChannelSigner: Sign+Clone, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> events::EventsProvider for ChainMonitor<ChannelSigner, C, T, F, L, P>
255+
impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> events::EventsProvider for ChainMonitor<ChannelSigner, C, T, F, L, P>
256256
where C::Target: chain::Filter,
257257
T::Target: BroadcasterInterface,
258258
F::Target: FeeEstimator,

lightning/src/chain/channelmonitor.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,14 @@ impl Readable for ChannelMonitorUpdateStep {
621621
/// the "reorg path" (ie disconnecting blocks until you find a common ancestor from both the
622622
/// returned block hash and the the current chain and then reconnecting blocks to get to the
623623
/// best chain) upon deserializing the object!
624-
pub struct ChannelMonitor<Signer: Sign + Clone> {
624+
pub struct ChannelMonitor<Signer: Sign> {
625625
#[cfg(test)]
626626
pub(crate) inner: Mutex<ChannelMonitorImpl<Signer>>,
627627
#[cfg(not(test))]
628628
inner: Mutex<ChannelMonitorImpl<Signer>>,
629629
}
630630

631-
pub(crate) struct ChannelMonitorImpl<Signer: Sign + Clone> {
631+
pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
632632
latest_update_id: u64,
633633
commitment_transaction_number_obscure_factor: u64,
634634

@@ -726,7 +726,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign + Clone> {
726726
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))]
727727
/// Used only in testing and fuzztarget to check serialization roundtrips don't change the
728728
/// underlying object
729-
impl<Signer: Sign+Clone> PartialEq for ChannelMonitor<Signer> {
729+
impl<Signer: Sign> PartialEq for ChannelMonitor<Signer> {
730730
fn eq(&self, other: &Self) -> bool {
731731
let inner = self.inner.lock().unwrap();
732732
let other = other.inner.lock().unwrap();
@@ -737,7 +737,7 @@ impl<Signer: Sign+Clone> PartialEq for ChannelMonitor<Signer> {
737737
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))]
738738
/// Used only in testing and fuzztarget to check serialization roundtrips don't change the
739739
/// underlying object
740-
impl<Signer: Sign+Clone> PartialEq for ChannelMonitorImpl<Signer> {
740+
impl<Signer: Sign> PartialEq for ChannelMonitorImpl<Signer> {
741741
fn eq(&self, other: &Self) -> bool {
742742
if self.latest_update_id != other.latest_update_id ||
743743
self.commitment_transaction_number_obscure_factor != other.commitment_transaction_number_obscure_factor ||
@@ -777,7 +777,7 @@ impl<Signer: Sign+Clone> PartialEq for ChannelMonitorImpl<Signer> {
777777
}
778778
}
779779

780-
impl<Signer: Sign+Clone> Writeable for ChannelMonitor<Signer> {
780+
impl<Signer: Sign> Writeable for ChannelMonitor<Signer> {
781781
fn write(&self, writer: &mut Writer) -> Result<(), Error> {
782782
//TODO: We still write out all the serialization here manually instead of using the fancy
783783
//serialization framework we have, we should migrate things over to it.
@@ -788,7 +788,7 @@ impl<Signer: Sign+Clone> Writeable for ChannelMonitor<Signer> {
788788
}
789789
}
790790

791-
impl<Signer: Sign+Clone> Writeable for ChannelMonitorImpl<Signer> {
791+
impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
792792
fn write(&self, writer: &mut Writer) -> Result<(), Error> {
793793
self.latest_update_id.write(writer)?;
794794

@@ -970,7 +970,7 @@ impl<Signer: Sign+Clone> Writeable for ChannelMonitorImpl<Signer> {
970970
}
971971
}
972972

973-
impl<Signer: Sign+Clone> ChannelMonitor<Signer> {
973+
impl<Signer: Sign> ChannelMonitor<Signer> {
974974
pub(crate) fn new(secp_ctx: Secp256k1<secp256k1::All>, keys: Signer, shutdown_pubkey: &PublicKey,
975975
on_counterparty_tx_csv: u16, destination_script: &Script, funding_info: (OutPoint, Script),
976976
channel_parameters: &ChannelTransactionParameters,
@@ -1283,7 +1283,7 @@ impl<Signer: Sign+Clone> ChannelMonitor<Signer> {
12831283
}
12841284
}
12851285

1286-
impl<Signer: Sign+Clone> ChannelMonitorImpl<Signer> {
1286+
impl<Signer: Sign> ChannelMonitorImpl<Signer> {
12871287
/// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither
12881288
/// needed by holder commitment transactions HTCLs nor by counterparty ones. Unless we haven't already seen
12891289
/// counterparty commitment transaction's secret, they are de facto pruned (we can use revocation key).
@@ -2445,7 +2445,7 @@ impl<Signer: Sign+Clone> ChannelMonitorImpl<Signer> {
24452445
/// transaction and losing money. This is a risk because previous channel states
24462446
/// are toxic, so it's important that whatever channel state is persisted is
24472447
/// kept up-to-date.
2448-
pub trait Persist<ChannelSigner: Sign+Clone>: Send + Sync {
2448+
pub trait Persist<ChannelSigner: Sign>: Send + Sync {
24492449
/// Persist a new channel's data. The data can be stored any way you want, but
24502450
/// the identifier provided by Rust-Lightning is the channel's outpoint (and
24512451
/// it is up to you to maintain a correct mapping between the outpoint and the
@@ -2481,7 +2481,7 @@ pub trait Persist<ChannelSigner: Sign+Clone>: Send + Sync {
24812481
fn update_persisted_channel(&self, id: OutPoint, update: &ChannelMonitorUpdate, data: &ChannelMonitor<ChannelSigner>) -> Result<(), ChannelMonitorUpdateErr>;
24822482
}
24832483

2484-
impl<Signer: Sign+Clone, T: Deref, F: Deref, L: Deref> chain::Listen for (ChannelMonitor<Signer>, T, F, L)
2484+
impl<Signer: Sign, T: Deref, F: Deref, L: Deref> chain::Listen for (ChannelMonitor<Signer>, T, F, L)
24852485
where
24862486
T::Target: BroadcasterInterface,
24872487
F::Target: FeeEstimator,
@@ -2499,7 +2499,7 @@ where
24992499

25002500
const MAX_ALLOC_SIZE: usize = 64*1024;
25012501

2502-
impl<'a, Signer: Sign+Clone, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
2502+
impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
25032503
for (BlockHash, ChannelMonitor<Signer>) {
25042504
fn read<R: ::std::io::Read>(reader: &mut R, keys_manager: &'a K) -> Result<Self, DecodeError> {
25052505
macro_rules! unwrap_obj {

lightning/src/chain/keysinterface.rs

Lines changed: 9 additions & 3 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 + 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,10 +344,14 @@ pub trait Sign : Send + Writeable {
344344
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters);
345345
}
346346

347+
/// XXX
348+
pub trait Sign: BaseSign + Clone {
349+
}
350+
347351
/// A trait to describe an object which can get user secrets and key material.
348352
pub trait KeysInterface: Send + Sync {
349353
/// A type which implements Sign which will be returned by get_channel_signer.
350-
type Signer : Sign+Clone;
354+
type Signer : Sign;
351355

352356
/// Get node secret key (aka node_id or network_key).
353357
///
@@ -549,7 +553,7 @@ impl InMemorySigner {
549553
}
550554
}
551555

552-
impl Sign for InMemorySigner {
556+
impl BaseSign for InMemorySigner {
553557
fn get_per_commitment_point(&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> PublicKey {
554558
let commitment_secret = SecretKey::from_slice(&chan_utils::build_commitment_secret(&self.commitment_seed, idx)).unwrap();
555559
PublicKey::from_secret_key(secp_ctx, &commitment_secret)
@@ -682,6 +686,8 @@ impl Sign for InMemorySigner {
682686
}
683687
}
684688

689+
impl Sign for InMemorySigner {}
690+
685691
impl Writeable for InMemorySigner {
686692
fn write(&self, writer: &mut Writer) -> Result<(), Error> {
687693
self.funding_key.write(writer)?;

lightning/src/chain/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub trait Listen {
7878
/// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
7979
/// [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr
8080
/// [`PermanentFailure`]: channelmonitor::ChannelMonitorUpdateErr::PermanentFailure
81-
pub trait Watch<ChannelSigner: Sign+Clone>: Send + Sync {
81+
pub trait Watch<ChannelSigner: Sign>: Send + Sync {
8282
/// Watches a channel identified by `funding_txo` using `monitor`.
8383
///
8484
/// Implementations are responsible for watching the chain for the funding transaction along

lightning/src/ln/channel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub struct CounterpartyForwardingInfo {
303303
//
304304
// Holder designates channel data owned for the benefice of the user client.
305305
// Counterparty designates channel data owned by the another channel participant entity.
306-
pub(super) struct Channel<Signer: Sign+Clone> {
306+
pub(super) struct Channel<Signer: Sign> {
307307
config: ChannelConfig,
308308

309309
user_id: u64,
@@ -489,7 +489,7 @@ macro_rules! secp_check {
489489
};
490490
}
491491

492-
impl<Signer: Sign+Clone> Channel<Signer> {
492+
impl<Signer: Sign> Channel<Signer> {
493493
// Convert constants + channel value to limits:
494494
fn get_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
495495
channel_value_satoshis * 1000 / 10 //TODO
@@ -4305,7 +4305,7 @@ impl Readable for InboundHTLCRemovalReason {
43054305
}
43064306
}
43074307

4308-
impl<Signer: Sign+Clone> Writeable for Channel<Signer> {
4308+
impl<Signer: Sign> Writeable for Channel<Signer> {
43094309
fn write(&self, writer: &mut Writer) -> Result<(), ::std::io::Error> {
43104310
// Note that we write out as if remove_uncommitted_htlcs_and_mark_paused had just been
43114311
// called but include holding cell updates (and obviously we don't modify self).
@@ -4502,7 +4502,7 @@ impl<Signer: Sign+Clone> Writeable for Channel<Signer> {
45024502
}
45034503

45044504
const MAX_ALLOC_SIZE: usize = 64*1024;
4505-
impl<'a, Signer: Sign+Clone, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4505+
impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
45064506
where K::Target: KeysInterface<Signer = Signer> {
45074507
fn read<R : ::std::io::Read>(reader: &mut R, keys_source: &'a K) -> Result<Self, DecodeError> {
45084508
let _ver: u8 = Readable::read(reader)?;
@@ -4762,14 +4762,14 @@ mod tests {
47624762
use bitcoin::hashes::hex::FromHex;
47634763
use hex;
47644764
use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
4765-
use ln::channel::{Channel,Sign,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,HTLCCandidate,HTLCInitiator,TxCreationKeys};
4765+
use ln::channel::{Channel,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,HTLCCandidate,HTLCInitiator,TxCreationKeys};
47664766
use ln::channel::MAX_FUNDING_SATOSHIS;
47674767
use ln::features::InitFeatures;
47684768
use ln::msgs::{ChannelUpdate, DataLossProtect, DecodeError, OptionalField, UnsignedChannelUpdate};
47694769
use ln::chan_utils;
47704770
use ln::chan_utils::{ChannelPublicKeys, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT};
47714771
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
4772-
use chain::keysinterface::{InMemorySigner, KeysInterface};
4772+
use chain::keysinterface::{InMemorySigner, KeysInterface, BaseSign};
47734773
use chain::transaction::OutPoint;
47744774
use util::config::UserConfig;
47754775
use util::enforcing_trait_impls::EnforcingSigner;

0 commit comments

Comments
 (0)