bolt7

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

commit cf2177ebbb8c31b41f49fd99be95d597c7ffe08d
parent d928a05a6e8b89d13eddbfa7a217fe5a61b1f069
Author: Jared Tobin <jared@jtobin.io>
Date:   Sun, 25 Jan 2026 15:58:57 +0400

Merge impl/validate-reply: complete validateReplyChannelRange

Diffstat:
Mlib/Lightning/Protocol/BOLT7/Validate.hs | 25+++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/lib/Lightning/Protocol/BOLT7/Validate.hs b/lib/Lightning/Protocol/BOLT7/Validate.hs @@ -30,6 +30,7 @@ module Lightning.Protocol.BOLT7.Validate ( import Control.DeepSeq (NFData) import Data.Word (Word32, Word64) import GHC.Generics (Generic) +import Lightning.Protocol.BOLT7.Codec (decodeShortChannelIdList) import Lightning.Protocol.BOLT7.Messages import Lightning.Protocol.BOLT7.Types @@ -108,20 +109,20 @@ validateQueryChannelRange msg = do -- | Validate reply_channel_range message. -- --- This function validates the encoded short_channel_ids are in ascending --- order. Since the data field contains encoded SCIDs (with encoding type --- byte), this validation requires decoding first. +-- Checks: -- --- Note: This is a simplified check that verifies the encoded data length --- is a multiple of 8 (for uncompressed encoding). Full ascending order --- validation would require parsing the encoded data. +-- * Encoded short_channel_ids are in ascending order validateReplyChannelRange :: ReplyChannelRange -> Either ValidationError () -validateReplyChannelRange _msg = do - -- For now, we just return success. Full validation would require - -- decoding the encoded_short_ids and checking ascending order. - -- The caller should use decodeShortChannelIdList and verify ordering - -- if needed. - Right () +validateReplyChannelRange msg = + case decodeShortChannelIdList (replyRangeData msg) of + Left _ -> Right () -- Can't decode, skip validation + Right scids -> checkAscending scids + where + checkAscending [] = Right () + checkAscending [_] = Right () + checkAscending (a:b:rest) + | getShortChannelId a < getShortChannelId b = checkAscending (b:rest) + | otherwise = Left ValidateScidNotAscending -- Internal helpers -----------------------------------------------------------