Skip to content

Commit 1d2a27d

Browse files
authored
Merge pull request #2910 from tnull/2024-02-rustfmt-sign-mod
`rustfmt`: Format `sign` module
2 parents eaf76f6 + 3a199c6 commit 1d2a27d

File tree

7 files changed

+834
-363
lines changed

7 files changed

+834
-363
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,11 @@ impl ChannelTransactionParameters {
852852
self.counterparty_parameters.is_some() && self.funding_outpoint.is_some()
853853
}
854854

855+
/// Whether the channel supports zero-fee HTLC transaction anchors.
856+
pub(crate) fn supports_anchors(&self) -> bool {
857+
self.channel_type_features.supports_anchors_zero_fee_htlc_tx()
858+
}
859+
855860
/// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
856861
/// given that the holder is the broadcaster.
857862
///

lightning/src/sign/ecdsa.rs

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
33
use bitcoin::blockdata::transaction::Transaction;
44

5-
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
6-
use bitcoin::secp256k1::ecdsa::Signature;
75
use bitcoin::secp256k1;
6+
use bitcoin::secp256k1::ecdsa::Signature;
7+
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
88

9-
use crate::util::ser::Writeable;
10-
use crate::ln::PaymentPreimage;
11-
use crate::ln::chan_utils::{HTLCOutputInCommitment, HolderCommitmentTransaction, CommitmentTransaction, ClosingTransaction};
9+
use crate::ln::chan_utils::{
10+
ClosingTransaction, CommitmentTransaction, HTLCOutputInCommitment, HolderCommitmentTransaction,
11+
};
1212
use crate::ln::msgs::UnsignedChannelAnnouncement;
13+
use crate::ln::PaymentPreimage;
14+
use crate::util::ser::Writeable;
1315

1416
#[allow(unused_imports)]
1517
use crate::prelude::*;
@@ -40,8 +42,8 @@ pub trait EcdsaChannelSigner: ChannelSigner {
4042
/// irrelevant or duplicate preimages.
4143
//
4244
// TODO: Document the things someone using this interface should enforce before signing.
43-
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction,
44-
inbound_htlc_preimages: Vec<PaymentPreimage>,
45+
fn sign_counterparty_commitment(
46+
&self, commitment_tx: &CommitmentTransaction, inbound_htlc_preimages: Vec<PaymentPreimage>,
4547
outbound_htlc_preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>,
4648
) -> Result<(Signature, Vec<Signature>), ()>;
4749
/// Creates a signature for a holder's commitment transaction.
@@ -62,15 +64,17 @@ pub trait EcdsaChannelSigner: ChannelSigner {
6264
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
6365
//
6466
// TODO: Document the things someone using this interface should enforce before signing.
65-
fn sign_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction,
66-
secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
67+
fn sign_holder_commitment(
68+
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
69+
) -> Result<Signature, ()>;
6770
/// Same as [`sign_holder_commitment`], but exists only for tests to get access to holder
6871
/// commitment transactions which will be broadcasted later, after the channel has moved on to a
6972
/// newer state. Thus, needs its own method as [`sign_holder_commitment`] may enforce that we
7073
/// only ever get called once.
71-
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
72-
fn unsafe_sign_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction,
73-
secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
74+
#[cfg(any(test, feature = "unsafe_revoked_tx_signing"))]
75+
fn unsafe_sign_holder_commitment(
76+
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
77+
) -> Result<Signature, ()>;
7478
/// Create a signature for the given input in a transaction spending an HTLC transaction output
7579
/// or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
7680
///
@@ -92,8 +96,9 @@ pub trait EcdsaChannelSigner: ChannelSigner {
9296
/// monitor.
9397
///
9498
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
95-
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64,
96-
per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>
99+
fn sign_justice_revoked_output(
100+
&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey,
101+
secp_ctx: &Secp256k1<secp256k1::All>,
97102
) -> Result<Signature, ()>;
98103
/// Create a signature for the given input in a transaction spending a commitment transaction
99104
/// HTLC output when our counterparty broadcasts an old state.
@@ -120,9 +125,10 @@ pub trait EcdsaChannelSigner: ChannelSigner {
120125
/// monitor.
121126
///
122127
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
123-
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64,
124-
per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment,
125-
secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
128+
fn sign_justice_revoked_htlc(
129+
&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey,
130+
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
131+
) -> Result<Signature, ()>;
126132
/// Computes the signature for a commitment transaction's HTLC output used as an input within
127133
/// `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned
128134
/// must be be computed using [`EcdsaSighashType::All`].
@@ -139,8 +145,9 @@ pub trait EcdsaChannelSigner: ChannelSigner {
139145
/// [`EcdsaSighashType::All`]: bitcoin::sighash::EcdsaSighashType::All
140146
/// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
141147
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
142-
fn sign_holder_htlc_transaction(&self, htlc_tx: &Transaction, input: usize,
143-
htlc_descriptor: &HTLCDescriptor, secp_ctx: &Secp256k1<secp256k1::All>
148+
fn sign_holder_htlc_transaction(
149+
&self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor,
150+
secp_ctx: &Secp256k1<secp256k1::All>,
144151
) -> Result<Signature, ()>;
145152
/// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
146153
/// transaction, either offered or received.
@@ -166,15 +173,17 @@ pub trait EcdsaChannelSigner: ChannelSigner {
166173
/// monitor.
167174
///
168175
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
169-
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64,
170-
per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment,
171-
secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
176+
fn sign_counterparty_htlc_transaction(
177+
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
178+
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
179+
) -> Result<Signature, ()>;
172180
/// Create a signature for a (proposed) closing transaction.
173181
///
174182
/// Note that, due to rounding, there may be one "missing" satoshi, and either party may have
175183
/// chosen to forgo their output as dust.
176-
fn sign_closing_transaction(&self, closing_tx: &ClosingTransaction,
177-
secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
184+
fn sign_closing_transaction(
185+
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
186+
) -> Result<Signature, ()>;
178187
/// Computes the signature for a commitment transaction's anchor output used as an
179188
/// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
180189
///
@@ -199,7 +208,7 @@ pub trait EcdsaChannelSigner: ChannelSigner {
199208
///
200209
/// [`NodeSigner::sign_gossip_message`]: crate::sign::NodeSigner::sign_gossip_message
201210
fn sign_channel_announcement_with_funding_key(
202-
&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>
211+
&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
203212
) -> Result<Signature, ()>;
204213
}
205214

0 commit comments

Comments
 (0)