Skip to content

Commit 40d77fd

Browse files
authored
LedgerDB.StateMachine test: actually test rollbacks (#1576)
This PR fixes a bug in the LedgerDB state machine test that caused us to never generate non-trivial rollbacks, only chain extensions. The first commit adds appropriate command labelling, demonstrating the problem: ``` Rollback depths (526356 in total): 100.0000% 0 ``` The second commit fixes the bug causing this: The precondition is overzeleaos, so all generated `ValidateAndCommit` actions that have a positive rollback are rejected: ``` Actions rejected by precondition (584429 in total): 100.0000% ValidateAndCommit ``` The third commit fixes a trivial bug in the testing infrastructure where rollbacks were not accounted for. With this PR, we now get a variety or rollback depths: ``` Rollback depths (898533 in total): 44.2447% 0 25.9243% 1 14.6631% 2 7.9446% 3 4.3239% 4 2.1126% 5 0.7868% 6 ```
2 parents eed7687 + 634e844 commit 40d77fd

File tree

1 file changed

+9
-2
lines changed
  • ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/LedgerDB

1 file changed

+9
-2
lines changed

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/LedgerDB/StateMachine.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ instance StateModel Model where
365365
n <= min (BT.unNonZero $ maxRollbacks secParam) (fromIntegral $ AS.length chain)
366366
&& case blks of
367367
[] -> True
368-
(b : _) -> tbSlot b == 1 + withOrigin 0 id (getTipSlot (AS.headAnchor chain))
368+
(b : _) -> tbSlot b == 1 + fromWithOrigin 0 (getTipSlot (AS.headAnchor chain'))
369+
where
370+
chain' = AS.dropNewest (fromIntegral n) chain
369371
precondition _ Init{} = False
370372
precondition _ _ = True
371373

@@ -551,7 +553,9 @@ instance RunModel Model (StateT Environment IO) where
551553
vr <- validateFork ldb rr (const $ pure ()) BlockCache.empty n (map getHeader blks)
552554
case vr of
553555
ValidateSuccessful forker -> do
554-
atomically $ modifyTVar (dbChain chainDb) (reverse (map blockRealPoint blks) ++)
556+
atomically $
557+
modifyTVar (dbChain chainDb) $
558+
(reverse (map blockRealPoint blks) ++) . drop (fromIntegral n)
555559
atomically (forkerCommit forker)
556560
forkerClose forker
557561
ValidateExceededRollBack{} -> error "Unexpected Rollback"
@@ -567,6 +571,9 @@ instance RunModel Model (StateT Environment IO) where
567571
lift $ truncateSnapshots testInternals
568572
perform UnInit _ _ = error "Uninitialized model created a command different than Init"
569573

574+
monitoring _ (ValidateAndCommit n _) _ _ = tabulate "Rollback depths" [show n]
575+
monitoring _ _ _ _ = id
576+
570577
-- NOTE
571578
--
572579
-- In terms of postcondition, we only need to check that the immutable and

0 commit comments

Comments
 (0)