Skip to content

Commit f90f299

Browse files
committed
Require several additional traits to be Clone
In 0.2 we added some places where `Clone` bounds on traits provided additional features. The bindings, of course, cannot capture such optionality as traits have to be concretized first. Thus, we add the `Clone` bounds explicitly on the traits themselves.
1 parent 6017742 commit f90f299

File tree

8 files changed

+57
-17
lines changed

8 files changed

+57
-17
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ struct FilesystemStoreInner {
5353
/// A [`KVStore`] and [`KVStoreSync`] implementation that writes to and reads from the file system.
5454
///
5555
/// [`KVStore`]: lightning::util::persist::KVStore
56+
#[derive(Clone)]
5657
pub struct FilesystemStore {
5758
inner: Arc<FilesystemStoreInner>,
5859

5960
// Version counter to ensure that writes are applied in the correct order. It is assumed that read and list
6061
// operations aren't sensitive to the order of execution.
61-
next_version: AtomicU64,
62+
next_version: Arc<AtomicU64>,
6263
}
6364

6465
impl FilesystemStore {
@@ -68,7 +69,7 @@ impl FilesystemStore {
6869
let tmp_file_counter = AtomicUsize::new(0);
6970
Self {
7071
inner: Arc::new(FilesystemStoreInner { data_dir, tmp_file_counter, locks }),
71-
next_version: AtomicU64::new(1),
72+
next_version: Arc::new(AtomicU64::new(1)),
7273
}
7374
}
7475

lightning/src/chain/chaininterface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64
2828
}
2929

3030
/// An interface to send a transaction to the Bitcoin network.
31-
pub trait BroadcasterInterface {
31+
pub trait BroadcasterInterface : Clone {
3232
/// Sends a list of transactions out to (hopefully) be mined.
3333
/// This only needs to handle the actual broadcasting of transactions, LDK will automatically
3434
/// rebroadcast transactions that haven't made it into a block.

lightning/src/chain/channelmonitor.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,17 @@ where
18321832
payment_hash: Option<PaymentHash>,
18331833
}
18341834

1835+
impl<'a, L: Deref> Clone for WithChannelMonitor<'a, L> where L::Target: Logger {
1836+
fn clone(&self) -> Self {
1837+
Self {
1838+
logger: self.logger,
1839+
peer_id: self.peer_id,
1840+
channel_id: self.channel_id,
1841+
payment_hash: self.payment_hash,
1842+
}
1843+
}
1844+
}
1845+
18351846
impl<'a, L: Deref> Logger for WithChannelMonitor<'a, L>
18361847
where
18371848
L::Target: Logger,

lightning/src/ln/channel.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,17 @@ where
968968
pub payment_hash: Option<PaymentHash>,
969969
}
970970

971+
impl<'a, L: Deref> Clone for WithChannelContext<'a, L> where L::Target: Logger {
972+
fn clone(&self) -> Self {
973+
Self {
974+
logger: self.logger,
975+
peer_id: self.peer_id,
976+
channel_id: self.channel_id,
977+
payment_hash: self.payment_hash,
978+
}
979+
}
980+
}
981+
971982
impl<'a, L: Deref> Logger for WithChannelContext<'a, L>
972983
where
973984
L::Target: Logger,

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,9 +2694,9 @@ pub struct ChannelManager<
26942694
router: R,
26952695

26962696
#[cfg(test)]
2697-
pub(super) flow: OffersMessageFlow<MR, L>,
2697+
pub(super) flow: OffersMessageFlow<MR, Box<L::Target>>,
26982698
#[cfg(not(test))]
2699-
flow: OffersMessageFlow<MR, L>,
2699+
flow: OffersMessageFlow<MR, Box<L::Target>>,
27002700

27012701
/// See `ChannelManager` struct-level documentation for lock order requirements.
27022702
#[cfg(any(test, feature = "_test_utils"))]
@@ -2718,7 +2718,7 @@ pub struct ChannelManager<
27182718
/// See `PendingOutboundPayment` documentation for more info.
27192719
///
27202720
/// See `ChannelManager` struct-level documentation for lock order requirements.
2721-
pending_outbound_payments: OutboundPayments<L>,
2721+
pending_outbound_payments: OutboundPayments<Box<L::Target>>,
27222722

27232723
/// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
27242724
///
@@ -3948,10 +3948,7 @@ where
39483948
fee_est: F, chain_monitor: M, tx_broadcaster: T, router: R, message_router: MR, logger: L,
39493949
entropy_source: ES, node_signer: NS, signer_provider: SP, config: UserConfig,
39503950
params: ChainParameters, current_timestamp: u32,
3951-
) -> Self
3952-
where
3953-
L: Clone,
3954-
{
3951+
) -> Self {
39553952
let mut secp_ctx = Secp256k1::new();
39563953
secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
39573954

@@ -3961,7 +3958,7 @@ where
39613958
let flow = OffersMessageFlow::new(
39623959
ChainHash::using_genesis_block(params.network), params.best_block,
39633960
our_network_pubkey, current_timestamp, expanded_inbound_key,
3964-
node_signer.get_receive_auth_key(), message_router, logger.clone(),
3961+
node_signer.get_receive_auth_key(), message_router, Box::new((*logger).clone()),
39653962
);
39663963

39673964
ChannelManager {
@@ -3976,7 +3973,7 @@ where
39763973
best_block: RwLock::new(params.best_block),
39773974

39783975
outbound_scid_aliases: Mutex::new(new_hash_set()),
3979-
pending_outbound_payments: OutboundPayments::new(new_hash_map(), logger.clone()),
3976+
pending_outbound_payments: OutboundPayments::new(new_hash_map(), Box::new((*logger).clone())),
39803977
forward_htlcs: Mutex::new(new_hash_map()),
39813978
decode_update_add_htlcs: Mutex::new(new_hash_map()),
39823979
claimable_payments: Mutex::new(ClaimablePayments { claimable_payments: new_hash_map(), pending_claiming_payments: new_hash_map() }),
@@ -17151,7 +17148,7 @@ where
1715117148
pending_outbound_payments = Some(outbounds);
1715217149
}
1715317150
let pending_outbounds =
17154-
OutboundPayments::new(pending_outbound_payments.unwrap(), args.logger.clone());
17151+
OutboundPayments::new(pending_outbound_payments.unwrap(), Box::new((*args.logger).clone()));
1715517152

1715617153
for (peer_pubkey, peer_storage) in peer_storage_dir {
1715717154
if let Some(peer_state) = per_peer_state.get_mut(&peer_pubkey) {
@@ -17997,7 +17994,7 @@ where
1799717994
expanded_inbound_key,
1799817995
args.node_signer.get_receive_auth_key(),
1799917996
args.message_router,
18000-
args.logger.clone(),
17997+
Box::new((*args.logger).clone()),
1800117998
)
1800217999
.with_async_payments_offers_cache(async_receive_offer_cache);
1800318000

lightning/src/ln/invoice_utils.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,15 @@ where
600600
details: &'b ChannelDetails,
601601
}
602602

603+
impl<'a, 'b, L: Deref> Clone for WithChannelDetails<'a, 'b, L> where L::Target: Logger {
604+
fn clone(&self) -> Self {
605+
Self {
606+
logger: self.logger,
607+
details: self.details,
608+
}
609+
}
610+
}
611+
603612
impl<'a, 'b, L: Deref> Logger for WithChannelDetails<'a, 'b, L>
604613
where
605614
L::Target: Logger,

lightning/src/util/logger.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl_record!('a, );
159159
impl_record!(, 'a);
160160

161161
/// A trait encapsulating the operations required of a logger.
162-
pub trait Logger {
162+
pub trait Logger: Clone {
163163
/// Logs the [`Record`].
164164
fn log(&self, record: Record);
165165
}
@@ -182,6 +182,17 @@ where
182182
payment_hash: Option<PaymentHash>,
183183
}
184184

185+
impl<'a, L: Deref> Clone for WithContext<'a, L> where L::Target: Logger {
186+
fn clone(&self) -> Self {
187+
WithContext {
188+
logger: self.logger,
189+
peer_id: self.peer_id,
190+
channel_id: self.channel_id,
191+
payment_hash: self.payment_hash,
192+
}
193+
}
194+
}
195+
185196
impl<'a, L: Deref> Logger for WithContext<'a, L>
186197
where
187198
L::Target: Logger,

lightning/src/util/persist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub const MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL: &[u8] = &[0xFF; 2];
142142
///
143143
/// For an asynchronous version of this trait, see [`KVStore`].
144144
// Note that updates to documentation on this trait should be copied to the asynchronous version.
145-
pub trait KVStoreSync {
145+
pub trait KVStoreSync : Clone {
146146
/// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
147147
/// `key`.
148148
///
@@ -339,7 +339,7 @@ pub trait KVStore {
339339

340340
/// Provides additional interface methods that are required for [`KVStore`]-to-[`KVStore`]
341341
/// data migration.
342-
pub trait MigratableKVStore: KVStoreSync {
342+
pub trait MigratableKVStore: KVStoreSync + Clone {
343343
/// Returns *all* known keys as a list of `primary_namespace`, `secondary_namespace`, `key` tuples.
344344
///
345345
/// This is useful for migrating data from [`KVStoreSync`] implementation to [`KVStoreSync`]

0 commit comments

Comments
 (0)