Skip to content

Commit 0c25046

Browse files
Merge pull request #2492 from optout21/payment-hash-display
[minor] Add Display to Payment ID types
2 parents 8866ed3 + 4146264 commit 0c25046

File tree

8 files changed

+107
-71
lines changed

8 files changed

+107
-71
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,
@@ -3625,12 +3625,12 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
36253625
(outbound_htlc && !$source_avail && (accepted_preimage_claim || offered_preimage_claim)) {
36263626
log_error!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}!",
36273627
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
3628-
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
3628+
if outbound_htlc { "outbound" } else { "inbound" }, &$htlc.payment_hash,
36293629
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" });
36303630
} else {
36313631
log_info!(logger, "Input spending {} ({}:{}) in {} resolves {} HTLC with payment hash {} with {}",
36323632
$tx_info, input.previous_output.txid, input.previous_output.vout, tx.txid(),
3633-
if outbound_htlc { "outbound" } else { "inbound" }, log_bytes!($htlc.payment_hash.0),
3633+
if outbound_htlc { "outbound" } else { "inbound" }, &$htlc.payment_hash,
36343634
if revocation_sig_claim { "revocation sig" } else if accepted_preimage_claim || offered_preimage_claim { "preimage" } else { "timeout" });
36353635
}
36363636
}
@@ -3777,7 +3777,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37773777
commitment_tx_output_idx: Some(input.previous_output.vout),
37783778
},
37793779
};
3780-
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());
3780+
log_info!(logger, "Failing HTLC with payment_hash {} timeout by a spend tx, waiting for confirmation (at height {})", &payment_hash, entry.confirmation_threshold());
37813781
self.onchain_events_awaiting_threshold_conf.push(entry);
37823782
}
37833783
}

lightning/src/ln/channel.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -1256,10 +1256,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
12561256
feerate_per_kw as u64 * htlc_timeout_tx_weight(self.get_channel_type()) / 1000
12571257
};
12581258
if $htlc.amount_msat / 1000 >= broadcaster_dust_limit_satoshis + htlc_tx_fee {
1259-
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);
1259+
log_trace!(logger, " ...including {} {} HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, &$htlc.payment_hash, $htlc.amount_msat);
12601260
included_non_dust_htlcs.push((htlc_in_tx, $source));
12611261
} else {
1262-
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);
1262+
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);
12631263
included_dust_htlcs.push((htlc_in_tx, $source));
12641264
}
12651265
} else {
@@ -1270,10 +1270,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
12701270
feerate_per_kw as u64 * htlc_success_tx_weight(self.get_channel_type()) / 1000
12711271
};
12721272
if $htlc.amount_msat / 1000 >= broadcaster_dust_limit_satoshis + htlc_tx_fee {
1273-
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);
1273+
log_trace!(logger, " ...including {} {} HTLC {} (hash {}) with value {}", if $outbound { "outbound" } else { "inbound" }, $state_name, $htlc.htlc_id, &$htlc.payment_hash, $htlc.amount_msat);
12741274
included_non_dust_htlcs.push((htlc_in_tx, $source));
12751275
} else {
1276-
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);
1276+
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);
12771277
included_dust_htlcs.push((htlc_in_tx, $source));
12781278
}
12791279
}
@@ -1293,7 +1293,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
12931293
add_htlc_output!(htlc, false, None, state_name);
12941294
remote_htlc_total_msat += htlc.amount_msat;
12951295
} else {
1296-
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);
1296+
log_trace!(logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
12971297
match &htlc.state {
12981298
&InboundHTLCState::LocalRemoved(ref reason) => {
12991299
if generated_by_local {
@@ -1333,7 +1333,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
13331333
add_htlc_output!(htlc, true, Some(&htlc.source), state_name);
13341334
local_htlc_total_msat += htlc.amount_msat;
13351335
} else {
1336-
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);
1336+
log_trace!(logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, &htlc.payment_hash, htlc.amount_msat, state_name);
13371337
match htlc.state {
13381338
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_))|OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) => {
13391339
value_to_self_msat_offset -= htlc.amount_msat as i64;
@@ -2222,7 +2222,7 @@ impl<SP: Deref> Channel<SP> where
22222222
InboundHTLCState::LocalRemoved(ref reason) => {
22232223
if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
22242224
} else {
2225-
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()));
2225+
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()));
22262226
debug_assert!(false, "Tried to fulfill an HTLC that was already failed");
22272227
}
22282228
return UpdateFulfillFetch::DuplicateClaim {};
@@ -2303,7 +2303,7 @@ impl<SP: Deref> Channel<SP> where
23032303
debug_assert!(false, "Have an inbound HTLC we tried to claim before it was fully committed to");
23042304
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
23052305
}
2306-
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
2306+
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", &htlc.payment_hash, log_bytes!(self.context.channel_id));
23072307
htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone()));
23082308
}
23092309

@@ -2985,7 +2985,7 @@ impl<SP: Deref> Channel<SP> where
29852985
} else { None };
29862986
if let Some(forward_info) = new_forward {
29872987
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToAnnounce due to commitment_signed in channel {}.",
2988-
log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
2988+
&htlc.payment_hash, log_bytes!(self.context.channel_id));
29892989
htlc.state = InboundHTLCState::AwaitingRemoteRevokeToAnnounce(forward_info);
29902990
need_commitment = true;
29912991
}
@@ -2994,7 +2994,7 @@ impl<SP: Deref> Channel<SP> where
29942994
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
29952995
if let &mut OutboundHTLCState::RemoteRemoved(ref mut outcome) = &mut htlc.state {
29962996
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
2997-
log_bytes!(htlc.payment_hash.0), log_bytes!(self.context.channel_id));
2997+
&htlc.payment_hash, log_bytes!(self.context.channel_id));
29982998
// Grab the preimage, if it exists, instead of cloning
29992999
let mut reason = OutboundHTLCOutcome::Success(None);
30003000
mem::swap(outcome, &mut reason);
@@ -3122,7 +3122,7 @@ impl<SP: Deref> Channel<SP> where
31223122
match e {
31233123
ChannelError::Ignore(ref msg) => {
31243124
log_info!(logger, "Failed to send HTLC with payment_hash {} due to {} in channel {}",
3125-
log_bytes!(payment_hash.0), msg, log_bytes!(self.context.channel_id()));
3125+
&payment_hash, msg, log_bytes!(self.context.channel_id()));
31263126
// If we fail to send here, then this HTLC should
31273127
// be failed backwards. Failing to send here
31283128
// indicates that this HTLC may keep being put back
@@ -3294,7 +3294,7 @@ impl<SP: Deref> Channel<SP> where
32943294
// We really shouldnt have two passes here, but retain gives a non-mutable ref (Rust bug)
32953295
pending_inbound_htlcs.retain(|htlc| {
32963296
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
3297-
log_trace!(logger, " ...removing inbound LocalRemoved {}", log_bytes!(htlc.payment_hash.0));
3297+
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
32983298
if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
32993299
value_to_self_msat_diff += htlc.amount_msat as i64;
33003300
}
@@ -3303,7 +3303,7 @@ impl<SP: Deref> Channel<SP> where
33033303
});
33043304
pending_outbound_htlcs.retain(|htlc| {
33053305
if let &OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) = &htlc.state {
3306-
log_trace!(logger, " ...removing outbound AwaitingRemovedRemoteRevoke {}", log_bytes!(htlc.payment_hash.0));
3306+
log_trace!(logger, " ...removing outbound AwaitingRemovedRemoteRevoke {}", &htlc.payment_hash);
33073307
if let OutboundHTLCOutcome::Failure(reason) = outcome.clone() { // We really want take() here, but, again, non-mut ref :(
33083308
revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
33093309
} else {
@@ -3325,13 +3325,13 @@ impl<SP: Deref> Channel<SP> where
33253325
mem::swap(&mut state, &mut htlc.state);
33263326

33273327
if let InboundHTLCState::AwaitingRemoteRevokeToAnnounce(forward_info) = state {
3328-
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
3328+
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", &htlc.payment_hash);
33293329
htlc.state = InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info);
33303330
require_commitment = true;
33313331
} else if let InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info) = state {
33323332
match forward_info {
33333333
PendingHTLCStatus::Fail(fail_msg) => {
3334-
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to LocalRemoved due to PendingHTLCStatus indicating failure", log_bytes!(htlc.payment_hash.0));
3334+
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to LocalRemoved due to PendingHTLCStatus indicating failure", &htlc.payment_hash);
33353335
require_commitment = true;
33363336
match fail_msg {
33373337
HTLCFailureMsg::Relay(msg) => {
@@ -3345,7 +3345,7 @@ impl<SP: Deref> Channel<SP> where
33453345
}
33463346
},
33473347
PendingHTLCStatus::Forward(forward_info) => {
3348-
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to Committed", log_bytes!(htlc.payment_hash.0));
3348+
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to Committed", &htlc.payment_hash);
33493349
to_forward_infos.push((forward_info, htlc.htlc_id));
33503350
htlc.state = InboundHTLCState::Committed;
33513351
}
@@ -3355,11 +3355,11 @@ impl<SP: Deref> Channel<SP> where
33553355
}
33563356
for htlc in pending_outbound_htlcs.iter_mut() {
33573357
if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
3358-
log_trace!(logger, " ...promoting outbound LocalAnnounced {} to Committed", log_bytes!(htlc.payment_hash.0));
3358+
log_trace!(logger, " ...promoting outbound LocalAnnounced {} to Committed", &htlc.payment_hash);
33593359
htlc.state = OutboundHTLCState::Committed;
33603360
}
33613361
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
3362-
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
3362+
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
33633363
// Grab the preimage, if it exists, instead of cloning
33643364
let mut reason = OutboundHTLCOutcome::Success(None);
33653365
mem::swap(outcome, &mut reason);
@@ -5266,13 +5266,13 @@ impl<SP: Deref> Channel<SP> where
52665266
Some(InboundHTLCState::AwaitingAnnouncedRemoteRevoke(forward_info.clone()))
52675267
} else { None };
52685268
if let Some(state) = new_state {
5269-
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
5269+
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce {} to AwaitingAnnouncedRemoteRevoke", &htlc.payment_hash);
52705270
htlc.state = state;
52715271
}
52725272
}
52735273
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
52745274
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
5275-
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", log_bytes!(htlc.payment_hash.0));
5275+
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
52765276
// Grab the preimage, if it exists, instead of cloning
52775277
let mut reason = OutboundHTLCOutcome::Success(None);
52785278
mem::swap(outcome, &mut reason);

0 commit comments

Comments
 (0)