Skip to content

Commit c2592ed

Browse files
Wen Kokkewenkokke
Wen Kokke
authored andcommitted
feat(config,simulation): add eb-max-age-slots parameter
1 parent 5d860cc commit c2592ed

File tree

11 files changed

+190
-24
lines changed

11 files changed

+190
-24
lines changed

conformance-testing/src/Leios/Conformance/Test/External.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import Test.QuickCheck.StateModel (
4747
runActions,
4848
)
4949

50-
import Text.PrettyPrint (hang, vcat, (<+>))
50+
import Text.PrettyPrint ((<+>))
5151
import Text.PrettyPrint.HughesPJClass (Pretty (pPrint))
5252

5353
import Prelude hiding (round)
@@ -103,7 +103,7 @@ callSUT RunState{hReader, hWriter} req =
103103
type Runtime = StateT RunState IO
104104

105105
instance Realized IO ([InputBlock], [EndorserBlock], [[Vote]]) ~ ([InputBlock], [EndorserBlock], [[Vote]]) => RunModel NetworkModel Runtime where
106-
perform NetworkModel{nodeModel = LeiosState{..}} (Step a) _ = case a of
106+
perform NetworkModel{nodeModel = LeiosState{}} (Step a) _ = case a of
107107
Tick -> do
108108
rs@RunState{..} <- get
109109
modify $ \rs' -> rs'{unfetchedIBs = mempty, unfetchedEBs = mempty, unfetchedVotes = mempty}

data/simulation/config.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export interface Config {
8686
"eb-diffusion-max-headers-to-request": bigint;
8787
/** Only supported by Haskell simulation. */
8888
"eb-diffusion-max-bodies-to-request": bigint;
89+
/**
90+
* The maximum age of EBs included in RBs.
91+
*
92+
* Only supported by Haskell simulation. */
93+
"eb-max-age-slots": bigint;
8994

9095
// Vote Configuration
9196
"vote-generation-probability": number;

data/simulation/config.default.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ eb-diffusion-max-bodies-to-request: 1
131131
eb-diffusion-max-headers-to-request: 100
132132
eb-diffusion-max-window-size: 100
133133

134+
# The maximum age of EBs included in RBs.
135+
eb-max-age-slots: 20 # TODO: sensible default
136+
134137
################################################################################
135138
# Vote Configuration
136139
################################################################################

data/simulation/config.schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@
135135
"eb-generation-probability": {
136136
"type": "number"
137137
},
138+
"eb-max-age-slots": {
139+
"additionalProperties": false,
140+
"description": "The maximum age of EBs included in RBs.\n\nOnly supported by Haskell simulation.",
141+
"properties": {},
142+
"type": "number"
143+
},
138144
"eb-size-bytes-constant": {
139145
"additionalProperties": false,
140146
"properties": {},

leios-trace-verifier/hs-src/app/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Main where
22

3+
import Data.ByteString.Lazy as BSL
34
import LeiosEvents
45
import Lib
5-
import Data.ByteString.Lazy as BSL
66

77
logFile :: FilePath
88
logFile = "leios-trace.log"

simulation/src/LeiosProtocol/Config.hs

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ data Config = Config
100100
, ebDiffusionMaxWindowSize :: Word16
101101
, ebDiffusionMaxHeadersToRequest :: Word16
102102
, ebDiffusionMaxBodiesToRequest :: Word16
103+
, ebMaxAgeSlots :: Word16
103104
, voteGenerationProbability :: Double
104105
, voteGenerationCpuTimeMsConstant :: DurationMs
105106
, voteGenerationCpuTimeMsPerIb :: DurationMs
@@ -164,6 +165,7 @@ instance Default Config where
164165
, ebDiffusionMaxWindowSize = 100
165166
, ebDiffusionMaxHeadersToRequest = 100
166167
, ebDiffusionMaxBodiesToRequest = 1
168+
, ebMaxAgeSlots = 20
167169
, voteGenerationProbability = 500.0
168170
, voteGenerationCpuTimeMsConstant = 0.164
169171
, voteGenerationCpuTimeMsPerIb = 0.0
@@ -232,6 +234,7 @@ configToKVsWith getter cfg =
232234
, get @"ebDiffusionMaxWindowSize" getter cfg
233235
, get @"ebDiffusionMaxHeadersToRequest" getter cfg
234236
, get @"ebDiffusionMaxBodiesToRequest" getter cfg
237+
, get @"ebMaxAgeSlots" getter cfg
235238
, get @"voteGenerationProbability" getter cfg
236239
, get @"voteGenerationCpuTimeMsConstant" getter cfg
237240
, get @"voteGenerationCpuTimeMsPerIb" getter cfg
@@ -310,6 +313,7 @@ instance FromJSON Config where
310313
ebDiffusionMaxWindowSize <- parseFieldOrDefault @Config @"ebDiffusionMaxWindowSize" obj
311314
ebDiffusionMaxHeadersToRequest <- parseFieldOrDefault @Config @"ebDiffusionMaxHeadersToRequest" obj
312315
ebDiffusionMaxBodiesToRequest <- parseFieldOrDefault @Config @"ebDiffusionMaxBodiesToRequest" obj
316+
ebMaxAgeSlots <- parseFieldOrDefault @Config @"ebMaxAgeSlots" obj
313317
voteGenerationProbability <- parseFieldOrDefault @Config @"voteGenerationProbability" obj
314318
voteGenerationCpuTimeMsConstant <- parseFieldOrDefault @Config @"voteGenerationCpuTimeMsConstant" obj
315319
voteGenerationCpuTimeMsPerIb <- parseFieldOrDefault @Config @"voteGenerationCpuTimeMsPerIb" obj

simulation/src/LeiosProtocol/RelayBuffer.hs

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module LeiosProtocol.RelayBuffer where
1111
import Data.FingerTree (FingerTree)
1212
import qualified Data.FingerTree as FingerTree
1313
import qualified Data.Foldable as Foldable
14+
import qualified Data.List as List
1415
import Data.Map (Map)
1516
import qualified Data.Map.Strict as Map
1617
import Data.Set (Set)
@@ -132,6 +133,13 @@ filter p RelayBuffer{..} =
132133
where
133134
filtered = Prelude.filter p $ Foldable.toList entries
134135

136+
partition :: Ord key => (EntryWithTicket key value -> Bool) -> RelayBuffer key value -> (RelayBuffer key value, RelayBuffer key value)
137+
partition p RelayBuffer{..} = (rebuildRelayBufferFor entryListTrue, rebuildRelayBufferFor entryListFalse)
138+
where
139+
(entryListTrue, entryListFalse) = List.partition p (Foldable.toList entries)
140+
restrictedIndexFor = Map.restrictKeys index . Set.fromList . map (.key)
141+
rebuildRelayBufferFor entryList = RelayBuffer{entries = FingerTree.fromList entryList, index = restrictedIndexFor entryList, nextTicket}
142+
135143
values :: Ord key => RelayBuffer key value -> [value]
136144
values = map value . toList
137145

simulation/src/LeiosProtocol/Short.hs

+28-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ data LeiosConfig = forall p. IsPipeline p => LeiosConfig
9999
-- ^ expected EndorseBlock generation rate per stage, at most one per _node_ in each (pipeline, stage).
100100
, activeVotingStageLength :: Int
101101
-- ^ prefix of the voting stage where new votes are generated, <= sliceLength.
102+
, maxEndorseBlockAgeSlots :: Int
103+
-- ^ maximum age of a certified endorsement block before it expires
102104
, votingFrequencyPerStage :: Double
103105
, voteSendStage :: Stage p
104106
, votesForCertificate :: Int
@@ -127,6 +129,7 @@ convertConfig disk =
127129
, sliceLength = fromIntegral disk.leiosStageLengthSlots
128130
, inputBlockFrequencyPerSlot = disk.ibGenerationProbability
129131
, endorseBlockFrequencyPerStage = disk.ebGenerationProbability
132+
, maxEndorseBlockAgeSlots = fromIntegral disk.ebMaxAgeSlots
130133
, activeVotingStageLength = fromIntegral disk.leiosStageActiveVotingSlots
131134
, votingFrequencyPerStage = disk.voteGenerationProbability
132135
, votesForCertificate = fromIntegral disk.voteThreshold
@@ -253,6 +256,7 @@ delaysAndSizesAsFull cfg@LeiosConfig{pipeline, voteSendStage} =
253256
, sliceLength = cfg.sliceLength
254257
, inputBlockFrequencyPerSlot = cfg.inputBlockFrequencyPerSlot
255258
, endorseBlockFrequencyPerStage = cfg.endorseBlockFrequencyPerStage
259+
, maxEndorseBlockAgeSlots = cfg.maxEndorseBlockAgeSlots
256260
, activeVotingStageLength = cfg.activeVotingStageLength
257261
, votingFrequencyPerStage = cfg.votingFrequencyPerStage
258262
, voteSendStage = voteSendStage
@@ -355,9 +359,13 @@ instance FixSize body => FixSize (Block body) where
355359
data Pipeline = SingleVote | SplitVote
356360

357361
data Stage :: Pipeline -> Type where
358-
Propose, Deliver1, Deliver2, Endorse :: Stage a
362+
Propose :: Stage a
363+
Deliver1 :: Stage a
364+
Deliver2 :: Stage a
365+
Endorse :: Stage a
359366
Vote :: Stage SingleVote
360-
VoteSend, VoteRecv :: Stage SplitVote
367+
VoteSend :: Stage SplitVote
368+
VoteRecv :: Stage SplitVote
361369

362370
deriving instance Eq (Stage a)
363371
deriving instance Ord (Stage a)
@@ -439,6 +447,24 @@ pipelineOf cfg stage sl =
439447
forEachPipeline :: (forall p. Stage p) -> (forall p. IsPipeline p => Stage p -> a) -> [a]
440448
forEachPipeline s k = [k @SingleVote s, k @SplitVote s]
441449

450+
lastVoteSend :: LeiosConfig -> PipelineNo -> SlotNo
451+
lastVoteSend leios@LeiosConfig{pipeline} pipelineNo = case pipeline of
452+
SingSingleVote -> snd (stageRangeOf leios pipelineNo Vote)
453+
SingSplitVote -> snd (stageRangeOf leios pipelineNo VoteSend)
454+
455+
lastVoteRecv :: LeiosConfig -> PipelineNo -> SlotNo
456+
lastVoteRecv leios@LeiosConfig{pipeline} pipelineNo = case pipeline of
457+
SingSingleVote -> snd (stageRangeOf leios pipelineNo Vote)
458+
SingSplitVote -> snd (stageRangeOf leios pipelineNo VoteRecv)
459+
460+
endorseRange :: LeiosConfig -> PipelineNo -> (SlotNo, SlotNo)
461+
endorseRange cfg@LeiosConfig{pipeline = (_ :: SingPipeline p)} p =
462+
stageRangeOf @p cfg p Endorse
463+
464+
lastUnadoptedEB :: LeiosConfig -> PipelineNo -> SlotNo
465+
lastUnadoptedEB leios@LeiosConfig{pipeline = (_ :: SingPipeline p), maxEndorseBlockAgeSlots} pipelineNo =
466+
lastVoteRecv leios pipelineNo + toEnum maxEndorseBlockAgeSlots
467+
442468
----------------------------------------------------------------------------------------------
443469
---- Smart constructors
444470
----------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)