Skip to content

Commit

Permalink
Merge pull request #3306 from TheBlueMatt/2024-09-chan-id-hex
Browse files Browse the repository at this point in the history
Write ChannelIds out as hex in Debug output
  • Loading branch information
tnull committed Sep 10, 2024
2 parents d65dc9c + 98d15f2 commit 479654b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 0 additions & 2 deletions lightning-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ _test_utils = []

[dependencies]
bitcoin = { version = "0.32.2", default-features = false }
# TODO: Once we switch to bitcoin 0.32 drop this explicit dep:
hex-conservative = { version = "0.2", default-features = false }
bech32 = { version = "0.9", default-features = false }

[lints]
Expand Down
4 changes: 1 addition & 3 deletions lightning-types/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use alloc::vec::Vec;
use core::borrow::Borrow;

use bitcoin::hashes::{sha256::Hash as Sha256, Hash as _};

// TODO: Once we switch to rust-bitcoin 0.32, import this as bitcoin::hex
use hex_conservative::display::impl_fmt_traits;
use bitcoin::hex::display::impl_fmt_traits;

/// The payment hash is the hash of the [`PaymentPreimage`] which is the value used to lock funds
/// in HTLCs while they transit the lightning network.
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7135,7 +7135,7 @@ where
chan
} else {
let update_actions = peer_state.monitor_update_blocked_actions
.remove(&channel_id).unwrap_or(Vec::new());
.remove(channel_id).unwrap_or(Vec::new());
mem::drop(peer_state_lock);
mem::drop(per_peer_state);
self.handle_monitor_update_completion_actions(update_actions);
Expand Down
17 changes: 12 additions & 5 deletions lightning/src/ln/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use bitcoin::hashes::{
HashEngine as _,
sha256::Hash as Sha256,
};
use core::fmt;
use bitcoin::hex::display::impl_fmt_traits;
use core::borrow::Borrow;
use core::ops::Deref;

/// A unique 32-byte identifier for a channel.
Expand All @@ -41,7 +42,7 @@ use core::ops::Deref;
/// A _temporary_ ID is generated randomly.
/// (Later revocation-point-based _v2_ is a possibility.)
/// The variety (context) is not stored, it is relevant only at creation.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ChannelId(pub [u8; 32]);

impl ChannelId {
Expand Down Expand Up @@ -121,9 +122,15 @@ impl Readable for ChannelId {
}
}

impl fmt::Display for ChannelId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
crate::util::logger::DebugBytes(&self.0).fmt(f)
impl Borrow<[u8]> for ChannelId {
fn borrow(&self) -> &[u8] {
&self.0[..]
}
}

impl_fmt_traits! {
impl fmt_traits for ChannelId {
const LENGTH: usize = 32;
}
}

Expand Down

0 comments on commit 479654b

Please sign in to comment.