Skip to content

Commit f2fe34b

Browse files
committed
WIP Linear Leios running simulations
- Add and respect eb-body-avg-size-bytes config file parameter. - Prune VTs 30 seconds after their EB's slot onset instead of as Short Leios would. - Fixup bug in submitLinearEB that wasn't adopting it if the certificate arrived first. - Include rb_ref in GenEB output for Linear EBs. - Partially fill in `error` stub for size calculation of certificates. - Avoid pipeline calculation when logging VBs in the shared format.
1 parent 61a7f5c commit f2fe34b

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

leios-trace-hs/src/LeiosConfig.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ data Config = Config
134134
, ebValidationCpuTimeMs :: DurationMs
135135
, ebSizeBytesConstant :: SizeBytes
136136
, ebSizeBytesPerIb :: SizeBytes
137+
, ebBodyAvgSizeBytes :: SizeBytes
137138
, ebDiffusionStrategy :: DiffusionStrategy
138139
, ebDiffusionMaxWindowSize :: Word16
139140
, ebDiffusionMaxHeadersToRequest :: Word16
@@ -210,6 +211,7 @@ instance Default Config where
210211
, ebValidationCpuTimeMs = 1.0
211212
, ebSizeBytesConstant = 240
212213
, ebSizeBytesPerIb = 32
214+
, ebBodyAvgSizeBytes = 5000000
213215
, ebDiffusionStrategy = PeerOrder
214216
, ebDiffusionMaxWindowSize = 100
215217
, ebDiffusionMaxHeadersToRequest = 100
@@ -288,6 +290,7 @@ configToKVsWith getter cfg =
288290
, get @"ebValidationCpuTimeMs" getter cfg
289291
, get @"ebSizeBytesConstant" getter cfg
290292
, get @"ebSizeBytesPerIb" getter cfg
293+
, get @"ebBodyAvgSizeBytes" getter cfg
291294
, get @"ebDiffusionStrategy" getter cfg
292295
, get @"ebDiffusionMaxWindowSize" getter cfg
293296
, get @"ebDiffusionMaxHeadersToRequest" getter cfg
@@ -378,6 +381,7 @@ instance FromJSON Config where
378381
ebValidationCpuTimeMs <- parseFieldOrDefault @Config @"ebValidationCpuTimeMs" obj
379382
ebSizeBytesConstant <- parseFieldOrDefault @Config @"ebSizeBytesConstant" obj
380383
ebSizeBytesPerIb <- parseFieldOrDefault @Config @"ebSizeBytesPerIb" obj
384+
ebBodyAvgSizeBytes <- parseFieldOrDefault @Config @"ebBodyAvgSizeBytes" obj
381385
ebDiffusionStrategy <- parseFieldOrDefault @Config @"ebDiffusionStrategy" obj
382386
ebDiffusionMaxWindowSize <- parseFieldOrDefault @Config @"ebDiffusionMaxWindowSize" obj
383387
ebDiffusionMaxHeadersToRequest <- parseFieldOrDefault @Config @"ebDiffusionMaxHeadersToRequest" obj

simulation/docs/SimulatorModel.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ The Linear Leios simulator adds the following new variables, some of which also
422422
A new custom thread monitors this variable in addition to the clock, so that it can avoid issugin a vote too early or too late.
423423
- `linearEbOfRb`.
424424
A mapping from RB to its announced Linear EB _that has been validated_, which is needed when issuing an RB.
425+
- `pruneExpiredLinearVotes`.
426+
This thread prunes votes 30 seconds after the onset of their EB's slot.
425427

426428
TODO RB Diffusion is not pipelined
427429

simulation/src/LeiosProtocol/Short.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ data SizesConfig = SizesConfig
4545
, inputBlockBodyAvgSize :: !Bytes
4646
-- ^ as we do not model transactions we just use a fixed size for bodies.
4747
, inputBlockBodyMaxSize :: !Bytes
48+
, endorseBlockBodyAvgSize :: !Bytes
49+
-- ^ unused by Short/Full Leios, used by Linear Leios eg
4850
, endorseBlock :: !(EndorseBlock -> Bytes)
4951
, voteMsg :: !(VoteMsg -> Bytes)
5052
, certificate :: !(Certificate -> Bytes)
@@ -232,6 +234,7 @@ convertConfig disk =
232234
{ inputBlockHeader = fromIntegral disk.ibHeadSizeBytes
233235
, inputBlockBodyAvgSize = fromIntegral disk.ibBodyAvgSizeBytes
234236
, inputBlockBodyMaxSize = fromIntegral disk.ibBodyMaxSizeBytes
237+
, endorseBlockBodyAvgSize = fromIntegral disk.ebBodyAvgSizeBytes
235238
, endorseBlock = \eb ->
236239
fromIntegral $
237240
disk.ebSizeBytesConstant
@@ -242,7 +245,10 @@ convertConfig disk =
242245
fromIntegral $
243246
disk.voteBundleSizeBytesConstant
244247
+ disk.voteBundleSizeBytesPerEb `forEach` vt.endorseBlocks
245-
, certificate = const $ error "certificate size config already included in PraosConfig{bodySize}"
248+
, certificate = \_cert ->
249+
fromIntegral $
250+
assert (0 == disk.certSizeBytesPerNode) $ -- TODO
251+
disk.certSizeBytesConstant
246252
, rankingBlockLegacyPraosPayloadAvgSize = fromIntegral disk.rbBodyLegacyPraosPayloadAvgSizeBytes
247253
}
248254
certificateGeneration (Certificate votesMap) =
@@ -357,6 +363,7 @@ delaysAndSizesAsFull cfg@LeiosConfig{pipeline, voteSendStage} =
357363
{ inputBlockHeader = cfg.sizes.inputBlockHeader :: Bytes
358364
, inputBlockBodyAvgSize = cfg.sizes.inputBlockBodyAvgSize :: Bytes
359365
, inputBlockBodyMaxSize = cfg.sizes.inputBlockBodyMaxSize :: Bytes
366+
, endorseBlockBodyAvgSize = cfg.sizes.endorseBlockBodyAvgSize :: Bytes
360367
, endorseBlock = const @Bytes $ cfg.sizes.endorseBlock $ mockFullEndorseBlock cfg
361368
, voteMsg = const @Bytes $ cfg.sizes.voteMsg $ mockFullVoteMsg cfg
362369
, certificate = const @Bytes $ cfg.sizes.certificate $ mockFullCertificate cfg

simulation/src/LeiosProtocol/Short/Node.hs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Control.Category ((>>>))
2020
import Control.Concurrent.Class.MonadMVar
2121
import Control.Concurrent.Class.MonadSTM.TSem
2222
import Control.Exception (assert)
23-
import Control.Monad (forever, guard, replicateM, unless, when)
23+
import Control.Monad (forever, guard, replicateM, unless, when, void)
2424
import Control.Monad.Class.MonadAsync
2525
import Control.Monad.Class.MonadFork
2626
import Control.Monad.Class.MonadThrow
@@ -692,7 +692,10 @@ leiosNode tracer cfg followers peers = do
692692
let pruningThreads =
693693
concat
694694
[ [ pruneExpiredVotes tracer cfg leiosState
695-
| CleanupExpiredVote `isEnabledIn` cfg.leios.cleanupPolicies
695+
| Linear /= cfg.leios.variant && CleanupExpiredVote `isEnabledIn` cfg.leios.cleanupPolicies
696+
]
697+
, [ pruneExpiredLinearVotes tracer cfg leiosState
698+
| Linear == cfg.leios.variant && CleanupExpiredVote `isEnabledIn` cfg.leios.cleanupPolicies
696699
]
697700
, [ pruneExpiredUncertifiedEBs tracer cfg leiosState
698701
| CleanupExpiredUncertifiedEb `isEnabledIn` cfg.leios.cleanupPolicies
@@ -879,6 +882,28 @@ pruneExpiredVotes _tracer LeiosNodeConfig{leios = leios@LeiosConfig{pipeline = _
879882
-- traceWith tracer $! LeiosNodeEvent Pruned (EventVote $ snd vt)
880883
go (succ p)
881884

885+
-- | Prune votes 30 seconds after the supported EB. TODO magic number
886+
pruneExpiredLinearVotes ::
887+
(Monad m, MonadDelay m, MonadTime m, MonadSTM m) =>
888+
Tracer m LeiosNodeEvent ->
889+
LeiosNodeConfig ->
890+
LeiosNodeState m ->
891+
m ()
892+
pruneExpiredLinearVotes _tracer cfg st = go (SlotNo 0)
893+
where
894+
go pruneTo = do
895+
_ <- waitNextSlot cfg.slotConfig (SlotNo $ unSlotNo pruneTo + 30) -- TODO magic number
896+
_votesPruned <- atomically $ do
897+
writeTVar st.prunedVoteStateToVar $! pruneTo
898+
partitionRBVar st.relayVoteState.relayBufferVar $
899+
\voteEntry ->
900+
let voteSlot = (snd voteEntry.value).slot
901+
in voteSlot < pruneTo
902+
-- TODO: batch these, too many events.
903+
-- for_ votesPruned $ \vt -> do
904+
-- traceWith tracer $! LeiosNodeEvent Pruned (EventVote $ snd vt)
905+
go (succ pruneTo)
906+
882907
referencedEBs :: MonadSTM m => LeiosConfig -> LeiosNodeState m -> Set EndorseBlockId -> STM m [EndorseBlockId]
883908
referencedEBs cfg st ebIds0
884909
| null ebIds0 = return []
@@ -1149,15 +1174,15 @@ dispatchValidationSTM tracer cfg leiosState req =
11491174
-- NOTE: block references are only inspected during voting.
11501175
return [valEB eb completion | eb <- ebs]
11511176
ValidateLinearEBs ibs completion -> do
1152-
let ifNoCert :: InputBlockId -> STM m () -> STM m ()
1177+
let ifNoCert :: InputBlockId -> (Bool -> STM m a) -> STM m ()
11531178
ifNoCert ibId k = do
11541179
votesForEB <- readTVar leiosState.votesForEBVar
1155-
case Map.lookup (convertLinearId ibId) votesForEB of
1156-
Just Certified{} -> pure ()
1157-
_ -> k
1180+
void $ k $ case Map.lookup (convertLinearId ibId) votesForEB of
1181+
Just Certified{} -> True
1182+
_ -> False
11581183
waitFor
11591184
leiosState.waitingForTipVar
1160-
[ (rbHash, [ifNoCert ib.id $ queue [valLinearEB ib False (const (pure ()))]])
1185+
[ (rbHash, [ifNoCert ib.id $ \alreadyCertified -> queue [valLinearEB ib alreadyCertified (const (pure ()))]])
11611186
| ib <- ibs
11621187
, BlockHash rbHash <- [ib.header.rankingBlock]
11631188
]
@@ -1365,7 +1390,11 @@ mkBuffersView cfg st = BuffersView{..}
13651390
-- TODO: start from votesForEB, would allow to drop EBs from relayBuffer as soon as Endorse ends.
13661391
$ bufferEB
13671392
}
1368-
newIBData = do
1393+
newIBData
1394+
| Linear <- cfg.leios.variant = do
1395+
let txsPayload = cfg.leios.sizes.endorseBlockBodyAvgSize
1396+
return $ NewInputBlockData{referenceRankingBlock = GenesisHash {- dummy value, ignored -}, txsPayload}
1397+
| otherwise = do
13691398
ledgerState <- readTVar st.ledgerStateVar
13701399
referenceRankingBlock <-
13711400
Chain.headHash . Chain.dropUntil (flip Map.member ledgerState . blockHash)

simulation/src/LeiosProtocol/Short/Sim.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ logLeiosEvent nodeNames loudness e = case e of
155155
mconcat
156156
[ "slot" .= eb.slot
157157
, "size_bytes" .= fromBytes (messageSizeBytes eb)
158+
, "rb_ref" .= rbRef (eb.header.rankingBlock)
158159
]
159160
EventVote vt ->
160161
mconcat
@@ -380,7 +381,7 @@ sharedEvent leios nodeNames e = case e of
380381
Shared.VTBundleGenerated
381382
{ bytes = fromIntegral (messageSizeBytes vt)
382383
, votes = Map.fromList $ map ((,vt.votes) . T.pack . mkStringId) vt.endorseBlocks
383-
, pipeline = coerce $ voteMsgPipeline leios vt
384+
, pipeline = if Linear == leios.variant then 0 else coerce $ voteMsgPipeline leios vt
384385
, ..
385386
}
386387
sharedEnterState :: T.Text -> String -> Word64 -> LeiosEventBlock -> Shared.Event
@@ -463,6 +464,7 @@ traceRelayLink1 connectionOptions =
463464
{ inputBlockHeader = kibibytes 1
464465
, inputBlockBodyAvgSize = kibibytes 95
465466
, inputBlockBodyMaxSize = kibibytes 100
467+
, endorseBlockBodyAvgSize = megabytes 5
466468
, endorseBlock = \eb -> coerce (length eb.inputBlocks) * 32 + 32 + 128
467469
, voteMsg = \v -> fromIntegral v.votes * 32 + 32 + 128
468470
, certificate = const (50 * 1024)

0 commit comments

Comments
 (0)