Skip to content

Let ChannelSigner set and spend LN scriptpubkeys #3512

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

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a775008
Add `ChannelSigner::get_channel_parameters`
tankyleo Jan 13, 2025
42d65da
Let `ChannelSigner` set `to_remote` script pubkey
tankyleo Dec 7, 2024
857ab29
Let `ChannelSigner` set `to_local` script pubkey
tankyleo Dec 13, 2024
8283838
Let `ChannelSigner` set htlc tx script pubkey
tankyleo Dec 13, 2024
2e8b3f8
Let `ChannelSigner` build the punishment witness
tankyleo Dec 15, 2024
70b9df6
Ask `ChannelSigner` the weight of the punishment witness
tankyleo Dec 20, 2024
907684b
Remove unused `RevokedOutput` fields
tankyleo Dec 20, 2024
4234663
Let `ChannelSigner` build the htlc punishment witness
tankyleo Dec 20, 2024
b0a20d8
Remove unused `RevokedHTLCOutput` fields
tankyleo Dec 20, 2024
2868379
Ask `ChannelSigner` the weight of the htlc punishment witness
tankyleo Dec 20, 2024
77d5e24
Let `ChannelSigner` build the counterparty htlc sweep witness
tankyleo Dec 20, 2024
563efd5
Remove unused `CounterpartyOfferedHTLCOutput` fields
tankyleo Dec 20, 2024
b7a37ca
Remove unused `CounterpartyReceivedHTLCOutput` fields
tankyleo Dec 20, 2024
35901b5
Ask `ChannelSigner` the weight of counterparty htlc output sweeps
tankyleo Dec 22, 2024
b88a2ac
Let `sign_holder_commitment` build the commitment tx witness
tankyleo Dec 22, 2024
4de22fa
Let `unsafe_sign_holder_commitment` build the commitment tx witness
tankyleo Dec 22, 2024
4c96432
Let `sign_holder_htlc_transaction` build the htlc tx witness
tankyleo Dec 22, 2024
9687da3
Relax `EcdsaChannelSigner` to `ChannelSigner` in `mod chain`
tankyleo Dec 22, 2024
0e3227e
Ask `ChannelSigner` the weight of the htlc tx input
tankyleo Dec 23, 2024
a9c3844
Let `ChannelSigner` set commit tx htlc output script pubkey
tankyleo Dec 24, 2024
ec40758
Remove `TxCreationKeys` from `CommitmentTransaction::internal_build_o…
tankyleo Dec 24, 2024
207b70f
Let `ChannelSigner` set commit tx anchor output script pubkey
tankyleo Jan 14, 2025
557a754
Let `ChannelSigner` build the anchor sweep witness
tankyleo Dec 25, 2024
7ec1efc
Ask `ChannelSigner` the weight of the anchor tx input
tankyleo Jan 6, 2025
f95a7c0
Mark `PackageSolvingData::HolderHTLCOutput` weight unreachable
tankyleo Jan 7, 2025
a606d03
Remove unused `HolderFundingOutput` fields
tankyleo Jan 10, 2025
03d6a40
Add `ChannelTransactionParameters::channel_type_features`
tankyleo Jan 13, 2025
fbc1b5c
Delete `EcdsaChannelSigner::sign_justice_revoked_output`
tankyleo Jan 14, 2025
5f27ad7
Delete `EcdsaChannelSigner::sign_justice_revoked_htlc`
tankyleo Jan 14, 2025
fc2a45e
Delete `EcdsaChannelSigner::sign_counterparty_htlc_transaction`
tankyleo Jan 14, 2025
c9050a5
Delete `EcdsaChannelSigner::sign_holder_anchor_input`
tankyleo Jan 14, 2025
c20b8fc
Add `ChannelSigner::get_to_remote_witness_weight`
tankyleo Jan 16, 2025
3ab0293
Add `ChannelSigner::get_to_local_witness_weight`
tankyleo Jan 16, 2025
61fc584
Delete `StaticPaymentOutputDescriptor::witness_script`
tankyleo Jan 16, 2025
2ed352c
Delete `HTLCDescriptor::tx_input_witness`
tankyleo Jan 16, 2025
fd1a47a
Delete `TrustedCommitmentTransaction::get_htlc_sigs`
tankyleo Jan 18, 2025
6ea5589
Move commitment tx sig validation from `FundedChannel` to `ChannelSig…
tankyleo Jan 18, 2025
e2f73a5
Move htlc tx sig validation from `FundedChannel` to `ChannelSigner`
tankyleo Jan 18, 2025
ccf9824
Delete `InitialRemoteCommitmentReceiver::check_counterparty_commitmen…
tankyleo Jan 18, 2025
5fc079b
Call `validate_counterparty_revocation` on `ChannelSigner` directly
tankyleo Jan 18, 2025
79f1ca8
f: Make id of revoked outputs in HTLC transactions generic over HTLC …
tankyleo Jan 27, 2025
0c2b44b
f: Make Counterparty{*}HTLCOutput ser backwards compatible
tankyleo Jan 20, 2025
7484c3b
f: Use `ChannelSigner::get_anchor_txout` to id the anchor output
tankyleo Jan 27, 2025
9ab6948
Remove generic from `CommitmentTransaction::internal_build_outputs`
tankyleo Jan 27, 2025
bb16170
Let `ChannelSigner` build the outputs of the commit tx
tankyleo Jan 27, 2025
09cbb8b
Let `ChannelSigner` build the inputs of the commit tx
tankyleo Jan 27, 2025
22c9a5c
Let `ChannelSigner` build the commit tx
tankyleo Jan 27, 2025
9d05b78
Add `ChannelSigner::validate_closing_signature`
tankyleo Feb 9, 2025
b06273b
Add `ChannelSigner::build_signed_closing_transaction`
tankyleo Feb 9, 2025
e6e4acf
Add `ChannelSigner::provide_counterparty_parameters`
tankyleo Feb 13, 2025
70788e0
Add `ChannelSigner::provide_funding_outpoint`
tankyleo Feb 13, 2025
77b6fd4
Provide counterparty parameters in accept channel checks
tankyleo Feb 13, 2025
e711b26
Add `ChannelSigner::get_funding_spk`
tankyleo Feb 13, 2025
bb13acb
Add `ChannelContext::get_funding_spk`
tankyleo Feb 13, 2025
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
Prev Previous commit
Next Next commit
Add ChannelSigner::get_to_remote_witness_weight
  • Loading branch information
tankyleo committed Jan 20, 2025
commit c20b8fc9bf16d5c38aa4e8fb7142062bdae5e539
2 changes: 2 additions & 0 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4611,6 +4611,7 @@ impl<Signer: ChannelSigner> ChannelMonitorImpl<Signer> {

fn get_spendable_outputs(&self, tx: &Transaction) -> Vec<SpendableOutputDescriptor> {
let mut spendable_outputs = Vec::new();
let signer = &self.onchain_tx_handler.signer;
for (i, outp) in tx.output.iter().enumerate() {
if outp.script_pubkey == self.destination_script {
spendable_outputs.push(SpendableOutputDescriptor::StaticOutput {
Expand Down Expand Up @@ -4640,6 +4641,7 @@ impl<Signer: ChannelSigner> ChannelMonitorImpl<Signer> {
channel_keys_id: self.channel_keys_id,
channel_value_satoshis: self.channel_value_satoshis,
channel_transaction_parameters: Some(self.onchain_tx_handler.channel_transaction_parameters.clone()),
witness_weight: signer.get_to_remote_witness_weight(),
}));
}
if self.shutdown_script.as_ref() == Some(&outp.script_pubkey) {
Expand Down
42 changes: 27 additions & 15 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ pub struct StaticPaymentOutputDescriptor {
///
/// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
pub channel_transaction_parameters: Option<ChannelTransactionParameters>,
/// Witness weight
pub witness_weight: u64,
}

impl StaticPaymentOutputDescriptor {
Expand All @@ -184,27 +186,22 @@ impl StaticPaymentOutputDescriptor {
}
})
}

/// The maximum length a well-formed witness spending one of these should have.
/// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
/// shorter.
pub fn max_witness_length(&self) -> u64 {
if self.channel_transaction_parameters.as_ref().map_or(false, |p| p.supports_anchors()) {
let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ +
1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */;
1 /* num witness items */ + 1 /* sig push */ + 73 /* sig including sighash flag */ +
1 /* witness script push */ + witness_script_weight
} else {
P2WPKH_WITNESS_WEIGHT
}
}
}
impl_writeable_tlv_based!(StaticPaymentOutputDescriptor, {
(0, outpoint, required),
(2, output, required),
(4, channel_keys_id, required),
(6, channel_value_satoshis, required),
(7, channel_transaction_parameters, option),
// Don't break downgrades ?
(9, witness_weight, (default_value,
if channel_transaction_parameters.as_ref().map_or(false, |p: &ChannelTransactionParameters| p.supports_anchors()) {
let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ + 1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */;
1 /* num witness items */ + 1 /* sig push */ + 73 /* sig including sighash flag */ + 1 /* witness script push */ + witness_script_weight
} else {
P2WPKH_WITNESS_WEIGHT
})
),
});

/// Describes the necessary information to spend a spendable output.
Expand Down Expand Up @@ -468,7 +465,7 @@ impl SpendableOutputDescriptor {
sequence,
witness: Witness::new(),
});
witness_weight += descriptor.max_witness_length();
witness_weight += descriptor.witness_weight;
#[cfg(feature = "grind_signatures")]
{
// Guarantees a low R signature
Expand Down Expand Up @@ -1051,6 +1048,21 @@ pub trait ChannelSigner {
fn get_holder_anchor_input_witness_weight(&self) -> u64 {
ANCHOR_INPUT_WITNESS_WEIGHT
}

/// Gets the weight of the witness that spends a `to_remote` output
fn get_to_remote_witness_weight(&self) -> u64 {
// The maximum length a well-formed witness spending one of these should have.
// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
// shorter.
if self.get_channel_parameters().as_ref().map_or(false, |p| p.supports_anchors()) {
let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ +
1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */;
1 /* num witness items */ + 1 /* sig push */ + 73 /* sig including sighash flag */ +
1 /* witness script push */ + witness_script_weight
} else {
P2WPKH_WITNESS_WEIGHT
}
}
}

/// Specifies the recipient of an invoice.
Expand Down