Skip to content

Commit

Permalink
Add ChannelSigner::spend_holder_anchor_input
Browse files Browse the repository at this point in the history
  • Loading branch information
tankyleo committed Dec 26, 2024
1 parent cab22c2 commit deb5267
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lightning/src/events/bump_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,7 @@ where
anchor_tx = self.utxo_source.sign_psbt(anchor_psbt)?;

let signer = anchor_descriptor.derive_channel_signer(&self.signer_provider);
let anchor_sig = signer.sign_holder_anchor_input(&anchor_tx, 0, &self.secp)?;
anchor_tx.input[0].witness = anchor_descriptor.tx_input_witness(&anchor_sig);
anchor_tx = signer.spend_holder_anchor_input(&anchor_tx, 0, &self.secp)?;

#[cfg(debug_assertions)] {
let signed_tx_weight = anchor_tx.weight().to_wu();
Expand Down
17 changes: 17 additions & 0 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,11 @@ pub trait ChannelSigner {

/// Get the counterparty anchor output of a commit tx
fn get_counterparty_anchor_txout(&self, is_holder_tx: bool) -> Option<TxOut>;

/// Spend the holder anchor input
fn spend_holder_anchor_input(
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Transaction, ()>;
}

/// Specifies the recipient of an invoice.
Expand Down Expand Up @@ -1891,6 +1896,18 @@ impl ChannelSigner for InMemorySigner {
None
}
}

fn spend_holder_anchor_input(
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Transaction, ()> {
let anchor_sig =
EcdsaChannelSigner::sign_holder_anchor_input(self, anchor_tx, input_idx, secp_ctx)?;
let mut tx = anchor_tx.clone();
let funding_pubkey = self.pubkeys().funding_pubkey;
let witness = chan_utils::build_anchor_input_witness(&funding_pubkey, &anchor_sig);
tx.input[0].witness = witness;
Ok(tx)
}
}

const MISSING_PARAMS_ERR: &'static str =
Expand Down
6 changes: 6 additions & 0 deletions lightning/src/util/test_channel_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ impl ChannelSigner for TestChannelSigner {
fn get_counterparty_anchor_txout(&self, is_holder_tx: bool) -> Option<TxOut> {
self.inner.get_counterparty_anchor_txout(is_holder_tx)
}

fn spend_holder_anchor_input(
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Transaction, ()> {
self.inner.spend_holder_anchor_input(anchor_tx, input_idx, secp_ctx)
}
}

impl EcdsaChannelSigner for TestChannelSigner {
Expand Down

0 comments on commit deb5267

Please sign in to comment.