Skip to content

Commit 0487186

Browse files
committed
wb | locli: early detection of unknown forger; fix remanifest
1 parent 8063de9 commit 0487186

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

bench/locli/src/Cardano/Analysis/BlockProp.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
module Cardano.Analysis.BlockProp
1212
( summariseMultiBlockProp
1313
, MachView
14+
, buildForgeTimeline
1415
, buildMachViews
1516
, rebuildChain
1617
, blockProp
1718
, BlockPropError(..)
1819
, renderBlockPropError
20+
, checkAllForgersKnown
1921
)
2022
where
2123

@@ -29,6 +31,7 @@ import Data.Function (on)
2931
import Data.List (dropWhileEnd, intercalate, partition)
3032
import Data.Map.Strict (Map)
3133
import Data.Map.Strict qualified as Map
34+
import Data.Set qualified as Set
3235
import Data.Maybe (catMaybes, mapMaybe, isNothing)
3336
import Data.Set (Set)
3437
import Data.Set qualified as Set
@@ -287,6 +290,13 @@ beForgedAt :: BlockEvents -> UTCTime
287290
beForgedAt BlockEvents{beForge=BlockForge{..}} =
288291
bfForged `afterSlot` bfSlotStart
289292

293+
buildForgeTimeline :: [(JsonLogfile, [LogObject])] -> IO [LogObject]
294+
buildForgeTimeline los = do
295+
loAllForges <- concat <$> mapConcurrentlyPure (filter match . snd) los
296+
pure $! sortOn loAt loAllForges
297+
where match LogObject{loBody = LOBlockForged{}} = True
298+
match _ = False
299+
290300
buildMachViews :: Run -> [(JsonLogfile, [LogObject])] -> IO [(JsonLogfile, MachView)]
291301
buildMachViews run = mapConcurrentlyPure (fst &&& blockEventMapsFromLogObjects run)
292302

@@ -832,3 +842,17 @@ collectEventErrors mbe phases =
832842
, let neg = ((< 0) <$> proj) == SJust True
833843
, miss || neg
834844
]
845+
846+
-- | Expects a log object stream of or including block forges.
847+
-- Returns those log objects where block hash doesn't reference a known forge.
848+
checkAllForgersKnown :: [LogObject] -> [LogObject]
849+
checkAllForgersKnown = go (Set.singleton $ Hash "GenesisHash")
850+
where
851+
go forged = \case
852+
[] -> []
853+
lo@LogObject{loBody = LOBlockForged{..}}:los ->
854+
let next = go (loBlock `Set.insert` forged)
855+
in if loPrev `Set.member` forged
856+
then next los
857+
else lo : next los
858+
lo:_ -> error $ "checkAllForgersKnown: unexpected LogObject: " ++ show lo

bench/locli/src/Cardano/Command.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ data ChainCommand
5555
| Unlog (JsonInputFile (RunLogs ())) Bool (Maybe [LOAnyType])
5656
| DumpLogObjects
5757

58+
| BuildForgeTimeline
59+
5860
| BuildMachViews
5961
| DumpMachViews
6062
| ReadMachViews [JsonLogfile]
@@ -144,6 +146,8 @@ parseChainCommand =
144146
]) <|>
145147

146148
subparser (mconcat [ commandGroup "Block propagation"
149+
, op "forge-timeline" "Validate timeline of all forge events"
150+
(BuildForgeTimeline & pure)
147151
, op "rebuild-chain" "Rebuild chain"
148152
(RebuildChain
149153
<$> many
@@ -443,6 +447,19 @@ runChainCommand _ c@DumpLogObjects = missingCommandData c
443447

444448
-- runChainCommand s c@(ReadMachViews _ _) -- () -> [(JsonLogfile, MachView)]
445449

450+
runChainCommand s@State{sRunLogs=Just (rlLogs -> objs)}
451+
c@BuildForgeTimeline = do
452+
progress "machviews" (Q $ printf "gathering forges from %d machines" $ length objs)
453+
allForges <- buildForgeTimeline objs & liftIO
454+
case checkAllForgersKnown allForges of
455+
[] -> progress "machviews" (Q $ printf "all forgers known")
456+
xs -> throwE $ CommandError c $ LT.toStrict $ LT.unlines $
457+
"unknown forger for previous block hash of:" : map Aeson.encodeToLazyText xs
458+
pure s
459+
460+
runChainCommand _ c@BuildForgeTimeline = missingCommandData c
461+
["lifted logobjects"]
462+
446463
runChainCommand s@State{sRun=Just run, sRunLogs=Just (rlLogs -> objs)}
447464
BuildMachViews = do
448465
progress "machviews" (Q $ printf "building %d machviews" $ length objs)

nix/workbench/analyse/analyse.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ EOF
223223
local script=(
224224
logs $(test -n "$dump_logobjects" && echo 'dump-logobjects')
225225
read-context
226+
forge-timeline
226227

227228
build-mach-views $(test -n "$dump_machviews" && echo 'dump-mach-views')
228229
rebuild-chain
@@ -400,9 +401,9 @@ EOF
400401
local v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 va vb vc vd ve vf vg vh vi vj vk vl vm vn vo
401402
v0=( $* )
402403
v1=("${v0[@]/#logs/ 'unlog' --run-logs \"$adir\"/log-manifest.json ${analysis_allowed_loanys[*]/#/--ok-loany } }")
403-
v2=("${v1[@]/#read-context/ 'read-meta-genesis' --run-metafile \"$dir\"/meta.json --shelley-genesis \"$dir\"/genesis-shelley.json }")
404+
v2=("${v1[@]/#read-context/ 'read-meta-genesis' --run-metafile \"$dir\"/meta.json --shelley-genesis \"$dir\"/genesis-shelley.json }")
404405
v3=("${v2[@]/#write-context/ 'write-meta-genesis' --run-metafile \"$dir\"/meta.json --shelley-genesis \"$dir\"/genesis-shelley.json }")
405-
v4=("${v3[@]/#read-chain/ 'read-chain' --chain \"$adir\"/chain.json}")
406+
v4=("${v3[@]/#read-chain/ 'read-chain' --chain \"$adir\"/chain.json}")
406407
v5=("${v4[@]/#rebuild-chain/ 'rebuild-chain' ${filters[@]}}")
407408
v6=("${v5[@]/#dump-chain/ 'dump-chain' --chain \"$adir\"/chain.json --chain-rejecta \"$adir\"/chain-rejecta.json }")
408409
v7=("${v6[@]/#chain-timeline/ 'timeline-chain' --timeline \"$adir\"/chain.txt ${locli_render[*]} ${locli_timeline[*]} }")
@@ -427,6 +428,7 @@ EOF
427428
vq=("${vp[@]/#read-summaries/ 'read-summaries' --summary \"$adir\"/summary.json }")
428429
vr=("${vq[@]/#summary-json/ 'render-summary' --json \"$adir\"/summary.json }")
429430
vs=("${vr[@]/#summary-report/ 'render-summary' --org-report \"$adir\"/summary.org ${locli_render[*]}}")
431+
vt=("${vs[@]/#forge-timeline/ 'forge-timeline'}")
430432
local ops_final=()
431433
for v in "${vs[@]}"
432434
do eval ops_final+=($v); done
@@ -564,13 +566,16 @@ EOF
564566
if test -z "$(ls 2>/dev/null $dir/node-*/*.json)"
565567
then remanifest_reasons+=("$(blue consolidated logs missing)")
566568
elif test ! -f "$run_logs"
567-
then remanifest_reasons+=("$(green logs-modified-after-manifest)")
568-
elif test "$(ls 2>/dev/null --sort=time $dir/node-*/*.json analysis/log-manifest.json | head -n1)" != "$run_logs"
569-
then remanifest_reasons+=("$(red logs-modified-after-manifest)")
569+
then remanifest_reasons+=("$(green missing $run_logs)")
570+
# with workbench runs, a node's log files are just called 'stdout'
571+
elif test "$(ls 2>/dev/null --sort=time $dir/node-*/*.json $dir/node-*/stdout $run_logs | head -n1)" != "$run_logs"
572+
then remanifest_reasons+=("$(red logs modified after manifest)")
570573
fi
571574

575+
echo $(ls 2>/dev/null --sort=time $dir/node-*/*.json $dir/node-*/stdout $run_logs)
576+
572577
if test ${#remanifest_reasons[*]} = 0
573-
then progress "analyse" "log manifest exist and is up to date"
578+
then progress "analyse" "log manifest exists and is up to date"
574579
else progress "analyse" "assembling log manifest: ${remanifest_reasons[*]}"
575580
echo '{}' > $run_logs
576581
time {

0 commit comments

Comments
 (0)