Skip to content

Commit b355be4

Browse files
committed
allow slot or points for --until.
1 parent 192e1c2 commit b355be4

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

src/Kupo.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import Kupo.Data.Configuration
118118
, DeferIndexesInstallation (..)
119119
, NodeTipHasBeenReachedException (..)
120120
, isReadOnlyReplica
121+
, untilPredicate
121122
)
122123
import Kupo.Data.FetchBlock
123124
( FetchBlockClient
@@ -267,7 +268,7 @@ kupoWith tr withProducer withFetchBlock =
267268
mailbox
268269
patterns
269270
db
270-
(maybe rollForwardAll rollForwardUntil until)
271+
(maybe rollForwardAll (rollForwardUntil . untilPredicate) until)
271272
)
272273

273274
-- Database garbage-collector

src/Kupo/App.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,10 @@ rollForwardUntil
445445
, Monad (DBTransaction m)
446446
, IsBlock block
447447
)
448-
=> SlotNo
448+
=> (Point -> Bool)
449449
-> RollForward m block
450450
rollForwardUntil until tr inputManagement notifyTip database patterns blks = do
451-
let blksBefore = NE.takeWhile ((<= until) . getPointSlotNo . getPoint . snd) blks
451+
let blksBefore = NE.takeWhile (until . getPoint . snd) blks
452452
whenJust (nonEmpty blksBefore) $
453453
rollForwardAll tr inputManagement notifyTip database patterns
454454

src/Kupo/Data/Configuration.hs

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ module Kupo.Data.Configuration
1414
Configuration (..)
1515
, DatabaseLocation (..)
1616
, Since (..)
17+
, Until (..)
18+
, untilPredicate
1719
, InputManagement (..)
1820
, ChainProducer (..)
1921
, LongestRollback (..)
@@ -58,6 +60,7 @@ import Kupo.Control.MonadTime
5860
import Kupo.Data.Cardano
5961
( Point
6062
, SlotNo
63+
, getPointSlotNo
6164
)
6265
import Kupo.Data.Pattern
6366
( Pattern (..)
@@ -93,7 +96,7 @@ data Configuration = Configuration
9396
-- ^ Port for the API HTTP Server
9497
, since :: !(Maybe Since)
9598
-- ^ Point from when a *new* synchronization should start
96-
, until :: !(Maybe SlotNo)
99+
, until :: !(Maybe Until)
97100
-- ^ Slot at which to stop indexing and just serve queries
98101
, patterns :: !(Set Pattern)
99102
-- ^ List of address patterns to look for when synchronizing
@@ -149,6 +152,15 @@ data ChainProducer
149152
data Since = SinceTip | SincePoint Point
150153
deriving (Generic, Eq, Show)
151154

155+
-- | Captures the point up-to which synchronize.
156+
data Until = UntilPoint Point | UntilSlot SlotNo
157+
deriving (Generic, Eq, Show)
158+
159+
untilPredicate :: Until -> Point -> Bool
160+
untilPredicate = \case
161+
UntilPoint until -> (<= until)
162+
UntilSlot until -> (<= until) . getPointSlotNo
163+
152164
-- | Database working directory. 'in-memory' runs the database in hot memory,
153165
-- only suitable for non-permissive patterns or testing.
154166
data DatabaseLocation

src/Kupo/Options.hs

+10-7
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ import Kupo.Control.MonadTime
6464
, secondsToDiffTime
6565
)
6666
import Kupo.Data.Cardano
67-
( SlotNo
68-
, pointFromText
67+
( pointFromText
6968
, slotNoFromText
7069
)
7170
import Kupo.Data.Configuration
@@ -75,6 +74,7 @@ import Kupo.Data.Configuration
7574
, DeferIndexesInstallation (..)
7675
, InputManagement (..)
7776
, Since (..)
77+
, Until (..)
7878
)
7979
import Kupo.Data.Pattern
8080
( Pattern
@@ -102,9 +102,9 @@ import Text.URI
102102
( URI
103103
)
104104

105-
import qualified Text.URI as URI
106105
import qualified Data.Text as T
107106
import qualified Data.Text.Read as T
107+
import qualified Text.URI as URI
108108

109109
data Command
110110
= Run !Configuration !(Tracers IO MinSeverities)
@@ -312,13 +312,16 @@ sinceOption = option (maybeReader rdr) $ mempty
312312
rdr s = fmap SincePoint (pointFromText $ toText s)
313313

314314
-- | [--until=SLOT]
315-
untilOption :: Parser SlotNo
316-
untilOption = option (maybeReader (slotNoFromText . toText)) $ mempty
315+
untilOption :: Parser Until
316+
untilOption = option (maybeReader asSlot <|> maybeReader asPoint) $ mempty
317317
<> long "until"
318-
<> metavar "SLOT"
318+
<> metavar "POINT|SLOT"
319319
<> helpDoc (Just $ mconcat
320-
[ "A slot (inclusive) to sync up-to. Useful for getting point in time snapshots."
320+
[ "A point or slot (inclusive) to sync up-to. Useful for getting point in time snapshots."
321321
])
322+
where
323+
asSlot = fmap UntilSlot . slotNoFromText . toText
324+
asPoint = fmap UntilPoint . pointFromText . toText
322325

323326
-- | [--match=PATTERN]
324327
patternOption :: Parser Pattern

test/Test/KupoSpec.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ import Control.Monad.Class.MonadThrow
179179
)
180180
import Kupo.Data.Configuration
181181
( Since (..)
182+
, Until (..)
182183
)
183184
import Kupo.Data.Health
184185
( ConnectionStatus (..)
@@ -591,7 +592,7 @@ spec = skippableContext "End-to-end" $ do
591592
-- if we don't want `waitSlot` down below to be waiting forever!
592593
(_, env) <- configure $ \defaultCfg -> defaultCfg
593594
{ since = Just (SincePoint somePoint)
594-
, until = Just maxSlot
595+
, until = Just (UntilSlot maxSlot)
595596
, patterns = fromList [MatchAny IncludingBootstrap]
596597
, deferIndexes = SkipNonEssentialIndexes
597598
}

0 commit comments

Comments
 (0)