Skip to content

Commit 875db96

Browse files
committed
Integrate Peras-related stuff
1 parent 5068c7e commit 875db96

File tree

9 files changed

+88
-54
lines changed

9 files changed

+88
-54
lines changed

cardano-node/src/Cardano/Node/TraceConstraints.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, HasTxId
2323
import Ouroboros.Consensus.Node.NetworkProtocolVersion
2424
(HasNetworkProtocolVersion (BlockNodeToClientVersion, BlockNodeToNodeVersion))
2525
import Ouroboros.Consensus.Node.Run (RunNode, SerialiseNodeToNodeConstraints)
26+
import Ouroboros.Consensus.Peras.SelectView
2627
import Ouroboros.Consensus.Protocol.Abstract (SelectView, ValidationErr)
2728
import Ouroboros.Consensus.Shelley.Ledger.Mempool (GenTx, TxId)
2829
import Ouroboros.Network.Block (Serialised)
@@ -51,7 +52,7 @@ type TraceConstraints blk =
5152
, ToObject (LedgerError blk)
5253
, ToObject (LedgerEvent blk)
5354
, ToObject (OtherHeaderEnvelopeError blk)
54-
, ToObject (SelectView (BlockProtocol blk))
55+
, ToObject (WeightedSelectView (BlockProtocol blk))
5556
, ToObject (ValidationErr (BlockProtocol blk))
5657
, ToObject (CannotForge blk)
5758
, ToObject (ForgeStateUpdateError blk)
@@ -66,7 +67,7 @@ type TraceConstraints blk =
6667
, LogFormatting (LedgerUpdate blk)
6768
, LogFormatting (LedgerWarning blk)
6869
, LogFormatting (OtherHeaderEnvelopeError blk)
69-
, LogFormatting (SelectView (BlockProtocol blk))
70+
, LogFormatting (WeightedSelectView (BlockProtocol blk))
7071
, LogFormatting (ValidationErr (BlockProtocol blk))
7172
, LogFormatting (CannotForge blk)
7273
, LogFormatting (ForgeStateUpdateError blk)

cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Cardano.Logging
1919
import Cardano.Slotting.Slot (EpochSize (..))
2020
import Cardano.Tracing.OrphanInstances.HardFork ()
2121
import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ForgeStateInfo,
22-
ForgeStateUpdateError)
22+
ForgeStateUpdateError, PerasWeight (..))
2323
import Ouroboros.Consensus.BlockchainTime (getSlotLength)
2424
import Ouroboros.Consensus.Cardano.Condense ()
2525
import Ouroboros.Consensus.HardFork.Combinator
@@ -36,8 +36,8 @@ import Ouroboros.Consensus.HeaderValidation (OtherHeaderEnvelopeError)
3636
import Ouroboros.Consensus.Ledger.Abstract (LedgerError)
3737
import Ouroboros.Consensus.Ledger.Inspect (LedgerUpdate, LedgerWarning)
3838
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr)
39-
import Ouroboros.Consensus.Protocol.Abstract (SelectView (..), TiebreakerView (..),
40-
ValidationErr)
39+
import Ouroboros.Consensus.Peras.SelectView
40+
import Ouroboros.Consensus.Protocol.Abstract (TiebreakerView (..), ValidationErr)
4141
import Ouroboros.Consensus.TypeFamilyWrappers
4242
import Ouroboros.Consensus.Util.Condense (Condense (..))
4343

@@ -353,10 +353,11 @@ instance LogFormatting (ForgeStateUpdateError blk) => LogFormatting (WrapForgeSt
353353
instance All (LogFormatting `Compose` WrapTiebreakerView) xs => LogFormatting (HardForkTiebreakerView xs) where
354354
forMachine dtal = forMachine dtal . getHardForkTiebreakerView
355355

356-
instance LogFormatting (TiebreakerView protocol) => LogFormatting (SelectView protocol) where
356+
instance LogFormatting (TiebreakerView protocol) => LogFormatting (WeightedSelectView protocol) where
357357
forMachine dtal sv = mconcat
358-
[ "blockNo" .= svBlockNo sv
359-
, forMachine dtal (svTiebreakerView sv)
358+
[ "length" .= wsvLength sv
359+
, "weightBoost" .= unPerasWeight (wsvWeightBoost sv)
360+
, forMachine dtal (wsvTiebreaker sv)
360361
]
361362

362363
instance All (LogFormatting `Compose` WrapTiebreakerView) xs => LogFormatting (OneEraTiebreakerView xs) where

cardano-node/src/Cardano/Node/Tracing/Tracers.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf
408408
traceWith consensusCsjTr
409409
, Consensus.dbfTracer = Tracer $
410410
traceWith consensusDbfTr
411+
-- TODO plug these in
412+
, Consensus.perasCertDiffusionInboundTracer = Tracer $ \_ -> pure ()
413+
, Consensus.perasCertDiffusionOutboundTracer = Tracer $ \_ -> pure ()
411414
}
412415

413416
mkNodeToClientTracers :: forall blk.
@@ -517,6 +520,8 @@ mkNodeToNodeTracers configReflection trBase trForward mbTrEKG _trDataPoint trCon
517520
traceWith keepAliveTracer
518521
, NtN.tPeerSharingTracer = Tracer $
519522
traceWith peerSharingTracer
523+
-- TODO plug in
524+
, NtN.tPerasCertDiffusionTracer = Tracer $ \_ -> pure ()
520525
}
521526

522527
mkDiffusionTracers

cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import Ouroboros.Consensus.Ledger.Abstract (LedgerError)
2828
import Ouroboros.Consensus.Ledger.Extended (ExtValidationError (..))
2929
import Ouroboros.Consensus.Ledger.Inspect (InspectLedger, LedgerEvent (..))
3030
import Ouroboros.Consensus.Ledger.SupportsProtocol (LedgerSupportsProtocol)
31-
import Ouroboros.Consensus.Protocol.Abstract (SelectView, ValidationErr)
31+
import Ouroboros.Consensus.Peras.SelectView
32+
import Ouroboros.Consensus.Protocol.Abstract (ValidationErr)
3233
import qualified Ouroboros.Consensus.Protocol.PBFT as PBFT
3334
import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
3435
import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmDB
@@ -79,7 +80,7 @@ withAddedToCurrentChainEmptyLimited tr = do
7980
instance ( LogFormatting (Header blk)
8081
, LogFormatting (LedgerEvent blk)
8182
, LogFormatting (RealPoint blk)
82-
, LogFormatting (SelectView (BlockProtocol blk))
83+
, LogFormatting (WeightedSelectView (BlockProtocol blk))
8384
, ConvertRawHash blk
8485
, ConvertRawHash (Header blk)
8586
, LedgerSupportsProtocol blk
@@ -103,6 +104,7 @@ instance ( LogFormatting (Header blk)
103104
"Chain Selection was starved."
104105
ChainDB.ChainSelStarvation (FallingEdgeWith pt) ->
105106
"Chain Selection was unstarved by " <> renderRealPoint pt
107+
forHuman _ = "TODO"
106108

107109
forMachine _ ChainDB.TraceLastShutdownUnclean =
108110
mconcat [ "kind" .= String "LastShutdownUnclean" ]
@@ -132,6 +134,10 @@ instance ( LogFormatting (Header blk)
132134
forMachine details v
133135
forMachine details (ChainDB.TraceVolatileDBEvent v) =
134136
forMachine details v
137+
forMachine _details (ChainDB.TracePerasCertDbEvent _v) =
138+
mempty -- TODO fill in
139+
forMachine _details (ChainDB.TraceAddPerasCertEvent _v) =
140+
mempty -- TODO fill in
135141

136142
asMetrics ChainDB.TraceLastShutdownUnclean = []
137143
asMetrics (ChainDB.TraceChainSelStarvationEvent _) = []
@@ -145,6 +151,9 @@ instance ( LogFormatting (Header blk)
145151
asMetrics (ChainDB.TraceLedgerDBEvent v) = asMetrics v
146152
asMetrics (ChainDB.TraceImmutableDBEvent v) = asMetrics v
147153
asMetrics (ChainDB.TraceVolatileDBEvent v) = asMetrics v
154+
-- TODO defer to v
155+
asMetrics (ChainDB.TracePerasCertDbEvent _v) = []
156+
asMetrics (ChainDB.TraceAddPerasCertEvent _v) = []
148157

149158

150159
instance MetaTrace (ChainDB.TraceEvent blk) where
@@ -172,6 +181,9 @@ instance MetaTrace (ChainDB.TraceEvent blk) where
172181
nsPrependInner "ImmDbEvent" (namespaceFor ev)
173182
namespaceFor (ChainDB.TraceVolatileDBEvent ev) =
174183
nsPrependInner "VolatileDbEvent" (namespaceFor ev)
184+
-- TODO defer to ev
185+
namespaceFor (ChainDB.TracePerasCertDbEvent _ev) = Namespace [] ["PerasCertDbEvent"]
186+
namespaceFor (ChainDB.TraceAddPerasCertEvent _ev) = Namespace [] ["AddPerasCertEvent"]
175187

176188
severityFor (Namespace _ ["LastShutdownUnclean"]) _ = Just Info
177189
severityFor (Namespace _ ["ChainSelStarvationEvent"]) _ = Just Debug
@@ -392,7 +404,7 @@ instance MetaTrace (ChainDB.TraceEvent blk) where
392404
instance ( LogFormatting (Header blk)
393405
, LogFormatting (LedgerEvent blk)
394406
, LogFormatting (RealPoint blk)
395-
, LogFormatting (SelectView (BlockProtocol blk))
407+
, LogFormatting (WeightedSelectView (BlockProtocol blk))
396408
, ConvertRawHash blk
397409
, ConvertRawHash (Header blk)
398410
, LedgerSupportsProtocol blk
@@ -486,10 +498,10 @@ instance ( LogFormatting (Header blk)
486498
in mconcat $
487499
[ "kind" .= String "AddedToCurrentChain"
488500
, "newtip" .= renderPointForDetails DDetailed (AF.headPoint extended)
489-
, "newTipSelectView" .= forMachine DDetailed (ChainDB.newTipSelectView selChangedInfo)
501+
, "newSuffixSelectView" .= forMachine DDetailed (ChainDB.newSuffixSelectView selChangedInfo)
490502
]
491-
++ [ "oldTipSelectView" .= forMachine DDetailed oldTipSelectView
492-
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
503+
++ [ "oldSuffixSelectView" .= forMachine DDetailed oldSuffixSelectView
504+
| Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo]
493505
]
494506
++ [ "headers" .= toJSON (forMachine DDetailed `map` addedHdrsNewChain base extended)
495507
]
@@ -502,10 +514,10 @@ instance ( LogFormatting (Header blk)
502514
mconcat $
503515
[ "kind" .= String "AddedToCurrentChain"
504516
, "newtip" .= renderPointForDetails dtal (AF.headPoint extended)
505-
, "newTipSelectView" .= forMachine dtal (ChainDB.newTipSelectView selChangedInfo)
517+
, "newSuffixSelectView" .= forMachine dtal (ChainDB.newSuffixSelectView selChangedInfo)
506518
]
507-
++ [ "oldTipSelectView" .= forMachine dtal oldTipSelectView
508-
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
519+
++ [ "oldSuffixSelectView" .= forMachine dtal oldSuffixSelectView
520+
| Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo]
509521
]
510522
++ [ "events" .= toJSON (map (forMachine dtal) events)
511523
| not (null events) ]
@@ -521,10 +533,10 @@ instance ( LogFormatting (Header blk)
521533
in mconcat $
522534
[ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork"
523535
, "newtip" .= renderPointForDetails DDetailed (AF.headPoint new)
524-
, "newTipSelectView" .= forMachine DDetailed (ChainDB.newTipSelectView selChangedInfo)
536+
, "newSuffixSelectView" .= forMachine DDetailed (ChainDB.newSuffixSelectView selChangedInfo)
525537
]
526-
++ [ "oldTipSelectView" .= forMachine DDetailed oldTipSelectView
527-
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
538+
++ [ "oldSuffixSelectView" .= forMachine DDetailed oldSuffixSelectView
539+
| Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo]
528540
]
529541
++ [ "headers" .= toJSON (forMachine DDetailed `map` addedHdrsNewChain old new)
530542
]
@@ -537,10 +549,10 @@ instance ( LogFormatting (Header blk)
537549
mconcat $
538550
[ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork"
539551
, "newtip" .= renderPointForDetails dtal (AF.headPoint new)
540-
, "newTipSelectView" .= forMachine dtal (ChainDB.newTipSelectView selChangedInfo)
552+
, "newSuffixSelectView" .= forMachine dtal (ChainDB.newSuffixSelectView selChangedInfo)
541553
]
542-
++ [ "oldTipSelectView" .= forMachine dtal oldTipSelectView
543-
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
554+
++ [ "oldSuffixSelectView" .= forMachine dtal oldSuffixSelectView
555+
| Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo]
544556
]
545557
++ [ "events" .= toJSON (map (forMachine dtal) events)
546558
| not (null events) ]

cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ nodeToClientVersionToInt = \case
475475
nodeToNodeVersionToInt :: NodeToNodeVersion -> Int
476476
nodeToNodeVersionToInt = \case
477477
NodeToNodeV_14 -> 14
478+
NodeToNodeV_15 -> 15
479+
NodeToNodeV_16 -> 16
478480

479481
-- | Pretty print 'StartupInfoTrace'
480482
--

cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import Ouroboros.Consensus.Node.GSM
5858
import Ouroboros.Consensus.Node.Run (RunNode, estimateBlockSize)
5959
import Ouroboros.Consensus.Node.Tracers (TraceForgeEvent (..))
6060
import qualified Ouroboros.Consensus.Node.Tracers as Consensus
61+
import Ouroboros.Consensus.Peras.SelectView
6162
import Ouroboros.Consensus.Protocol.Abstract
6263
import qualified Ouroboros.Consensus.Protocol.BFT as BFT
6364
import qualified Ouroboros.Consensus.Protocol.PBFT as PBFT
@@ -517,7 +518,7 @@ instance ( ConvertRawHash blk
517518
, InspectLedger blk
518519
, ToObject (Header blk)
519520
, ToObject (LedgerEvent blk)
520-
, ToObject (SelectView (BlockProtocol blk)))
521+
, ToObject (WeightedSelectView (BlockProtocol blk)))
521522
=> Transformable Text IO (ChainDB.TraceEvent blk) where
522523
trTransformer = trStructuredText
523524

@@ -922,7 +923,7 @@ instance ( ConvertRawHash blk
922923
, LedgerSupportsProtocol blk
923924
, ToObject (Header blk)
924925
, ToObject (LedgerEvent blk)
925-
, ToObject (SelectView (BlockProtocol blk)))
926+
, ToObject (WeightedSelectView (BlockProtocol blk)))
926927
=> ToObject (ChainDB.TraceEvent blk) where
927928
toObject _verb ChainDB.TraceLastShutdownUnclean =
928929
mconcat [ "kind" .= String "TraceLastShutdownUnclean" ]
@@ -963,10 +964,10 @@ instance ( ConvertRawHash blk
963964
[ "kind" .= String "TraceAddBlockEvent.AddedToCurrentChain"
964965
, "newtip" .= renderPointForVerbosity verb (AF.headPoint extended)
965966
, "chainLengthDelta" .= extended `chainLengthΔ` base
966-
, "newTipSelectView" .= toObject verb (ChainDB.newTipSelectView selChangedInfo)
967+
, "newSuffixSelectView" .= toObject verb (ChainDB.newSuffixSelectView selChangedInfo)
967968
]
968-
++ [ "oldTipSelectView" .= toObject verb oldTipSelectView
969-
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
969+
++ [ "oldSuffixSelectView" .= toObject verb oldSuffixSelectView
970+
| Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo]
970971
]
971972
++ [ "headers" .= toJSON (toObject verb `map` addedHdrsNewChain base extended)
972973
| verb == MaximalVerbosity ]
@@ -979,10 +980,10 @@ instance ( ConvertRawHash blk
979980
, "chainLengthDelta" .= new `chainLengthΔ` old
980981
-- Check that the SwitchedToAFork event was triggered by a proper fork.
981982
, "realFork" .= not (AF.withinFragmentBounds (AF.headPoint old) new)
982-
, "newTipSelectView" .= toObject verb (ChainDB.newTipSelectView selChangedInfo)
983+
, "newSuffixSelectView" .= toObject verb (ChainDB.newSuffixSelectView selChangedInfo)
983984
]
984-
++ [ "oldTipSelectView" .= toObject verb oldTipSelectView
985-
| Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo]
985+
++ [ "oldSuffixSelectView" .= toObject verb oldSuffixSelectView
986+
| Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo]
986987
]
987988
++ [ "headers" .= toJSON (toObject verb `map` addedHdrsNewChain old new)
988989
| verb == MaximalVerbosity ]

cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Cardano.Slotting.Slot (EpochSize (..))
2222
import Cardano.Tracing.OrphanInstances.Common
2323
import Cardano.Tracing.OrphanInstances.Consensus ()
2424
import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ForgeStateInfo,
25-
ForgeStateUpdateError)
25+
ForgeStateUpdateError, PerasWeight (..))
2626
import Ouroboros.Consensus.BlockchainTime (getSlotLength)
2727
import Ouroboros.Consensus.Cardano.Condense ()
2828
import Ouroboros.Consensus.HardFork.Combinator
@@ -42,8 +42,9 @@ import Ouroboros.Consensus.Ledger.Inspect (LedgerUpdate, LedgerWarning
4242
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr)
4343
import Ouroboros.Consensus.Node.NetworkProtocolVersion (BlockNodeToClientVersion,
4444
BlockNodeToNodeVersion)
45+
import Ouroboros.Consensus.Peras.SelectView
4546
import Ouroboros.Consensus.Protocol.Abstract (ConsensusProtocol (TiebreakerView),
46-
SelectView (svBlockNo, svTiebreakerView), ValidationErr)
47+
ValidationErr)
4748
import Ouroboros.Consensus.TypeFamilyWrappers
4849
import Ouroboros.Consensus.Util.Condense (Condense (..))
4950

@@ -434,10 +435,11 @@ instance (ToJSON (BlockNodeToNodeVersion blk)) => ToJSON (WrapNodeToNodeVersion
434435
instance All (ToObject `Compose` WrapTiebreakerView) xs => ToObject (HardForkTiebreakerView xs) where
435436
toObject verb = toObject verb . getHardForkTiebreakerView
436437

437-
instance ToObject (TiebreakerView protocol) => ToObject (SelectView protocol) where
438+
instance ToObject (TiebreakerView protocol) => ToObject (WeightedSelectView protocol) where
438439
toObject verb sv = mconcat
439-
[ "blockNo" .= svBlockNo sv
440-
, toObject verb (svTiebreakerView sv)
440+
[ "length" .= wsvLength sv
441+
, "weightBoost" .= unPerasWeight (wsvWeightBoost sv)
442+
, toObject verb (wsvTiebreaker sv)
441443
]
442444

443445
instance All (ToObject `Compose` WrapTiebreakerView) xs => ToObject (OneEraTiebreakerView xs) where

0 commit comments

Comments
 (0)