Skip to content

Commit 9291a38

Browse files
committed
Use new get_commitment_transaction_number_obscure_factor utility function
1 parent 2de29ae commit 9291a38

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

lightning/src/ln/channel.rs

+7-28
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bitcoin::blockdata::opcodes;
1414
use bitcoin::util::bip143;
1515
use bitcoin::consensus::encode;
1616

17-
use bitcoin::hashes::{Hash, HashEngine};
17+
use bitcoin::hashes::Hash;
1818
use bitcoin::hashes::sha256::Hash as Sha256;
1919
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
2020

@@ -26,7 +26,7 @@ use ln::features::{ChannelFeatures, InitFeatures};
2626
use ln::msgs;
2727
use ln::msgs::{DecodeError, OptionalField, DataLossProtect};
2828
use ln::channelmanager::{PendingHTLCStatus, HTLCSource, HTLCFailReason, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT};
29-
use ln::chan_utils::{CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction, HolderCommitmentTransaction, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, MAX_HTLCS};
29+
use ln::chan_utils::{CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction, HolderCommitmentTransaction, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, MAX_HTLCS, get_commitment_transaction_number_obscure_factor};
3030
use ln::chan_utils;
3131
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
3232
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER};
@@ -795,29 +795,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
795795
Ok(chan)
796796
}
797797

798-
// Utilities to build transactions:
799-
800-
fn get_commitment_transaction_number_obscure_factor(&self) -> u64 {
801-
let mut sha = Sha256::engine();
802-
803-
let counterparty_payment_point = &self.get_counterparty_pubkeys().payment_point.serialize();
804-
if self.is_outbound() {
805-
sha.input(&self.get_holder_pubkeys().payment_point.serialize());
806-
sha.input(counterparty_payment_point);
807-
} else {
808-
sha.input(counterparty_payment_point);
809-
sha.input(&self.get_holder_pubkeys().payment_point.serialize());
810-
}
811-
let res = Sha256::from_engine(sha).into_inner();
812-
813-
((res[26] as u64) << 5*8) |
814-
((res[27] as u64) << 4*8) |
815-
((res[28] as u64) << 3*8) |
816-
((res[29] as u64) << 2*8) |
817-
((res[30] as u64) << 1*8) |
818-
((res[31] as u64) << 0*8)
819-
}
820-
821798
/// Transaction nomenclature is somewhat confusing here as there are many different cases - a
822799
/// transaction is referred to as "a's transaction" implying that a will be able to broadcast
823800
/// the transaction. Thus, b will generally be sending a signature over such a transaction to
@@ -846,7 +823,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
846823
let mut local_htlc_total_msat = 0;
847824
let mut value_to_self_msat_offset = 0;
848825

849-
log_trace!(logger, "Building commitment transaction number {} (really {} xor {}) for {}, generated by {} with fee {}...", commitment_number, (INITIAL_COMMITMENT_NUMBER - commitment_number), self.get_commitment_transaction_number_obscure_factor(), if local { "us" } else { "remote" }, if generated_by_local { "us" } else { "remote" }, feerate_per_kw);
826+
log_trace!(logger, "Building commitment transaction number {} (really {} xor {}) for {}, generated by {} with fee {}...", commitment_number, (INITIAL_COMMITMENT_NUMBER - commitment_number), get_commitment_transaction_number_obscure_factor(&self.get_holder_pubkeys().payment_point, &self.get_counterparty_pubkeys().payment_point, self.is_outbound()), if local { "us" } else { "remote" }, if generated_by_local { "us" } else { "remote" }, feerate_per_kw);
850827

851828
macro_rules! get_htlc_in_commitment {
852829
($htlc: expr, $offered: expr) => {
@@ -1539,12 +1516,13 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15391516

15401517
let funding_redeemscript = self.get_funding_redeemscript();
15411518
let funding_txo_script = funding_redeemscript.to_v0_p2wsh();
1519+
let obscure_factor = get_commitment_transaction_number_obscure_factor(&self.get_holder_pubkeys().payment_point, &self.get_counterparty_pubkeys().payment_point, self.is_outbound());
15421520
let mut channel_monitor = ChannelMonitor::new(self.holder_keys.clone(),
15431521
&self.shutdown_pubkey, self.get_holder_selected_contest_delay(),
15441522
&self.destination_script, (funding_txo, funding_txo_script.clone()),
15451523
&self.channel_transaction_parameters,
15461524
funding_redeemscript.clone(), self.channel_value_satoshis,
1547-
self.get_commitment_transaction_number_obscure_factor(),
1525+
obscure_factor,
15481526
holder_commitment_tx);
15491527

15501528
channel_monitor.provide_latest_counterparty_commitment_tx(counterparty_initial_commitment_txid, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);
@@ -1608,12 +1586,13 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
16081586
let funding_redeemscript = self.get_funding_redeemscript();
16091587
let funding_txo = self.get_funding_txo().unwrap();
16101588
let funding_txo_script = funding_redeemscript.to_v0_p2wsh();
1589+
let obscure_factor = get_commitment_transaction_number_obscure_factor(&self.get_holder_pubkeys().payment_point, &self.get_counterparty_pubkeys().payment_point, self.is_outbound());
16111590
let mut channel_monitor = ChannelMonitor::new(self.holder_keys.clone(),
16121591
&self.shutdown_pubkey, self.get_holder_selected_contest_delay(),
16131592
&self.destination_script, (funding_txo, funding_txo_script),
16141593
&self.channel_transaction_parameters,
16151594
funding_redeemscript.clone(), self.channel_value_satoshis,
1616-
self.get_commitment_transaction_number_obscure_factor(),
1595+
obscure_factor,
16171596
holder_commitment_tx);
16181597

16191598
channel_monitor.provide_latest_counterparty_commitment_tx(counterparty_initial_bitcoin_tx.txid, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);

0 commit comments

Comments
 (0)