Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAD-2907 trace: AddedToCurrentChain/SwitchedToAFork: log elongation as headBlockNo Δ #2678

Merged
merged 1 commit into from
May 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Cardano.Tracing.Render (renderChainHash, renderChunkNo, renderH
renderHeaderHashForVerbosity, renderPoint, renderPointAsPhrase,
renderPointForVerbosity, renderRealPoint, renderRealPointAsPhrase,
renderTipBlockNo, renderTipForVerbosity, renderTipHash, renderWithOrigin)
import Cardano.Slotting.Slot (fromWithOrigin)

import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ConvertRawHash (..),
ForgeStateUpdateError, Header, RealPoint, getHeader, headerPoint, realPointHash,
Expand Down Expand Up @@ -660,6 +661,7 @@ instance ( ConvertRawHash blk
mkObject $
[ "kind" .= String "TraceAddBlockEvent.AddedToCurrentChain"
, "newtip" .= renderPointForVerbosity verb (AF.headPoint extended)
, "chainLengthDelta" .= extended `chainLengthΔ` base
]
++ [ "headers" .= toJSON (toObject verb `map` addedHdrsNewChain base extended)
| verb == MaximalVerbosity ]
Expand All @@ -669,6 +671,7 @@ instance ( ConvertRawHash blk
mkObject $
[ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork"
, "newtip" .= renderPointForVerbosity verb (AF.headPoint new)
, "chainLengthDelta" .= new `chainLengthΔ` old
]
++ [ "headers" .= toJSON (toObject verb `map` addedHdrsNewChain old new)
| verb == MaximalVerbosity ]
Expand Down Expand Up @@ -710,6 +713,8 @@ instance ( ConvertRawHash blk
Just (_, _, _, s2 :: AF.AnchoredFragment (Header blk)) ->
AF.toOldestFirst s2
Nothing -> [] -- No sense to do validation here.
chainLengthΔ :: AF.AnchoredFragment (Header blk) -> AF.AnchoredFragment (Header blk) -> Int
chainLengthΔ = on (-) (fromWithOrigin (-1) . fmap (fromIntegral . unBlockNo) . AF.headBlockNo)
nfrisby marked this conversation as resolved.
Show resolved Hide resolved
toObject MinimalVerbosity (ChainDB.TraceLedgerReplayEvent _ev) = emptyObject -- no output
toObject verb (ChainDB.TraceLedgerReplayEvent ev) = case ev of
LedgerDB.ReplayFromGenesis _replayTo ->
Expand Down