From 85c2165f22072627b190ca6952308f49d8f44a55 Mon Sep 17 00:00:00 2001 From: KadenaFriend <241389759+kdafriend@users.noreply.github.com> Date: Wed, 8 Jul 2026 16:36:19 +0000 Subject: [PATCH 1/2] Fix a warning during chains computations from Sqlite files --- haskell-src/exec/Chainweb/RichList.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haskell-src/exec/Chainweb/RichList.hs b/haskell-src/exec/Chainweb/RichList.hs index 618c118c..18d63096 100644 --- a/haskell-src/exec/Chainweb/RichList.hs +++ b/haskell-src/exec/Chainweb/RichList.hs @@ -70,7 +70,7 @@ richList logger fp (ChainwebVersion version) = do (fdl, cdl) = foldMap go files chains = cdl [] isConsecutive = all (\(x,y) -> succ x == y) - . (zip <*> tail) + . (zip <*> (drop 1)) . sort unless (isConsecutive chains) $ ioError $ userError From 943077ab88814c8d31711c21ec6e2fa86bbc6959 Mon Sep 17 00:00:00 2001 From: KadenaFriend <241389759+kdafriend@users.noreply.github.com> Date: Wed, 8 Jul 2026 16:36:40 +0000 Subject: [PATCH 2/2] groupOf returns a Non Empty list --- haskell-src/lib/ChainwebData/Backfill.hs | 5 +++-- haskell-src/lib/ChainwebData/Types.hs | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/haskell-src/lib/ChainwebData/Backfill.hs b/haskell-src/lib/ChainwebData/Backfill.hs index 774b5e72..d849f4cd 100644 --- a/haskell-src/lib/ChainwebData/Backfill.hs +++ b/haskell-src/lib/ChainwebData/Backfill.hs @@ -14,6 +14,7 @@ import Data.Maybe (mapMaybe) import Chainweb.Api.ChainId (ChainId(..)) import ChainwebData.Genesis import ChainwebData.Types +import qualified Data.List.NonEmpty as NE lookupPlan :: GenesisInfo -> Map ChainId Int -> [(ChainId, Low, High)] @@ -30,7 +31,7 @@ lookupPlan gi = M.foldrWithKey go [] -- calculate 100-entry batches using min blockheight @cmin@ -- and genesis height -- - ranges = map (Low . last &&& High . head) $ + ranges = map (Low . NE.last &&& High . NE.head) $ groupsOf blockRequestSize [cmin - 1, cmin - 2 .. genesis] -- calculate high water entry against minimum block height for cid @@ -63,7 +64,7 @@ oldLookupPlan mins = concatMap (\pair -> mapMaybe (g pair) asList) ranges asList = map (second (\n -> High . max 0 $ n - 1)) $ M.toList mins ranges :: [(Low, High)] - ranges = map (Low . last &&& High . head) $ groupsOf blockRequestSize [maxi, maxi-1 .. 0] + ranges = map (Low . NE.last &&& High . NE.head) $ groupsOf blockRequestSize [maxi, maxi-1 .. 0] g :: (Low, High) -> (ChainId, High) -> Maybe (ChainId, Low, High) g (l@(Low l'), u) (cid, mx@(High mx')) diff --git a/haskell-src/lib/ChainwebData/Types.hs b/haskell-src/lib/ChainwebData/Types.hs index afe50856..8bc915d4 100644 --- a/haskell-src/lib/ChainwebData/Types.hs +++ b/haskell-src/lib/ChainwebData/Types.hs @@ -35,6 +35,7 @@ import Data.Time.Clock.POSIX (posixSecondsToUTCTime) import Control.Lens import Data.Aeson.Lens import Network.Wai.EventSource.Streaming +import Data.List.NonEmpty (nonEmpty) --- @@ -72,7 +73,7 @@ hashToDbHash = DbHash . hashB64U -- | Break a list into groups of @n@ elements. The last item in the result is -- not guaranteed to have the same length as the others. -groupsOf :: Int -> [a] -> [[a]] +groupsOf :: Int -> [a] -> [NonEmpty a] groupsOf n as | n <= 0 = [] | otherwise = go as @@ -80,7 +81,9 @@ groupsOf n as go [] = [] go bs = xs : go rest where - (xs, rest) = splitAt n bs + -- Since n > 0, _xs is never Empty, fromJust will never throw an error + xs = (fromJust . nonEmpty) _xs + (_xs, rest) = splitAt n bs newtype Low = Low Int deriving newtype (Eq, Ord, Show, Num)