From d85a1a9a8d935fc98fb24427d78f2bbc8c1017ca Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Fri, 16 Aug 2024 08:45:27 -0700 Subject: [PATCH] Fix lightning warnings. Version 0.32.2 of `rust-bitcoin` deprecates a number of methods that are commonly used in this project, most visibly `txid()`, which is now called `compute_txid()`. This resulted in a lot of warnings, and this commit is part of a series that seeks to address that. --- lightning/src/blinded_path/mod.rs | 1 - lightning/src/chain/channelmonitor.rs | 44 +++---- lightning/src/chain/onchaintx.rs | 24 ++-- lightning/src/chain/transaction.rs | 4 +- lightning/src/events/bump_transaction.rs | 12 +- lightning/src/lib.rs | 2 +- lightning/src/ln/async_signer_tests.rs | 4 +- lightning/src/ln/chan_utils.rs | 6 +- lightning/src/ln/chanmon_update_fail_tests.rs | 4 +- lightning/src/ln/channel.rs | 14 +-- lightning/src/ln/channelmanager.rs | 12 +- lightning/src/ln/functional_test_utils.rs | 26 ++-- lightning/src/ln/functional_tests.rs | 116 +++++++++--------- lightning/src/ln/interactivetxs.rs | 20 +-- lightning/src/ln/monitor_tests.rs | 72 +++++------ lightning/src/ln/payment_tests.rs | 4 +- lightning/src/ln/reload_tests.rs | 12 +- lightning/src/ln/reorg_tests.rs | 12 +- lightning/src/ln/shutdown_tests.rs | 4 +- lightning/src/routing/gossip.rs | 6 +- lightning/src/util/macro_logger.rs | 2 +- lightning/src/util/ser.rs | 2 +- lightning/src/util/sweep.rs | 12 +- lightning/src/util/test_channel_signer.rs | 2 +- lightning/src/util/test_utils.rs | 2 +- lightning/src/util/transaction_utils.rs | 28 ++--- 26 files changed, 226 insertions(+), 221 deletions(-) diff --git a/lightning/src/blinded_path/mod.rs b/lightning/src/blinded_path/mod.rs index be94367f9..6b607bc0e 100644 --- a/lightning/src/blinded_path/mod.rs +++ b/lightning/src/blinded_path/mod.rs @@ -280,7 +280,6 @@ impl Readable for BlindedPath { 0 => IntroductionNode::DirectedShortChannelId(Direction::NodeOne, Readable::read(r)?), 1 => IntroductionNode::DirectedShortChannelId(Direction::NodeTwo, Readable::read(r)?), 2|3 => { - use io::Read; let mut bytes = [0; 33]; bytes[0] = first_byte; r.read_exact(&mut bytes[1..])?; diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 68bdba1c9..4cfb4bf12 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -2141,7 +2141,7 @@ impl ChannelMonitorImpl { } = &event.event { if event.transaction.as_ref().map(|tx| tx.input.iter().any(|inp| { if let Some(htlc_spend_txid) = htlc_spend_txid_opt { - tx.txid() == *htlc_spend_txid || inp.previous_output.txid == *htlc_spend_txid + tx.compute_txid() == *htlc_spend_txid || inp.previous_output.txid == *htlc_spend_txid } else { Some(inp.previous_output.txid) == confirmed_txid && inp.previous_output.vout == htlc_commitment_tx_output_idx @@ -2590,7 +2590,7 @@ impl ChannelMonitor { macro_rules! fail_unbroadcast_htlcs { ($self: expr, $commitment_tx_type: expr, $commitment_txid_confirmed: expr, $commitment_tx_confirmed: expr, $commitment_tx_conf_height: expr, $commitment_tx_conf_hash: expr, $confirmed_htlcs_list: expr, $logger: expr) => { { - debug_assert_eq!($commitment_tx_confirmed.txid(), $commitment_txid_confirmed); + debug_assert_eq!($commitment_tx_confirmed.compute_txid(), $commitment_txid_confirmed); macro_rules! check_htlc_fails { ($txid: expr, $commitment_tx: expr, $per_commitment_outpoints: expr) => { @@ -3223,7 +3223,7 @@ impl ChannelMonitorImpl { // introduced with v0.0.116. counterparty_node_id is guaranteed to be `Some` // since v0.0.110. let counterparty_node_id = self.counterparty_node_id.unwrap(); - let commitment_txid = commitment_tx.txid(); + let commitment_txid = commitment_tx.compute_txid(); debug_assert_eq!(self.current_holder_commitment_tx.txid, commitment_txid); let pending_htlcs = self.current_holder_commitment_tx.non_dust_htlcs(); let commitment_tx_fee_satoshis = self.channel_value_satoshis - @@ -3403,7 +3403,7 @@ impl ChannelMonitorImpl { let mut claimable_outpoints = Vec::new(); let mut to_counterparty_output_info = None; - let commitment_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers! + let commitment_txid = tx.compute_txid(); //TODO: This is gonna be a performance bottleneck for watchtowers! let per_commitment_option = self.counterparty_claimable_outpoints.get(&commitment_txid); macro_rules! ignore_error { @@ -3589,7 +3589,7 @@ impl ChannelMonitorImpl { }; let per_commitment_point = PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key); - let htlc_txid = tx.txid(); + let htlc_txid = tx.compute_txid(); let mut claimable_outpoints = vec![]; let mut outputs_to_watch = None; // Previously, we would only claim HTLCs from revoked HTLC transactions if they had 1 input @@ -3681,7 +3681,7 @@ impl ChannelMonitorImpl { /// Should not be used if check_spend_revoked_transaction succeeds. /// Returns None unless the transaction is definitely one of our commitment transactions. fn check_spend_holder_transaction(&mut self, tx: &Transaction, height: u32, block_hash: &BlockHash, logger: &L) -> Option<(Vec, TransactionOutputs)> where L::Target: Logger { - let commitment_txid = tx.txid(); + let commitment_txid = tx.compute_txid(); let mut claim_requests = Vec::new(); let mut watch_outputs = Vec::new(); @@ -3786,7 +3786,7 @@ impl ChannelMonitorImpl { ) -> Vec where L::Target: Logger { log_debug!(logger, "Getting signed copy of latest holder commitment transaction!"); let commitment_tx = self.onchain_tx_handler.get_fully_signed_copy_holder_tx(&self.funding_redeemscript); - let txid = commitment_tx.txid(); + let txid = commitment_tx.compute_txid(); let mut holder_transactions = vec![commitment_tx]; // When anchor outputs are present, the HTLC transactions are only final once the commitment // transaction confirms due to the CSV 1 encumberance. @@ -3885,7 +3885,7 @@ impl ChannelMonitorImpl { let mut watch_outputs = Vec::new(); let mut claimable_outpoints = Vec::new(); 'tx_iter: for tx in &txn_matched { - let txid = tx.txid(); + let txid = tx.compute_txid(); log_trace!(logger, "Transaction {} confirmed in block {}", txid , block_hash); // If a transaction has already been confirmed, ensure we don't bother processing it duplicatively. if Some(txid) == self.funding_spend_confirmed { @@ -4131,7 +4131,7 @@ impl ChannelMonitorImpl { // make sure the registered scriptpubkey at the expected index match // the actual transaction output one. We failed this case before #653. for tx in &txn_matched { - if let Some(outputs) = self.get_outputs_to_watch().get(&tx.txid()) { + if let Some(outputs) = self.get_outputs_to_watch().get(&tx.compute_txid()) { for idx_and_script in outputs.iter() { assert!((idx_and_script.0 as usize) < tx.output.len()); assert_eq!(tx.output[idx_and_script.0 as usize].script_pubkey, idx_and_script.1); @@ -4206,7 +4206,7 @@ impl ChannelMonitorImpl { } } if matches { - matched_txn.insert(tx.txid()); + matched_txn.insert(tx.compute_txid()); } matches }).map(|(_, tx)| *tx).collect() @@ -4360,12 +4360,12 @@ impl ChannelMonitorImpl { if ($holder_tx && revocation_sig_claim) || (outbound_htlc && !$source_avail && (accepted_preimage_claim || offered_preimage_claim)) { log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!", - $tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(), + $tx_info, input.previous_output.txid, input.previous_output.vout, tx.compute_txid(), if outbound_htlc { "outbound" } else { "inbound" }, &$htlc.payment_hash, if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back. We can likely claim the HTLC output with a revocation claim" }); } else { log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}", - $tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(), + $tx_info, input.previous_output.txid, input.previous_output.vout, tx.compute_txid(), if outbound_htlc { "outbound" } else { "inbound" }, &$htlc.payment_hash, if revocation_sig_claim { "revocation sig" } else if accepted_preimage_claim || offered_preimage_claim { "preimage" } else { "timeout" }); } @@ -4412,7 +4412,7 @@ impl ChannelMonitorImpl { log_claim!($tx_info, $holder_tx, htlc_output, false); let outbound_htlc = $holder_tx == htlc_output.offered; self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry { - txid: tx.txid(), height, block_hash: Some(*block_hash), transaction: Some(tx.clone()), + txid: tx.compute_txid(), height, block_hash: Some(*block_hash), transaction: Some(tx.clone()), event: OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx: input.previous_output.vout, preimage: if accepted_preimage_claim || offered_preimage_claim { @@ -4454,7 +4454,7 @@ impl ChannelMonitorImpl { if !self.pending_monitor_events.iter().any( |update| if let &MonitorEvent::HTLCEvent(ref upd) = update { upd.source == source } else { false }) { self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry { - txid: tx.txid(), + txid: tx.compute_txid(), height, block_hash: Some(*block_hash), transaction: Some(tx.clone()), @@ -4477,7 +4477,7 @@ impl ChannelMonitorImpl { upd.source == source } else { false }) { self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry { - txid: tx.txid(), + txid: tx.compute_txid(), transaction: Some(tx.clone()), height, block_hash: Some(*block_hash), @@ -4505,7 +4505,7 @@ impl ChannelMonitorImpl { } }); let entry = OnchainEventEntry { - txid: tx.txid(), + txid: tx.compute_txid(), transaction: Some(tx.clone()), height, block_hash: Some(*block_hash), @@ -4527,7 +4527,7 @@ impl ChannelMonitorImpl { for (i, outp) in tx.output.iter().enumerate() { if outp.script_pubkey == self.destination_script { spendable_outputs.push(SpendableOutputDescriptor::StaticOutput { - outpoint: OutPoint { txid: tx.txid(), index: i as u16 }, + outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 }, output: outp.clone(), channel_keys_id: Some(self.channel_keys_id), }); @@ -4535,7 +4535,7 @@ impl ChannelMonitorImpl { if let Some(ref broadcasted_holder_revokable_script) = self.broadcasted_holder_revokable_script { if broadcasted_holder_revokable_script.0 == outp.script_pubkey { spendable_outputs.push(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor { - outpoint: OutPoint { txid: tx.txid(), index: i as u16 }, + outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 }, per_commitment_point: broadcasted_holder_revokable_script.1, to_self_delay: self.on_holder_tx_csv, output: outp.clone(), @@ -4548,7 +4548,7 @@ impl ChannelMonitorImpl { } if self.counterparty_payment_script == outp.script_pubkey { spendable_outputs.push(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor { - outpoint: OutPoint { txid: tx.txid(), index: i as u16 }, + outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 }, output: outp.clone(), channel_keys_id: self.channel_keys_id, channel_value_satoshis: self.channel_value_satoshis, @@ -4557,7 +4557,7 @@ impl ChannelMonitorImpl { } if self.shutdown_script.as_ref() == Some(&outp.script_pubkey) { spendable_outputs.push(SpendableOutputDescriptor::StaticOutput { - outpoint: OutPoint { txid: tx.txid(), index: i as u16 }, + outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 }, output: outp.clone(), channel_keys_id: Some(self.channel_keys_id), }); @@ -4573,7 +4573,7 @@ impl ChannelMonitorImpl { ) where L::Target: Logger { for spendable_output in self.get_spendable_outputs(tx) { let entry = OnchainEventEntry { - txid: tx.txid(), + txid: tx.compute_txid(), transaction: Some(tx.clone()), height, block_hash: Some(*block_hash), @@ -5066,7 +5066,7 @@ mod tests { assert!(txn_broadcasted.len() >= 2); let htlc_txn = txn_broadcasted.iter().filter(|tx| { assert_eq!(tx.input.len(), 1); - tx.input[0].previous_output.txid == broadcast_tx.txid() + tx.input[0].previous_output.txid == broadcast_tx.compute_txid() }).collect::>(); assert_eq!(htlc_txn.len(), 2); check_spends!(htlc_txn[0], broadcast_tx); diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index cfb58c0be..eff827983 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -514,7 +514,7 @@ impl OnchainTxHandler { log_info!(logger, "{} onchain {}", log_start, log_tx!(tx.0)); broadcaster.broadcast_transactions(&[&tx.0]); } else { - log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.txid()); + log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.compute_txid()); } }, OnchainClaim::Event(event) => { @@ -535,7 +535,7 @@ impl OnchainTxHandler { } } - /// Returns true if we are currently tracking any pending claim requests that are not fully + /// Returns true if we are currently tracking any pending claim requests that are not fully /// confirmed yet. pub(super) fn has_pending_claims(&self) -> bool { @@ -619,7 +619,7 @@ impl OnchainTxHandler { let predicted_weight = cached_request.package_weight(&self.destination_script); if let Some((output_value, new_feerate)) = cached_request.compute_package_output( - predicted_weight, self.destination_script.dust_value().to_sat(), + predicted_weight, self.destination_script.minimal_non_dust().to_sat(), feerate_strategy, fee_estimator, logger, ) { assert!(new_feerate != 0); @@ -647,7 +647,7 @@ impl OnchainTxHandler { // Commitment inputs with anchors support are the only untractable inputs supported // thus far that require external funding. PackageSolvingData::HolderFundingOutput(output) => { - debug_assert_eq!(tx.0.txid(), self.holder_commitment.trust().txid(), + debug_assert_eq!(tx.0.compute_txid(), self.holder_commitment.trust().txid(), "Holder commitment transaction mismatch"); let conf_target = ConfirmationTarget::OnChainSweep; @@ -659,7 +659,7 @@ impl OnchainTxHandler { compute_feerate_sat_per_1000_weight(fee_sat, tx.0.weight().to_wu()); if commitment_tx_feerate_sat_per_1000_weight >= package_target_feerate_sat_per_1000_weight { log_debug!(logger, "Pre-signed commitment {} already has feerate {} sat/kW above required {} sat/kW", - tx.0.txid(), commitment_tx_feerate_sat_per_1000_weight, + tx.0.compute_txid(), commitment_tx_feerate_sat_per_1000_weight, package_target_feerate_sat_per_1000_weight); return Some((new_timer, 0, OnchainClaim::Tx(tx.clone()))); } @@ -811,9 +811,9 @@ impl OnchainTxHandler { log_info!(logger, "Broadcasting onchain {}", log_tx!(tx.0)); broadcaster.broadcast_transactions(&[&tx.0]); } else { - log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.txid()); + log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.compute_txid()); } - ClaimId(tx.0.txid().to_byte_array()) + ClaimId(tx.0.compute_txid().to_byte_array()) }, OnchainClaim::Event(claim_event) => { log_info!(logger, "Yielding onchain event to spend inputs {:?}", req.outpoints()); @@ -821,7 +821,7 @@ impl OnchainTxHandler { ClaimEvent::BumpCommitment { ref commitment_tx, .. } => // For commitment claims, we can just use their txid as it should // already be unique. - ClaimId(commitment_tx.txid().to_byte_array()), + ClaimId(commitment_tx.compute_txid().to_byte_array()), ClaimEvent::BumpHTLC { ref htlcs, .. } => { // For HTLC claims, commit to the entire set of HTLC outputs to // claim, which will always be unique per request. Once a claim ID @@ -900,7 +900,7 @@ impl OnchainTxHandler { macro_rules! clean_claim_request_after_safety_delay { () => { let entry = OnchainEventEntry { - txid: tx.txid(), + txid: tx.compute_txid(), height: conf_height, block_hash: Some(conf_hash), event: OnchainEvent::Claim { claim_id: *claim_id } @@ -953,7 +953,7 @@ impl OnchainTxHandler { } for package in claimed_outputs_material.drain(..) { let entry = OnchainEventEntry { - txid: tx.txid(), + txid: tx.compute_txid(), height: conf_height, block_hash: Some(conf_hash), event: OnchainEvent::ContentiousOutpoint { package }, @@ -1023,7 +1023,7 @@ impl OnchainTxHandler { broadcaster.broadcast_transactions(&[&bump_tx.0]); } else { log_info!(logger, "Waiting for signature of RBF-bumped unsigned onchain transaction {}", - bump_tx.0.txid()); + bump_tx.0.compute_txid()); } }, OnchainClaim::Event(claim_event) => { @@ -1110,7 +1110,7 @@ impl OnchainTxHandler { log_info!(logger, "Broadcasting onchain {}", log_tx!(bump_tx.0)); broadcaster.broadcast_transactions(&[&bump_tx.0]); } else { - log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", bump_tx.0.txid()); + log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", bump_tx.0.compute_txid()); } }, OnchainClaim::Event(claim_event) => { diff --git a/lightning/src/chain/transaction.rs b/lightning/src/chain/transaction.rs index e9b75a639..60c1e4475 100644 --- a/lightning/src/chain/transaction.rs +++ b/lightning/src/chain/transaction.rs @@ -98,11 +98,11 @@ mod tests { fn test_channel_id_calculation() { let tx: Transaction = encode::deserialize(&>::from_hex("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap(); assert_eq!(&ChannelId::v1_from_funding_outpoint(OutPoint { - txid: tx.txid(), + txid: tx.compute_txid(), index: 0 }).0[..], &>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25e").unwrap()[..]); assert_eq!(&ChannelId::v1_from_funding_outpoint(OutPoint { - txid: tx.txid(), + txid: tx.compute_txid(), index: 1 }).0[..], &>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25f").unwrap()[..]); } diff --git a/lightning/src/events/bump_transaction.rs b/lightning/src/events/bump_transaction.rs index 482a92828..4f4e0c15c 100644 --- a/lightning/src/events/bump_transaction.rs +++ b/lightning/src/events/bump_transaction.rs @@ -471,7 +471,7 @@ where WITNESS_SCALE_FACTOR as u64, ); let change_output_amount = Amount::from_sat(remaining_amount.to_sat().saturating_sub(change_output_fee)); - let change_output = if change_output_amount < change_script.dust_value() { + let change_output = if change_output_amount < change_script.minimal_non_dust() { log_debug!(self.logger, "Coin selection attempt did not yield change output"); None } else { @@ -632,7 +632,7 @@ where coin_selection.confirmed_utxos.iter().map(|utxo| utxo.output.value).sum(); self.process_coin_selection(&mut anchor_tx, &coin_selection); - let anchor_txid = anchor_tx.txid(); + let anchor_txid = anchor_tx.compute_txid(); // construct psbt let mut anchor_psbt = Psbt::from_unsigned_tx(anchor_tx).unwrap(); @@ -679,7 +679,7 @@ where } log_info!(self.logger, "Broadcasting anchor transaction {} to bump channel close with txid {}", - anchor_txid, commitment_tx.txid()); + anchor_txid, commitment_tx.compute_txid()); self.broadcaster.broadcast_transactions(&[&commitment_tx, &anchor_tx]); Ok(()) } @@ -755,7 +755,7 @@ where #[cfg(debug_assertions)] let unsigned_tx_weight = htlc_psbt.unsigned_tx.weight().to_wu() - (htlc_psbt.unsigned_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT); - log_debug!(self.logger, "Signing HTLC transaction {}", htlc_psbt.unsigned_tx.txid()); + log_debug!(self.logger, "Signing HTLC transaction {}", htlc_psbt.unsigned_tx.compute_txid()); htlc_tx = self.utxo_source.sign_psbt(htlc_psbt)?; let mut signers = BTreeMap::new(); @@ -798,13 +798,13 @@ where commitment_tx_fee_satoshis, anchor_descriptor, .. } => { log_info!(self.logger, "Handling channel close bump (claim_id = {}, commitment_txid = {})", - log_bytes!(claim_id.0), commitment_tx.txid()); + log_bytes!(claim_id.0), commitment_tx.compute_txid()); if let Err(_) = self.handle_channel_close( *claim_id, *package_target_feerate_sat_per_1000_weight, commitment_tx, *commitment_tx_fee_satoshis, anchor_descriptor, ) { log_error!(self.logger, "Failed bumping commitment transaction fee for {}", - commitment_tx.txid()); + commitment_tx.compute_txid()); } } BumpTransactionEvent::HTLCResolution { diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 2215f82bd..1bcd02a9f 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -119,7 +119,7 @@ pub mod io_extras { Ok(count) } - pub fn read_to_end(mut d: &mut D) -> Result, io::Error> { + pub fn read_to_end(d: &mut D) -> Result, io::Error> { let mut result = vec![]; let mut buf = [0u8; 64]; loop { diff --git a/lightning/src/ln/async_signer_tests.rs b/lightning/src/ln/async_signer_tests.rs index 06fd39867..167d2daac 100644 --- a/lightning/src/ln/async_signer_tests.rs +++ b/lightning/src/ln/async_signer_tests.rs @@ -734,7 +734,7 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) { if anchors { *nodes[0].fee_estimator.sat_per_kw.lock().unwrap() *= 2; *nodes[1].fee_estimator.sat_per_kw.lock().unwrap() *= 2; - closing_node.wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); + closing_node.wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); } // Route an HTLC and set the signer as unavailable. @@ -773,7 +773,7 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) { txn.remove(0) } else { assert_eq!(txn.len(), 2); - if txn[0].input[0].previous_output.txid == funding_tx.txid() { + if txn[0].input[0].previous_output.txid == funding_tx.compute_txid() { check_spends!(txn[0], funding_tx); check_spends!(txn[1], txn[0]); txn.remove(0) diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index 407bfd3db..88b830f16 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -1427,7 +1427,7 @@ impl CommitmentTransaction { let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters); let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs); - let txid = transaction.txid(); + let txid = transaction.compute_txid(); CommitmentTransaction { commitment_number, to_broadcaster_value_sat, @@ -1459,7 +1459,7 @@ impl CommitmentTransaction { let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters, broadcaster_funding_key, countersignatory_funding_key)?; let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs); - let txid = transaction.txid(); + let txid = transaction.compute_txid(); let built_transaction = BuiltCommitmentTransaction { transaction, txid @@ -2052,7 +2052,7 @@ mod tests { let justice_tx = tx.trust().build_to_local_justice_tx(253, destination_script.clone()).unwrap(); assert_eq!(justice_tx.input.len(), 1); - assert_eq!(justice_tx.input[0].previous_output.txid, tx.built.transaction.txid()); + assert_eq!(justice_tx.input[0].previous_output.txid, tx.built.transaction.compute_txid()); assert_eq!(justice_tx.input[0].previous_output.vout, tx.trust().revokeable_output_index().unwrap() as u32); assert!(justice_tx.input[0].sequence.is_rbf()); diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 9bc48f12f..b61b7c63f 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -50,7 +50,7 @@ fn test_monitor_and_persister_update_fail() { // Create some initial channel let chan = create_announced_chan_between_nodes(&nodes, 0, 1); - let outpoint = OutPoint { txid: chan.3.txid(), index: 0 }; + let outpoint = OutPoint { txid: chan.3.compute_txid(), index: 0 }; // Rebalance the network to generate htlc in the two directions send_payment(&nodes[0], &vec!(&nodes[1])[..], 10_000_000); @@ -1884,7 +1884,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 0); assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1); - assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0)[0].txid(), funding_output.txid); + assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0)[0].compute_txid(), funding_output.txid); if confirm_a_first { confirm_transaction(&nodes[0], &funding_tx); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 4db39f0d6..907a50587 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -6714,7 +6714,7 @@ impl Channel where // Check if the transaction is the expected funding transaction, and if it is, // check that it pays the right amount to the right script. if self.context.funding_tx_confirmation_height == 0 { - if tx.txid() == funding_txo.txid { + if tx.compute_txid() == funding_txo.txid { let txo_idx = funding_txo.index as usize; if txo_idx >= tx.output.len() || tx.output[txo_idx].script_pubkey != self.context.get_funding_redeemscript().to_p2wsh() || tx.output[txo_idx].value.to_sat() != self.context.channel_value_satoshis { @@ -6769,7 +6769,7 @@ impl Channel where } for inp in tx.input.iter() { if inp.previous_output == funding_txo.into_bitcoin_outpoint() { - log_info!(logger, "Detected channel-closing tx {} spending {}:{}, closing channel {}", tx.txid(), inp.previous_output.txid, inp.previous_output.vout, &self.context.channel_id()); + log_info!(logger, "Detected channel-closing tx {} spending {}:{}, closing channel {}", tx.compute_txid(), inp.previous_output.txid, inp.previous_output.vout, &self.context.channel_id()); return Err(ClosureReason::CommitmentTxConfirmed); } } @@ -9752,7 +9752,7 @@ mod tests { let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut { value: Amount::from_sat(10000000), script_pubkey: output_script.clone(), }]}; - let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 }; + let funding_outpoint = OutPoint{ txid: tx.compute_txid(), index: 0 }; let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap(); let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap(); @@ -9882,7 +9882,7 @@ mod tests { let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut { value: Amount::from_sat(10000000), script_pubkey: output_script.clone(), }]}; - let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 }; + let funding_outpoint = OutPoint{ txid: tx.compute_txid(), index: 0 }; let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap(); let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap(); @@ -10071,7 +10071,7 @@ mod tests { let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut { value: Amount::from_sat(10000000), script_pubkey: output_script.clone(), }]}; - let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 }; + let funding_outpoint = OutPoint{ txid: tx.compute_txid(), index: 0 }; let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap(); let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap(); @@ -10139,7 +10139,7 @@ mod tests { let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut { value: Amount::from_sat(10000000), script_pubkey: outbound_chan.context.get_funding_redeemscript(), }]}; - let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 }; + let funding_outpoint = OutPoint{ txid: tx.compute_txid(), index: 0 }; let funding_created = outbound_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap().unwrap(); let mut chan = match inbound_chan.funding_created(&funding_created, best_block, &&keys_provider, &&logger) { Ok((chan, _, _)) => chan, @@ -11272,7 +11272,7 @@ mod tests { value: Amount::from_sat(10000000), script_pubkey: Builder::new().into_script(), }, ]}; - let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 }; + let funding_outpoint = OutPoint{ txid: tx.compute_txid(), index: 0 }; let funding_created_msg = node_a_chan.get_funding_created( tx.clone(), funding_outpoint, true, &&logger, ).map_err(|_| ()).unwrap(); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 4ce3ebc37..2233eddfc 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -723,7 +723,7 @@ enum FundingType { impl FundingType { fn txid(&self) -> Txid { match self { - FundingType::Checked(tx) => tx.txid(), + FundingType::Checked(tx) => tx.compute_txid(), FundingType::Unchecked(outp) => outp.txid, } } @@ -2850,7 +2850,7 @@ macro_rules! handle_monitor_update_completion { } } if let Some(tx) = batch_funding_tx { - log_info!($self.logger, "Broadcasting batch funding transaction with txid {}", tx.txid()); + log_info!($self.logger, "Broadcasting batch funding transaction with txid {}", tx.compute_txid()); $self.tx_broadcaster.broadcast_transactions(&[&tx]); } } @@ -4543,7 +4543,7 @@ where #[cfg(test)] pub(crate) fn funding_transaction_generated_unchecked(&self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding_transaction: Transaction, output_index: u16) -> Result<(), APIError> { - let txid = funding_transaction.txid(); + let txid = funding_transaction.compute_txid(); self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, false, |_| { Ok(OutPoint { txid, index: output_index }) }, false) @@ -7048,7 +7048,7 @@ where if let Some(tx) = funding_broadcastable { if channel.context.is_manual_broadcast() { - log_info!(logger, "Not broadcasting funding transaction with txid {} as it is manually managed", tx.txid()); + log_info!(logger, "Not broadcasting funding transaction with txid {} as it is manually managed", tx.compute_txid()); let mut pending_events = self.pending_events.lock().unwrap(); match channel.context.get_funding_txo() { Some(funding_txo) => { @@ -7060,7 +7060,7 @@ where } }; } else { - log_info!(logger, "Broadcasting funding transaction with txid {}", tx.txid()); + log_info!(logger, "Broadcasting funding transaction with txid {}", tx.compute_txid()); self.tx_broadcaster.broadcast_transactions(&[&tx]); } } @@ -13340,7 +13340,7 @@ mod tests { nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42); - let channel_id = ChannelId::from_bytes(tx.txid().to_byte_array()); + let channel_id = ChannelId::from_bytes(tx.compute_txid().to_byte_array()); { // Ensure that the `outpoint_to_peer` map is empty until either party has received the // funding transaction, and have the real `channel_id`. diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 5f1b7123d..879d77f37 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -331,7 +331,7 @@ fn do_connect_block_without_consistency_checks<'a, 'b, 'c, 'd>(node: &'a Node<'b let wallet_script = node.wallet_source.get_change_script().unwrap(); for (idx, output) in tx.output.iter().enumerate() { if output.script_pubkey == wallet_script { - let outpoint = bitcoin::OutPoint { txid: tx.txid(), vout: idx as u32 }; + let outpoint = bitcoin::OutPoint { txid: tx.compute_txid(), vout: idx as u32 }; node.wallet_source.add_utxo(outpoint, output.value); } } @@ -362,8 +362,8 @@ pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32) }, ConnectStyle::BestBlockFirstReorgsOnlyTip|ConnectStyle::TransactionsFirstReorgsOnlyTip => { for tx in orig.0.txdata { - node.chain_monitor.chain_monitor.transaction_unconfirmed(&tx.txid()); - node.node.transaction_unconfirmed(&tx.txid()); + node.chain_monitor.chain_monitor.transaction_unconfirmed(&tx.compute_txid()); + node.node.transaction_unconfirmed(&tx.compute_txid()); } }, _ => { @@ -1207,7 +1207,7 @@ fn internal_create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, let tx = Transaction { version: transaction::Version(chan_id as i32), lock_time: LockTime::ZERO, input, output: vec![TxOut { value: Amount::from_sat(*channel_value_satoshis), script_pubkey: output_script.clone(), }]}; - let funding_outpoint = OutPoint { txid: tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: tx.compute_txid(), index: 0 }; (*temporary_channel_id, tx, funding_outpoint) }, _ => panic!("Unexpected event"), @@ -1525,7 +1525,7 @@ pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec Option>(tx: &Transaction, get_output: F) { for outp in tx.output.iter() { - assert!(outp.value >= outp.script_pubkey.dust_value(), "Spending tx output didn't meet dust limit"); + assert!(outp.value >= outp.script_pubkey.minimal_non_dust(), "Spending tx output didn't meet dust limit"); } let mut total_value_in = 0; for input in tx.input.iter() { @@ -1547,12 +1547,12 @@ macro_rules! check_spends { { $( for outp in $spends_txn.output.iter() { - assert!(outp.value >= outp.script_pubkey.dust_value(), "Input tx output didn't meet dust limit"); + assert!(outp.value >= outp.script_pubkey.minimal_non_dust(), "Input tx output didn't meet dust limit"); } )* let get_output = |out_point: &bitcoin::transaction::OutPoint| { $( - if out_point.txid == $spends_txn.txid() { + if out_point.txid == $spends_txn.compute_txid() { return $spends_txn.output.get(out_point.vout as usize).cloned() } )* @@ -3369,12 +3369,12 @@ pub enum HTLCType { NONE, TIMEOUT, SUCCESS } pub fn test_txn_broadcast<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, chan: &(msgs::ChannelUpdate, msgs::ChannelUpdate, ChannelId, Transaction), commitment_tx: Option, has_htlc_tx: HTLCType) -> Vec { let mut node_txn = node.tx_broadcaster.txn_broadcasted.lock().unwrap(); let mut txn_seen = new_hash_set(); - node_txn.retain(|tx| txn_seen.insert(tx.txid())); + node_txn.retain(|tx| txn_seen.insert(tx.compute_txid())); assert!(node_txn.len() >= if commitment_tx.is_some() { 0 } else { 1 } + if has_htlc_tx == HTLCType::NONE { 0 } else { 1 }); let mut res = Vec::with_capacity(2); node_txn.retain(|tx| { - if tx.input.len() == 1 && tx.input[0].previous_output.txid == chan.3.txid() { + if tx.input.len() == 1 && tx.input[0].previous_output.txid == chan.3.compute_txid() { check_spends!(tx, chan.3); if commitment_tx.is_none() { res.push(tx.clone()); @@ -3390,7 +3390,7 @@ pub fn test_txn_broadcast<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, chan: &(msgs::Cha if has_htlc_tx != HTLCType::NONE { node_txn.retain(|tx| { - if tx.input.len() == 1 && tx.input[0].previous_output.txid == res[0].txid() { + if tx.input.len() == 1 && tx.input[0].previous_output.txid == res[0].compute_txid() { check_spends!(tx, res[0]); if has_htlc_tx == HTLCType::TIMEOUT { assert_ne!(tx.lock_time, LockTime::ZERO); @@ -3419,7 +3419,7 @@ pub fn test_revoked_htlc_claim_txn_broadcast<'a, 'b, 'c>(node: &Node<'a, 'b, 'c> // for revoked htlc outputs if node_txn.len() != 1 && node_txn.len() != 2 && node_txn.len() != 3 { assert!(false); } node_txn.retain(|tx| { - if tx.input.len() == 1 && tx.input[0].previous_output.txid == revoked_tx.txid() { + if tx.input.len() == 1 && tx.input[0].previous_output.txid == revoked_tx.compute_txid() { check_spends!(tx, revoked_tx); false } else { true } @@ -3434,12 +3434,12 @@ pub fn test_revoked_htlc_claim_txn_broadcast<'a, 'b, 'c>(node: &Node<'a, 'b, 'c> pub fn check_preimage_claim<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, prev_txn: &Vec) -> Vec { let mut node_txn = node.tx_broadcaster.txn_broadcasted.lock().unwrap(); let mut txn_seen = new_hash_set(); - node_txn.retain(|tx| txn_seen.insert(tx.txid())); + node_txn.retain(|tx| txn_seen.insert(tx.compute_txid())); let mut found_prev = false; for prev_tx in prev_txn { for tx in &*node_txn { - if tx.input[0].previous_output.txid == prev_tx.txid() { + if tx.input[0].previous_output.txid == prev_tx.compute_txid() { check_spends!(tx, prev_tx); let mut iter = tx.input[0].witness.iter(); iter.next().expect("expected 3 witness items"); diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 99063334a..e78640ab9 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -2382,7 +2382,7 @@ fn channel_monitor_network_test() { let node_txn = test_txn_broadcast(&nodes[2], &chan_3, None, HTLCType::NONE); connect_blocks(&nodes[2], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + MIN_CLTV_EXPIRY_DELTA as u32 + 1); test_txn_broadcast(&nodes[2], &chan_3, None, HTLCType::TIMEOUT); - node2_commitment_txid = node_txn[0].txid(); + node2_commitment_txid = node_txn[0].compute_txid(); // Claim the payment on nodes[3], giving it knowledge of the preimage claim_funds!(nodes[3], nodes[2], payment_preimage_1, payment_hash_1); @@ -2398,7 +2398,7 @@ fn channel_monitor_network_test() { // Drop the ChannelMonitor for the previous channel to avoid it broadcasting transactions and // confusing us in the following tests. - let chan_3_mon = nodes[3].chain_monitor.chain_monitor.remove_monitor(&OutPoint { txid: chan_3.3.txid(), index: 0 }); + let chan_3_mon = nodes[3].chain_monitor.chain_monitor.remove_monitor(&OutPoint { txid: chan_3.3.compute_txid(), index: 0 }); // One pending HTLC to time out: let (payment_preimage_2, payment_hash_2, ..) = route_payment(&nodes[3], &[&nodes[4]], 3_000_000); @@ -2466,7 +2466,7 @@ fn channel_monitor_network_test() { assert_eq!(nodes[3].node.list_channels().len(), 0); assert_eq!(nodes[4].node.list_channels().len(), 0); - assert_eq!(nodes[3].chain_monitor.chain_monitor.watch_channel(OutPoint { txid: chan_3.3.txid(), index: 0 }, chan_3_mon), + assert_eq!(nodes[3].chain_monitor.chain_monitor.watch_channel(OutPoint { txid: chan_3.3.compute_txid(), index: 0 }, chan_3_mon), Ok(ChannelMonitorUpdateStatus::Completed)); check_closed_event!(nodes[3], 1, ClosureReason::HTLCsTimedOut, [nodes[4].node.get_our_node_id()], 100000); } @@ -2498,10 +2498,10 @@ fn test_justice_tx_htlc_timeout() { let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan_5.2); assert_eq!(revoked_local_txn.len(), 2); // First commitment tx, then HTLC tx assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_5.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_5.3.compute_txid()); assert_eq!(revoked_local_txn[0].output.len(), 2); // Only HTLC and output back to 0 are present assert_eq!(revoked_local_txn[1].input.len(), 1); - assert_eq!(revoked_local_txn[1].input[0].previous_output.txid, revoked_local_txn[0].txid()); + assert_eq!(revoked_local_txn[1].input[0].previous_output.txid, revoked_local_txn[0].compute_txid()); assert_eq!(revoked_local_txn[1].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC-Timeout // Revoke the old state claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage_3); @@ -2561,7 +2561,7 @@ fn test_justice_tx_htlc_success() { let revoked_local_txn = get_local_commitment_txn!(nodes[1], chan_6.2); assert_eq!(revoked_local_txn.len(), 1); // Only commitment tx assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_6.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_6.3.compute_txid()); assert_eq!(revoked_local_txn[0].output.len(), 2); // Only HTLC and output back to A are present // Revoke the old state claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage_4); @@ -2644,7 +2644,7 @@ fn do_test_forming_justice_tx_from_monitor_updates(broadcast_initial_commitment: let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let (_, _, channel_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1); - let funding_txo = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_txo = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; if !broadcast_initial_commitment { // Send a payment to move the channel forward @@ -2660,7 +2660,7 @@ fn do_test_forming_justice_tx_from_monitor_updates(broadcast_initial_commitment: // Send another payment, now revoking the previous commitment tx send_payment(&nodes[0], &vec!(&nodes[1])[..], 5_000_000); - let justice_tx = persisters[1].justice_tx(funding_txo, &revoked_commitment_tx.txid()).unwrap(); + let justice_tx = persisters[1].justice_tx(funding_txo, &revoked_commitment_tx.compute_txid()).unwrap(); check_spends!(justice_tx, revoked_commitment_tx); mine_transactions(&nodes[1], &[revoked_commitment_tx, &justice_tx]); @@ -2712,9 +2712,9 @@ fn claim_htlc_outputs_shared_tx() { let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan_1.2); assert_eq!(revoked_local_txn.len(), 2); // commitment tx + 1 HTLC-Timeout tx assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.compute_txid()); assert_eq!(revoked_local_txn[1].input.len(), 1); - assert_eq!(revoked_local_txn[1].input[0].previous_output.txid, revoked_local_txn[0].txid()); + assert_eq!(revoked_local_txn[1].input[0].previous_output.txid, revoked_local_txn[0].compute_txid()); assert_eq!(revoked_local_txn[1].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT); // HTLC-Timeout check_spends!(revoked_local_txn[1], revoked_local_txn[0]); @@ -2808,7 +2808,7 @@ fn claim_htlc_outputs_single_tx() { check_spends!(node_txn[1], node_txn[0]); // Filter out any non justice transactions. - node_txn.retain(|tx| tx.input[0].previous_output.txid == revoked_local_txn[0].txid()); + node_txn.retain(|tx| tx.input[0].previous_output.txid == revoked_local_txn[0].compute_txid()); assert!(node_txn.len() > 3); assert_eq!(node_txn[0].input.len(), 1); @@ -2916,7 +2916,7 @@ fn test_htlc_on_chain_success() { { let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); - assert_eq!(added_monitors[0].0.txid, chan_2.3.txid()); + assert_eq!(added_monitors[0].0.txid, chan_2.3.compute_txid()); added_monitors.clear(); } let forwarded_events = nodes[1].node.get_and_clear_pending_events(); @@ -2954,8 +2954,8 @@ fn test_htlc_on_chain_success() { { let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 2); - assert_eq!(added_monitors[0].0.txid, chan_1.3.txid()); - assert_eq!(added_monitors[1].0.txid, chan_1.3.txid()); + assert_eq!(added_monitors[0].0.txid, chan_1.3.compute_txid()); + assert_eq!(added_monitors[1].0.txid, chan_1.3.compute_txid()); added_monitors.clear(); } assert_eq!(events.len(), 3); @@ -3028,7 +3028,7 @@ fn test_htlc_on_chain_success() { } else { // Certain `ConnectStyle`s will cause RBF bumps of the previous HTLC transaction to be broadcast. // FullBlockViaListen - if node_txn[0].input[0].previous_output.txid == node_a_commitment_tx[0].txid() { + if node_txn[0].input[0].previous_output.txid == node_a_commitment_tx[0].compute_txid() { check_spends!(node_txn[1], commitment_tx[0]); check_spends!(node_txn[2], commitment_tx[0]); assert_ne!(node_txn[1].input[0].previous_output.vout, node_txn[2].input[0].previous_output.vout); @@ -3697,7 +3697,7 @@ fn test_force_close_fail_back() { assert_eq!(node_txn.len(), if nodes[2].connect_style.borrow().updates_best_block_first() { 2 } else { 1 }); let htlc_tx = node_txn.pop().unwrap(); assert_eq!(htlc_tx.input.len(), 1); - assert_eq!(htlc_tx.input[0].previous_output.txid, commitment_tx.txid()); + assert_eq!(htlc_tx.input[0].previous_output.txid, commitment_tx.compute_txid()); assert_eq!(htlc_tx.lock_time, LockTime::ZERO); // Must be an HTLC-Success assert_eq!(htlc_tx.input[0].witness.len(), 5); // Must be an HTLC-Success @@ -4614,7 +4614,7 @@ fn test_claim_on_remote_revoked_sizeable_push_msat() { let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan.2); assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan.3.compute_txid()); claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage); mine_transaction(&nodes[1], &revoked_local_txn[0]); @@ -4647,7 +4647,7 @@ fn test_static_spendable_outputs_preimage_tx() { let commitment_tx = get_local_commitment_txn!(nodes[0], chan_1.2); assert_eq!(commitment_tx[0].input.len(), 1); - assert_eq!(commitment_tx[0].input[0].previous_output.txid, chan_1.3.txid()); + assert_eq!(commitment_tx[0].input[0].previous_output.txid, chan_1.3.compute_txid()); // Settle A's commitment tx on B's chain nodes[1].node.claim_funds(payment_preimage); @@ -4697,7 +4697,7 @@ fn test_static_spendable_outputs_timeout_tx() { let commitment_tx = get_local_commitment_txn!(nodes[0], chan_1.2); assert_eq!(commitment_tx[0].input.len(), 1); - assert_eq!(commitment_tx[0].input[0].previous_output.txid, chan_1.3.txid()); + assert_eq!(commitment_tx[0].input[0].previous_output.txid, chan_1.3.compute_txid()); // Settle A's commitment tx on B' chain mine_transaction(&nodes[1], &commitment_tx[0]); @@ -4740,7 +4740,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_commitment_tx() { let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan_1.2); assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.compute_txid()); claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage); @@ -4776,7 +4776,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() { let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan_1.2); assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.compute_txid()); claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage); @@ -4810,10 +4810,10 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() { assert_eq!(node_txn[1].input.len(), 2); check_spends!(node_txn[1], revoked_local_txn[0], revoked_htlc_txn[0]); - if node_txn[1].input[1].previous_output.txid == revoked_htlc_txn[0].txid() { + if node_txn[1].input[1].previous_output.txid == revoked_htlc_txn[0].compute_txid() { assert_ne!(node_txn[1].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output); } else { - assert_eq!(node_txn[1].input[0].previous_output.txid, revoked_htlc_txn[0].txid()); + assert_eq!(node_txn[1].input[0].previous_output.txid, revoked_htlc_txn[0].compute_txid()); assert_ne!(node_txn[1].input[1].previous_output, revoked_htlc_txn[0].input[0].previous_output); } @@ -4841,7 +4841,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() { let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let revoked_local_txn = get_local_commitment_txn!(nodes[1], chan_1.2); assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.compute_txid()); // The to-be-revoked commitment tx should have one HTLC and one to_remote output assert_eq!(revoked_local_txn[0].output.len(), 2); @@ -4878,10 +4878,10 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() { // transactions next... assert_eq!(node_txn[0].input.len(), 2); check_spends!(node_txn[0], revoked_local_txn[0], revoked_htlc_txn[0]); - if node_txn[0].input[1].previous_output.txid == revoked_htlc_txn[0].txid() { + if node_txn[0].input[1].previous_output.txid == revoked_htlc_txn[0].compute_txid() { assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output); } else { - assert_eq!(node_txn[0].input[0].previous_output.txid, revoked_htlc_txn[0].txid()); + assert_eq!(node_txn[0].input[0].previous_output.txid, revoked_htlc_txn[0].compute_txid()); assert_eq!(node_txn[0].input[1].previous_output, revoked_htlc_txn[0].input[0].previous_output); } @@ -7205,7 +7205,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) { connect_blocks(&nodes[0], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires timeout_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().drain(..) - .filter(|tx| tx.input[0].previous_output.txid == bs_commitment_tx[0].txid()).collect(); + .filter(|tx| tx.input[0].previous_output.txid == bs_commitment_tx[0].compute_txid()).collect(); check_spends!(timeout_tx[0], bs_commitment_tx[0]); // For both a revoked or non-revoked commitment transaction, after ANTI_REORG_DELAY the // dust HTLC should have been failed. @@ -7490,8 +7490,8 @@ fn test_bump_penalty_txn_on_revoked_commitment() { // Revoked commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC assert_eq!(revoked_txn[0].output.len(), 4); assert_eq!(revoked_txn[0].input.len(), 1); - assert_eq!(revoked_txn[0].input[0].previous_output.txid, chan.3.txid()); - let revoked_txid = revoked_txn[0].txid(); + assert_eq!(revoked_txn[0].input[0].previous_output.txid, chan.3.compute_txid()); + let revoked_txid = revoked_txn[0].compute_txid(); let mut penalty_sum = 0; for outp in revoked_txn[0].output.iter() { @@ -7519,7 +7519,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() { check_spends!(node_txn[0], revoked_txn[0]); let fee_1 = penalty_sum - node_txn[0].output[0].value.to_sat(); feerate_1 = fee_1 * 1000 / node_txn[0].weight().to_wu(); - penalty_1 = node_txn[0].txid(); + penalty_1 = node_txn[0].compute_txid(); node_txn.clear(); }; @@ -7534,7 +7534,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() { assert_eq!(node_txn[0].input.len(), 3); // Penalty txn claims to_local, offered_htlc and received_htlc outputs assert_eq!(node_txn[0].output.len(), 1); check_spends!(node_txn[0], revoked_txn[0]); - penalty_2 = node_txn[0].txid(); + penalty_2 = node_txn[0].compute_txid(); // Verify new bumped tx is different from last claiming transaction, we don't want spurrious rebroadcast assert_ne!(penalty_2, penalty_1); let fee_2 = penalty_sum - node_txn[0].output[0].value.to_sat(); @@ -7557,7 +7557,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() { assert_eq!(node_txn[0].input.len(), 3); // Penalty txn claims to_local, offered_htlc and received_htlc outputs assert_eq!(node_txn[0].output.len(), 1); check_spends!(node_txn[0], revoked_txn[0]); - penalty_3 = node_txn[0].txid(); + penalty_3 = node_txn[0].compute_txid(); // Verify new bumped tx is different from last claiming transaction, we don't want spurrious rebroadcast assert_ne!(penalty_3, penalty_2); let fee_3 = penalty_sum - node_txn[0].output[0].value.to_sat(); @@ -7602,7 +7602,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() { let revoked_local_txn = get_local_commitment_txn!(nodes[1], chan.2); assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan.3.compute_txid()); // Revoke local commitment tx claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage); @@ -7677,7 +7677,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() { assert_eq!(node_txn[3].output.len(), 1); check_spends!(node_txn[3], revoked_htlc_txn[0], revoked_htlc_txn[1]); - first = node_txn[3].txid(); + first = node_txn[3].compute_txid(); // Store both feerates for later comparison let fee_1 = revoked_htlc_txn[0].output[0].value + revoked_htlc_txn[1].output[0].value - node_txn[3].output[0].value; feerate_1 = fee_1 * 1000 / node_txn[3].weight().to_wu(); @@ -7702,7 +7702,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() { assert_eq!(node_txn[0].input.len(), 2); check_spends!(node_txn[0], revoked_htlc_txn[0], revoked_htlc_txn[1]); // Verify bumped tx is different and 25% bump heuristic - assert_ne!(first, node_txn[0].txid()); + assert_ne!(first, node_txn[0].compute_txid()); let fee_2 = revoked_htlc_txn[0].output[0].value + revoked_htlc_txn[1].output[0].value - node_txn[0].output[0].value; let feerate_2 = fee_2 * 1000 / node_txn[0].weight().to_wu(); assert!(feerate_2 * 100 > feerate_1 * 125); @@ -7750,7 +7750,7 @@ fn test_bump_penalty_txn_on_remote_commitment() { let remote_txn = get_local_commitment_txn!(nodes[0], chan.2); assert_eq!(remote_txn[0].output.len(), 4); assert_eq!(remote_txn[0].input.len(), 1); - assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.txid()); + assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid()); // Claim a HTLC without revocation (provide B monitor with preimage) nodes[1].node.claim_funds(payment_preimage); @@ -7777,7 +7777,7 @@ fn test_bump_penalty_txn_on_remote_commitment() { check_spends!(node_txn[1], remote_txn[0]); check_spends!(node_txn[2], remote_txn[0]); - preimage = node_txn[0].txid(); + preimage = node_txn[0].compute_txid(); let index = node_txn[0].input[0].previous_output.vout; let fee = remote_txn[0].output[index as usize].value.to_sat() - node_txn[0].output[0].value.to_sat(); feerate_preimage = fee * 1000 / node_txn[0].weight().to_wu(); @@ -7792,7 +7792,7 @@ fn test_bump_penalty_txn_on_remote_commitment() { check_spends!(preimage_bump, remote_txn[0]); assert_eq!(node_txn[0].input[0].previous_output, preimage_bump.input[0].previous_output); - timeout = timeout_tx.txid(); + timeout = timeout_tx.compute_txid(); let index = timeout_tx.input[0].previous_output.vout; let fee = remote_txn[0].output[index as usize].value.to_sat() - timeout_tx.output[0].value.to_sat(); feerate_timeout = fee * 1000 / timeout_tx.weight().to_wu(); @@ -7816,13 +7816,13 @@ fn test_bump_penalty_txn_on_remote_commitment() { let fee = remote_txn[0].output[index as usize].value.to_sat() - preimage_bump.output[0].value.to_sat(); let new_feerate = fee * 1000 / preimage_bump.weight().to_wu(); assert!(new_feerate * 100 > feerate_timeout * 125); - assert_ne!(timeout, preimage_bump.txid()); + assert_ne!(timeout, preimage_bump.compute_txid()); let index = node_txn[0].input[0].previous_output.vout; let fee = remote_txn[0].output[index as usize].value.to_sat() - node_txn[0].output[0].value.to_sat(); let new_feerate = fee * 1000 / node_txn[0].weight().to_wu(); assert!(new_feerate * 100 > feerate_preimage * 125); - assert_ne!(preimage, node_txn[0].txid()); + assert_ne!(preimage, node_txn[0].compute_txid()); node_txn.clear(); } @@ -7902,7 +7902,7 @@ fn test_bump_txn_sanitize_tracking_maps() { let revoked_local_txn = get_local_commitment_txn!(nodes[1], chan.2); assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan.3.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan.3.compute_txid()); // Revoke local commitment tx claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage_1); @@ -7929,7 +7929,7 @@ fn test_bump_txn_sanitize_tracking_maps() { connect_block(&nodes[0], &create_dummy_block(nodes[0].best_block_hash(), 42, penalty_txn)); connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1); { - let monitor = nodes[0].chain_monitor.chain_monitor.get_monitor(OutPoint { txid: chan.3.txid(), index: 0 }).unwrap(); + let monitor = nodes[0].chain_monitor.chain_monitor.get_monitor(OutPoint { txid: chan.3.compute_txid(), index: 0 }).unwrap(); assert!(monitor.inner.lock().unwrap().onchain_tx_handler.pending_claim_requests.is_empty()); assert!(monitor.inner.lock().unwrap().onchain_tx_handler.claimable_outpoints.is_empty()); } @@ -8544,7 +8544,7 @@ fn test_update_err_monitor_lockdown() { // Create some initial channel let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1); - let outpoint = OutPoint { txid: chan_1.3.txid(), index: 0 }; + let outpoint = OutPoint { txid: chan_1.3.compute_txid(), index: 0 }; // Rebalance the network to generate htlc in the two directions send_payment(&nodes[0], &vec!(&nodes[1])[..], 10_000_000); @@ -8614,7 +8614,7 @@ fn test_concurrent_monitor_claim() { // Create some initial channel let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1); - let outpoint = OutPoint { txid: chan_1.3.txid(), index: 0 }; + let outpoint = OutPoint { txid: chan_1.3.compute_txid(), index: 0 }; // Rebalance the network to generate htlc in the two directions send_payment(&nodes[0], &vec!(&nodes[1])[..], 10_000_000); @@ -8965,7 +8965,7 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain } else { if nodes[1].connect_style.borrow().updates_best_block_first() { assert_eq!(bob_txn.len(), 3); - assert_eq!(bob_txn[0].txid(), bob_txn[1].txid()); + assert_eq!(bob_txn[0].compute_txid(), bob_txn[1].compute_txid()); } else { assert_eq!(bob_txn.len(), 2); } @@ -9164,7 +9164,7 @@ fn test_duplicate_funding_err_in_funding() { let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let (_, _, _, real_channel_id, funding_tx) = create_chan_between_nodes(&nodes[0], &nodes[1]); - let real_chan_funding_txo = chain::transaction::OutPoint { txid: funding_tx.txid(), index: 0 }; + let real_chan_funding_txo = chain::transaction::OutPoint { txid: funding_tx.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(real_chan_funding_txo), real_channel_id); nodes[2].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).unwrap(); @@ -9491,7 +9491,7 @@ fn test_invalid_funding_tx() { version: Version::TWO, lock_time: LockTime::ZERO, input: tx.output.iter().enumerate().map(|(idx, _)| TxIn { previous_output: BitcoinOutPoint { - txid: tx.txid(), + txid: tx.compute_txid(), vout: idx as u32, }, script_sig: ScriptBuf::new(), @@ -9618,7 +9618,7 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t // We should broadcast an HTLC transaction spending our funding transaction first let spending_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(spending_txn.len(), 2); - let htlc_tx = if spending_txn[0].txid() == node_txn[0].txid() { + let htlc_tx = if spending_txn[0].compute_txid() == node_txn[0].compute_txid() { &spending_txn[1] } else { &spending_txn[0] @@ -10923,7 +10923,7 @@ fn test_batch_channel_open() { // Complete the persistence of the monitor. nodes[0].chain_monitor.complete_sole_pending_chan_update( - &ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.txid(), index: 1 }) + &ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.compute_txid(), index: 1 }) ); let events = nodes[0].node.get_and_clear_pending_events(); @@ -10977,8 +10977,8 @@ fn test_close_in_funding_batch() { assert_eq!(nodes[0].tx_broadcaster.txn_broadcast().len(), 0); // Force-close the channel for which we've completed the initial monitor. - let funding_txo_1 = OutPoint { txid: tx.txid(), index: 0 }; - let funding_txo_2 = OutPoint { txid: tx.txid(), index: 1 }; + let funding_txo_1 = OutPoint { txid: tx.compute_txid(), index: 0 }; + let funding_txo_2 = OutPoint { txid: tx.compute_txid(), index: 1 }; let channel_id_1 = ChannelId::v1_from_funding_outpoint(funding_txo_1); let channel_id_2 = ChannelId::v1_from_funding_outpoint(funding_txo_2); let error_message = "Channel force-closed"; @@ -11003,9 +11003,9 @@ fn test_close_in_funding_batch() { { let broadcasted_txs = nodes[0].tx_broadcaster.txn_broadcast(); assert_eq!(broadcasted_txs.len(), 1); - assert!(broadcasted_txs[0].txid() != tx.txid()); + assert!(broadcasted_txs[0].compute_txid() != tx.compute_txid()); assert_eq!(broadcasted_txs[0].input.len(), 1); - assert_eq!(broadcasted_txs[0].input[0].previous_output.txid, tx.txid()); + assert_eq!(broadcasted_txs[0].input[0].previous_output.txid, tx.compute_txid()); } // All channels in the batch should close immediately. @@ -11066,8 +11066,8 @@ fn test_batch_funding_close_after_funding_signed() { assert_eq!(nodes[0].tx_broadcaster.txn_broadcast().len(), 0); // Force-close the channel for which we've completed the initial monitor. - let funding_txo_1 = OutPoint { txid: tx.txid(), index: 0 }; - let funding_txo_2 = OutPoint { txid: tx.txid(), index: 1 }; + let funding_txo_1 = OutPoint { txid: tx.compute_txid(), index: 0 }; + let funding_txo_2 = OutPoint { txid: tx.compute_txid(), index: 1 }; let channel_id_1 = ChannelId::v1_from_funding_outpoint(funding_txo_1); let channel_id_2 = ChannelId::v1_from_funding_outpoint(funding_txo_2); let error_message = "Channel force-closed"; @@ -11092,9 +11092,9 @@ fn test_batch_funding_close_after_funding_signed() { { let broadcasted_txs = nodes[0].tx_broadcaster.txn_broadcast(); assert_eq!(broadcasted_txs.len(), 1); - assert!(broadcasted_txs[0].txid() != tx.txid()); + assert!(broadcasted_txs[0].compute_txid() != tx.compute_txid()); assert_eq!(broadcasted_txs[0].input.len(), 1); - assert_eq!(broadcasted_txs[0].input[0].previous_output.txid, tx.txid()); + assert_eq!(broadcasted_txs[0].input[0].previous_output.txid, tx.compute_txid()); } // All channels in the batch should close immediately. @@ -11130,7 +11130,7 @@ fn do_test_funding_and_commitment_tx_confirm_same_block(confirm_remote_commitmen let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let funding_tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 1_000_000, 0); - let chan_id = ChannelId::v1_from_funding_outpoint(chain::transaction::OutPoint { txid: funding_tx.txid(), index: 0 }); + let chan_id = ChannelId::v1_from_funding_outpoint(chain::transaction::OutPoint { txid: funding_tx.compute_txid(), index: 0 }); assert_eq!(nodes[0].node.list_channels().len(), 1); assert_eq!(nodes[1].node.list_channels().len(), 1); diff --git a/lightning/src/ln/interactivetxs.rs b/lightning/src/ln/interactivetxs.rs index 4e358ec72..deec638f7 100644 --- a/lightning/src/ln/interactivetxs.rs +++ b/lightning/src/ln/interactivetxs.rs @@ -331,7 +331,7 @@ impl NegotiationContext { } let transaction = msg.prevtx.as_transaction(); - let txid = transaction.txid(); + let txid = transaction.compute_txid(); if let Some(tx_out) = transaction.output.get(msg.prevtx_out as usize) { if !tx_out.script_pubkey.is_witness_program() { @@ -415,7 +415,7 @@ impl NegotiationContext { return Err(AbortReason::ReceivedTooManyTxAddOutputs); } - if msg.sats < msg.script.dust_value().to_sat() { + if msg.sats < msg.script.minimal_non_dust().to_sat() { // The receiving node: // - MUST fail the negotiation if: // - the sats amount is less than the dust_limit @@ -504,7 +504,7 @@ impl NegotiationContext { fn sent_tx_add_input(&mut self, msg: &msgs::TxAddInput) -> Result<(), AbortReason> { let tx = msg.prevtx.as_transaction(); let txin = TxIn { - previous_output: OutPoint { txid: tx.txid(), vout: msg.prevtx_out }, + previous_output: OutPoint { txid: tx.compute_txid(), vout: msg.prevtx_out }, sequence: Sequence(msg.sequence), ..Default::default() }; @@ -1629,7 +1629,7 @@ mod tests { fn generate_inputs(outputs: &[TestOutput]) -> Vec<(TxIn, TransactionU16LenLimited)> { let tx = generate_tx(outputs); - let txid = tx.txid(); + let txid = tx.compute_txid(); tx.output .iter() .enumerate() @@ -1704,7 +1704,7 @@ mod tests { &vec![TestOutput::P2WPKH(1_000_000); tx_output_count as usize], (1337 + remaining).into(), ); - let txid = tx.txid(); + let txid = tx.compute_txid(); let mut temp: Vec<(TxIn, TransactionU16LenLimited)> = tx .output @@ -1908,7 +1908,7 @@ mod tests { let tx = TransactionU16LenLimited::new(generate_tx(&[TestOutput::P2WPKH(1_000_000)])).unwrap(); let invalid_sequence_input = TxIn { - previous_output: OutPoint { txid: tx.as_transaction().txid(), vout: 0 }, + previous_output: OutPoint { txid: tx.as_transaction().compute_txid(), vout: 0 }, ..Default::default() }; do_test_interactive_tx_constructor(TestSession { @@ -1922,7 +1922,7 @@ mod tests { b_expected_remote_shared_output: Some((generate_p2wpkh_script_pubkey(), 0)), }); let duplicate_input = TxIn { - previous_output: OutPoint { txid: tx.as_transaction().txid(), vout: 0 }, + previous_output: OutPoint { txid: tx.as_transaction().compute_txid(), vout: 0 }, sequence: Sequence::ENABLE_RBF_NO_LOCKTIME, ..Default::default() }; @@ -1938,7 +1938,7 @@ mod tests { }); // Non-initiator uses same prevout as initiator. let duplicate_input = TxIn { - previous_output: OutPoint { txid: tx.as_transaction().txid(), vout: 0 }, + previous_output: OutPoint { txid: tx.as_transaction().compute_txid(), vout: 0 }, sequence: Sequence::ENABLE_RBF_NO_LOCKTIME, ..Default::default() }; @@ -1953,7 +1953,7 @@ mod tests { b_expected_remote_shared_output: Some((generate_funding_script_pubkey(), 95_000)), }); let duplicate_input = TxIn { - previous_output: OutPoint { txid: tx.as_transaction().txid(), vout: 0 }, + previous_output: OutPoint { txid: tx.as_transaction().compute_txid(), vout: 0 }, sequence: Sequence::ENABLE_RBF_NO_LOCKTIME, ..Default::default() }; @@ -2005,7 +2005,7 @@ mod tests { description: "Initiator sends an output below dust value", inputs_a: vec![], outputs_a: generate_funding_output( - generate_p2wsh_script_pubkey().dust_value().to_sat() - 1, + generate_p2wsh_script_pubkey().minimal_non_dust().to_sat() - 1, ), inputs_b: vec![], outputs_b: vec![], diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 2e4b7326c..16f3b4926 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -209,7 +209,7 @@ fn archive_fully_resolved_monitors() { // Remove the corresponding outputs and transactions the chain source is // watching. This is to make sure the `Drop` function assertions pass. nodes.get_mut(0).unwrap().chain_source.remove_watched_txn_and_outputs( - OutPoint { txid: funding_tx.txid(), index: 0 }, + OutPoint { txid: funding_tx.compute_txid(), index: 0 }, funding_tx.output[0].script_pubkey.clone() ); } @@ -231,7 +231,7 @@ fn do_chanmon_claim_value_coop_close(anchors: bool) { let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 1_000_000); - let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(funding_outpoint), chan_id); let chan_feerate = get_feerate!(nodes[0], nodes[1], chan_id) as u64; @@ -389,13 +389,13 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) { ], }; if anchors { - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); - nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 1 }, coinbase_tx.output[1].value); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 1 }, coinbase_tx.output[1].value); } let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 1_000_000); - let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(funding_outpoint), chan_id); // This HTLC is immediately claimed, giving node B the preimage @@ -789,14 +789,14 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) { ], }; if anchors { - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); - nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 1 }, coinbase_tx.output[1].value); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 1 }, coinbase_tx.output[1].value); } // Create a single channel with two pending HTLCs from nodes[0] to nodes[1], one which nodes[1] // knows the preimage for, one which it does not. let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0); - let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 10_000_000); let htlc_cltv_timeout = nodes[0].best_block_info().1 + TEST_FINAL_CLTV + 1; // Note ChannelManager adds one to CLTV timeouts for safety @@ -849,7 +849,7 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) { if nodes[0].connect_style.borrow().updates_best_block_first() { let mut txn = nodes[0].tx_broadcaster.txn_broadcast(); assert_eq!(txn.len(), 1); - assert_eq!(txn[0].txid(), commitment_tx.txid()); + assert_eq!(txn[0].compute_txid(), commitment_tx.compute_txid()); } let htlc_balance_known_preimage = Balance::MaybeTimeoutClaimableHTLC { @@ -1000,7 +1000,7 @@ fn test_no_preimage_inbound_htlc_balances() { let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 500_000_000); - let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; // Send two HTLCs, one from A to B, and one from B to A. let to_b_failed_payment_hash = route_payment(&nodes[0], &[&nodes[1]], 10_000_000).1; @@ -1263,7 +1263,7 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_ let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 100_000_000); - let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(funding_outpoint), chan_id); // We create five HTLCs for B to claim against A's revoked commitment transaction: @@ -1368,7 +1368,7 @@ fn do_test_revoked_counterparty_commitment_balances(anchors: bool, confirm_htlc_ sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); mine_transaction(&nodes[1], &as_revoked_txn[0]); - let mut claim_txn: Vec<_> = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().drain(..).filter(|tx| tx.input.iter().any(|inp| inp.previous_output.txid == as_revoked_txn[0].txid())).collect(); + let mut claim_txn: Vec<_> = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().drain(..).filter(|tx| tx.input.iter().any(|inp| inp.previous_output.txid == as_revoked_txn[0].compute_txid())).collect(); // Currently the revoked commitment is claimed in four transactions as the HTLCs all expire // quite soon. assert_eq!(claim_txn.len(), 4); @@ -1554,21 +1554,21 @@ fn do_test_revoked_counterparty_htlc_tx_balances(anchors: bool) { ], }; if anchors { - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); - nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 1 }, coinbase_tx.output[1].value); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 1 }, coinbase_tx.output[1].value); } // Create some initial channels let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 12_000_000); - let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(funding_outpoint), chan_id); let payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 3_000_100).0; let failed_payment_hash = route_payment(&nodes[1], &[&nodes[0]], 1_000_000).1; let revoked_local_txn = get_local_commitment_txn!(nodes[1], chan_id); assert_eq!(revoked_local_txn[0].input.len(), 1); - assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, funding_tx.txid()); + assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, funding_tx.compute_txid()); if anchors { assert_eq!(revoked_local_txn[0].output[4].value.to_sat(), 11000); // to_self output } else { @@ -1866,11 +1866,11 @@ fn do_test_revoked_counterparty_aggregated_claims(anchors: bool) { script_pubkey: nodes[0].wallet_source.get_change_script().unwrap(), }], }; - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 100_000_000); - let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(funding_outpoint), chan_id); // We create two HTLCs, one which we will give A the preimage to to generate an HTLC-Success @@ -2183,19 +2183,19 @@ fn do_test_claimable_balance_correct_while_payment_pending(outbound_payment: boo ], }; if anchors { - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); - nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 1 }, coinbase_tx.output[1].value); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 1 }, coinbase_tx.output[1].value); } // Create a channel from A -> B let (_, _, chan_ab_id, funding_tx_ab) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000 /* channel_value (sat) */, 0 /* push_msat */); - let funding_outpoint_ab = OutPoint { txid: funding_tx_ab.txid(), index: 0 }; + let funding_outpoint_ab = OutPoint { txid: funding_tx_ab.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(funding_outpoint_ab), chan_ab_id); // Create a channel from B -> C let (_, _, chan_bc_id, funding_tx_bc) = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000 /* channel_value (sat) */, 0 /* push_msat */); - let funding_outpoint_bc = OutPoint { txid: funding_tx_bc.txid(), index: 0 }; + let funding_outpoint_bc = OutPoint { txid: funding_tx_bc.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(funding_outpoint_bc), chan_bc_id); let (chan_feerate, channel_type_features) = if outbound_payment { @@ -2274,7 +2274,7 @@ fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool if nodes[0].connect_style.borrow().updates_best_block_first() { let txn = nodes[0].tx_broadcaster.txn_broadcast(); assert_eq!(txn.len(), 1); - assert_eq!(txn[0].txid(), commitment_tx.txid()); + assert_eq!(txn[0].compute_txid(), commitment_tx.compute_txid()); } // Connect blocks until the HTLC's expiration is met, expecting a transaction broadcast. @@ -2362,7 +2362,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) { script_pubkey: nodes[0].wallet_source.get_change_script().unwrap(), }], }; - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); // Set up a helper closure we'll use throughout our test. We should only expect retries without // bumps if fees have not increased after a block has been connected (assuming the height timer @@ -2444,8 +2444,8 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) { // If we have a `ConnectStyle` that advertises the new block first without the transactions, // we'll receive an extra bumped claim. if nodes[0].connect_style.borrow().updates_best_block_first() { - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); - nodes[0].wallet_source.remove_utxo(bitcoin::OutPoint { txid: htlc_tx.txid(), vout: 1 }); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[0].wallet_source.remove_utxo(bitcoin::OutPoint { txid: htlc_tx.compute_txid(), vout: 1 }); check_htlc_retry(true, anchors); } nodes[0].chain_monitor.chain_monitor.rebroadcast_pending_claims(); @@ -2518,7 +2518,7 @@ fn test_yield_anchors_events() { script_pubkey: nodes[0].wallet_source.get_change_script().unwrap(), }], }; - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); nodes[0].bump_tx_handler.handle_event(&event); let mut txn = nodes[0].tx_broadcaster.unique_txn_broadcast(); assert_eq!(txn.len(), 2); @@ -2697,7 +2697,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { script_pubkey: nodes[1].wallet_source.get_change_script().unwrap(), }], }; - nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, utxo_value); + nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, utxo_value); match event { Event::BumpTransaction(event) => nodes[1].bump_tx_handler.handle_event(&event), _ => panic!("Unexpected event"), @@ -2705,7 +2705,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { let txn = nodes[1].tx_broadcaster.txn_broadcast(); assert_eq!(txn.len(), 2); assert_eq!(txn[0].output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs - if txn[0].input[0].previous_output.txid == chan_a.3.txid() { + if txn[0].input[0].previous_output.txid == chan_a.3.compute_txid() { check_spends!(&txn[0], &chan_a.3); } else { check_spends!(&txn[0], &chan_b.3); @@ -2730,7 +2730,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { let txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(txn.len(), 4); - let (revoked_htlc_claim_a, revoked_htlc_claim_b) = if txn[0].input[0].previous_output.txid == revoked_commitment_txs[0].txid() { + let (revoked_htlc_claim_a, revoked_htlc_claim_b) = if txn[0].input[0].previous_output.txid == revoked_commitment_txs[0].compute_txid() { (if txn[0].input.len() == 2 { &txn[0] } else { &txn[1] }, if txn[2].input.len() == 2 { &txn[2] } else { &txn[3] }) } else { (if txn[2].input.len() == 2 { &txn[2] } else { &txn[3] }, if txn[0].input.len() == 2 { &txn[0] } else { &txn[1] }) @@ -2778,7 +2778,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { version: Version::TWO, lock_time: LockTime::ZERO, input: vec![TxIn { // Fee input - previous_output: bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, + previous_output: bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, ..Default::default() }], output: vec![TxOut { // Fee input change @@ -2838,7 +2838,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { let revoked_htlc_claims = txn.iter().filter(|tx| tx.input.len() == 2 && tx.output.len() == 1 && - tx.input[0].previous_output.txid == htlc_tx.txid() + tx.input[0].previous_output.txid == htlc_tx.compute_txid() ).collect::>(); assert_eq!(revoked_htlc_claims.len(), 2); for revoked_htlc_claim in revoked_htlc_claims { @@ -2847,7 +2847,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { let mut revoked_claim_transaction_map = new_hash_map(); for current_tx in txn.into_iter() { - revoked_claim_transaction_map.insert(current_tx.txid(), current_tx); + revoked_claim_transaction_map.insert(current_tx.compute_txid(), current_tx); } revoked_claim_transaction_map }; @@ -3016,7 +3016,7 @@ fn do_test_monitor_claims_with_random_signatures(anchors: bool, confirm_counterp ], }; if anchors { - nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value); + nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 }, coinbase_tx.output[0].value); } // Open a channel and route a payment. We'll let it timeout to claim it. @@ -3084,8 +3084,8 @@ fn do_test_monitor_claims_with_random_signatures(anchors: bool, confirm_counterp { let mut txn = nodes[0].tx_broadcaster.txn_broadcast(); assert_eq!(txn.len(), 1); - assert_eq!(txn[0].txid(), htlc_timeout_tx.txid()); - assert_ne!(txn[0].wtxid(), htlc_timeout_tx.wtxid()); + assert_eq!(txn[0].compute_txid(), htlc_timeout_tx.compute_txid()); + assert_ne!(txn[0].compute_wtxid(), htlc_timeout_tx.compute_wtxid()); } } diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 3ab055d2a..89f62d18a 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -702,7 +702,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { if !confirm_before_reload { let as_broadcasted_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(as_broadcasted_txn.len(), 1); - assert_eq!(as_broadcasted_txn[0].txid(), as_commitment_tx.txid()); + assert_eq!(as_broadcasted_txn[0].compute_txid(), as_commitment_tx.compute_txid()); } else { assert!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().is_empty()); } @@ -772,7 +772,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { mine_transaction(&nodes[0], &as_commitment_tx); let txn = nodes[0].tx_broadcaster.unique_txn_broadcast(); assert_eq!(txn.len(), 1); - assert_eq!(txn[0].txid(), as_commitment_tx.txid()); + assert_eq!(txn[0].compute_txid(), as_commitment_tx.compute_txid()); } mine_transaction(&nodes[0], &bs_htlc_claim_txn); expect_payment_sent(&nodes[0], payment_preimage_1, None, true, false); diff --git a/lightning/src/ln/reload_tests.rs b/lightning/src/ln/reload_tests.rs index 990fc20a3..21bc1a0b5 100644 --- a/lightning/src/ln/reload_tests.rs +++ b/lightning/src/ln/reload_tests.rs @@ -201,7 +201,7 @@ fn test_no_txn_manager_serialize_deserialize() { nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); let chan_0_monitor_serialized = - get_monitor!(nodes[0], ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.txid(), index: 0 })).encode(); + get_monitor!(nodes[0], ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.compute_txid(), index: 0 })).encode(); reload_node!(nodes[0], nodes[0].node.encode(), &[&chan_0_monitor_serialized], persister, new_chain_monitor, nodes_0_deserialized); nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { @@ -289,7 +289,7 @@ fn test_manager_serialize_deserialize_events() { let events_4 = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events_4.len(), 0); assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 1); - assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap()[0].txid(), funding_output.txid); + assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap()[0].compute_txid(), funding_output.txid); // Make sure the channel is functioning as though the de/serialization never happened assert_eq!(nodes[0].node.list_channels().len(), 1); @@ -459,7 +459,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() { let txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap(); assert_eq!(txn.len(), 1); check_spends!(txn[0], funding_tx); - assert_eq!(txn[0].input[0].previous_output.txid, funding_tx.txid()); + assert_eq!(txn[0].input[0].previous_output.txid, funding_tx.compute_txid()); } check_added_monitors!(nodes[0], 1); @@ -1227,7 +1227,7 @@ fn test_reload_partial_funding_batch() { assert_eq!(nodes[0].tx_broadcaster.txn_broadcast().len(), 0); // Reload the node while a subset of the channels in the funding batch have persisted monitors. - let channel_id_1 = ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.txid(), index: 0 }); + let channel_id_1 = ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.compute_txid(), index: 0 }); let node_encoded = nodes[0].node.encode(); let channel_monitor_1_serialized = get_monitor!(nodes[0], channel_id_1).encode(); reload_node!(nodes[0], node_encoded, &[&channel_monitor_1_serialized], new_persister, new_chain_monitor, new_channel_manager); @@ -1249,9 +1249,9 @@ fn test_reload_partial_funding_batch() { { let broadcasted_txs = nodes[0].tx_broadcaster.txn_broadcast(); assert_eq!(broadcasted_txs.len(), 1); - assert!(broadcasted_txs[0].txid() != tx.txid()); + assert!(broadcasted_txs[0].compute_txid() != tx.compute_txid()); assert_eq!(broadcasted_txs[0].input.len(), 1); - assert_eq!(broadcasted_txs[0].input[0].previous_output.txid, tx.txid()); + assert_eq!(broadcasted_txs[0].input[0].previous_output.txid, tx.compute_txid()); } // Ensure the channels don't exist anymore. diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index 487822565..4fa740e02 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -277,7 +277,7 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_ assert_eq!(relevant_txids[0].1, chan_conf_height); assert_eq!(block_hash_opt, Some(expected_hash)); let txid = relevant_txids[0].0; - assert_eq!(txid, chan.3.txid()); + assert_eq!(txid, chan.3.compute_txid()); nodes[0].node.transaction_unconfirmed(&txid); assert_eq!(nodes[0].node.list_usable_channels().len(), 0); } else if connect_style == ConnectStyle::FullBlockViaListen { @@ -323,7 +323,7 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_ assert_eq!(chan_conf_height, relevant_txids[0].1); assert_eq!(block_hash_opt, Some(expected_hash)); let txid = relevant_txids[0].0; - assert_eq!(txid, chan.3.txid()); + assert_eq!(txid, chan.3.compute_txid()); nodes[0].node.transaction_unconfirmed(&txid); assert_eq!(nodes[0].node.list_channels().len(), 0); } else if connect_style == ConnectStyle::FullBlockViaListen { @@ -436,7 +436,7 @@ fn test_set_outpoints_partial_claiming() { assert_eq!(remote_txn.len(), 3); assert_eq!(remote_txn[0].output.len(), 4); assert_eq!(remote_txn[0].input.len(), 1); - assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.txid()); + assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid()); check_spends!(remote_txn[1], remote_txn[0]); check_spends!(remote_txn[2], remote_txn[0]); @@ -532,7 +532,7 @@ fn do_test_to_remote_after_local_detection(style: ConnectStyle) { let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 100_000_000); - let funding_outpoint = OutPoint { txid: funding_tx.txid(), index: 0 }; + let funding_outpoint = OutPoint { txid: funding_tx.compute_txid(), index: 0 }; assert_eq!(ChannelId::v1_from_funding_outpoint(funding_outpoint), chan_id); let remote_txn_a = get_local_commitment_txn!(nodes[0], chan_id); @@ -732,7 +732,7 @@ fn test_htlc_preimage_claim_prev_counterparty_commitment_after_current_counterpa let mut txn = nodes[0].tx_broadcaster.txn_broadcast(); assert_eq!(txn.len(), 1); let current_commitment_a = txn.pop().unwrap(); - assert_ne!(current_commitment_a.txid(), prev_commitment_a.txid()); + assert_ne!(current_commitment_a.compute_txid(), prev_commitment_a.compute_txid()); check_spends!(current_commitment_a, funding_tx); mine_transaction(&nodes[0], ¤t_commitment_a); @@ -871,7 +871,7 @@ fn do_test_retries_own_commitment_broadcast_after_reorg(anchors: bool, revoked_c assert_eq!(txn.len(), 2); check_spends!(txn[0], txn[1]); // HTLC timeout A check_spends!(txn[1], funding_tx); // Commitment A - assert_ne!(txn[1].txid(), commitment_b.txid()); + assert_ne!(txn[1].compute_txid(), commitment_b.compute_txid()); } } } diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index b86c3482f..0ba6e1259 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -50,7 +50,7 @@ fn pre_funding_lock_shutdown_test() { mine_transaction(&nodes[0], &tx); mine_transaction(&nodes[1], &tx); - nodes[0].node.close_channel(&ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.txid(), index: 0 }), &nodes[1].node.get_our_node_id()).unwrap(); + nodes[0].node.close_channel(&ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.compute_txid(), index: 0 }), &nodes[1].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); @@ -1425,7 +1425,7 @@ fn batch_funding_failure() { let err = "Error in transaction funding: Misuse error: No output matched the script_pubkey and value in the FundingGenerationReady event".to_string(); let temp_err = "No output matched the script_pubkey and value in the FundingGenerationReady event".to_string(); - let post_funding_chan_id_a = ChannelId::v1_from_funding_txid(tx.txid().as_ref(), 0); + let post_funding_chan_id_a = ChannelId::v1_from_funding_txid(tx.compute_txid().as_ref(), 0); let close = [ ExpectedCloseEvent::from_id_reason(post_funding_chan_id_a, true, ClosureReason::ProcessingError { err: err.clone() }), ExpectedCloseEvent::from_id_reason(temp_chan_id_b, false, ClosureReason::ProcessingError { err: temp_err }), diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 22a3f6e79..e822b512a 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -3908,14 +3908,16 @@ pub mod benches { let mut v = Vec::new(); d.read_to_end(&mut v).unwrap(); bench.bench_function("read_network_graph", |b| b.iter(|| - NetworkGraph::read(&mut std::io::Cursor::new(black_box(&v)), &logger).unwrap() + NetworkGraph::read(&mut crate::io::Cursor::new(black_box(&v)), &logger).unwrap() )); } pub fn write_network_graph(bench: &mut Criterion) { let logger = crate::util::test_utils::TestLogger::new(); let (mut d, _) = crate::routing::router::bench_utils::get_graph_scorer_file().unwrap(); - let net_graph = NetworkGraph::read(&mut d, &logger).unwrap(); + let mut graph_buffer = Vec::new(); + d.read_to_end(&mut graph_buffer).unwrap(); + let net_graph = NetworkGraph::read(&mut &graph_buffer[..], &logger).unwrap(); bench.bench_function("write_network_graph", |b| b.iter(|| black_box(&net_graph).encode() )); diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs index d8f7ee3b6..10452c57d 100644 --- a/lightning/src/util/macro_logger.rs +++ b/lightning/src/util/macro_logger.rs @@ -107,7 +107,7 @@ impl<'a> core::fmt::Display for DebugTx<'a> { debug_assert!(false, "We should never generate unknown transaction types"); write!(f, "unknown tx type ").unwrap(); } - write!(f, "with txid {}", self.0.txid())?; + write!(f, "with txid {}", self.0.compute_txid())?; Ok(()) } } diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 7c1f97071..85e63aa0e 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -724,7 +724,7 @@ impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec> { impl Readable for WithoutLength> { #[inline] - fn read(mut reader: &mut R) -> Result { + fn read(reader: &mut R) -> Result { let mut values = Vec::new(); loop { let mut track_read = ReadTrackingReader::new(reader); diff --git a/lightning/src/util/sweep.rs b/lightning/src/util/sweep.rs index 2c01e1ecc..49c293054 100644 --- a/lightning/src/util/sweep.rs +++ b/lightning/src/util/sweep.rs @@ -500,7 +500,7 @@ where log_debug!( self.logger, "Generating and broadcasting sweeping transaction {}", - spending_tx.txid() + spending_tx.compute_txid() ); spending_tx }, @@ -534,7 +534,7 @@ where if cur_height >= confirmation_height + ANTI_REORG_DELAY - 1 { log_debug!(self.logger, "Pruning swept output as sufficiently confirmed via spend in transaction {:?}. Pruned descriptor: {:?}", - o.status.latest_spending_tx().map(|t| t.txid()), o.descriptor + o.status.latest_spending_tx().map(|t| t.compute_txid()), o.descriptor ); return false; } @@ -697,7 +697,7 @@ where let unconf_height = state_lock .outputs .iter() - .find(|o| o.status.latest_spending_tx().map(|tx| tx.txid()) == Some(*txid)) + .find(|o| o.status.latest_spending_tx().map(|tx| tx.compute_txid()) == Some(*txid)) .and_then(|o| o.status.confirmation_height()); if let Some(unconf_height) = unconf_height { @@ -742,7 +742,11 @@ where confirmation_height, confirmation_hash, .. - } => Some((latest_spending_tx.txid(), confirmation_height, Some(confirmation_hash))), + } => Some(( + latest_spending_tx.compute_txid(), + confirmation_height, + Some(confirmation_hash), + )), _ => None, }) .collect::>() diff --git a/lightning/src/util/test_channel_signer.rs b/lightning/src/util/test_channel_signer.rs index 4dc349c97..d47c47b91 100644 --- a/lightning/src/util/test_channel_signer.rs +++ b/lightning/src/util/test_channel_signer.rs @@ -33,7 +33,7 @@ use bitcoin::secp256k1::All; use bitcoin::secp256k1::{SecretKey, PublicKey}; use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature}; #[cfg(taproot)] -use musig2::types::{PartialSignature, PublicNonce, SecretNonce}; +use musig2::types::{PartialSignature, PublicNonce}; use crate::sign::HTLCDescriptor; use crate::util::ser::{Writeable, Writer}; use crate::io::Error; diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index b639cb673..a4e8b3a35 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -733,7 +733,7 @@ impl TestBroadcaster { pub fn unique_txn_broadcast(&self) -> Vec { let mut txn = self.txn_broadcasted.lock().unwrap().split_off(0); let mut seen = new_hash_set(); - txn.retain(|tx| seen.insert(tx.txid())); + txn.retain(|tx| seen.insert(tx.compute_txid())); txn } } diff --git a/lightning/src/util/transaction_utils.rs b/lightning/src/util/transaction_utils.rs index 7bc8175d8..da8ff4343 100644 --- a/lightning/src/util/transaction_utils.rs +++ b/lightning/src/util/transaction_utils.rs @@ -45,7 +45,7 @@ pub(crate) fn maybe_add_change_output(tx: &mut Transaction, input_value: Amount, if output_value >= input_value { return Err(()); } } - let dust_value = change_destination_script.dust_value(); + let dust_value = change_destination_script.minimal_non_dust(); let mut change_output = TxOut { script_pubkey: change_destination_script, value: Amount::ZERO, @@ -227,27 +227,27 @@ mod tests { fn test_tx_change_edge() { // Check that we never add dust outputs let mut tx = Transaction { version: Version::TWO, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() }; - let orig_wtxid = tx.wtxid(); + let orig_wtxid = tx.compute_wtxid(); let output_spk = ScriptBuf::new_p2pkh(&PubkeyHash::hash(&[0; 0])); - assert_eq!(output_spk.dust_value().to_sat(), 546); + assert_eq!(output_spk.minimal_non_dust().to_sat(), 546); // base size = version size + varint[input count] + input size + varint[output count] + output size + lock time size // total size = version size + marker + flag + varint[input count] + input size + varint[output count] + output size + lock time size // weight = 3 * base size + total size = 3 * (4 + 1 + 0 + 1 + 0 + 4) + (4 + 1 + 1 + 1 + 0 + 1 + 0 + 4) = 3 * 10 + 12 = 42 assert_eq!(tx.weight().to_wu(), 42); // 10 sats isn't enough to pay fee on a dummy transaction... assert!(maybe_add_change_output(&mut tx, Amount::from_sat(10), 0, 250, output_spk.clone()).is_err()); - assert_eq!(tx.wtxid(), orig_wtxid); // Failure doesn't change the transaction + assert_eq!(tx.compute_wtxid(), orig_wtxid); // Failure doesn't change the transaction // but 11 (= ceil(42 * 250 / 1000)) is, just not enough to add a change output... assert!(maybe_add_change_output(&mut tx, Amount::from_sat(11), 0, 250, output_spk.clone()).is_ok()); assert_eq!(tx.output.len(), 0); - assert_eq!(tx.wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction + assert_eq!(tx.compute_wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction assert!(maybe_add_change_output(&mut tx, Amount::from_sat(549), 0, 250, output_spk.clone()).is_ok()); assert_eq!(tx.output.len(), 0); - assert_eq!(tx.wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction + assert_eq!(tx.compute_wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction // 590 is also not enough assert!(maybe_add_change_output(&mut tx, Amount::from_sat(590), 0, 250, output_spk.clone()).is_ok()); assert_eq!(tx.output.len(), 0); - assert_eq!(tx.wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction + assert_eq!(tx.compute_wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction // at 591 we can afford the change output at the dust limit (546) assert!(maybe_add_change_output(&mut tx, Amount::from_sat(591), 0, 250, output_spk.clone()).is_ok()); assert_eq!(tx.output.len(), 1); @@ -256,7 +256,7 @@ mod tests { assert_eq!(tx.weight().to_wu() / 4, 590-546); // New weight is exactly the fee we wanted. tx.output.pop(); - assert_eq!(tx.wtxid(), orig_wtxid); // The only change is the addition of one output. + assert_eq!(tx.compute_wtxid(), orig_wtxid); // The only change is the addition of one output. } #[test] @@ -267,21 +267,21 @@ mod tests { }], output: vec![TxOut { script_pubkey: Builder::new().push_int(1).into_script(), value: Amount::from_sat(1000) }] }; - let orig_wtxid = tx.wtxid(); + let orig_wtxid = tx.compute_wtxid(); let orig_weight = tx.weight().to_wu(); assert_eq!(orig_weight / 4, 61); - assert_eq!(Builder::new().push_int(2).into_script().dust_value().to_sat(), 474); + assert_eq!(Builder::new().push_int(2).into_script().minimal_non_dust().to_sat(), 474); // Input value of the output value + fee - 1 should fail: assert!(maybe_add_change_output(&mut tx, Amount::from_sat(1000 + 61 + 100 - 1), 400, 250, Builder::new().push_int(2).into_script()).is_err()); - assert_eq!(tx.wtxid(), orig_wtxid); // Failure doesn't change the transaction + assert_eq!(tx.compute_wtxid(), orig_wtxid); // Failure doesn't change the transaction // but one more input sat should succeed, without changing the transaction assert!(maybe_add_change_output(&mut tx, Amount::from_sat(1000 + 61 + 100), 400, 250, Builder::new().push_int(2).into_script()).is_ok()); - assert_eq!(tx.wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction + assert_eq!(tx.compute_wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction // In order to get a change output, we need to add 474 plus the output's weight / 4 (10)... assert!(maybe_add_change_output(&mut tx, Amount::from_sat(1000 + 61 + 100 + 474 + 9), 400, 250, Builder::new().push_int(2).into_script()).is_ok()); - assert_eq!(tx.wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction + assert_eq!(tx.compute_wtxid(), orig_wtxid); // If we don't add an output, we don't change the transaction assert!(maybe_add_change_output(&mut tx, Amount::from_sat(1000 + 61 + 100 + 474 + 10), 400, 250, Builder::new().push_int(2).into_script()).is_ok()); assert_eq!(tx.output.len(), 2); @@ -289,6 +289,6 @@ mod tests { assert_eq!(tx.output[1].script_pubkey, Builder::new().push_int(2).into_script()); assert_eq!(tx.weight().to_wu() - orig_weight, 40); // Weight difference matches what we had to add above tx.output.pop(); - assert_eq!(tx.wtxid(), orig_wtxid); // The only change is the addition of one output. + assert_eq!(tx.compute_wtxid(), orig_wtxid); // The only change is the addition of one output. } } -- 2.39.5