Skip to content

Write ChannelIds out as hex in Debug output #3306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading