Skip to content

Commit b9fd163

Browse files
committed
simulation: added parent field to RB blocks in log
1 parent 64283ff commit b9fd163

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

data/simulation/trace.haskell.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ interface GeneratedRankingBlock extends GeneratedBlockEvent {
5656
vrf? : number;
5757
id? : string;
5858
payload_bytes? : number;
59+
parent?: {
60+
id: string;
61+
};
5962
}
6063

6164
interface GeneratedVote extends GeneratedBlockEvent {

data/simulation/trace.haskell.schema.json

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@
133133
"id": {
134134
"type": "string"
135135
},
136+
"parent": {
137+
"properties": {
138+
"id": {
139+
"type": "string"
140+
}
141+
},
142+
"type": "object"
143+
},
136144
"payload_bytes": {
137145
"type": "number"
138146
},

leios-trace-hs/src/LeiosEvents.hs

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ data Event where
104104
, endorsement :: !(Maybe Endorsement)
105105
, endorsements :: !(Maybe [Endorsement])
106106
, payload_bytes :: !(Maybe Word64)
107+
, parent :: !(Maybe BlockRef)
107108
} ->
108109
Event
109110
VTBundleGenerated ::

simulation/src/LeiosProtocol/Short/Sim.hs

+12-9
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ logLeiosEvent nodeNames loudness e = case e of
106106
vtKind = "kind" .= asString "VT"
107107
rbKind = "kind" .= asString "RB"
108108
cpuTag = "tag" .= asString "Cpu"
109+
rbRef h = case h of
110+
GenesisHash -> "genesis"
111+
BlockHash x -> show (coerce x :: Int)
109112
logNode nid (PraosNodeEvent x) = logPraos nid x
110113
logNode nid (LeiosNodeEventCPU CPUTask{..}) =
111114
Just $
@@ -124,9 +127,7 @@ logLeiosEvent nodeNames loudness e = case e of
124127
[ "slot" .= ib.header.slot
125128
, "payload_bytes" .= fromBytes ib.body.size
126129
, "size_bytes" .= fromBytes (messageSizeBytes ib)
127-
, "rb_ref" .= case (ib.header.rankingBlock) of
128-
GenesisHash -> "genesis"
129-
BlockHash x -> show (coerce x :: Int)
130+
, "rb_ref" .= rbRef (ib.header.rankingBlock)
130131
]
131132
EventEB eb ->
132133
mconcat
@@ -160,6 +161,7 @@ logLeiosEvent nodeNames loudness e = case e of
160161
, "size_bytes" .= fromBytes (messageSizeBytes h + messageSizeBytes b)
161162
, node nid
162163
, "endorsed" .= map fst b.endorseBlocks
164+
, "parent" .= rbRef (blockPrevHash blk)
163165
]
164166
logPraos nid (PraosNodeEventReceived blk) =
165167
Just $
@@ -254,6 +256,9 @@ sharedEvent nodeNames e = case e of
254256
, endorsement = Nothing
255257
, endorsements = Just . map (Shared.Endorsement . Shared.BlockRef . T.pack . mkStringId . fst) $ blk.blockBody.endorseBlocks
256258
, payload_bytes = Just . fromIntegral $ blk.blockBody.payload
259+
, parent = do
260+
h@BlockHash{} <- pure $ blockPrevHash blk
261+
Just $! Shared.BlockRef{id = rbRef h}
257262
, ..
258263
}
259264
PraosNodeEventReceived blk ->
@@ -295,6 +300,9 @@ sharedEvent nodeNames e = case e of
295300
Shared.RBSent{block_id = Just $ T.pack $ show hash, block_ids = Just [], ..}
296301
_ -> Nothing
297302

303+
rbRef h = T.pack $ case h of
304+
GenesisHash -> "genesis"
305+
BlockHash x -> show (coerce x :: Int)
298306
sharedGenerated :: T.Text -> String -> Word64 -> LeiosEventBlock -> Shared.Event
299307
sharedGenerated producer (T.pack -> id) slot blk =
300308
case blk of
@@ -303,12 +311,7 @@ sharedEvent nodeNames e = case e of
303311
{ size_bytes = Just (fromIntegral $ messageSizeBytes ib)
304312
, payload_bytes = Just (fromIntegral $ ib.body.size)
305313
, rb_ref =
306-
Just $
307-
T.pack
308-
( case (ib.header.rankingBlock) of
309-
GenesisHash -> "genesis"
310-
BlockHash x -> show (coerce x :: Int)
311-
)
314+
Just $ rbRef (ib.header.rankingBlock)
312315
, ..
313316
}
314317
EventEB eb -> Shared.EBGenerated{bytes = fromIntegral (messageSizeBytes eb), input_blocks = map (Shared.BlockRef . T.pack . mkStringId) eb.inputBlocks, ..}

0 commit comments

Comments
 (0)