Skip to content

Commit a621194

Browse files
committed
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.
1 parent 107a741 commit a621194

28 files changed

+228
-223
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ impl Readable for BlindedPath {
280280
0 => IntroductionNode::DirectedShortChannelId(Direction::NodeOne, Readable::read(r)?),
281281
1 => IntroductionNode::DirectedShortChannelId(Direction::NodeTwo, Readable::read(r)?),
282282
2|3 => {
283-
use io::Read;
284283
let mut bytes = [0; 33];
285284
bytes[0] = first_byte;
286285
r.read_exact(&mut bytes[1..])?;

lightning/src/chain/channelmonitor.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
21412141
} = &event.event {
21422142
if event.transaction.as_ref().map(|tx| tx.input.iter().any(|inp| {
21432143
if let Some(htlc_spend_txid) = htlc_spend_txid_opt {
2144-
tx.txid() == *htlc_spend_txid || inp.previous_output.txid == *htlc_spend_txid
2144+
tx.compute_txid() == *htlc_spend_txid || inp.previous_output.txid == *htlc_spend_txid
21452145
} else {
21462146
Some(inp.previous_output.txid) == confirmed_txid &&
21472147
inp.previous_output.vout == htlc_commitment_tx_output_idx
@@ -2590,7 +2590,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
25902590
macro_rules! fail_unbroadcast_htlcs {
25912591
($self: expr, $commitment_tx_type: expr, $commitment_txid_confirmed: expr, $commitment_tx_confirmed: expr,
25922592
$commitment_tx_conf_height: expr, $commitment_tx_conf_hash: expr, $confirmed_htlcs_list: expr, $logger: expr) => { {
2593-
debug_assert_eq!($commitment_tx_confirmed.txid(), $commitment_txid_confirmed);
2593+
debug_assert_eq!($commitment_tx_confirmed.compute_txid(), $commitment_txid_confirmed);
25942594

25952595
macro_rules! check_htlc_fails {
25962596
($txid: expr, $commitment_tx: expr, $per_commitment_outpoints: expr) => {
@@ -3223,7 +3223,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32233223
// introduced with v0.0.116. counterparty_node_id is guaranteed to be `Some`
32243224
// since v0.0.110.
32253225
let counterparty_node_id = self.counterparty_node_id.unwrap();
3226-
let commitment_txid = commitment_tx.txid();
3226+
let commitment_txid = commitment_tx.compute_txid();
32273227
debug_assert_eq!(self.current_holder_commitment_tx.txid, commitment_txid);
32283228
let pending_htlcs = self.current_holder_commitment_tx.non_dust_htlcs();
32293229
let commitment_tx_fee_satoshis = self.channel_value_satoshis -
@@ -3403,7 +3403,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34033403
let mut claimable_outpoints = Vec::new();
34043404
let mut to_counterparty_output_info = None;
34053405

3406-
let commitment_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
3406+
let commitment_txid = tx.compute_txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
34073407
let per_commitment_option = self.counterparty_claimable_outpoints.get(&commitment_txid);
34083408

34093409
macro_rules! ignore_error {
@@ -3589,7 +3589,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
35893589
};
35903590
let per_commitment_point = PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key);
35913591

3592-
let htlc_txid = tx.txid();
3592+
let htlc_txid = tx.compute_txid();
35933593
let mut claimable_outpoints = vec![];
35943594
let mut outputs_to_watch = None;
35953595
// Previously, we would only claim HTLCs from revoked HTLC transactions if they had 1 input
@@ -3681,7 +3681,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36813681
/// Should not be used if check_spend_revoked_transaction succeeds.
36823682
/// Returns None unless the transaction is definitely one of our commitment transactions.
36833683
fn check_spend_holder_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, block_hash: &BlockHash, logger: &L) -> Option<(Vec<PackageTemplate>, TransactionOutputs)> where L::Target: Logger {
3684-
let commitment_txid = tx.txid();
3684+
let commitment_txid = tx.compute_txid();
36853685
let mut claim_requests = Vec::new();
36863686
let mut watch_outputs = Vec::new();
36873687

@@ -3786,7 +3786,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37863786
) -> Vec<Transaction> where L::Target: Logger {
37873787
log_debug!(logger, "Getting signed copy of latest holder commitment transaction!");
37883788
let commitment_tx = self.onchain_tx_handler.get_fully_signed_copy_holder_tx(&self.funding_redeemscript);
3789-
let txid = commitment_tx.txid();
3789+
let txid = commitment_tx.compute_txid();
37903790
let mut holder_transactions = vec![commitment_tx];
37913791
// When anchor outputs are present, the HTLC transactions are only final once the commitment
37923792
// transaction confirms due to the CSV 1 encumberance.
@@ -3885,7 +3885,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
38853885
let mut watch_outputs = Vec::new();
38863886
let mut claimable_outpoints = Vec::new();
38873887
'tx_iter: for tx in &txn_matched {
3888-
let txid = tx.txid();
3888+
let txid = tx.compute_txid();
38893889
log_trace!(logger, "Transaction {} confirmed in block {}", txid , block_hash);
38903890
// If a transaction has already been confirmed, ensure we don't bother processing it duplicatively.
38913891
if Some(txid) == self.funding_spend_confirmed {
@@ -4131,7 +4131,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
41314131
// make sure the registered scriptpubkey at the expected index match
41324132
// the actual transaction output one. We failed this case before #653.
41334133
for tx in &txn_matched {
4134-
if let Some(outputs) = self.get_outputs_to_watch().get(&tx.txid()) {
4134+
if let Some(outputs) = self.get_outputs_to_watch().get(&tx.compute_txid()) {
41354135
for idx_and_script in outputs.iter() {
41364136
assert!((idx_and_script.0 as usize) < tx.output.len());
41374137
assert_eq!(tx.output[idx_and_script.0 as usize].script_pubkey, idx_and_script.1);
@@ -4206,7 +4206,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42064206
}
42074207
}
42084208
if matches {
4209-
matched_txn.insert(tx.txid());
4209+
matched_txn.insert(tx.compute_txid());
42104210
}
42114211
matches
42124212
}).map(|(_, tx)| *tx).collect()
@@ -4360,12 +4360,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
43604360
if ($holder_tx && revocation_sig_claim) ||
43614361
(outbound_htlc && !$source_avail && (accepted_preimage_claim || offered_preimage_claim)) {
43624362
log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
4363-
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
4363+
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.compute_txid(),
43644364
if outbound_htlc { "outbound" } else { "inbound" }, &$htlc.payment_hash,
43654365
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" });
43664366
} else {
43674367
log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
4368-
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
4368+
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.compute_txid(),
43694369
if outbound_htlc { "outbound" } else { "inbound" }, &$htlc.payment_hash,
43704370
if revocation_sig_claim { "revocation sig" } else if accepted_preimage_claim || offered_preimage_claim { "preimage" } else { "timeout" });
43714371
}
@@ -4412,7 +4412,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
44124412
log_claim!($tx_info, $holder_tx, htlc_output, false);
44134413
let outbound_htlc = $holder_tx == htlc_output.offered;
44144414
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
4415-
txid: tx.txid(), height, block_hash: Some(*block_hash), transaction: Some(tx.clone()),
4415+
txid: tx.compute_txid(), height, block_hash: Some(*block_hash), transaction: Some(tx.clone()),
44164416
event: OnchainEvent::HTLCSpendConfirmation {
44174417
commitment_tx_output_idx: input.previous_output.vout,
44184418
preimage: if accepted_preimage_claim || offered_preimage_claim {
@@ -4454,7 +4454,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
44544454
if !self.pending_monitor_events.iter().any(
44554455
|update| if let &MonitorEvent::HTLCEvent(ref upd) = update { upd.source == source } else { false }) {
44564456
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
4457-
txid: tx.txid(),
4457+
txid: tx.compute_txid(),
44584458
height,
44594459
block_hash: Some(*block_hash),
44604460
transaction: Some(tx.clone()),
@@ -4477,7 +4477,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
44774477
upd.source == source
44784478
} else { false }) {
44794479
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
4480-
txid: tx.txid(),
4480+
txid: tx.compute_txid(),
44814481
transaction: Some(tx.clone()),
44824482
height,
44834483
block_hash: Some(*block_hash),
@@ -4505,7 +4505,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45054505
}
45064506
});
45074507
let entry = OnchainEventEntry {
4508-
txid: tx.txid(),
4508+
txid: tx.compute_txid(),
45094509
transaction: Some(tx.clone()),
45104510
height,
45114511
block_hash: Some(*block_hash),
@@ -4527,15 +4527,15 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45274527
for (i, outp) in tx.output.iter().enumerate() {
45284528
if outp.script_pubkey == self.destination_script {
45294529
spendable_outputs.push(SpendableOutputDescriptor::StaticOutput {
4530-
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
4530+
outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 },
45314531
output: outp.clone(),
45324532
channel_keys_id: Some(self.channel_keys_id),
45334533
});
45344534
}
45354535
if let Some(ref broadcasted_holder_revokable_script) = self.broadcasted_holder_revokable_script {
45364536
if broadcasted_holder_revokable_script.0 == outp.script_pubkey {
45374537
spendable_outputs.push(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor {
4538-
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
4538+
outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 },
45394539
per_commitment_point: broadcasted_holder_revokable_script.1,
45404540
to_self_delay: self.on_holder_tx_csv,
45414541
output: outp.clone(),
@@ -4548,7 +4548,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45484548
}
45494549
if self.counterparty_payment_script == outp.script_pubkey {
45504550
spendable_outputs.push(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor {
4551-
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
4551+
outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 },
45524552
output: outp.clone(),
45534553
channel_keys_id: self.channel_keys_id,
45544554
channel_value_satoshis: self.channel_value_satoshis,
@@ -4557,7 +4557,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45574557
}
45584558
if self.shutdown_script.as_ref() == Some(&outp.script_pubkey) {
45594559
spendable_outputs.push(SpendableOutputDescriptor::StaticOutput {
4560-
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
4560+
outpoint: OutPoint { txid: tx.compute_txid(), index: i as u16 },
45614561
output: outp.clone(),
45624562
channel_keys_id: Some(self.channel_keys_id),
45634563
});
@@ -4573,7 +4573,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45734573
) where L::Target: Logger {
45744574
for spendable_output in self.get_spendable_outputs(tx) {
45754575
let entry = OnchainEventEntry {
4576-
txid: tx.txid(),
4576+
txid: tx.compute_txid(),
45774577
transaction: Some(tx.clone()),
45784578
height,
45794579
block_hash: Some(*block_hash),
@@ -5066,7 +5066,7 @@ mod tests {
50665066
assert!(txn_broadcasted.len() >= 2);
50675067
let htlc_txn = txn_broadcasted.iter().filter(|tx| {
50685068
assert_eq!(tx.input.len(), 1);
5069-
tx.input[0].previous_output.txid == broadcast_tx.txid()
5069+
tx.input[0].previous_output.txid == broadcast_tx.compute_txid()
50705070
}).collect::<Vec<_>>();
50715071
assert_eq!(htlc_txn.len(), 2);
50725072
check_spends!(htlc_txn[0], broadcast_tx);

lightning/src/chain/onchaintx.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
514514
log_info!(logger, "{} onchain {}", log_start, log_tx!(tx.0));
515515
broadcaster.broadcast_transactions(&[&tx.0]);
516516
} else {
517-
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.txid());
517+
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.compute_txid());
518518
}
519519
},
520520
OnchainClaim::Event(event) => {
@@ -535,7 +535,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
535535
}
536536
}
537537

538-
/// Returns true if we are currently tracking any pending claim requests that are not fully
538+
/// Returns true if we are currently tracking any pending claim requests that are not fully
539539
/// confirmed yet.
540540
pub(super) fn has_pending_claims(&self) -> bool
541541
{
@@ -619,7 +619,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
619619

620620
let predicted_weight = cached_request.package_weight(&self.destination_script);
621621
if let Some((output_value, new_feerate)) = cached_request.compute_package_output(
622-
predicted_weight, self.destination_script.dust_value().to_sat(),
622+
predicted_weight, self.destination_script.minimal_non_dust().to_sat(),
623623
feerate_strategy, fee_estimator, logger,
624624
) {
625625
assert!(new_feerate != 0);
@@ -647,7 +647,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
647647
// Commitment inputs with anchors support are the only untractable inputs supported
648648
// thus far that require external funding.
649649
PackageSolvingData::HolderFundingOutput(output) => {
650-
debug_assert_eq!(tx.0.txid(), self.holder_commitment.trust().txid(),
650+
debug_assert_eq!(tx.0.compute_txid(), self.holder_commitment.trust().txid(),
651651
"Holder commitment transaction mismatch");
652652

653653
let conf_target = ConfirmationTarget::OnChainSweep;
@@ -659,7 +659,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
659659
compute_feerate_sat_per_1000_weight(fee_sat, tx.0.weight().to_wu());
660660
if commitment_tx_feerate_sat_per_1000_weight >= package_target_feerate_sat_per_1000_weight {
661661
log_debug!(logger, "Pre-signed commitment {} already has feerate {} sat/kW above required {} sat/kW",
662-
tx.0.txid(), commitment_tx_feerate_sat_per_1000_weight,
662+
tx.0.compute_txid(), commitment_tx_feerate_sat_per_1000_weight,
663663
package_target_feerate_sat_per_1000_weight);
664664
return Some((new_timer, 0, OnchainClaim::Tx(tx.clone())));
665665
}
@@ -811,17 +811,17 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
811811
log_info!(logger, "Broadcasting onchain {}", log_tx!(tx.0));
812812
broadcaster.broadcast_transactions(&[&tx.0]);
813813
} else {
814-
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.txid());
814+
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.compute_txid());
815815
}
816-
ClaimId(tx.0.txid().to_byte_array())
816+
ClaimId(tx.0.compute_txid().to_byte_array())
817817
},
818818
OnchainClaim::Event(claim_event) => {
819819
log_info!(logger, "Yielding onchain event to spend inputs {:?}", req.outpoints());
820820
let claim_id = match claim_event {
821821
ClaimEvent::BumpCommitment { ref commitment_tx, .. } =>
822822
// For commitment claims, we can just use their txid as it should
823823
// already be unique.
824-
ClaimId(commitment_tx.txid().to_byte_array()),
824+
ClaimId(commitment_tx.compute_txid().to_byte_array()),
825825
ClaimEvent::BumpHTLC { ref htlcs, .. } => {
826826
// For HTLC claims, commit to the entire set of HTLC outputs to
827827
// claim, which will always be unique per request. Once a claim ID
@@ -900,7 +900,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
900900
macro_rules! clean_claim_request_after_safety_delay {
901901
() => {
902902
let entry = OnchainEventEntry {
903-
txid: tx.txid(),
903+
txid: tx.compute_txid(),
904904
height: conf_height,
905905
block_hash: Some(conf_hash),
906906
event: OnchainEvent::Claim { claim_id: *claim_id }
@@ -953,7 +953,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
953953
}
954954
for package in claimed_outputs_material.drain(..) {
955955
let entry = OnchainEventEntry {
956-
txid: tx.txid(),
956+
txid: tx.compute_txid(),
957957
height: conf_height,
958958
block_hash: Some(conf_hash),
959959
event: OnchainEvent::ContentiousOutpoint { package },
@@ -1023,7 +1023,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
10231023
broadcaster.broadcast_transactions(&[&bump_tx.0]);
10241024
} else {
10251025
log_info!(logger, "Waiting for signature of RBF-bumped unsigned onchain transaction {}",
1026-
bump_tx.0.txid());
1026+
bump_tx.0.compute_txid());
10271027
}
10281028
},
10291029
OnchainClaim::Event(claim_event) => {
@@ -1110,7 +1110,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11101110
log_info!(logger, "Broadcasting onchain {}", log_tx!(bump_tx.0));
11111111
broadcaster.broadcast_transactions(&[&bump_tx.0]);
11121112
} else {
1113-
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", bump_tx.0.txid());
1113+
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", bump_tx.0.compute_txid());
11141114
}
11151115
},
11161116
OnchainClaim::Event(claim_event) => {

lightning/src/chain/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ mod tests {
9898
fn test_channel_id_calculation() {
9999
let tx: Transaction = encode::deserialize(&<Vec<u8>>::from_hex("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap();
100100
assert_eq!(&ChannelId::v1_from_funding_outpoint(OutPoint {
101-
txid: tx.txid(),
101+
txid: tx.compute_txid(),
102102
index: 0
103103
}).0[..], &<Vec<u8>>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25e").unwrap()[..]);
104104
assert_eq!(&ChannelId::v1_from_funding_outpoint(OutPoint {
105-
txid: tx.txid(),
105+
txid: tx.compute_txid(),
106106
index: 1
107107
}).0[..], &<Vec<u8>>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25f").unwrap()[..]);
108108
}

lightning/src/crypto/streams.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<T: Readable> LengthReadableArgs<[u8; 32]> for ChaChaPolyReadAdapter<T> {
5757
// Simultaneously read and decrypt an object from a LengthRead, storing it in Self::readable.
5858
// LengthRead must be used instead of std::io::Read because we need the total length to separate
5959
// out the tag at the end.
60-
fn read<R: LengthRead>(mut r: &mut R, secret: [u8; 32]) -> Result<Self, DecodeError> {
60+
fn read<R: LengthRead>(r: &mut R, secret: [u8; 32]) -> Result<Self, DecodeError> {
6161
if r.total_bytes() < 16 { return Err(DecodeError::InvalidValue) }
6262

6363
let mut chacha = ChaCha20Poly1305RFC::new(&secret, &[0; 12], &[]);

0 commit comments

Comments
 (0)