Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion haskell-src/exec/Chainweb/RichList.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions haskell-src/lib/ChainwebData/Backfill.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand Down Expand Up @@ -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'))
Expand Down
7 changes: 5 additions & 2 deletions haskell-src/lib/ChainwebData/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

---

Expand Down Expand Up @@ -72,15 +73,17 @@ 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
where
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)
Expand Down
Loading