commit 6ba8404173c6d4e84d4c9a7443aca476aac6b2f9
parent 1353cecbe771b61d2d1dbee207fe0b14e929b389
Author: Jared Tobin <jared@jtobin.io>
Date: Sun, 25 Jan 2026 15:54:30 +0400
Complete validateReplyChannelRange implementation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat:
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 -----------------------------------------------------------