Skip to content

Commit 9731e3a

Browse files
committed
simulation: added OldestFirst, and {eb,vote}-diffusion-strategy to config
1 parent ea9eb93 commit 9731e3a

File tree

6 files changed

+64
-33
lines changed

6 files changed

+64
-33
lines changed

data/simulation/config.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface Config {
4040
"eb-validation-cpu-time-ms": number;
4141
"eb-size-bytes-constant": bigint;
4242
"eb-size-bytes-per-ib": bigint;
43+
"eb-diffusion-strategy": DiffusionStrategy;
4344

4445
// Vote Configuration
4546
"vote-generation-probability": number;
@@ -49,6 +50,7 @@ export interface Config {
4950
"vote-threshold": bigint;
5051
"vote-bundle-size-bytes-constant": bigint;
5152
"vote-bundle-size-bytes-per-eb": bigint;
53+
"vote-diffusion-strategy": DiffusionStrategy;
5254

5355
// deprecated:
5456
// "vote-one-eb-per-vrf-win": boolean;
@@ -94,5 +96,6 @@ export interface ConstantDistribution {
9496
export enum DiffusionStrategy {
9597
PeerOrder = "peer-order",
9698
FreshestFirst = "freshest-first",
99+
OldestFirst = "oldest-first",
97100
}
98101

data/simulation/config.default.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ eb-generation-cpu-time-ms: 300.0
7272
eb-validation-cpu-time-ms: 1.0
7373
eb-size-bytes-constant: 32
7474
eb-size-bytes-per-ib: 32
75+
eb-diffusion-strategy: "peer-order"
7576

7677
################################################################################
7778
# Vote Configuration
@@ -84,6 +85,7 @@ vote-validation-cpu-time-ms: 3.0
8485
vote-threshold: 150
8586
vote-bundle-size-bytes-constant: 32
8687
vote-bundle-size-bytes-per-eb: 32
88+
vote-diffusion-strategy: "peer-order"
8789

8890
################################################################################
8991
# Certificate Configuration

data/simulation/config.schema.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"type": "object"
1515
},
1616
"DiffusionStrategy": {
17-
"enum": ["peer-order", "freshest-first"],
17+
"enum": ["peer-order", "freshest-first", "oldest-first"],
1818
"type": "string"
1919
},
2020
"Distribution": {
@@ -103,6 +103,9 @@
103103
"cert-validation-cpu-time-ms-per-node": {
104104
"type": "number"
105105
},
106+
"eb-diffusion-strategy": {
107+
"$ref": "#/definitions/DiffusionStrategy"
108+
},
106109
"eb-generation-cpu-time-ms": {
107110
"type": "number"
108111
},
@@ -222,6 +225,9 @@
222225
"properties": {},
223226
"type": "number"
224227
},
228+
"vote-diffusion-strategy": {
229+
"$ref": "#/definitions/DiffusionStrategy"
230+
},
225231
"vote-generation-cpu-time-ms-constant": {
226232
"type": "number"
227233
},

simulation/src/LeiosProtocol/Config.hs

+10-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ data DiffusionStrategy
4747
PeerOrder
4848
| -- | request message with highest slot
4949
FreshestFirst
50+
| -- | request message with lowest slot
51+
OldestFirst
5052
deriving (Show, Eq, Generic)
5153

5254
data Config = Config
@@ -79,17 +81,17 @@ data Config = Config
7981
, ebValidationCpuTimeMs :: DurationMs
8082
, ebSizeBytesConstant :: SizeBytes
8183
, ebSizeBytesPerIb :: SizeBytes
82-
, -- , ebDiffusionStrategy :: DiffusionStrategy -- TBD?
83-
voteGenerationProbability :: Double
84+
, ebDiffusionStrategy :: DiffusionStrategy
85+
, voteGenerationProbability :: Double
8486
, voteGenerationCpuTimeMsConstant :: DurationMs
8587
, voteGenerationCpuTimeMsPerIb :: DurationMs
8688
, voteValidationCpuTimeMs :: DurationMs
8789
, voteThreshold :: Word
8890
, voteOneEbPerVrfWin :: Bool
8991
, voteBundleSizeBytesConstant :: SizeBytes
9092
, voteBundleSizeBytesPerEb :: SizeBytes
91-
, -- , voteDiffusionStrategy :: DiffusionStrategy -- TBS?
92-
certGenerationCpuTimeMsConstant :: DurationMs
93+
, voteDiffusionStrategy :: DiffusionStrategy
94+
, certGenerationCpuTimeMsConstant :: DurationMs
9395
, certGenerationCpuTimeMsPerNode :: DurationMs
9496
, certValidationCpuTimeMsConstant :: DurationMs
9597
, certValidationCpuTimeMsPerNode :: DurationMs
@@ -131,6 +133,7 @@ instance Default Config where
131133
, ebValidationCpuTimeMs = 1.0
132134
, ebSizeBytesConstant = 32
133135
, ebSizeBytesPerIb = 32
136+
, ebDiffusionStrategy = PeerOrder
134137
, voteGenerationProbability = 500.0
135138
, voteGenerationCpuTimeMsConstant = 1.0
136139
, voteGenerationCpuTimeMsPerIb = 1.0
@@ -139,6 +142,7 @@ instance Default Config where
139142
, voteOneEbPerVrfWin = False
140143
, voteBundleSizeBytesConstant = 32
141144
, voteBundleSizeBytesPerEb = 32
145+
, voteDiffusionStrategy = PeerOrder
142146
, certGenerationCpuTimeMsConstant = 50.0
143147
, certGenerationCpuTimeMsPerNode = 1.0
144148
, certValidationCpuTimeMsConstant = 50.0
@@ -247,6 +251,7 @@ instance FromJSON Config where
247251
ebValidationCpuTimeMs <- parseFieldOrDefault @Config @"ebValidationCpuTimeMs" obj
248252
ebSizeBytesConstant <- parseFieldOrDefault @Config @"ebSizeBytesConstant" obj
249253
ebSizeBytesPerIb <- parseFieldOrDefault @Config @"ebSizeBytesPerIb" obj
254+
ebDiffusionStrategy <- parseFieldOrDefault @Config @"ebDiffusionStrategy" obj
250255
voteGenerationProbability <- parseFieldOrDefault @Config @"voteGenerationProbability" obj
251256
voteGenerationCpuTimeMsConstant <- parseFieldOrDefault @Config @"voteGenerationCpuTimeMsConstant" obj
252257
voteGenerationCpuTimeMsPerIb <- parseFieldOrDefault @Config @"voteGenerationCpuTimeMsPerIb" obj
@@ -255,6 +260,7 @@ instance FromJSON Config where
255260
voteOneEbPerVrfWin <- parseFieldOrDefault @Config @"voteOneEbPerVrfWin" obj
256261
voteBundleSizeBytesConstant <- parseFieldOrDefault @Config @"voteBundleSizeBytesConstant" obj
257262
voteBundleSizeBytesPerEb <- parseFieldOrDefault @Config @"voteBundleSizeBytesPerEb" obj
263+
voteDiffusionStrategy <- parseFieldOrDefault @Config @"voteDiffusionStrategy" obj
258264
certGenerationCpuTimeMsConstant <- parseFieldOrDefault @Config @"certGenerationCpuTimeMsConstant" obj
259265
certGenerationCpuTimeMsPerNode <- parseFieldOrDefault @Config @"certGenerationCpuTimeMsPerNode" obj
260266
certValidationCpuTimeMsConstant <- parseFieldOrDefault @Config @"certValidationCpuTimeMsConstant" obj

simulation/src/LeiosProtocol/Short.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ prioritize ::
7373
[header]
7474
prioritize PeerOrder _ = \_ hs -> hs
7575
prioritize FreshestFirst sl = \m _ -> sortOn (Down . sl) . Map.elems $ m
76+
prioritize OldestFirst sl = \m _ -> sortOn sl . Map.elems $ m
7677

7778
data SingPipeline (p :: Pipeline) where
7879
SingSingleVote :: SingPipeline SingleVote
@@ -116,8 +117,8 @@ convertConfig disk =
116117
, sizes
117118
, delays
118119
, ibDiffusionStrategy = disk.ibDiffusionStrategy
119-
, ebDiffusionStrategy = PeerOrder
120-
, voteDiffusionStrategy = PeerOrder
120+
, ebDiffusionStrategy = disk.ebDiffusionStrategy
121+
, voteDiffusionStrategy = disk.voteDiffusionStrategy
121122
}
122123
where
123124
forEach n xs = n * fromIntegral (length xs)

simulation/src/LeiosProtocol/Short/Node.hs

+39-26
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{-# LANGUAGE TypeApplications #-}
1010
{-# LANGUAGE TypeFamilies #-}
1111
{-# LANGUAGE ViewPatterns #-}
12+
{-# LANGUAGE NoFieldSelectors #-}
1213

1314
module LeiosProtocol.Short.Node where
1415

@@ -22,6 +23,7 @@ import Control.Monad.Class.MonadAsync
2223
import Control.Monad.Class.MonadFork
2324
import Control.Monad.Class.MonadThrow
2425
import Control.Tracer
26+
import Data.Bifunctor
2527
import Data.Coerce (coerce)
2628
import Data.Foldable (forM_)
2729
import Data.Ix (Ix)
@@ -121,8 +123,8 @@ data LeiosNodeTask
121123
deriving (Eq, Ord, Ix, Bounded, Show)
122124

123125
type RelayIBState = RelayConsumerSharedState InputBlockId InputBlockHeader InputBlockBody
124-
type RelayEBState = RelayConsumerSharedState EndorseBlockId EndorseBlockId EndorseBlock
125-
type RelayVoteState = RelayConsumerSharedState VoteId VoteId VoteMsg
126+
type RelayEBState = RelayConsumerSharedState EndorseBlockId (RelayHeader EndorseBlockId) EndorseBlock
127+
type RelayVoteState = RelayConsumerSharedState VoteId (RelayHeader VoteId) VoteMsg
126128

127129
data LedgerState = LedgerState
128130

@@ -136,9 +138,15 @@ data ValidationRequest m
136138
--- Messages
137139
--------------------------------------------------------------
138140

141+
data RelayHeader id = RelayHeader {id :: !id, slot :: !SlotNo}
142+
deriving (Show)
143+
144+
instance MessageSize id => MessageSize (RelayHeader id) where
145+
messageSizeBytes (RelayHeader x y) = messageSizeBytes x + messageSizeBytes y
146+
139147
type RelayIBMessage = RelayMessage InputBlockId InputBlockHeader InputBlockBody
140-
type RelayEBMessage = RelayMessage EndorseBlockId EndorseBlockId EndorseBlock
141-
type RelayVoteMessage = RelayMessage VoteId VoteId VoteMsg
148+
type RelayEBMessage = RelayMessage EndorseBlockId (RelayHeader EndorseBlockId) EndorseBlock
149+
type RelayVoteMessage = RelayMessage VoteId (RelayHeader VoteId) VoteMsg
142150
type PraosMessage = PraosNode.PraosMessage RankingBlockBody
143151

144152
data LeiosMessage
@@ -166,14 +174,14 @@ instance MuxBundle Leios where
166174
type MuxMsg Leios = LeiosMessage
167175
toFromMuxMsgBundle =
168176
Leios
169-
{ protocolIB = ToFromMuxMsg RelayIB fromRelayIB
170-
, protocolEB = ToFromMuxMsg RelayEB fromRelayEB
171-
, protocolVote = ToFromMuxMsg RelayVote fromRelayVote
177+
{ protocolIB = ToFromMuxMsg RelayIB (.fromRelayIB)
178+
, protocolEB = ToFromMuxMsg RelayEB (.fromRelayEB)
179+
, protocolVote = ToFromMuxMsg RelayVote (.fromRelayVote)
172180
, protocolPraos = case toFromMuxMsgBundle @(PraosNode.Praos RankingBlockBody) of
173181
PraosNode.Praos a b -> PraosNode.Praos (p >>> a) (p >>> b)
174182
}
175183
where
176-
p = ToFromMuxMsg PraosMsg fromPraosMsg
184+
p = ToFromMuxMsg PraosMsg (.fromPraosMsg)
177185

178186
traverseMuxBundle f (Leios a b c d) = Leios <$> f a <*> f b <*> f c <*> traverseMuxBundle f d
179187

@@ -230,35 +238,37 @@ relayEBConfig ::
230238
Tracer m LeiosNodeEvent ->
231239
LeiosNodeConfig ->
232240
SubmitBlocks m EndorseBlockId EndorseBlock ->
233-
RelayConsumerConfig EndorseBlockId EndorseBlockId EndorseBlock m
241+
RelayConsumerConfig EndorseBlockId (RelayHeader EndorseBlockId) EndorseBlock m
234242
relayEBConfig _tracer cfg submitBlocks =
235243
RelayConsumerConfig
236244
{ relay = RelayConfig{maxWindowSize = 100}
237-
, headerId = id
245+
, headerId = (.id)
238246
, validateHeaders = const $ return ()
239-
, prioritize = prioritize cfg.leios.ebDiffusionStrategy $ error "FFD not supported for endorse blocks."
247+
, prioritize = prioritize cfg.leios.ebDiffusionStrategy (.slot)
240248
, submitPolicy = SubmitAll
241249
, maxHeadersToRequest = 100
242250
, maxBodiesToRequest = 1 -- should we chunk bodies here?
243-
, submitBlocks
251+
, submitBlocks = \hbs t k ->
252+
submitBlocks (map (first (.id)) hbs) t (k . map (\(i, b) -> (RelayHeader i b.slot, b)))
244253
}
245254

246255
relayVoteConfig ::
247256
MonadDelay m =>
248257
Tracer m LeiosNodeEvent ->
249258
LeiosNodeConfig ->
250259
SubmitBlocks m VoteId VoteMsg ->
251-
RelayConsumerConfig VoteId VoteId VoteMsg m
260+
RelayConsumerConfig VoteId (RelayHeader VoteId) VoteMsg m
252261
relayVoteConfig _tracer cfg submitBlocks =
253262
RelayConsumerConfig
254263
{ relay = RelayConfig{maxWindowSize = 100}
255-
, headerId = id
264+
, headerId = (.id)
256265
, validateHeaders = const $ return ()
257-
, prioritize = prioritize cfg.leios.voteDiffusionStrategy $ error "FFD not supported for vote bundles."
266+
, prioritize = prioritize cfg.leios.voteDiffusionStrategy (.slot)
258267
, submitPolicy = SubmitAll
259268
, maxHeadersToRequest = 100
260269
, maxBodiesToRequest = 1 -- should we chunk bodies here?
261-
, submitBlocks
270+
, submitBlocks = \hbs t k ->
271+
submitBlocks (map (first (.id)) hbs) t (k . map (\(i, b) -> (RelayHeader i b.slot, b)))
262272
}
263273

264274
queueAndWait :: (MonadSTM m, MonadDelay m) => LeiosNodeState m -> LeiosNodeTask -> [CPUTask] -> m ()
@@ -337,29 +347,29 @@ leiosNode tracer cfg followers peers = do
337347
valHeaderRB
338348
submitRB
339349
praosState
340-
(map protocolPraos followers)
341-
(map protocolPraos peers)
350+
(map (.protocolPraos) followers)
351+
(map (.protocolPraos) peers)
342352

343353
ibThreads <-
344354
setupRelay
345355
(relayIBConfig tracer cfg valHeaderIB submitIB)
346356
relayIBState
347-
(map protocolIB followers)
348-
(map protocolIB peers)
357+
(map (.protocolIB) followers)
358+
(map (.protocolIB) peers)
349359

350360
ebThreads <-
351361
setupRelay
352362
(relayEBConfig tracer cfg submitEB)
353363
relayEBState
354-
(map protocolEB followers)
355-
(map protocolEB peers)
364+
(map (.protocolEB) followers)
365+
(map (.protocolEB) peers)
356366

357367
voteThreads <-
358368
setupRelay
359369
(relayVoteConfig tracer cfg submitVote)
360370
relayVoteState
361-
(map protocolVote followers)
362-
(map protocolVote peers)
371+
(map (.protocolVote) followers)
372+
(map (.protocolVote) peers)
363373

364374
let processWaitingForRB =
365375
processWaiting'
@@ -554,10 +564,10 @@ generator tracer cfg st = do
554564
atomically $ modifyTVar' st.relayIBState.relayBufferVar (RB.snoc ib.header.id (ib.header, ib.body))
555565
traceWith tracer (LeiosNodeEvent Generate (EventIB ib))
556566
SomeAction Generate.Endorse eb -> (GenEB,) $ do
557-
atomically $ modifyTVar' st.relayEBState.relayBufferVar (RB.snoc eb.id (eb.id, eb))
567+
atomically $ modifyTVar' st.relayEBState.relayBufferVar (RB.snoc eb.id (RelayHeader eb.id eb.slot, eb))
558568
traceWith tracer (LeiosNodeEvent Generate (EventEB eb))
559569
SomeAction Generate.Vote v -> (GenVote,) $ do
560-
atomically $ modifyTVar' st.relayVoteState.relayBufferVar (RB.snoc v.id (v.id, v))
570+
atomically $ modifyTVar' st.relayVoteState.relayBufferVar (RB.snoc v.id (RelayHeader v.id v.slot, v))
561571
traceWith tracer (LeiosNodeEvent Generate (EventVote v))
562572
let LeiosNodeConfig{..} = cfg
563573
leiosBlockGenerator $ LeiosGeneratorConfig{submit = mapM_ submitOne, ..}
@@ -620,6 +630,9 @@ mkBuffersView cfg st = BuffersView{..}
620630

621631
mkSchedule :: MonadSTM m => LeiosNodeConfig -> m (SlotNo -> m [(SomeRole, Word64)])
622632
mkSchedule cfg = do
633+
-- For each pipeline, we want to deploy all our votes in a single
634+
-- message to cut down on traffic, so we pick one slot out of each
635+
-- active voting range (they are assumed not to overlap).
623636
votingSlots <- newTVarIO $ pickFromRanges rng1 $ votingRanges cfg.leios
624637
mkScheduler rng2 (rates votingSlots)
625638
where

0 commit comments

Comments
 (0)