Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3282,7 +3282,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
for (htlc, _) in per_commitment_claimable_data {
if let Some(transaction_output_index) = htlc.transaction_output_index {
if transaction_output_index as usize >= tx.output.len() ||
tx.output[transaction_output_index as usize].value != htlc.to_bitcoin_amount() {
tx.output[transaction_output_index as usize].value != htlc.satoshi_amount() {
// per_commitment_data is corrupt or our commitment signing key leaked!
return (claimable_outpoints, to_counterparty_output_info);
}
Expand Down Expand Up @@ -3389,7 +3389,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if let Some(transaction_output_index) = htlc.transaction_output_index {
if let Some(transaction) = tx {
if transaction_output_index as usize >= transaction.output.len() ||
transaction.output[transaction_output_index as usize].value != htlc.to_bitcoin_amount() {
transaction.output[transaction_output_index as usize].value != htlc.satoshi_amount() {
// per_commitment_data is corrupt or our commitment signing key leaked!
return (claimable_outpoints, to_counterparty_output_info);
}
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,10 @@ pub struct HTLCOutputInCommitment {
}

impl HTLCOutputInCommitment {
/// Converts HTLC's value with millisatoshi precision into [bitcoin::Amount] with satoshi precision.
/// Typically this conversion is needed when transitioning from LN into base-layer Bitcoin,
/// Returns HTLC's value with millisatoshi precision as [bitcoin::Amount] with satoshi precision.
/// Typically this is needed when transitioning from LN into base-layer Bitcoin,
/// e. g. in commitment transactions.
pub const fn to_bitcoin_amount(&self) -> Amount {
pub const fn satoshi_amount(&self) -> Amount {
Amount::from_sat(self.amount_msat / 1000)
}
}
Expand Down Expand Up @@ -710,10 +710,10 @@ pub(crate) fn build_htlc_output(
htlc_success_tx_weight(channel_type_features)
};
let output_value = if channel_type_features.supports_anchors_zero_fee_htlc_tx() && !channel_type_features.supports_anchors_nonzero_fee_htlc_tx() {
htlc.to_bitcoin_amount()
htlc.satoshi_amount()
} else {
let total_fee = Amount::from_sat(feerate_per_kw as u64 * weight / 1000);
htlc.to_bitcoin_amount() - total_fee
htlc.satoshi_amount() - total_fee
};

TxOut {
Expand Down Expand Up @@ -1513,7 +1513,7 @@ impl CommitmentTransaction {
let script = chan_utils::get_htlc_redeemscript(&htlc, &channel_parameters.channel_type_features(), &keys);
let txout = TxOut {
script_pubkey: script.to_p2wsh(),
value: htlc.to_bitcoin_amount(),
value: htlc.satoshi_amount(),
};
txouts.push((txout, Some(htlc)));
}
Expand Down Expand Up @@ -1696,7 +1696,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {

let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, &self.channel_type_features, &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);

let sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, this_htlc.to_bitcoin_amount(), EcdsaSighashType::All).unwrap()[..]);
let sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, this_htlc.satoshi_amount(), EcdsaSighashType::All).unwrap()[..]);
ret.push(sign_with_aux_rand(secp_ctx, &sighash, &holder_htlc_key, entropy_source));
}
Ok(ret)
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4273,7 +4273,7 @@ impl<SP: Deref> Channel<SP> where

let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &self.context.channel_type, &keys);
let htlc_sighashtype = if self.context.channel_type.supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap()[..]);
let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.satoshi_amount(), htlc_sighashtype).unwrap()[..]);
log_trace!(logger, "Checking HTLC tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}.",
log_bytes!(msg.htlc_signatures[idx].serialize_compact()[..]), log_bytes!(keys.countersignatory_htlc_key.to_public_key().serialize()),
encode::serialize_hex(&htlc_tx), log_bytes!(htlc_sighash[..]), encode::serialize_hex(&htlc_redeemscript), &self.context.channel_id());
Expand Down Expand Up @@ -10050,7 +10050,7 @@ mod tests {
&htlc, $opt_anchors, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, $opt_anchors, &keys);
let htlc_sighashtype = if $opt_anchors.supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
let htlc_sighash = Message::from_digest(sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap().as_raw_hash().to_byte_array());
let htlc_sighash = Message::from_digest(sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.satoshi_amount(), htlc_sighashtype).unwrap().as_raw_hash().to_byte_array());
assert!(secp_ctx.verify_ecdsa(&htlc_sighash, &remote_signature, &keys.countersignatory_htlc_key.to_public_key()).is_ok(), "verify counterparty htlc sig");

let mut preimage: Option<PaymentPreimage> = None;
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ impl HTLCDescriptor {
) -> TxOut {
TxOut {
script_pubkey: self.witness_script(secp).to_p2wsh(),
value: self.htlc.to_bitcoin_amount(),
value: self.htlc.satoshi_amount(),
}
}

Expand Down Expand Up @@ -1439,7 +1439,7 @@ impl EcdsaChannelSigner for InMemorySigner {
.p2wsh_signature_hash(
0,
&htlc_redeemscript,
htlc.to_bitcoin_amount(),
htlc.satoshi_amount(),
htlc_sighashtype
)
.unwrap()[..]
Expand Down Expand Up @@ -1593,7 +1593,7 @@ impl EcdsaChannelSigner for InMemorySigner {
.p2wsh_signature_hash(
input,
&witness_script,
htlc_descriptor.htlc.to_bitcoin_amount(),
htlc_descriptor.htlc.satoshi_amount(),
EcdsaSighashType::All,
)
.map_err(|_| ())?;
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/util/test_channel_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
EcdsaSighashType::All
};
let sighash = &sighash::SighashCache::new(&*htlc_tx).p2wsh_signature_hash(
input, &witness_script, htlc_descriptor.htlc.to_bitcoin_amount(), sighash_type
input, &witness_script, htlc_descriptor.htlc.satoshi_amount(), sighash_type
).unwrap();
let countersignatory_htlc_key = HtlcKey::from_basepoint(
&secp_ctx, &self.inner.counterparty_pubkeys().unwrap().htlc_basepoint, &htlc_descriptor.per_commitment_point,
Expand Down