Skip to content

Commit 53c8f89

Browse files
committed
Avoid unnecessarily cloning unsigned Transaction when broadcasting
Our `Trusted*` wrappers in `chan_utils` expose additional inner fields by reference. However, because they were not explicitly marked as returning a reference with the wrapped struct's lifetimes, rustc was considering them to return a reference with the wrapper struct's lifetime. This is unnecessarily restrictive, and resulted in the addition of a clone in 9850c58 which we remove here.
1 parent 9850c58 commit 53c8f89

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lightning/src/chain/onchaintx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,8 +1123,8 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
11231123
ret
11241124
}
11251125

1126-
pub(crate) fn get_unsigned_holder_commitment_tx(&self) -> Transaction {
1127-
self.holder_commitment.trust().built_transaction().transaction.clone()
1126+
pub(crate) fn get_unsigned_holder_commitment_tx(&self) -> &Transaction {
1127+
&self.holder_commitment.trust().built_transaction().transaction
11281128
}
11291129

11301130
//TODO: getting lastest holder transactions should be infallible and result in us "force-closing the channel", but we may

lightning/src/ln/chan_utils.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ pub struct DirectedChannelTransactionParameters<'a> {
982982

983983
impl<'a> DirectedChannelTransactionParameters<'a> {
984984
/// Get the channel pubkeys for the broadcaster
985-
pub fn broadcaster_pubkeys(&self) -> &ChannelPublicKeys {
985+
pub fn broadcaster_pubkeys(&self) -> &'a ChannelPublicKeys {
986986
if self.holder_is_broadcaster {
987987
&self.inner.holder_pubkeys
988988
} else {
@@ -991,7 +991,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> {
991991
}
992992

993993
/// Get the channel pubkeys for the countersignatory
994-
pub fn countersignatory_pubkeys(&self) -> &ChannelPublicKeys {
994+
pub fn countersignatory_pubkeys(&self) -> &'a ChannelPublicKeys {
995995
if self.holder_is_broadcaster {
996996
&self.inner.counterparty_parameters.as_ref().unwrap().pubkeys
997997
} else {
@@ -1020,7 +1020,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> {
10201020
}
10211021

10221022
/// Whether to use anchors for this channel
1023-
pub fn channel_type_features(&self) -> &ChannelTypeFeatures {
1023+
pub fn channel_type_features(&self) -> &'a ChannelTypeFeatures {
10241024
&self.inner.channel_type_features
10251025
}
10261026
}
@@ -1279,7 +1279,7 @@ impl<'a> Deref for TrustedClosingTransaction<'a> {
12791279

12801280
impl<'a> TrustedClosingTransaction<'a> {
12811281
/// The pre-built Bitcoin commitment transaction
1282-
pub fn built_transaction(&self) -> &Transaction {
1282+
pub fn built_transaction(&self) -> &'a Transaction {
12831283
&self.inner.built
12841284
}
12851285

@@ -1668,17 +1668,17 @@ impl<'a> TrustedCommitmentTransaction<'a> {
16681668
}
16691669

16701670
/// The pre-built Bitcoin commitment transaction
1671-
pub fn built_transaction(&self) -> &BuiltCommitmentTransaction {
1671+
pub fn built_transaction(&self) -> &'a BuiltCommitmentTransaction {
16721672
&self.inner.built
16731673
}
16741674

16751675
/// The pre-calculated transaction creation public keys.
1676-
pub fn keys(&self) -> &TxCreationKeys {
1676+
pub fn keys(&self) -> &'a TxCreationKeys {
16771677
&self.inner.keys
16781678
}
16791679

16801680
/// Should anchors be used.
1681-
pub fn channel_type_features(&self) -> &ChannelTypeFeatures {
1681+
pub fn channel_type_features(&self) -> &'a ChannelTypeFeatures {
16821682
&self.inner.channel_type_features
16831683
}
16841684

0 commit comments

Comments
 (0)