From ce661b6aa4ab0e1e1d3e637446e593bfebb9420d Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Fri, 26 Jul 2024 18:59:34 +0200 Subject: [PATCH] gossip_map: patch the gossip map info The code generation is buggy because it decode a single byte with a Bitfield and then some type in the lightning network are decoded as [u8; 3]; This mean that the Bitfield should be able to skip the leng encoding, or semplify the implementation by having a type that is without size. Signed-off-by: Vincenzo Palazzo --- gossip_map/Cargo.toml | 1 - gossip_map/src/bolt7.rs | 30 ++++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/gossip_map/Cargo.toml b/gossip_map/Cargo.toml index cf29aa5..15516f3 100644 --- a/gossip_map/Cargo.toml +++ b/gossip_map/Cargo.toml @@ -11,7 +11,6 @@ hex = "0.4.3" bitcoin = { version = "0.30.0" } fundamentals = { git = "https://github.com/lnspec-tools/ln-fundamentals.git", branch = "macros/fix_fixed_read" } fundamentals-derive = { git = "https://github.com/lnspec-tools/ln-fundamentals.git", branch = "macros/fix_fixed_read" } -lightning = "0.0.121" [dev-dependencies] anyhow = "1.0.70" diff --git a/gossip_map/src/bolt7.rs b/gossip_map/src/bolt7.rs index 68eb506..782a693 100644 --- a/gossip_map/src/bolt7.rs +++ b/gossip_map/src/bolt7.rs @@ -41,8 +41,9 @@ pub struct ChannelUpdate { pub chain_hash: ChainHash, pub short_channel_id: ShortChannelId, pub timestamp: u32, - pub message_flags: BitFlag, - pub channel_flags: BitFlag, + // FIXME: these are u8 but the codegen will decode it to BitFlag + pub message_flags: u8, + pub channel_flags: u8, pub cltv_expiry_delta: u16, pub htlc_minimum_msat: u64, pub fee_base_msat: u32, @@ -59,6 +60,27 @@ pub struct GossipTimestampFilter { pub timestamp_range: u32, } +macro_rules! to_wire_type_with_size { + ($ty: ty, $size: expr) => { + impl ToWire for $ty { + fn to_wire(&self, buff: &mut W) -> std::io::Result<()> { + buff.write_all(self) + } + } + + impl FromWire for $ty { + fn from_wire(reader: &mut R) -> std::io::Result { + let mut buff = [0; $size]; + reader.read_exact(&mut buff)?; + Ok(buff) + } + } + }; +} + +pub type Alias = [u8; 32]; +pub type Rgb = [u8; 3]; + #[derive(DecodeWire, EncodeWire, Debug, Clone)] pub struct NodeAnnouncement { #[msg_type = 257] @@ -67,8 +89,8 @@ pub struct NodeAnnouncement { pub features: BitFlag, pub timestamp: u32, pub node_id: Point, - pub rgb_color: BitFlag, - pub alias: BitFlag, + pub rgb_color: Rgb, + pub alias: Alias, pub addresses: BitFlag, pub node_ann_tlvs: Stream, }