2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
#[rustfmt::skip]
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_secret[31]]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
let secret_key = SecretKey::from_slice(&[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
unreachable!()
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
unreachable!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1347,7 +1347,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
let counterparty_payment_script = chan_utils::get_counterparty_payment_script(
&channel_parameters.channel_type_features, &keys.pubkeys().payment_point
&channel_parameters.channel_type_features, &keys.pubkeys().payment_basepoint
);

let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
Expand DownExpand Up@@ -3298,7 +3298,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand All@@ -3322,7 +3322,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for htlc in htlcs {
htlc_descriptors.push(HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand DownExpand Up@@ -4971,9 +4971,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
if onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() &&
counterparty_payment_script.is_p2wpkh()
{
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
let payment_basepoint = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_basepoint;
counterparty_payment_script =
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_basepoint).to_p2wsh();
}

Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
Expand DownExpand Up@@ -5243,7 +5243,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
};
Expand DownExpand Up@@ -5495,7 +5495,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())),
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1199,7 +1199,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
let htlc_descriptor = HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: self.channel_value_satoshis,
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
transaction_parameters: self.channel_transaction_parameters.clone(),
},
commitment_txid: trusted_tx.txid(),
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ impl AnchorDescriptor {
{
let mut signer = signer_provider.derive_channel_signer(
self.channel_derivation_parameters.value_satoshis,
self.channel_derivation_parameters.keys_id,
self.channel_derivation_parameters.channel_keys_id,
);
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
signer
Expand DownExpand Up@@ -791,7 +791,7 @@ where

let mut signers = BTreeMap::new();
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.channel_keys_id)
.or_insert_with(|| htlc_descriptor.derive_channel_signer(&self.signer_provider));
let htlc_sig = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
let witness_script = htlc_descriptor.witness_script(&self.secp);
Expand DownExpand Up@@ -955,7 +955,7 @@ mod tests {
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
channel_keys_id: [42; 32],
transaction_parameters: ChannelTransactionParameters::test_dummy(),
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
if extra_closing_signed {
let node_1_closing_signed_2_bad = {
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
let channel_keys_id = [42u8; 32];
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
counterparty_script.into(), funding_outpoint);
Expand Down
38 changes: 19 additions & 19 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -478,7 +478,7 @@ pub struct ChannelPublicKeys {
/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
/// spendable primary channel balance on the broadcaster's commitment transaction. This key is
/// static across every commitment transaction.
pub payment_point: PublicKey,
pub payment_basepoint: PublicKey,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this elsewhere but IMO we should fix this in the spec, not here. The "base" in the "basepoint"s refer to the fact that its extended with the per_commitment_point to build a new point for each state. Since static_remotekey (which is now "ASSUMED" in the spec, and not described) its no longer used to derive a key but rather simply a key used as-is. The spec needs updating to remove references to its use as a base key.

/// The base point which is used (with derive_public_key) to derive a per-commitment payment
/// public key which receives non-HTLC-encumbered funds which are only available for spending
/// after some delay (or can be claimed via the revocation path).
Expand All@@ -491,7 +491,7 @@ pub struct ChannelPublicKeys {
impl_writeable_tlv_based!(ChannelPublicKeys, {
(0, funding_pubkey, required),
(2, revocation_basepoint, required),
(4, payment_point, required),
(4, payment_basepoint, required),
(6, delayed_payment_basepoint, required),
(8, htlc_basepoint, required),
});
Expand DownExpand Up@@ -550,11 +550,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay

/// Returns the script for the counterparty's output on a holder's commitment transaction based on
/// the channel type.
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_basepoint: &PublicKey) -> ScriptBuf {
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(payment_key).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_basepoint.serialize()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm quite confused by this. The point of calling it a "key" and not a "basepoint" is that the script is paid directly to the key (in this case as a P2WPKH) rather than incorporating the per_commitment_secret/per_commitment_point when building t the output.

}
}

Expand DownExpand Up@@ -816,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features

/// Gets the witnessScript for the to_remote output when anchors are enabled.
#[inline]
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_basepoint: &PublicKey) -> ScriptBuf {
Builder::new()
.push_slice(payment_point.serialize())
.push_slice(payment_basepoint.serialize())
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
.push_int(1)
.push_opcode(opcodes::all::OP_CSV)
Expand DownExpand Up@@ -933,7 +933,7 @@ impl ChannelTransactionParameters {
let dummy_keys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
revocation_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
payment_point: PublicKey::from_slice(&[2; 33]).unwrap(),
payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap(),
delayed_payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
htlc_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
};
Expand DownExpand Up@@ -1119,7 +1119,7 @@ impl HolderCommitmentTransaction {
let channel_pubkeys = ChannelPublicKeys {
funding_pubkey: dummy_key.clone(),
revocation_basepoint: RevocationBasepoint::from(dummy_key),
payment_point: dummy_key.clone(),
payment_basepoint: dummy_key.clone(),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(dummy_key.clone()),
htlc_basepoint: HtlcBasepoint::from(dummy_key.clone())
};
Expand DownExpand Up@@ -1515,9 +1515,9 @@ impl CommitmentTransaction {

if to_countersignatory_value_sat > Amount::ZERO {
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into())
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_basepoint.serialize()).into())
};
txouts.push((
TxOut {
Expand DownExpand Up@@ -1608,8 +1608,8 @@ impl CommitmentTransaction {
let broadcaster_pubkeys = channel_parameters.broadcaster_pubkeys();
let countersignatory_pubkeys = channel_parameters.countersignatory_pubkeys();
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor(
&broadcaster_pubkeys.payment_point,
&countersignatory_pubkeys.payment_point,
&broadcaster_pubkeys.payment_basepoint,
&countersignatory_pubkeys.payment_basepoint,
channel_parameters.is_outbound(),
);

Expand DownExpand Up@@ -1974,13 +1974,13 @@ mod tests {
// Generate broadcaster and counterparty outputs
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 2);
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_basepoint), Network::Testnet).script_pubkey());

// Generate broadcaster and counterparty outputs as well as two anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 4);
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_basepoint).to_p2wsh());

// Generate broadcaster output and anchor
let tx = builder.build(3000, 0);
Expand DownExpand Up@@ -2015,9 +2015,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
"0020510277dd095f7e3a7a46efbd9de3a49f527b5b32f4acc70f144dc5c928529520");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
"0020b981c1ea6c0d0c3971e89800312d6fd5564872f22040771d1555605edf5b1cfe");

// Generate broadcaster output and received and offered HTLC outputs, with anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
Expand All@@ -2027,9 +2027,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
"002078193f615fc1b050814d866d6c46097f9d19fdae0dbc4905b2b35f427c8d0662");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
"0020ac28c4778c24e79755cedc11e7feb638630aa74478781ae7c809aed06e6bd325");
}

#[test]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
#[rustfmt::skip]
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_secret[31]]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
let secret_key = SecretKey::from_slice(&[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
unreachable!()
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
unreachable!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1347,7 +1347,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
let counterparty_payment_script = chan_utils::get_counterparty_payment_script(
&channel_parameters.channel_type_features, &keys.pubkeys().payment_point
&channel_parameters.channel_type_features, &keys.pubkeys().payment_basepoint
);

let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
Expand DownExpand Up@@ -3298,7 +3298,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand All@@ -3322,7 +3322,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for htlc in htlcs {
htlc_descriptors.push(HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand DownExpand Up@@ -4971,9 +4971,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
if onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() &&
counterparty_payment_script.is_p2wpkh()
{
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
let payment_basepoint = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_basepoint;
counterparty_payment_script =
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_basepoint).to_p2wsh();
}

Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
Expand DownExpand Up@@ -5243,7 +5243,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
};
Expand DownExpand Up@@ -5495,7 +5495,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())),
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1199,7 +1199,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
let htlc_descriptor = HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: self.channel_value_satoshis,
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
transaction_parameters: self.channel_transaction_parameters.clone(),
},
commitment_txid: trusted_tx.txid(),
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ impl AnchorDescriptor {
{
let mut signer = signer_provider.derive_channel_signer(
self.channel_derivation_parameters.value_satoshis,
self.channel_derivation_parameters.keys_id,
self.channel_derivation_parameters.channel_keys_id,
);
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
signer
Expand DownExpand Up@@ -791,7 +791,7 @@ where

let mut signers = BTreeMap::new();
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.channel_keys_id)
.or_insert_with(|| htlc_descriptor.derive_channel_signer(&self.signer_provider));
let htlc_sig = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
let witness_script = htlc_descriptor.witness_script(&self.secp);
Expand DownExpand Up@@ -955,7 +955,7 @@ mod tests {
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
channel_keys_id: [42; 32],
transaction_parameters: ChannelTransactionParameters::test_dummy(),
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
if extra_closing_signed {
let node_1_closing_signed_2_bad = {
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
let channel_keys_id = [42u8; 32];
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
counterparty_script.into(), funding_outpoint);
Expand Down
38 changes: 19 additions & 19 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -478,7 +478,7 @@ pub struct ChannelPublicKeys {
/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
/// spendable primary channel balance on the broadcaster's commitment transaction. This key is
/// static across every commitment transaction.
pub payment_point: PublicKey,
pub payment_basepoint: PublicKey,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this elsewhere but IMO we should fix this in the spec, not here. The "base" in the "basepoint"s refer to the fact that its extended with the per_commitment_point to build a new point for each state. Since static_remotekey (which is now "ASSUMED" in the spec, and not described) its no longer used to derive a key but rather simply a key used as-is. The spec needs updating to remove references to its use as a base key.

/// The base point which is used (with derive_public_key) to derive a per-commitment payment
/// public key which receives non-HTLC-encumbered funds which are only available for spending
/// after some delay (or can be claimed via the revocation path).
Expand All@@ -491,7 +491,7 @@ pub struct ChannelPublicKeys {
impl_writeable_tlv_based!(ChannelPublicKeys, {
(0, funding_pubkey, required),
(2, revocation_basepoint, required),
(4, payment_point, required),
(4, payment_basepoint, required),
(6, delayed_payment_basepoint, required),
(8, htlc_basepoint, required),
});
Expand DownExpand Up@@ -550,11 +550,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay

/// Returns the script for the counterparty's output on a holder's commitment transaction based on
/// the channel type.
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_basepoint: &PublicKey) -> ScriptBuf {
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(payment_key).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_basepoint.serialize()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm quite confused by this. The point of calling it a "key" and not a "basepoint" is that the script is paid directly to the key (in this case as a P2WPKH) rather than incorporating the per_commitment_secret/per_commitment_point when building t the output.

}
}

Expand DownExpand Up@@ -816,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features

/// Gets the witnessScript for the to_remote output when anchors are enabled.
#[inline]
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_basepoint: &PublicKey) -> ScriptBuf {
Builder::new()
.push_slice(payment_point.serialize())
.push_slice(payment_basepoint.serialize())
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
.push_int(1)
.push_opcode(opcodes::all::OP_CSV)
Expand DownExpand Up@@ -933,7 +933,7 @@ impl ChannelTransactionParameters {
let dummy_keys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
revocation_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
payment_point: PublicKey::from_slice(&[2; 33]).unwrap(),
payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap(),
delayed_payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
htlc_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
};
Expand DownExpand Up@@ -1119,7 +1119,7 @@ impl HolderCommitmentTransaction {
let channel_pubkeys = ChannelPublicKeys {
funding_pubkey: dummy_key.clone(),
revocation_basepoint: RevocationBasepoint::from(dummy_key),
payment_point: dummy_key.clone(),
payment_basepoint: dummy_key.clone(),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(dummy_key.clone()),
htlc_basepoint: HtlcBasepoint::from(dummy_key.clone())
};
Expand DownExpand Up@@ -1515,9 +1515,9 @@ impl CommitmentTransaction {

if to_countersignatory_value_sat > Amount::ZERO {
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into())
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_basepoint.serialize()).into())
};
txouts.push((
TxOut {
Expand DownExpand Up@@ -1608,8 +1608,8 @@ impl CommitmentTransaction {
let broadcaster_pubkeys = channel_parameters.broadcaster_pubkeys();
let countersignatory_pubkeys = channel_parameters.countersignatory_pubkeys();
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor(
&broadcaster_pubkeys.payment_point,
&countersignatory_pubkeys.payment_point,
&broadcaster_pubkeys.payment_basepoint,
&countersignatory_pubkeys.payment_basepoint,
channel_parameters.is_outbound(),
);

Expand DownExpand Up@@ -1974,13 +1974,13 @@ mod tests {
// Generate broadcaster and counterparty outputs
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 2);
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_basepoint), Network::Testnet).script_pubkey());

// Generate broadcaster and counterparty outputs as well as two anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 4);
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_basepoint).to_p2wsh());

// Generate broadcaster output and anchor
let tx = builder.build(3000, 0);
Expand DownExpand Up@@ -2015,9 +2015,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
"0020510277dd095f7e3a7a46efbd9de3a49f527b5b32f4acc70f144dc5c928529520");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
"0020b981c1ea6c0d0c3971e89800312d6fd5564872f22040771d1555605edf5b1cfe");

// Generate broadcaster output and received and offered HTLC outputs, with anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
Expand All@@ -2027,9 +2027,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
"002078193f615fc1b050814d866d6c46097f9d19fdae0dbc4905b2b35f427c8d0662");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
"0020ac28c4778c24e79755cedc11e7feb638630aa74478781ae7c809aed06e6bd325");
}

#[test]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
#[rustfmt::skip]
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_secret[31]]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
let secret_key = SecretKey::from_slice(&[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
unreachable!()
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
unreachable!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1347,7 +1347,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
let counterparty_payment_script = chan_utils::get_counterparty_payment_script(
&channel_parameters.channel_type_features, &keys.pubkeys().payment_point
&channel_parameters.channel_type_features, &keys.pubkeys().payment_basepoint
);

let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
Expand DownExpand Up@@ -3298,7 +3298,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand All@@ -3322,7 +3322,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for htlc in htlcs {
htlc_descriptors.push(HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand DownExpand Up@@ -4971,9 +4971,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
if onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() &&
counterparty_payment_script.is_p2wpkh()
{
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
let payment_basepoint = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_basepoint;
counterparty_payment_script =
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_basepoint).to_p2wsh();
}

Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
Expand DownExpand Up@@ -5243,7 +5243,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
};
Expand DownExpand Up@@ -5495,7 +5495,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())),
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1199,7 +1199,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
let htlc_descriptor = HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: self.channel_value_satoshis,
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
transaction_parameters: self.channel_transaction_parameters.clone(),
},
commitment_txid: trusted_tx.txid(),
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ impl AnchorDescriptor {
{
let mut signer = signer_provider.derive_channel_signer(
self.channel_derivation_parameters.value_satoshis,
self.channel_derivation_parameters.keys_id,
self.channel_derivation_parameters.channel_keys_id,
);
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
signer
Expand DownExpand Up@@ -791,7 +791,7 @@ where

let mut signers = BTreeMap::new();
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.channel_keys_id)
.or_insert_with(|| htlc_descriptor.derive_channel_signer(&self.signer_provider));
let htlc_sig = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
let witness_script = htlc_descriptor.witness_script(&self.secp);
Expand DownExpand Up@@ -955,7 +955,7 @@ mod tests {
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
channel_keys_id: [42; 32],
transaction_parameters: ChannelTransactionParameters::test_dummy(),
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
if extra_closing_signed {
let node_1_closing_signed_2_bad = {
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
let channel_keys_id = [42u8; 32];
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
counterparty_script.into(), funding_outpoint);
Expand Down
38 changes: 19 additions & 19 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -478,7 +478,7 @@ pub struct ChannelPublicKeys {
/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
/// spendable primary channel balance on the broadcaster's commitment transaction. This key is
/// static across every commitment transaction.
pub payment_point: PublicKey,
pub payment_basepoint: PublicKey,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this elsewhere but IMO we should fix this in the spec, not here. The "base" in the "basepoint"s refer to the fact that its extended with the per_commitment_point to build a new point for each state. Since static_remotekey (which is now "ASSUMED" in the spec, and not described) its no longer used to derive a key but rather simply a key used as-is. The spec needs updating to remove references to its use as a base key.

/// The base point which is used (with derive_public_key) to derive a per-commitment payment
/// public key which receives non-HTLC-encumbered funds which are only available for spending
/// after some delay (or can be claimed via the revocation path).
Expand All@@ -491,7 +491,7 @@ pub struct ChannelPublicKeys {
impl_writeable_tlv_based!(ChannelPublicKeys, {
(0, funding_pubkey, required),
(2, revocation_basepoint, required),
(4, payment_point, required),
(4, payment_basepoint, required),
(6, delayed_payment_basepoint, required),
(8, htlc_basepoint, required),
});
Expand DownExpand Up@@ -550,11 +550,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay

/// Returns the script for the counterparty's output on a holder's commitment transaction based on
/// the channel type.
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_basepoint: &PublicKey) -> ScriptBuf {
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(payment_key).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_basepoint.serialize()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm quite confused by this. The point of calling it a "key" and not a "basepoint" is that the script is paid directly to the key (in this case as a P2WPKH) rather than incorporating the per_commitment_secret/per_commitment_point when building t the output.

}
}

Expand DownExpand Up@@ -816,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features

/// Gets the witnessScript for the to_remote output when anchors are enabled.
#[inline]
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_basepoint: &PublicKey) -> ScriptBuf {
Builder::new()
.push_slice(payment_point.serialize())
.push_slice(payment_basepoint.serialize())
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
.push_int(1)
.push_opcode(opcodes::all::OP_CSV)
Expand DownExpand Up@@ -933,7 +933,7 @@ impl ChannelTransactionParameters {
let dummy_keys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
revocation_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
payment_point: PublicKey::from_slice(&[2; 33]).unwrap(),
payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap(),
delayed_payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
htlc_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
};
Expand DownExpand Up@@ -1119,7 +1119,7 @@ impl HolderCommitmentTransaction {
let channel_pubkeys = ChannelPublicKeys {
funding_pubkey: dummy_key.clone(),
revocation_basepoint: RevocationBasepoint::from(dummy_key),
payment_point: dummy_key.clone(),
payment_basepoint: dummy_key.clone(),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(dummy_key.clone()),
htlc_basepoint: HtlcBasepoint::from(dummy_key.clone())
};
Expand DownExpand Up@@ -1515,9 +1515,9 @@ impl CommitmentTransaction {

if to_countersignatory_value_sat > Amount::ZERO {
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into())
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_basepoint.serialize()).into())
};
txouts.push((
TxOut {
Expand DownExpand Up@@ -1608,8 +1608,8 @@ impl CommitmentTransaction {
let broadcaster_pubkeys = channel_parameters.broadcaster_pubkeys();
let countersignatory_pubkeys = channel_parameters.countersignatory_pubkeys();
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor(
&broadcaster_pubkeys.payment_point,
&countersignatory_pubkeys.payment_point,
&broadcaster_pubkeys.payment_basepoint,
&countersignatory_pubkeys.payment_basepoint,
channel_parameters.is_outbound(),
);

Expand DownExpand Up@@ -1974,13 +1974,13 @@ mod tests {
// Generate broadcaster and counterparty outputs
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 2);
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_basepoint), Network::Testnet).script_pubkey());

// Generate broadcaster and counterparty outputs as well as two anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 4);
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_basepoint).to_p2wsh());

// Generate broadcaster output and anchor
let tx = builder.build(3000, 0);
Expand DownExpand Up@@ -2015,9 +2015,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
"0020510277dd095f7e3a7a46efbd9de3a49f527b5b32f4acc70f144dc5c928529520");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
"0020b981c1ea6c0d0c3971e89800312d6fd5564872f22040771d1555605edf5b1cfe");

// Generate broadcaster output and received and offered HTLC outputs, with anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
Expand All@@ -2027,9 +2027,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
"002078193f615fc1b050814d866d6c46097f9d19fdae0dbc4905b2b35f427c8d0662");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
"0020ac28c4778c24e79755cedc11e7feb638630aa74478781ae7c809aed06e6bd325");
}

#[test]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
#[rustfmt::skip]
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_secret[31]]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
let secret_key = SecretKey::from_slice(&[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
unreachable!()
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
unreachable!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1347,7 +1347,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
let counterparty_payment_script = chan_utils::get_counterparty_payment_script(
&channel_parameters.channel_type_features, &keys.pubkeys().payment_point
&channel_parameters.channel_type_features, &keys.pubkeys().payment_basepoint
);

let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
Expand DownExpand Up@@ -3298,7 +3298,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand All@@ -3322,7 +3322,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for htlc in htlcs {
htlc_descriptors.push(HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand DownExpand Up@@ -4971,9 +4971,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
if onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() &&
counterparty_payment_script.is_p2wpkh()
{
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
let payment_basepoint = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_basepoint;
counterparty_payment_script =
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_basepoint).to_p2wsh();
}

Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
Expand DownExpand Up@@ -5243,7 +5243,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
};
Expand DownExpand Up@@ -5495,7 +5495,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())),
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1199,7 +1199,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
let htlc_descriptor = HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: self.channel_value_satoshis,
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
transaction_parameters: self.channel_transaction_parameters.clone(),
},
commitment_txid: trusted_tx.txid(),
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ impl AnchorDescriptor {
{
let mut signer = signer_provider.derive_channel_signer(
self.channel_derivation_parameters.value_satoshis,
self.channel_derivation_parameters.keys_id,
self.channel_derivation_parameters.channel_keys_id,
);
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
signer
Expand DownExpand Up@@ -791,7 +791,7 @@ where

let mut signers = BTreeMap::new();
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.channel_keys_id)
.or_insert_with(|| htlc_descriptor.derive_channel_signer(&self.signer_provider));
let htlc_sig = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
let witness_script = htlc_descriptor.witness_script(&self.secp);
Expand DownExpand Up@@ -955,7 +955,7 @@ mod tests {
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
channel_keys_id: [42; 32],
transaction_parameters: ChannelTransactionParameters::test_dummy(),
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
if extra_closing_signed {
let node_1_closing_signed_2_bad = {
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
let channel_keys_id = [42u8; 32];
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
counterparty_script.into(), funding_outpoint);
Expand Down
38 changes: 19 additions & 19 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -478,7 +478,7 @@ pub struct ChannelPublicKeys {
/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
/// spendable primary channel balance on the broadcaster's commitment transaction. This key is
/// static across every commitment transaction.
pub payment_point: PublicKey,
pub payment_basepoint: PublicKey,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this elsewhere but IMO we should fix this in the spec, not here. The "base" in the "basepoint"s refer to the fact that its extended with the per_commitment_point to build a new point for each state. Since static_remotekey (which is now "ASSUMED" in the spec, and not described) its no longer used to derive a key but rather simply a key used as-is. The spec needs updating to remove references to its use as a base key.

/// The base point which is used (with derive_public_key) to derive a per-commitment payment
/// public key which receives non-HTLC-encumbered funds which are only available for spending
/// after some delay (or can be claimed via the revocation path).
Expand All@@ -491,7 +491,7 @@ pub struct ChannelPublicKeys {
impl_writeable_tlv_based!(ChannelPublicKeys, {
(0, funding_pubkey, required),
(2, revocation_basepoint, required),
(4, payment_point, required),
(4, payment_basepoint, required),
(6, delayed_payment_basepoint, required),
(8, htlc_basepoint, required),
});
Expand DownExpand Up@@ -550,11 +550,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay

/// Returns the script for the counterparty's output on a holder's commitment transaction based on
/// the channel type.
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_basepoint: &PublicKey) -> ScriptBuf {
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(payment_key).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_basepoint.serialize()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm quite confused by this. The point of calling it a "key" and not a "basepoint" is that the script is paid directly to the key (in this case as a P2WPKH) rather than incorporating the per_commitment_secret/per_commitment_point when building t the output.

}
}

Expand DownExpand Up@@ -816,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features

/// Gets the witnessScript for the to_remote output when anchors are enabled.
#[inline]
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_basepoint: &PublicKey) -> ScriptBuf {
Builder::new()
.push_slice(payment_point.serialize())
.push_slice(payment_basepoint.serialize())
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
.push_int(1)
.push_opcode(opcodes::all::OP_CSV)
Expand DownExpand Up@@ -933,7 +933,7 @@ impl ChannelTransactionParameters {
let dummy_keys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
revocation_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
payment_point: PublicKey::from_slice(&[2; 33]).unwrap(),
payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap(),
delayed_payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
htlc_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
};
Expand DownExpand Up@@ -1119,7 +1119,7 @@ impl HolderCommitmentTransaction {
let channel_pubkeys = ChannelPublicKeys {
funding_pubkey: dummy_key.clone(),
revocation_basepoint: RevocationBasepoint::from(dummy_key),
payment_point: dummy_key.clone(),
payment_basepoint: dummy_key.clone(),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(dummy_key.clone()),
htlc_basepoint: HtlcBasepoint::from(dummy_key.clone())
};
Expand DownExpand Up@@ -1515,9 +1515,9 @@ impl CommitmentTransaction {

if to_countersignatory_value_sat > Amount::ZERO {
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into())
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_basepoint.serialize()).into())
};
txouts.push((
TxOut {
Expand DownExpand Up@@ -1608,8 +1608,8 @@ impl CommitmentTransaction {
let broadcaster_pubkeys = channel_parameters.broadcaster_pubkeys();
let countersignatory_pubkeys = channel_parameters.countersignatory_pubkeys();
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor(
&broadcaster_pubkeys.payment_point,
&countersignatory_pubkeys.payment_point,
&broadcaster_pubkeys.payment_basepoint,
&countersignatory_pubkeys.payment_basepoint,
channel_parameters.is_outbound(),
);

Expand DownExpand Up@@ -1974,13 +1974,13 @@ mod tests {
// Generate broadcaster and counterparty outputs
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 2);
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_basepoint), Network::Testnet).script_pubkey());

// Generate broadcaster and counterparty outputs as well as two anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 4);
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_basepoint).to_p2wsh());

// Generate broadcaster output and anchor
let tx = builder.build(3000, 0);
Expand DownExpand Up@@ -2015,9 +2015,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
"0020510277dd095f7e3a7a46efbd9de3a49f527b5b32f4acc70f144dc5c928529520");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
"0020b981c1ea6c0d0c3971e89800312d6fd5564872f22040771d1555605edf5b1cfe");

// Generate broadcaster output and received and offered HTLC outputs, with anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
Expand All@@ -2027,9 +2027,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
"002078193f615fc1b050814d866d6c46097f9d19fdae0dbc4905b2b35f427c8d0662");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
"0020ac28c4778c24e79755cedc11e7feb638630aa74478781ae7c809aed06e6bd325");
}

#[test]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
#[rustfmt::skip]
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_secret[31]]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
let secret_key = SecretKey::from_slice(&[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
unreachable!()
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
unreachable!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1347,7 +1347,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
let counterparty_payment_script = chan_utils::get_counterparty_payment_script(
&channel_parameters.channel_type_features, &keys.pubkeys().payment_point
&channel_parameters.channel_type_features, &keys.pubkeys().payment_basepoint
);

let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
Expand DownExpand Up@@ -3298,7 +3298,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand All@@ -3322,7 +3322,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for htlc in htlcs {
htlc_descriptors.push(HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand DownExpand Up@@ -4971,9 +4971,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
if onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() &&
counterparty_payment_script.is_p2wpkh()
{
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
let payment_basepoint = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_basepoint;
counterparty_payment_script =
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_basepoint).to_p2wsh();
}

Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
Expand DownExpand Up@@ -5243,7 +5243,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
};
Expand DownExpand Up@@ -5495,7 +5495,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())),
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1199,7 +1199,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
let htlc_descriptor = HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: self.channel_value_satoshis,
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
transaction_parameters: self.channel_transaction_parameters.clone(),
},
commitment_txid: trusted_tx.txid(),
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ impl AnchorDescriptor {
{
let mut signer = signer_provider.derive_channel_signer(
self.channel_derivation_parameters.value_satoshis,
self.channel_derivation_parameters.keys_id,
self.channel_derivation_parameters.channel_keys_id,
);
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
signer
Expand DownExpand Up@@ -791,7 +791,7 @@ where

let mut signers = BTreeMap::new();
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.channel_keys_id)
.or_insert_with(|| htlc_descriptor.derive_channel_signer(&self.signer_provider));
let htlc_sig = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
let witness_script = htlc_descriptor.witness_script(&self.secp);
Expand DownExpand Up@@ -955,7 +955,7 @@ mod tests {
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
channel_keys_id: [42; 32],
transaction_parameters: ChannelTransactionParameters::test_dummy(),
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
if extra_closing_signed {
let node_1_closing_signed_2_bad = {
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
let channel_keys_id = [42u8; 32];
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
counterparty_script.into(), funding_outpoint);
Expand Down
38 changes: 19 additions & 19 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -478,7 +478,7 @@ pub struct ChannelPublicKeys {
/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
/// spendable primary channel balance on the broadcaster's commitment transaction. This key is
/// static across every commitment transaction.
pub payment_point: PublicKey,
pub payment_basepoint: PublicKey,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this elsewhere but IMO we should fix this in the spec, not here. The "base" in the "basepoint"s refer to the fact that its extended with the per_commitment_point to build a new point for each state. Since static_remotekey (which is now "ASSUMED" in the spec, and not described) its no longer used to derive a key but rather simply a key used as-is. The spec needs updating to remove references to its use as a base key.

/// The base point which is used (with derive_public_key) to derive a per-commitment payment
/// public key which receives non-HTLC-encumbered funds which are only available for spending
/// after some delay (or can be claimed via the revocation path).
Expand All@@ -491,7 +491,7 @@ pub struct ChannelPublicKeys {
impl_writeable_tlv_based!(ChannelPublicKeys, {
(0, funding_pubkey, required),
(2, revocation_basepoint, required),
(4, payment_point, required),
(4, payment_basepoint, required),
(6, delayed_payment_basepoint, required),
(8, htlc_basepoint, required),
});
Expand DownExpand Up@@ -550,11 +550,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay

/// Returns the script for the counterparty's output on a holder's commitment transaction based on
/// the channel type.
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_basepoint: &PublicKey) -> ScriptBuf {
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(payment_key).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_basepoint.serialize()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm quite confused by this. The point of calling it a "key" and not a "basepoint" is that the script is paid directly to the key (in this case as a P2WPKH) rather than incorporating the per_commitment_secret/per_commitment_point when building t the output.

}
}

Expand DownExpand Up@@ -816,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features

/// Gets the witnessScript for the to_remote output when anchors are enabled.
#[inline]
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_basepoint: &PublicKey) -> ScriptBuf {
Builder::new()
.push_slice(payment_point.serialize())
.push_slice(payment_basepoint.serialize())
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
.push_int(1)
.push_opcode(opcodes::all::OP_CSV)
Expand DownExpand Up@@ -933,7 +933,7 @@ impl ChannelTransactionParameters {
let dummy_keys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
revocation_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
payment_point: PublicKey::from_slice(&[2; 33]).unwrap(),
payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap(),
delayed_payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
htlc_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
};
Expand DownExpand Up@@ -1119,7 +1119,7 @@ impl HolderCommitmentTransaction {
let channel_pubkeys = ChannelPublicKeys {
funding_pubkey: dummy_key.clone(),
revocation_basepoint: RevocationBasepoint::from(dummy_key),
payment_point: dummy_key.clone(),
payment_basepoint: dummy_key.clone(),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(dummy_key.clone()),
htlc_basepoint: HtlcBasepoint::from(dummy_key.clone())
};
Expand DownExpand Up@@ -1515,9 +1515,9 @@ impl CommitmentTransaction {

if to_countersignatory_value_sat > Amount::ZERO {
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into())
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_basepoint.serialize()).into())
};
txouts.push((
TxOut {
Expand DownExpand Up@@ -1608,8 +1608,8 @@ impl CommitmentTransaction {
let broadcaster_pubkeys = channel_parameters.broadcaster_pubkeys();
let countersignatory_pubkeys = channel_parameters.countersignatory_pubkeys();
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor(
&broadcaster_pubkeys.payment_point,
&countersignatory_pubkeys.payment_point,
&broadcaster_pubkeys.payment_basepoint,
&countersignatory_pubkeys.payment_basepoint,
channel_parameters.is_outbound(),
);

Expand DownExpand Up@@ -1974,13 +1974,13 @@ mod tests {
// Generate broadcaster and counterparty outputs
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 2);
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_basepoint), Network::Testnet).script_pubkey());

// Generate broadcaster and counterparty outputs as well as two anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 4);
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_basepoint).to_p2wsh());

// Generate broadcaster output and anchor
let tx = builder.build(3000, 0);
Expand DownExpand Up@@ -2015,9 +2015,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
"0020510277dd095f7e3a7a46efbd9de3a49f527b5b32f4acc70f144dc5c928529520");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
"0020b981c1ea6c0d0c3971e89800312d6fd5564872f22040771d1555605edf5b1cfe");

// Generate broadcaster output and received and offered HTLC outputs, with anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
Expand All@@ -2027,9 +2027,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
"002078193f615fc1b050814d866d6c46097f9d19fdae0dbc4905b2b35f427c8d0662");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
"0020ac28c4778c24e79755cedc11e7feb638630aa74478781ae7c809aed06e6bd325");
}

#[test]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
#[rustfmt::skip]
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_secret[31]]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
let secret_key = SecretKey::from_slice(&[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
unreachable!()
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
unreachable!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1347,7 +1347,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
let counterparty_payment_script = chan_utils::get_counterparty_payment_script(
&channel_parameters.channel_type_features, &keys.pubkeys().payment_point
&channel_parameters.channel_type_features, &keys.pubkeys().payment_basepoint
);

let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
Expand DownExpand Up@@ -3298,7 +3298,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand All@@ -3322,7 +3322,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for htlc in htlcs {
htlc_descriptors.push(HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand DownExpand Up@@ -4971,9 +4971,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
if onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() &&
counterparty_payment_script.is_p2wpkh()
{
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
let payment_basepoint = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_basepoint;
counterparty_payment_script =
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_basepoint).to_p2wsh();
}

Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
Expand DownExpand Up@@ -5243,7 +5243,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
};
Expand DownExpand Up@@ -5495,7 +5495,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())),
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1199,7 +1199,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
let htlc_descriptor = HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: self.channel_value_satoshis,
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
transaction_parameters: self.channel_transaction_parameters.clone(),
},
commitment_txid: trusted_tx.txid(),
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ impl AnchorDescriptor {
{
let mut signer = signer_provider.derive_channel_signer(
self.channel_derivation_parameters.value_satoshis,
self.channel_derivation_parameters.keys_id,
self.channel_derivation_parameters.channel_keys_id,
);
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
signer
Expand DownExpand Up@@ -791,7 +791,7 @@ where

let mut signers = BTreeMap::new();
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.channel_keys_id)
.or_insert_with(|| htlc_descriptor.derive_channel_signer(&self.signer_provider));
let htlc_sig = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
let witness_script = htlc_descriptor.witness_script(&self.secp);
Expand DownExpand Up@@ -955,7 +955,7 @@ mod tests {
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
channel_keys_id: [42; 32],
transaction_parameters: ChannelTransactionParameters::test_dummy(),
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
if extra_closing_signed {
let node_1_closing_signed_2_bad = {
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
let channel_keys_id = [42u8; 32];
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
counterparty_script.into(), funding_outpoint);
Expand Down
38 changes: 19 additions & 19 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -478,7 +478,7 @@ pub struct ChannelPublicKeys {
/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
/// spendable primary channel balance on the broadcaster's commitment transaction. This key is
/// static across every commitment transaction.
pub payment_point: PublicKey,
pub payment_basepoint: PublicKey,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this elsewhere but IMO we should fix this in the spec, not here. The "base" in the "basepoint"s refer to the fact that its extended with the per_commitment_point to build a new point for each state. Since static_remotekey (which is now "ASSUMED" in the spec, and not described) its no longer used to derive a key but rather simply a key used as-is. The spec needs updating to remove references to its use as a base key.

/// The base point which is used (with derive_public_key) to derive a per-commitment payment
/// public key which receives non-HTLC-encumbered funds which are only available for spending
/// after some delay (or can be claimed via the revocation path).
Expand All@@ -491,7 +491,7 @@ pub struct ChannelPublicKeys {
impl_writeable_tlv_based!(ChannelPublicKeys, {
(0, funding_pubkey, required),
(2, revocation_basepoint, required),
(4, payment_point, required),
(4, payment_basepoint, required),
(6, delayed_payment_basepoint, required),
(8, htlc_basepoint, required),
});
Expand DownExpand Up@@ -550,11 +550,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay

/// Returns the script for the counterparty's output on a holder's commitment transaction based on
/// the channel type.
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_basepoint: &PublicKey) -> ScriptBuf {
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(payment_key).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_basepoint.serialize()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm quite confused by this. The point of calling it a "key" and not a "basepoint" is that the script is paid directly to the key (in this case as a P2WPKH) rather than incorporating the per_commitment_secret/per_commitment_point when building t the output.

}
}

Expand DownExpand Up@@ -816,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features

/// Gets the witnessScript for the to_remote output when anchors are enabled.
#[inline]
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_basepoint: &PublicKey) -> ScriptBuf {
Builder::new()
.push_slice(payment_point.serialize())
.push_slice(payment_basepoint.serialize())
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
.push_int(1)
.push_opcode(opcodes::all::OP_CSV)
Expand DownExpand Up@@ -933,7 +933,7 @@ impl ChannelTransactionParameters {
let dummy_keys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
revocation_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
payment_point: PublicKey::from_slice(&[2; 33]).unwrap(),
payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap(),
delayed_payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
htlc_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
};
Expand DownExpand Up@@ -1119,7 +1119,7 @@ impl HolderCommitmentTransaction {
let channel_pubkeys = ChannelPublicKeys {
funding_pubkey: dummy_key.clone(),
revocation_basepoint: RevocationBasepoint::from(dummy_key),
payment_point: dummy_key.clone(),
payment_basepoint: dummy_key.clone(),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(dummy_key.clone()),
htlc_basepoint: HtlcBasepoint::from(dummy_key.clone())
};
Expand DownExpand Up@@ -1515,9 +1515,9 @@ impl CommitmentTransaction {

if to_countersignatory_value_sat > Amount::ZERO {
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into())
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_basepoint.serialize()).into())
};
txouts.push((
TxOut {
Expand DownExpand Up@@ -1608,8 +1608,8 @@ impl CommitmentTransaction {
let broadcaster_pubkeys = channel_parameters.broadcaster_pubkeys();
let countersignatory_pubkeys = channel_parameters.countersignatory_pubkeys();
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor(
&broadcaster_pubkeys.payment_point,
&countersignatory_pubkeys.payment_point,
&broadcaster_pubkeys.payment_basepoint,
&countersignatory_pubkeys.payment_basepoint,
channel_parameters.is_outbound(),
);

Expand DownExpand Up@@ -1974,13 +1974,13 @@ mod tests {
// Generate broadcaster and counterparty outputs
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 2);
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_basepoint), Network::Testnet).script_pubkey());

// Generate broadcaster and counterparty outputs as well as two anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 4);
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_basepoint).to_p2wsh());

// Generate broadcaster output and anchor
let tx = builder.build(3000, 0);
Expand DownExpand Up@@ -2015,9 +2015,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
"0020510277dd095f7e3a7a46efbd9de3a49f527b5b32f4acc70f144dc5c928529520");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
"0020b981c1ea6c0d0c3971e89800312d6fd5564872f22040771d1555605edf5b1cfe");

// Generate broadcaster output and received and offered HTLC outputs, with anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
Expand All@@ -2027,9 +2027,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
"002078193f615fc1b050814d866d6c46097f9d19fdae0dbc4905b2b35f427c8d0662");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
"0020ac28c4778c24e79755cedc11e7feb638630aa74478781ae7c809aed06e6bd325");
}

#[test]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
#[rustfmt::skip]
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_secret[31]]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
let secret_key = SecretKey::from_slice(&[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
unreachable!()
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
unreachable!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1347,7 +1347,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
let counterparty_payment_script = chan_utils::get_counterparty_payment_script(
&channel_parameters.channel_type_features, &keys.pubkeys().payment_point
&channel_parameters.channel_type_features, &keys.pubkeys().payment_basepoint
);

let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
Expand DownExpand Up@@ -3298,7 +3298,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand All@@ -3322,7 +3322,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for htlc in htlcs {
htlc_descriptors.push(HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand DownExpand Up@@ -4971,9 +4971,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
if onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() &&
counterparty_payment_script.is_p2wpkh()
{
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
let payment_basepoint = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_basepoint;
counterparty_payment_script =
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_basepoint).to_p2wsh();
}

Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
Expand DownExpand Up@@ -5243,7 +5243,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
};
Expand DownExpand Up@@ -5495,7 +5495,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())),
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1199,7 +1199,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
let htlc_descriptor = HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: self.channel_value_satoshis,
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
transaction_parameters: self.channel_transaction_parameters.clone(),
},
commitment_txid: trusted_tx.txid(),
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ impl AnchorDescriptor {
{
let mut signer = signer_provider.derive_channel_signer(
self.channel_derivation_parameters.value_satoshis,
self.channel_derivation_parameters.keys_id,
self.channel_derivation_parameters.channel_keys_id,
);
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
signer
Expand DownExpand Up@@ -791,7 +791,7 @@ where

let mut signers = BTreeMap::new();
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.channel_keys_id)
.or_insert_with(|| htlc_descriptor.derive_channel_signer(&self.signer_provider));
let htlc_sig = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
let witness_script = htlc_descriptor.witness_script(&self.secp);
Expand DownExpand Up@@ -955,7 +955,7 @@ mod tests {
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
channel_keys_id: [42; 32],
transaction_parameters: ChannelTransactionParameters::test_dummy(),
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
if extra_closing_signed {
let node_1_closing_signed_2_bad = {
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
let channel_keys_id = [42u8; 32];
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
counterparty_script.into(), funding_outpoint);
Expand Down
38 changes: 19 additions & 19 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -478,7 +478,7 @@ pub struct ChannelPublicKeys {
/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
/// spendable primary channel balance on the broadcaster's commitment transaction. This key is
/// static across every commitment transaction.
pub payment_point: PublicKey,
pub payment_basepoint: PublicKey,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this elsewhere but IMO we should fix this in the spec, not here. The "base" in the "basepoint"s refer to the fact that its extended with the per_commitment_point to build a new point for each state. Since static_remotekey (which is now "ASSUMED" in the spec, and not described) its no longer used to derive a key but rather simply a key used as-is. The spec needs updating to remove references to its use as a base key.

/// The base point which is used (with derive_public_key) to derive a per-commitment payment
/// public key which receives non-HTLC-encumbered funds which are only available for spending
/// after some delay (or can be claimed via the revocation path).
Expand All@@ -491,7 +491,7 @@ pub struct ChannelPublicKeys {
impl_writeable_tlv_based!(ChannelPublicKeys, {
(0, funding_pubkey, required),
(2, revocation_basepoint, required),
(4, payment_point, required),
(4, payment_basepoint, required),
(6, delayed_payment_basepoint, required),
(8, htlc_basepoint, required),
});
Expand DownExpand Up@@ -550,11 +550,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay

/// Returns the script for the counterparty's output on a holder's commitment transaction based on
/// the channel type.
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_basepoint: &PublicKey) -> ScriptBuf {
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(payment_key).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_basepoint.serialize()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm quite confused by this. The point of calling it a "key" and not a "basepoint" is that the script is paid directly to the key (in this case as a P2WPKH) rather than incorporating the per_commitment_secret/per_commitment_point when building t the output.

}
}

Expand DownExpand Up@@ -816,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features

/// Gets the witnessScript for the to_remote output when anchors are enabled.
#[inline]
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_basepoint: &PublicKey) -> ScriptBuf {
Builder::new()
.push_slice(payment_point.serialize())
.push_slice(payment_basepoint.serialize())
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
.push_int(1)
.push_opcode(opcodes::all::OP_CSV)
Expand DownExpand Up@@ -933,7 +933,7 @@ impl ChannelTransactionParameters {
let dummy_keys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
revocation_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
payment_point: PublicKey::from_slice(&[2; 33]).unwrap(),
payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap(),
delayed_payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
htlc_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
};
Expand DownExpand Up@@ -1119,7 +1119,7 @@ impl HolderCommitmentTransaction {
let channel_pubkeys = ChannelPublicKeys {
funding_pubkey: dummy_key.clone(),
revocation_basepoint: RevocationBasepoint::from(dummy_key),
payment_point: dummy_key.clone(),
payment_basepoint: dummy_key.clone(),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(dummy_key.clone()),
htlc_basepoint: HtlcBasepoint::from(dummy_key.clone())
};
Expand DownExpand Up@@ -1515,9 +1515,9 @@ impl CommitmentTransaction {

if to_countersignatory_value_sat > Amount::ZERO {
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into())
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_basepoint.serialize()).into())
};
txouts.push((
TxOut {
Expand DownExpand Up@@ -1608,8 +1608,8 @@ impl CommitmentTransaction {
let broadcaster_pubkeys = channel_parameters.broadcaster_pubkeys();
let countersignatory_pubkeys = channel_parameters.countersignatory_pubkeys();
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor(
&broadcaster_pubkeys.payment_point,
&countersignatory_pubkeys.payment_point,
&broadcaster_pubkeys.payment_basepoint,
&countersignatory_pubkeys.payment_basepoint,
channel_parameters.is_outbound(),
);

Expand DownExpand Up@@ -1974,13 +1974,13 @@ mod tests {
// Generate broadcaster and counterparty outputs
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 2);
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_basepoint), Network::Testnet).script_pubkey());

// Generate broadcaster and counterparty outputs as well as two anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 4);
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_basepoint).to_p2wsh());

// Generate broadcaster output and anchor
let tx = builder.build(3000, 0);
Expand DownExpand Up@@ -2015,9 +2015,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
"0020510277dd095f7e3a7a46efbd9de3a49f527b5b32f4acc70f144dc5c928529520");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
"0020b981c1ea6c0d0c3971e89800312d6fd5564872f22040771d1555605edf5b1cfe");

// Generate broadcaster output and received and offered HTLC outputs, with anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
Expand All@@ -2027,9 +2027,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
"002078193f615fc1b050814d866d6c46097f9d19fdae0dbc4905b2b35f427c8d0662");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
"0020ac28c4778c24e79755cedc11e7feb638630aa74478781ae7c809aed06e6bd325");
}

#[test]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
#[rustfmt::skip]
let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_secret[31]]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
.into_script())
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
let secp_ctx = Secp256k1::signing_only();
let secret_key = SecretKey::from_slice(&[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
unreachable!()
}

fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
unreachable!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1347,7 +1347,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
let counterparty_payment_script = chan_utils::get_counterparty_payment_script(
&channel_parameters.channel_type_features, &keys.pubkeys().payment_point
&channel_parameters.channel_type_features, &keys.pubkeys().payment_basepoint
);

let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
Expand DownExpand Up@@ -3298,7 +3298,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand All@@ -3322,7 +3322,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for htlc in htlcs {
htlc_descriptors.push(HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
value_satoshis: self.channel_value_satoshis,
transaction_parameters: self.onchain_tx_handler.channel_transaction_parameters.clone(),
},
Expand DownExpand Up@@ -4971,9 +4971,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
if onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() &&
counterparty_payment_script.is_p2wpkh()
{
let payment_point = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_point;
let payment_basepoint = onchain_tx_handler.channel_transaction_parameters.holder_pubkeys.payment_basepoint;
counterparty_payment_script =
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point).to_p2wsh();
chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_basepoint).to_p2wsh();
}

Ok((best_block.block_hash, ChannelMonitor::from_impl(ChannelMonitorImpl {
Expand DownExpand Up@@ -5243,7 +5243,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
};
Expand DownExpand Up@@ -5495,7 +5495,7 @@ mod tests {
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())),
};
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1199,7 +1199,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
let htlc_descriptor = HTLCDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: self.channel_value_satoshis,
keys_id: self.channel_keys_id,
channel_keys_id: self.channel_keys_id,
transaction_parameters: self.channel_transaction_parameters.clone(),
},
commitment_txid: trusted_tx.txid(),
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ impl AnchorDescriptor {
{
let mut signer = signer_provider.derive_channel_signer(
self.channel_derivation_parameters.value_satoshis,
self.channel_derivation_parameters.keys_id,
self.channel_derivation_parameters.channel_keys_id,
);
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
signer
Expand DownExpand Up@@ -791,7 +791,7 @@ where

let mut signers = BTreeMap::new();
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
let signer = signers.entry(htlc_descriptor.channel_derivation_parameters.channel_keys_id)
.or_insert_with(|| htlc_descriptor.derive_channel_signer(&self.signer_provider));
let htlc_sig = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
let witness_script = htlc_descriptor.witness_script(&self.secp);
Expand DownExpand Up@@ -955,7 +955,7 @@ mod tests {
anchor_descriptor: AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
channel_keys_id: [42; 32],
transaction_parameters: ChannelTransactionParameters::test_dummy(),
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
if extra_closing_signed {
let node_1_closing_signed_2_bad = {
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
let channel_keys_id = [42u8; 32];
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
counterparty_script.into(), funding_outpoint);
Expand Down
38 changes: 19 additions & 19 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -478,7 +478,7 @@ pub struct ChannelPublicKeys {
/// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
/// spendable primary channel balance on the broadcaster's commitment transaction. This key is
/// static across every commitment transaction.
pub payment_point: PublicKey,
pub payment_basepoint: PublicKey,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this elsewhere but IMO we should fix this in the spec, not here. The "base" in the "basepoint"s refer to the fact that its extended with the per_commitment_point to build a new point for each state. Since static_remotekey (which is now "ASSUMED" in the spec, and not described) its no longer used to derive a key but rather simply a key used as-is. The spec needs updating to remove references to its use as a base key.

/// The base point which is used (with derive_public_key) to derive a per-commitment payment
/// public key which receives non-HTLC-encumbered funds which are only available for spending
/// after some delay (or can be claimed via the revocation path).
Expand All@@ -491,7 +491,7 @@ pub struct ChannelPublicKeys {
impl_writeable_tlv_based!(ChannelPublicKeys, {
(0, funding_pubkey, required),
(2, revocation_basepoint, required),
(4, payment_point, required),
(4, payment_basepoint, required),
(6, delayed_payment_basepoint, required),
(8, htlc_basepoint, required),
});
Expand DownExpand Up@@ -550,11 +550,11 @@ pub fn get_revokeable_redeemscript(revocation_key: &RevocationKey, contest_delay

/// Returns the script for the counterparty's output on a holder's commitment transaction based on
/// the channel type.
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> ScriptBuf {
pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_basepoint: &PublicKey) -> ScriptBuf {
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(payment_key).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize()))
ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&payment_basepoint.serialize()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm quite confused by this. The point of calling it a "key" and not a "basepoint" is that the script is paid directly to the key (in this case as a P2WPKH) rather than incorporating the per_commitment_secret/per_commitment_point when building t the output.

}
}

Expand DownExpand Up@@ -816,9 +816,9 @@ pub(crate) fn legacy_deserialization_prevention_marker_for_channel_type_features

/// Gets the witnessScript for the to_remote output when anchors are enabled.
#[inline]
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_point: &PublicKey) -> ScriptBuf {
pub fn get_to_countersignatory_with_anchors_redeemscript(payment_basepoint: &PublicKey) -> ScriptBuf {
Builder::new()
.push_slice(payment_point.serialize())
.push_slice(payment_basepoint.serialize())
.push_opcode(opcodes::all::OP_CHECKSIGVERIFY)
.push_int(1)
.push_opcode(opcodes::all::OP_CSV)
Expand DownExpand Up@@ -933,7 +933,7 @@ impl ChannelTransactionParameters {
let dummy_keys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_slice(&[2; 33]).unwrap(),
revocation_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
payment_point: PublicKey::from_slice(&[2; 33]).unwrap(),
payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap(),
delayed_payment_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
htlc_basepoint: PublicKey::from_slice(&[2; 33]).unwrap().into(),
};
Expand DownExpand Up@@ -1119,7 +1119,7 @@ impl HolderCommitmentTransaction {
let channel_pubkeys = ChannelPublicKeys {
funding_pubkey: dummy_key.clone(),
revocation_basepoint: RevocationBasepoint::from(dummy_key),
payment_point: dummy_key.clone(),
payment_basepoint: dummy_key.clone(),
delayed_payment_basepoint: DelayedPaymentBasepoint::from(dummy_key.clone()),
htlc_basepoint: HtlcBasepoint::from(dummy_key.clone())
};
Expand DownExpand Up@@ -1515,9 +1515,9 @@ impl CommitmentTransaction {

if to_countersignatory_value_sat > Amount::ZERO {
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_p2wsh()
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_basepoint).to_p2wsh()
} else {
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_point.serialize()).into())
ScriptBuf::new_p2wpkh(&Hash160::hash(&countersignatory_pubkeys.payment_basepoint.serialize()).into())
};
txouts.push((
TxOut {
Expand DownExpand Up@@ -1608,8 +1608,8 @@ impl CommitmentTransaction {
let broadcaster_pubkeys = channel_parameters.broadcaster_pubkeys();
let countersignatory_pubkeys = channel_parameters.countersignatory_pubkeys();
let commitment_transaction_number_obscure_factor = get_commitment_transaction_number_obscure_factor(
&broadcaster_pubkeys.payment_point,
&countersignatory_pubkeys.payment_point,
&broadcaster_pubkeys.payment_basepoint,
&countersignatory_pubkeys.payment_basepoint,
channel_parameters.is_outbound(),
);

Expand DownExpand Up@@ -1974,13 +1974,13 @@ mod tests {
// Generate broadcaster and counterparty outputs
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 2);
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
assert_eq!(tx.built.transaction.output[1].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_basepoint), Network::Testnet).script_pubkey());

// Generate broadcaster and counterparty outputs as well as two anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
let tx = builder.build(1000, 2000);
assert_eq!(tx.built.transaction.output.len(), 4);
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_point).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_to_countersignatory_with_anchors_redeemscript(&builder.counterparty_pubkeys.payment_basepoint).to_p2wsh());

// Generate broadcaster output and anchor
let tx = builder.build(3000, 0);
Expand DownExpand Up@@ -2015,9 +2015,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[0].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
"0020510277dd095f7e3a7a46efbd9de3a49f527b5b32f4acc70f144dc5c928529520");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
"0020b981c1ea6c0d0c3971e89800312d6fd5564872f22040771d1555605edf5b1cfe");

// Generate broadcaster output and received and offered HTLC outputs, with anchors
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
Expand All@@ -2027,9 +2027,9 @@ mod tests {
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(tx.built.transaction.output[3].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh());
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
"002078193f615fc1b050814d866d6c46097f9d19fdae0dbc4905b2b35f427c8d0662");
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
"0020ac28c4778c24e79755cedc11e7feb638630aa74478781ae7c809aed06e6bd325");
}

#[test]
Expand Down
Loading