Skip to content

Commit

Permalink
gossip_map: patch the gossip map info
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vincenzopalazzo committed Jul 26, 2024
1 parent 1268f4c commit ce661b6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
1 change: 0 additions & 1 deletion gossip_map/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 26 additions & 4 deletions gossip_map/src/bolt7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<W: Write>(&self, buff: &mut W) -> std::io::Result<()> {
buff.write_all(self)
}
}

impl FromWire for $ty {
fn from_wire<R: Read>(reader: &mut R) -> std::io::Result<Self> {
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]
Expand All @@ -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,
}
Expand Down

0 comments on commit ce661b6

Please sign in to comment.