Skip to content

Commit 2703b27

Browse files
committed
remove lagging config as per review
1 parent b91eac5 commit 2703b27

File tree

5 files changed

+7
-40
lines changed

5 files changed

+7
-40
lines changed

cardano-db-sync/src/Cardano/DbSync/Config/Types.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ data JsonTypeConfig
282282

283283
data SnapshotIntervalConfig = SnapshotIntervalConfig
284284
{ sicNearTipEpoch :: !Word64
285-
, sicLagging :: !Word64
286285
}
287286
deriving (Eq, Show)
288287

@@ -740,20 +739,17 @@ instance ToJSON SnapshotIntervalConfig where
740739
toJSON cfg =
741740
Aeson.object
742741
[ "near_tip_epoch" .= sicNearTipEpoch cfg
743-
, "lagging" .= sicLagging cfg
744742
]
745743

746744
instance FromJSON SnapshotIntervalConfig where
747745
parseJSON = Aeson.withObject "snapshot_interval" $ \obj ->
748746
SnapshotIntervalConfig
749747
<$> obj .:? "near_tip_epoch" .!= sicNearTipEpoch def
750-
<*> obj .:? "lagging" .!= sicLagging def
751748

752749
instance Default SnapshotIntervalConfig where
753750
def =
754751
SnapshotIntervalConfig
755752
{ sicNearTipEpoch = 580 -- Epoch threshold to consider being near tip
756-
, sicLagging = 100000 -- Every 100,000 blocks when syncing (less frequent)
757753
}
758754

759755
instance Default SyncInsertConfig where

cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import qualified Cardano.Ledger.BaseTypes as Ledger
5454
import Cardano.Ledger.Shelley.AdaPots (AdaPots)
5555
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
5656
import Cardano.Prelude hiding (atomically)
57-
import Cardano.Slotting.Block (BlockNo (..))
5857
import Cardano.Slotting.EpochInfo (EpochInfo, epochInfoEpoch)
5958
import Cardano.Slotting.Slot (
6059
EpochNo (..),
@@ -128,7 +127,7 @@ import qualified Ouroboros.Consensus.Shelley.Ledger.Ledger as Consensus
128127
import Ouroboros.Consensus.Storage.Serialisation (DecodeDisk (..), EncodeDisk (..))
129128
import Ouroboros.Network.AnchoredSeq (AnchoredSeq (..))
130129
import qualified Ouroboros.Network.AnchoredSeq as AS
131-
import Ouroboros.Network.Block (HeaderHash, Point (..), blockNo)
130+
import Ouroboros.Network.Block (HeaderHash, Point (..))
132131
import qualified Ouroboros.Network.Point as Point
133132
import System.Directory (doesFileExist, listDirectory, removeFile)
134133
import System.FilePath (dropExtension, takeExtension, (</>))
@@ -187,7 +186,6 @@ mkHasLedgerEnv trce protoInfo dir nw systemStart syncOptions = do
187186
, leSystemStart = systemStart
188187
, leAbortOnPanic = soptAbortOnInvalid syncOptions
189188
, leSnapshotNearTipEpoch = sicNearTipEpoch $ soptSnapshotInterval syncOptions
190-
, leSnapshotEveryLagging = sicLagging $ soptSnapshotInterval syncOptions
191189
, leInterpreter = intervar
192190
, leStateVar = svar
193191
, leStateWriteQueue = swQueue
@@ -219,7 +217,7 @@ applyBlockAndSnapshot :: HasLedgerEnv -> CardanoBlock -> Bool -> IO (ApplyResult
219217
applyBlockAndSnapshot ledgerEnv blk isCons = do
220218
(oldState, appResult) <- applyBlock ledgerEnv blk
221219
-- 864000 seconds = 10 days; consider synced "near tip" if within 10 days of current time
222-
tookSnapshot <- storeSnapshotAndCleanupMaybe ledgerEnv oldState appResult (blockNo blk) isCons (isSyncedWithinSeconds (apSlotDetails appResult) 864000)
220+
tookSnapshot <- storeSnapshotAndCleanupMaybe ledgerEnv oldState appResult isCons (isSyncedWithinSeconds (apSlotDetails appResult) 864000)
223221
pure (appResult, tookSnapshot)
224222

225223
-- The function 'tickThenReapply' does zero validation, so add minimal validation ('blockPrevHash'
@@ -322,11 +320,10 @@ storeSnapshotAndCleanupMaybe ::
322320
HasLedgerEnv ->
323321
CardanoLedgerState ->
324322
ApplyResult ->
325-
BlockNo ->
326323
Bool ->
327324
SyncState ->
328325
IO Bool
329-
storeSnapshotAndCleanupMaybe env oldState appResult blkNo isCons syncState =
326+
storeSnapshotAndCleanupMaybe env oldState appResult isCons syncState =
330327
case maybeFromStrict (apNewEpoch appResult) of
331328
Just newEpoch
332329
| newEpochNo <- unEpochNo (Generic.neEpoch newEpoch)
@@ -337,18 +334,7 @@ storeSnapshotAndCleanupMaybe env oldState appResult blkNo isCons syncState =
337334
-- TODO: Instead of newEpochNo - 1, is there any way to get the epochNo from 'lssOldState'?
338335
liftIO $ saveCleanupState env oldState (Just $ EpochNo $ newEpochNo - 1)
339336
pure True
340-
_ ->
341-
if timeToSnapshot syncState blkNo && isCons
342-
then do
343-
liftIO $ saveCleanupState env oldState Nothing
344-
pure True
345-
else pure False
346-
where
347-
timeToSnapshot :: SyncState -> BlockNo -> Bool
348-
timeToSnapshot syncSt bNo =
349-
case (syncSt, unBlockNo bNo) of
350-
(SyncFollowing, _) -> False -- No block-based snapshots when following
351-
(SyncLagging, bno) -> bno `mod` leSnapshotEveryLagging env == 0
337+
_ -> pure False
352338

353339
saveCurrentLedgerState :: HasLedgerEnv -> CardanoLedgerState -> Maybe EpochNo -> IO ()
354340
saveCurrentLedgerState env lState mEpochNo = do

cardano-db-sync/src/Cardano/DbSync/Ledger/Types.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ data HasLedgerEnv = HasLedgerEnv
6868
, leSystemStart :: !SystemStart
6969
, leAbortOnPanic :: !Bool
7070
, leSnapshotNearTipEpoch :: !Word64
71-
, leSnapshotEveryLagging :: !Word64
7271
, leInterpreter :: !(StrictTVar IO (Strict.Maybe CardanoInterpreter))
7372
, leStateVar :: !(StrictTVar IO (Strict.Maybe LedgerDB))
7473
, leStateWriteQueue :: !(TBQueue (FilePath, CardanoLedgerState))

cardano-db-sync/test/Cardano/DbSync/Gen.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ snapshotIntervalConfig :: Gen SnapshotIntervalConfig
6464
snapshotIntervalConfig =
6565
SnapshotIntervalConfig
6666
<$> Gen.word64 (Range.linear 100 1000)
67-
<*> Gen.word64 (Range.linear 10000 100000)
6867

6968
syncNodeParams :: MonadGen m => m SyncNodeParams
7069
syncNodeParams =

doc/configuration.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,6 @@ Snapshot Interval Properties:
617617
| Property | Type | Required | Default |
618618
| :------------------------------- | :-------- | :------- | :------ |
619619
| [near\_tip\_epoch](#near-tip-epoch) | `integer` | Optional | 580 |
620-
| [lagging](#lagging) | `integer` | Optional | 100000 |
621620

622621
### Near Tip Epoch
623622

@@ -626,33 +625,21 @@ Snapshot Interval Properties:
626625
* Type: `integer`
627626
* Default: `580`
628627

629-
Epoch threshold used to determine snapshot behavior. When syncing reaches this epoch or later, db-sync is considered to be approaching or at the current tip of the chain. Combined with time-based detection (within 10 days of current time), this ensures snapshots are taken every epoch when near the tip for fast rollback recovery. During earlier epochs or when syncing behind, snapshots are taken every 10 epochs or according to the `lagging` block interval.
630-
631-
### Lagging
632-
633-
`snapshot_interval.lagging`
634-
635-
* Type: `integer`
636-
* Default: `100000`
637-
638-
Number of blocks between snapshots when db-sync is syncing and significantly behind the tip of the chain (more than 10 days behind current time). Less frequent snapshots during initial sync improves performance by reducing expensive disk operations.
628+
Epoch threshold used to determine snapshot behavior. When syncing reaches this epoch or later, db-sync is considered to be approaching or at the current tip of the chain. Combined with time-based detection (within 10 days of current time), this ensures snapshots are taken every epoch when near the tip for fast rollback recovery. During earlier epochs or when syncing behind, snapshots are taken every 10 epochs.
639629

640630
### Example
641631

642632
```json
643633
{
644634
"snapshot_interval": {
645-
"near_tip_epoch": 580,
646-
"lagging": 100000
635+
"near_tip_epoch": 580
647636
}
648637
}
649638
```
650639

651640
### Performance Considerations
652641

653642
- **Lower `near_tip_epoch` value**: Start taking frequent epoch-based snapshots earlier in the chain history
654-
- **Higher `near_tip_epoch` value**: Delay frequent snapshots until later in the chain, improving sync speed for longer
655-
- **Larger `lagging` value**: Faster initial sync with reduced IOPS, but slower recovery if rollback is needed during sync
656-
- **Recommended for initial sync**: Use a large `lagging` value (100000+) and appropriate `near_tip_epoch` to maximize sync speed
643+
- **Higher `near_tip_epoch` value**: Delay frequent snapshots until later in the chain, improving sync speed for longer. During initial sync (before reaching `near_tip_epoch`), snapshots are taken every 10 epochs
657644
- **Near tip detection**: Automatically switches to epoch-based snapshots when within 10 days of current time, regardless of epoch number
658645

0 commit comments

Comments
 (0)