Skip to content

Commit 513c2b4

Browse files
committed
Use Display of PaymentHash; avoid log_bytes macro
1 parent a545683 commit 513c2b4

File tree

6 files changed

+64
-58
lines changed

6 files changed

+64
-58
lines changed

lightning-invoice/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ where
191191
};
192192

193193
log_trace!(logger, "Creating phantom invoice from {} participating nodes with payment hash {}",
194-
phantom_route_hints.len(), log_bytes!(payment_hash.0));
194+
phantom_route_hints.len(), &payment_hash);
195195

196196
let mut invoice = invoice
197197
.duration_since_epoch(duration_since_epoch)
@@ -534,7 +534,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
534534
return Err(SignOrCreationError::CreationError(CreationError::MinFinalCltvExpiryDeltaTooShort));
535535
}
536536

537-
log_trace!(logger, "Creating invoice with payment hash {}", log_bytes!(payment_hash.0));
537+
log_trace!(logger, "Creating invoice with payment hash {}", &payment_hash);
538538

539539
let invoice = match description {
540540
Bolt11InvoiceDescription::Direct(description) => {

lightning/src/chain/channelmonitor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,7 @@ macro_rules! fail_unbroadcast_htlcs {
21222122
},
21232123
};
21242124
log_trace!($logger, "Failing HTLC with payment_hash {} from {} counterparty commitment tx due to broadcast of {} commitment transaction {}, waiting for confirmation (at height {})",
2125-
log_bytes!(htlc.payment_hash.0), $commitment_tx, $commitment_tx_type,
2125+
&htlc.payment_hash, $commitment_tx, $commitment_tx_type,
21262126
$commitment_txid_confirmed, entry.confirmation_threshold());
21272127
$self.onchain_events_awaiting_threshold_conf.push(entry);
21282128
}
@@ -3348,7 +3348,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33483348
}
33493349

33503350
log_debug!(logger, "HTLC {} failure update in {} has got enough confirmations to be passed upstream",
3351-
log_bytes!(payment_hash.0), entry.txid);
3351+
&payment_hash, entry.txid);
33523352
self.pending_monitor_events.push(MonitorEvent::HTLCEvent(HTLCUpdate {
33533353
payment_hash,
33543354
payment_preimage: None,
@@ -3624,12 +3624,12 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36243624
(outbound_htlc && !$source_avail && (accepted_preimage_claim || offered_preimage_claim)) {
36253625
log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
36263626
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
3627-
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
3627+
if outbound_htlc { "outbound" } else { "inbound" }, &$htlc.payment_hash,
36283628
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" });
36293629
} else {
36303630
log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
36313631
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
3632-
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
3632+
if outbound_htlc { "outbound" } else { "inbound" }, &$htlc.payment_hash,
36333633
if revocation_sig_claim { "revocation sig" } else if accepted_preimage_claim || offered_preimage_claim { "preimage" } else { "timeout" });
36343634
}
36353635
}
@@ -3776,7 +3776,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37763776
commitment_tx_output_idx: Some(input.previous_output.vout),
37773777
},
37783778
};
3779-
log_info!(logger, "Failing HTLC with payment_hash {} timeout by a spend tx, waiting for confirmation (at height {})", log_bytes!(payment_hash.0), entry.confirmation_threshold());
3779+
log_info!(logger, "Failing HTLC with payment_hash {} timeout by a spend tx, waiting for confirmation (at height {})", &payment_hash, entry.confirmation_threshold());
37803780
self.onchain_events_awaiting_threshold_conf.push(entry);
37813781
}
37823782
}

lightning/src/ln/channel.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,10 +1255,10 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
12551255
feerate_per_kw as u64 * htlc_timeout_tx_weight(self.get_channel_type()) / 1000
12561256
};
12571257
if $htlc.amount_msat / 1000 >= broadcaster_dust_limit_satoshis + htlc_tx_fee {
1258-
log_trace!(logger, " ...including {} {} HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, log_bytes!($htlc.payment_hash.0), $htlc.amount_msat);
1258+
log_trace!(logger, " ...including {} {} HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, &$htlc.payment_hash, $htlc.amount_msat);
12591259
included_non_dust_htlcs.push((htlc_in_tx, $source));
12601260
} else {
1261-
log_trace!(logger, " ...including {} {} dust HTLC {} (hash {}) with value {} due to dust limit", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, log_bytes!($htlc.payment_hash.0), $htlc.amount_msat);
1261+
log_trace!(logger, " ...including {} {} dust HTLC {} (hash {}) with value {} due to dust limit", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, &$htlc.payment_hash, $htlc.amount_msat);
12621262
included_dust_htlcs.push((htlc_in_tx, $source));
12631263
}
12641264
} else {
@@ -1269,10 +1269,10 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
12691269
feerate_per_kw as u64 * htlc_success_tx_weight(self.get_channel_type()) / 1000
12701270
};
12711271
if $htlc.amount_msat / 1000 >= broadcaster_dust_limit_satoshis + htlc_tx_fee {
1272-
log_trace!(logger, " ...including {} {} HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, log_bytes!($htlc.payment_hash.0), $htlc.amount_msat);
1272+
log_trace!(logger, " ...including {} {} HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, &$htlc.payment_hash, $htlc.amount_msat);
12731273
included_non_dust_htlcs.push((htlc_in_tx, $source));
12741274
} else {
1275-
log_trace!(logger, " ...including {} {} dust HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, log_bytes!($htlc.payment_hash.0), $htlc.amount_msat);
1275+
log_trace!(logger, " ...including {} {} dust HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, &$htlc.payment_hash, $htlc.amount_msat);
12761276
included_dust_htlcs.push((htlc_in_tx, $source));
12771277
}
12781278
}
@@ -1292,7 +1292,7 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
12921292
add_htlc_output!(htlc, false, None, state_name);
12931293
remote_htlc_total_msat += htlc.amount_msat;
12941294
} else {
1295-
log_trace!(logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, log_bytes!(htlc.payment_hash.0), htlc.amount_msat, state_name);
1295+
log_trace!(logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
12961296
match &htlc.state {
12971297
&InboundHTLCState::LocalRemoved(ref reason) => {
12981298
if generated_by_local {
@@ -1332,7 +1332,7 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
13321332
add_htlc_output!(htlc, true, Some(&htlc.source), state_name);
13331333
local_htlc_total_msat += htlc.amount_msat;
13341334
} else {
1335-
log_trace!(logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, log_bytes!(htlc.payment_hash.0), htlc.amount_msat, state_name);
1335+
log_trace!(logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
13361336
match htlc.state {
13371337
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_))|OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) => {
13381338
value_to_self_msat_offset -= htlc.amount_msat as i64;
@@ -2218,7 +2218,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22182218
InboundHTLCState::LocalRemoved(ref reason) => {
22192219
if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
22202220
} else {
2221-
log_warn!(logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {}", log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id()));
2221+
log_warn!(logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {}", &htlc.payment_hash, log_bytes!(self.context.channel_id()));
22222222
debug_assert!(false, "Tried to fulfill an HTLC that was already failed");
22232223
}
22242224
return UpdateFulfillFetch::DuplicateClaim {};
@@ -2299,7 +2299,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22992299
debug_assert!(false, "Have an inbound HTLC we tried to claim before it was fully committed to");
23002300
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
23012301
}
2302-
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
2302+
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", &htlc.payment_hash, log_bytes!(self.context.channel_id));
23032303
htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone()));
23042304
}
23052305

@@ -2982,7 +2982,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
29822982
} else { None };
29832983
if let Some(forward_info) = new_forward {
29842984
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToAnnounce due to commitment_signed in channel {}.",
2985-
log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
2985+
&htlc.payment_hash, log_bytes!(self.context.channel_id));
29862986
htlc.state = InboundHTLCState::AwaitingRemoteRevokeToAnnounce(forward_info);
29872987
need_commitment = true;
29882988
}
@@ -2991,7 +2991,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
29912991
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
29922992
if let &mut OutboundHTLCState::RemoteRemoved(ref mut outcome) = &mut htlc.state {
29932993
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
2994-
log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
2994+
&htlc.payment_hash, log_bytes!(self.context.channel_id));
29952995
// Grab the preimage, if it exists, instead of cloning
29962996
let mut reason = OutboundHTLCOutcome::Success(None);
29972997
mem::swap(outcome, &mut reason);
@@ -3119,7 +3119,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
31193119
match e {
31203120
ChannelError::Ignore(ref msg) => {
31213121
log_info!(logger, "Failed to send HTLC with payment_hash {} due to {} in channel {}",
3122-
log_bytes!(payment_hash.0), msg, log_bytes!(self.context.channel_id()));
3122+
&payment_hash, msg, log_bytes!(self.context.channel_id()));
31233123
// If we fail to send here, then this HTLC should
31243124
// be failed backwards. Failing to send here
31253125
// indicates that this HTLC may keep being put back
@@ -3287,7 +3287,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
32873287
// We really shouldnt have two passes here, but retain gives a non-mutable ref (Rust bug)
32883288
pending_inbound_htlcs.retain(|htlc| {
32893289
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
3290-
log_trace!(logger, " ...removing inbound LocalRemoved {}", log_bytes!(htlc.payment_hash.0));
3290+
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
32913291
if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
32923292
value_to_self_msat_diff += htlc.amount_msat as i64;
32933293
}
@@ -3296,7 +3296,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
32963296
});
32973297
pending_outbound_htlcs.retain(|htlc| {
32983298
if let &OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) = &htlc.state {
3299-
log_trace!(logger, " ...removing outbound AwaitingRemovedRemoteRevoke {}", log_bytes!(htlc.payment_hash.0));
3299+
log_trace!(logger, " ...removing outbound AwaitingRemovedRemoteRevoke {}", &htlc.payment_hash);
33003300
if let OutboundHTLCOutcome::Failure(reason) = outcome.clone() { // We really want take() here, but, again, non-mut ref :(
33013301
revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
33023302
} else {
@@ -3318,13 +3318,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33183318
mem::swap(&mut state, &mut htlc.state);
33193319

33203320
if let InboundHTLCState::AwaitingRemoteRevokeToAnnounce(forward_info) = state {
3321-
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
3321+
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", &htlc.payment_hash);
33223322
htlc.state = InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info);
33233323
require_commitment = true;
33243324
} else if let InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info) = state {
33253325
match forward_info {
33263326
PendingHTLCStatus::Fail(fail_msg) => {
3327-
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to LocalRemoved due to PendingHTLCStatus indicating failure", log_bytes!(htlc.payment_hash.0));
3327+
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to LocalRemoved due to PendingHTLCStatus indicating failure", &htlc.payment_hash);
33283328
require_commitment = true;
33293329
match fail_msg {
33303330
HTLCFailureMsg::Relay(msg) => {
@@ -3338,7 +3338,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33383338
}
33393339
},
33403340
PendingHTLCStatus::Forward(forward_info) => {
3341-
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to Committed", log_bytes!(htlc.payment_hash.0));
3341+
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to Committed", &htlc.payment_hash);
33423342
to_forward_infos.push((forward_info, htlc.htlc_id));
33433343
htlc.state = InboundHTLCState::Committed;
33443344
}
@@ -3348,11 +3348,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33483348
}
33493349
for htlc in pending_outbound_htlcs.iter_mut() {
33503350
if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
3351-
log_trace!(logger, " ...promoting outbound LocalAnnounced {} to Committed", log_bytes!(htlc.payment_hash.0));
3351+
log_trace!(logger, " ...promoting outbound LocalAnnounced {} to Committed", &htlc.payment_hash);
33523352
htlc.state = OutboundHTLCState::Committed;
33533353
}
33543354
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
3355-
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
3355+
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
33563356
// Grab the preimage, if it exists, instead of cloning
33573357
let mut reason = OutboundHTLCOutcome::Success(None);
33583358
mem::swap(outcome, &mut reason);
@@ -5244,13 +5244,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
52445244
Some(InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info.clone()))
52455245
} else { None };
52465246
if let Some(state) = new_state {
5247-
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
5247+
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", &htlc.payment_hash);
52485248
htlc.state = state;
52495249
}
52505250
}
52515251
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
52525252
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
5253-
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
5253+
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
52545254
// Grab the preimage, if it exists, instead of cloning
52555255
let mut reason = OutboundHTLCOutcome::Success(None);
52565256
mem::swap(outcome, &mut reason);

0 commit comments

Comments
 (0)