Skip to content

Avoid unnecessarily cloning unsigned Transaction when broadcasting #2582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,8 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
ret
}

pub(crate) fn get_unsigned_holder_commitment_tx(&self) -> Transaction {
self.holder_commitment.trust().built_transaction().transaction.clone()
pub(crate) fn get_unsigned_holder_commitment_tx(&self) -> &Transaction {
&self.holder_commitment.trust().built_transaction().transaction
}

//TODO: getting lastest holder transactions should be infallible and result in us "force-closing the channel", but we may
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ pub struct DirectedChannelTransactionParameters<'a> {

impl<'a> DirectedChannelTransactionParameters<'a> {
/// Get the channel pubkeys for the broadcaster
pub fn broadcaster_pubkeys(&self) -> &ChannelPublicKeys {
pub fn broadcaster_pubkeys(&self) -> &'a ChannelPublicKeys {
if self.holder_is_broadcaster {
&self.inner.holder_pubkeys
} else {
Expand All @@ -991,7 +991,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> {
}

/// Get the channel pubkeys for the countersignatory
pub fn countersignatory_pubkeys(&self) -> &ChannelPublicKeys {
pub fn countersignatory_pubkeys(&self) -> &'a ChannelPublicKeys {
if self.holder_is_broadcaster {
&self.inner.counterparty_parameters.as_ref().unwrap().pubkeys
} else {
Expand Down Expand Up @@ -1020,7 +1020,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> {
}

/// Whether to use anchors for this channel
pub fn channel_type_features(&self) -> &ChannelTypeFeatures {
pub fn channel_type_features(&self) -> &'a ChannelTypeFeatures {
&self.inner.channel_type_features
}
}
Expand Down Expand Up @@ -1279,7 +1279,7 @@ impl<'a> Deref for TrustedClosingTransaction<'a> {

impl<'a> TrustedClosingTransaction<'a> {
/// The pre-built Bitcoin commitment transaction
pub fn built_transaction(&self) -> &Transaction {
pub fn built_transaction(&self) -> &'a Transaction {
&self.inner.built
}

Expand Down Expand Up @@ -1668,17 +1668,17 @@ impl<'a> TrustedCommitmentTransaction<'a> {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this apply to Txid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not returned by reference, its returned by copy, so there's no need to add the lifetime.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I meant its equivalent to clone right ? 😅
But yeah since its already like that, nbd i guess.


/// The pre-built Bitcoin commitment transaction
pub fn built_transaction(&self) -> &BuiltCommitmentTransaction {
pub fn built_transaction(&self) -> &'a BuiltCommitmentTransaction {
&self.inner.built
}

/// The pre-calculated transaction creation public keys.
pub fn keys(&self) -> &TxCreationKeys {
pub fn keys(&self) -> &'a TxCreationKeys {
&self.inner.keys
}

/// Should anchors be used.
pub fn channel_type_features(&self) -> &ChannelTypeFeatures {
pub fn channel_type_features(&self) -> &'a ChannelTypeFeatures {
&self.inner.channel_type_features
}

Expand Down