Skip to content

Commit 021717e

Browse files
author
Antoine Riard
committed
Extend ChannelKeys API with sign_cpfp
A bumping CPFP must spend the holder anchor output which is encumbered by the funding public key. An external signer can thus verify that the CPFP feerate transaction is "reasonable".
1 parent 0769f7e commit 021717e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,17 @@ pub trait BaseSign {
309309
/// chosen to forgo their output as dust.
310310
fn sign_closing_transaction(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
311311

312+
/// Create a signature for a Child-Pay-For-Parent transaction.
313+
///
314+
/// Such a transaction is used to unilaterally bump a commitment transaction feerate when this
315+
/// is one isn't confirming quickly.
316+
///
317+
/// Input index is the position of the spending input committed by this BIP 143 signature.
318+
///
319+
/// Spent amount is the value of the output spent by this input committed by this BIP 143
320+
/// signature.
321+
fn sign_cpfp(&self, cpfp: &Transaction, input_index: usize, spent_amount: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
322+
312323
/// Signs a channel announcement message with our funding key, proving it comes from one
313324
/// of the channel participants.
314325
///
@@ -667,6 +678,13 @@ impl BaseSign for InMemorySigner {
667678
Ok(secp_ctx.sign(&msghash, &self.funding_key))
668679
}
669680

681+
fn sign_cpfp(&self, cpfp_tx: &Transaction, input_index: usize, spent_amount: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
682+
let anchor_redeemscript = chan_utils::get_anchor_redeemscript(&self.pubkeys().funding_pubkey);
683+
let mut sighash_parts = bip143::SigHashCache::new(cpfp_tx);
684+
let sighash = hash_to_message!(&sighash_parts.signature_hash(input_index, &anchor_redeemscript, spent_amount, SigHashType::All)[..]);
685+
Ok(secp_ctx.sign(&sighash, &self.funding_key))
686+
}
687+
670688
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters) {
671689
assert!(self.channel_parameters.is_none(), "Acceptance already noted");
672690
assert!(channel_parameters.is_populated(), "Channel parameters must be fully populated");

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ impl BaseSign for EnforcingSigner {
160160
Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap())
161161
}
162162

163+
fn sign_cpfp(&self, cpfp_tx: &Transaction, input_index: usize, spent_amount: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
164+
Ok(self.inner.sign_cpfp(cpfp_tx, input_index, spent_amount, secp_ctx).unwrap())
165+
}
166+
163167
fn sign_channel_announcement(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
164168
self.inner.sign_channel_announcement(msg, secp_ctx)
165169
}

0 commit comments

Comments
 (0)