bolt7

Routing gossip protocol, per BOLT #7 (docs.ppad.tech/bolt7).
git clone git://git.ppad.tech/bolt7.git
Log | Files | Refs | README | LICENSE

BOLT7.hs (4070B)


      1 {-# OPTIONS_HADDOCK prune #-}
      2 
      3 -- |
      4 -- Module: Lightning.Protocol.BOLT7
      5 -- Copyright: (c) 2025 Jared Tobin
      6 -- License: MIT
      7 -- Maintainer: Jared Tobin <jared@ppad.tech>
      8 --
      9 -- Routing gossip protocol for the Lightning Network, per
     10 -- [BOLT #7](https://github.com/lightning/bolts/blob/master/07-routing-gossip.md).
     11 --
     12 -- = Overview
     13 --
     14 -- This module provides types, encoding\/decoding, and validation for
     15 -- BOLT #7 routing gossip messages. The protocol enables nodes to
     16 -- share channel and node information across the network.
     17 --
     18 -- = Usage
     19 --
     20 -- Import this module to access all BOLT #7 functionality:
     21 --
     22 -- @
     23 -- import Lightning.Protocol.BOLT7
     24 -- @
     25 --
     26 -- == Decoding messages
     27 --
     28 -- @
     29 -- -- Decode a channel_announcement from wire format
     30 -- case decodeChannelAnnouncement wireBytes of
     31 --   Left err -> handleError err
     32 --   Right (msg, rest) -> processAnnouncement msg
     33 -- @
     34 --
     35 -- == Encoding messages
     36 --
     37 -- @
     38 -- -- Encode a gossip_timestamp_filter
     39 -- let msg = GossipTimestampFilter
     40 --       { gossipFilterChainHash      = mainnetChainHash
     41 --       , gossipFilterFirstTimestamp = 1609459200
     42 --       , gossipFilterTimestampRange = 86400
     43 --       }
     44 -- let wireBytes = encodeGossipTimestampFilter msg
     45 -- @
     46 --
     47 -- == Validation
     48 --
     49 -- @
     50 -- -- Validate a channel_announcement before processing
     51 -- case validateChannelAnnouncement announcement of
     52 --   Left ValidateNodeIdOrdering -> rejectMessage
     53 --   Right () -> processValidMessage
     54 -- @
     55 --
     56 -- == Signature verification
     57 --
     58 -- This library provides hash computation for signature verification:
     59 --
     60 -- @
     61 -- -- Compute the hash that should be signed
     62 -- let sigHash = channelAnnouncementHash encodedMessage
     63 -- -- Verify signatures using ppad-secp256k1 (not included)
     64 -- @
     65 --
     66 -- = Protocol overview
     67 --
     68 -- BOLT #7 defines gossip messages for routing in the Lightning Network.
     69 -- Nodes use these messages to build a view of the channel graph.
     70 
     71 module Lightning.Protocol.BOLT7 (
     72   -- * Core types
     73   -- | Re-exported from "Lightning.Protocol.BOLT7.Types".
     74     module Lightning.Protocol.BOLT7.Types
     75 
     76   -- * Message types
     77   -- | Re-exported from "Lightning.Protocol.BOLT7.Messages".
     78   , module Lightning.Protocol.BOLT7.Messages
     79 
     80   -- * Codec functions
     81   -- | Re-exported from "Lightning.Protocol.BOLT7.Codec".
     82   , module Lightning.Protocol.BOLT7.Codec
     83 
     84   -- * Hash functions
     85   -- | Re-exported from "Lightning.Protocol.BOLT7.Hash".
     86   , module Lightning.Protocol.BOLT7.Hash
     87 
     88   -- * Validation functions
     89   -- | Re-exported from "Lightning.Protocol.BOLT7.Validate".
     90   , module Lightning.Protocol.BOLT7.Validate
     91 
     92   -- $messagetypes
     93 
     94   -- ** Channel announcement
     95   -- $announcement
     96 
     97   -- ** Node announcement
     98   -- $nodeannouncement
     99 
    100   -- ** Channel updates
    101   -- $updates
    102 
    103   -- ** Gossip queries
    104   -- $queries
    105   ) where
    106 
    107 import Lightning.Protocol.BOLT7.Codec
    108 import Lightning.Protocol.BOLT7.Hash
    109 import Lightning.Protocol.BOLT7.Messages
    110 import Lightning.Protocol.BOLT7.Types
    111 import Lightning.Protocol.BOLT7.Validate
    112 
    113 -- $messagetypes
    114 --
    115 -- BOLT #7 defines the following message types:
    116 --
    117 -- * 256: channel_announcement
    118 -- * 257: node_announcement
    119 -- * 258: channel_update
    120 -- * 259: announcement_signatures
    121 -- * 261: query_short_channel_ids
    122 -- * 262: reply_short_channel_ids_end
    123 -- * 263: query_channel_range
    124 -- * 264: reply_channel_range
    125 -- * 265: gossip_timestamp_filter
    126 
    127 -- $announcement
    128 --
    129 -- Channel announcement messages:
    130 --
    131 -- * channel_announcement (256) - public channel announcement
    132 -- * announcement_signatures (259) - signatures enabling announcement
    133 
    134 -- $nodeannouncement
    135 --
    136 -- Node announcement message:
    137 --
    138 -- * node_announcement (257) - advertises node metadata
    139 
    140 -- $updates
    141 --
    142 -- Channel update message:
    143 --
    144 -- * channel_update (258) - per-direction routing parameters
    145 
    146 -- $queries
    147 --
    148 -- Gossip query messages:
    149 --
    150 -- * query_short_channel_ids (261) - request specific channel info
    151 -- * reply_short_channel_ids_end (262) - concludes query response
    152 -- * query_channel_range (263) - query channels in block range
    153 -- * reply_channel_range (264) - response with channel IDs
    154 -- * gossip_timestamp_filter (265) - constrain relayed gossip