Skip to content

Commit 774046d

Browse files
committed
Add Display to PaymentHash, avoid log_bytes macro
1 parent 131560e commit 774046d

File tree

7 files changed

+67
-58
lines changed

7 files changed

+67
-58
lines changed

lightning-invoice/src/utils.rs

+2-2
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

+5-5
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

+20-20
Original file line numberDiff line numberDiff line change
@@ -1269,10 +1269,10 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
12691269
feerate_per_kw as u64 * htlc_timeout_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 {} due to dust limit", 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 {} due to dust limit", 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
} else {
@@ -1283,10 +1283,10 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
12831283
feerate_per_kw as u64 * htlc_success_tx_weight(self.get_channel_type()) / 1000
12841284
};
12851285
if $htlc.amount_msat / 1000 >= broadcaster_dust_limit_satoshis + htlc_tx_fee {
1286-
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);
1286+
log_trace!(logger, " ...including {} {} HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, &$htlc.payment_hash, $htlc.amount_msat);
12871287
included_non_dust_htlcs.push((htlc_in_tx, $source));
12881288
} else {
1289-
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);
1289+
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);
12901290
included_dust_htlcs.push((htlc_in_tx, $source));
12911291
}
12921292
}
@@ -1306,7 +1306,7 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
13061306
add_htlc_output!(htlc, false, None, state_name);
13071307
remote_htlc_total_msat += htlc.amount_msat;
13081308
} else {
1309-
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);
1309+
log_trace!(logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
13101310
match &htlc.state {
13111311
&InboundHTLCState::LocalRemoved(ref reason) => {
13121312
if generated_by_local {
@@ -1346,7 +1346,7 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
13461346
add_htlc_output!(htlc, true, Some(&htlc.source), state_name);
13471347
local_htlc_total_msat += htlc.amount_msat;
13481348
} else {
1349-
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);
1349+
log_trace!(logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
13501350
match htlc.state {
13511351
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_))|OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) => {
13521352
value_to_self_msat_offset -= htlc.amount_msat as i64;
@@ -2241,7 +2241,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
22412241
InboundHTLCState::LocalRemoved(ref reason) => {
22422242
if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
22432243
} else {
2244-
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()));
2244+
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()));
22452245
debug_assert!(false, "Tried to fulfill an HTLC that was already failed");
22462246
}
22472247
return UpdateFulfillFetch::DuplicateClaim {};
@@ -2322,7 +2322,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
23222322
debug_assert!(false, "Have an inbound HTLC we tried to claim before it was fully committed to");
23232323
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
23242324
}
2325-
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
2325+
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", &htlc.payment_hash, log_bytes!(self.context.channel_id));
23262326
htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone()));
23272327
}
23282328

@@ -3005,7 +3005,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
30053005
} else { None };
30063006
if let Some(forward_info) = new_forward {
30073007
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToAnnounce due to commitment_signed in channel {}.",
3008-
log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
3008+
&htlc.payment_hash, log_bytes!(self.context.channel_id));
30093009
htlc.state = InboundHTLCState::AwaitingRemoteRevokeToAnnounce(forward_info);
30103010
need_commitment = true;
30113011
}
@@ -3014,7 +3014,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
30143014
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
30153015
if let &mut OutboundHTLCState::RemoteRemoved(ref mut outcome) = &mut htlc.state {
30163016
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
3017-
log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
3017+
&htlc.payment_hash, log_bytes!(self.context.channel_id));
30183018
// Grab the preimage, if it exists, instead of cloning
30193019
let mut reason = OutboundHTLCOutcome::Success(None);
30203020
mem::swap(outcome, &mut reason);
@@ -3142,7 +3142,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
31423142
match e {
31433143
ChannelError::Ignore(ref msg) => {
31443144
log_info!(logger, "Failed to send HTLC with payment_hash {} due to {} in channel {}",
3145-
log_bytes!(payment_hash.0), msg, log_bytes!(self.context.channel_id()));
3145+
&payment_hash, msg, log_bytes!(self.context.channel_id()));
31463146
// If we fail to send here, then this HTLC should
31473147
// be failed backwards. Failing to send here
31483148
// indicates that this HTLC may keep being put back
@@ -3310,7 +3310,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33103310
// We really shouldnt have two passes here, but retain gives a non-mutable ref (Rust bug)
33113311
pending_inbound_htlcs.retain(|htlc| {
33123312
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
3313-
log_trace!(logger, " ...removing inbound LocalRemoved {}", log_bytes!(htlc.payment_hash.0));
3313+
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
33143314
if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
33153315
value_to_self_msat_diff += htlc.amount_msat as i64;
33163316
}
@@ -3319,7 +3319,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33193319
});
33203320
pending_outbound_htlcs.retain(|htlc| {
33213321
if let &OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) = &htlc.state {
3322-
log_trace!(logger, " ...removing outbound AwaitingRemovedRemoteRevoke {}", log_bytes!(htlc.payment_hash.0));
3322+
log_trace!(logger, " ...removing outbound AwaitingRemovedRemoteRevoke {}", &htlc.payment_hash);
33233323
if let OutboundHTLCOutcome::Failure(reason) = outcome.clone() { // We really want take() here, but, again, non-mut ref :(
33243324
revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
33253325
} else {
@@ -3341,13 +3341,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33413341
mem::swap(&mut state, &mut htlc.state);
33423342

33433343
if let InboundHTLCState::AwaitingRemoteRevokeToAnnounce(forward_info) = state {
3344-
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
3344+
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", &htlc.payment_hash);
33453345
htlc.state = InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info);
33463346
require_commitment = true;
33473347
} else if let InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info) = state {
33483348
match forward_info {
33493349
PendingHTLCStatus::Fail(fail_msg) => {
3350-
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to LocalRemoved due to PendingHTLCStatus indicating failure", log_bytes!(htlc.payment_hash.0));
3350+
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to LocalRemoved due to PendingHTLCStatus indicating failure", &htlc.payment_hash);
33513351
require_commitment = true;
33523352
match fail_msg {
33533353
HTLCFailureMsg::Relay(msg) => {
@@ -3361,7 +3361,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33613361
}
33623362
},
33633363
PendingHTLCStatus::Forward(forward_info) => {
3364-
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to Committed", log_bytes!(htlc.payment_hash.0));
3364+
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to Committed", &htlc.payment_hash);
33653365
to_forward_infos.push((forward_info, htlc.htlc_id));
33663366
htlc.state = InboundHTLCState::Committed;
33673367
}
@@ -3371,11 +3371,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
33713371
}
33723372
for htlc in pending_outbound_htlcs.iter_mut() {
33733373
if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
3374-
log_trace!(logger, " ...promoting outbound LocalAnnounced {} to Committed", log_bytes!(htlc.payment_hash.0));
3374+
log_trace!(logger, " ...promoting outbound LocalAnnounced {} to Committed", &htlc.payment_hash);
33753375
htlc.state = OutboundHTLCState::Committed;
33763376
}
33773377
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
3378-
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
3378+
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
33793379
// Grab the preimage, if it exists, instead of cloning
33803380
let mut reason = OutboundHTLCOutcome::Success(None);
33813381
mem::swap(outcome, &mut reason);
@@ -5238,13 +5238,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
52385238
Some(InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info.clone()))
52395239
} else { None };
52405240
if let Some(state) = new_state {
5241-
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
5241+
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", &htlc.payment_hash);
52425242
htlc.state = state;
52435243
}
52445244
}
52455245
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
52465246
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
5247-
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
5247+
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
52485248
// Grab the preimage, if it exists, instead of cloning
52495249
let mut reason = OutboundHTLCOutcome::Success(None);
52505250
mem::swap(outcome, &mut reason);

0 commit comments

Comments
 (0)