Skip to content

Commit 3647aa0

Browse files
authored
[Peras 6] Improve generation of Peras events in ChainDB state machine tests (#1772)
This PR introduces a sequence of changes to progressively improve the chances of observing possible-but-currently-uncommon Peras events in the ChainDB state machine tests. Concretely, we are interested in observing the chain selection algorithm switching from a longer to a shorter chain. For this, we rely on the following changes: 1. Tweaking the `Cmd` generation frequencies to produce more `AddBlock` and `AddPerasCerts` commands. 2. Enhancing the `Cmd` generator to "remember" previously generated blocks so that generated gaps can actually be filled sometimes (this previously relied entirely on randomness). 3. Generating a geometrically-distributed security parameter (k) on the fly, while first addressing #1745. This includes a rationale for why we have chosen to sample k using a geometric distribution with `p=0.5`. Please check the commit messages to find the empirical effect of these changes between commits. In short, we improve the chances of observing `TagSwitchedToShorterChain` from ~0.03% to about ~1.8%. Closes #1745
2 parents c0d8e62 + ee92a0b commit 3647aa0

File tree

7 files changed

+382
-101
lines changed

7 files changed

+382
-101
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Patch
10+
11+
- A bullet item for the Patch category.
12+
13+
-->
14+
### Non-Breaking
15+
16+
- Allow generating k>2 in ChainDB state machine tests on the fly.
17+
- Improve chances of switching to a shorter chain in ChainDB state machine tests.
18+
19+
<!--
20+
### Breaking
21+
22+
- A bullet item for the Breaking category.
23+
24+
-->

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block/SupportsPeras.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
module Ouroboros.Consensus.Block.SupportsPeras
1515
( PerasRoundNo (..)
1616
, PerasWeight (..)
17-
, boostPerCert
1817
, BlockSupportsPeras (..)
1918
, PerasCert (..)
19+
, PerasCfg (..)
2020
, ValidatedPerasCert (..)
2121
, makePerasCfg
2222
, HasPerasCert (..)

ouroboros-consensus/test/consensus-test/Test/Consensus/MiniProtocol/ObjectDiffusion/PerasCert/Smoke.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ tests =
5454
prop_smoke
5555
]
5656

57+
perasTestCfg :: PerasCfg TestBlock
58+
perasTestCfg = makePerasCfg Nothing
59+
5760
genPoint :: Gen (Point (TestBlock))
5861
genPoint =
5962
-- Sometimes pick the genesis point
@@ -77,15 +80,19 @@ genPerasCert = do
7780
instance WithId (PerasCert blk) PerasRoundNo where
7881
getId = pcCertRound
7982

80-
newCertDB :: (IOLike m, StandardHash blk) => [PerasCert blk] -> m (PerasCertDB m blk)
81-
newCertDB certs = do
83+
newCertDB ::
84+
(IOLike m, StandardHash blk) =>
85+
PerasCfg blk ->
86+
[PerasCert blk] ->
87+
m (PerasCertDB m blk)
88+
newCertDB perasCfg certs = do
8289
db <- PerasCertDB.openDB (PerasCertDB.PerasCertDbArgs @Identity nullTracer)
8390
mapM_
8491
( \cert -> do
8592
let validatedCert =
8693
ValidatedPerasCert
8794
{ vpcCert = cert
88-
, vpcCertBoost = boostPerCert
95+
, vpcCertBoost = perasCfgWeightBoost perasCfg
8996
}
9097
result <- PerasCertDB.addCert db validatedCert
9198
case result of
@@ -123,8 +130,8 @@ prop_smoke =
123130
, m [PerasCert TestBlock]
124131
)
125132
mkPoolInterfaces = do
126-
outboundPool <- newCertDB certs
127-
inboundPool <- newCertDB []
133+
outboundPool <- newCertDB perasTestCfg certs
134+
inboundPool <- newCertDB perasTestCfg []
128135

129136
let outboundPoolReader = makePerasCertPoolReaderFromCertDB outboundPool
130137
inboundPoolWriter = makePerasCertPoolWriterFromCertDB inboundPool

0 commit comments

Comments
 (0)