/
Consensus.hs
1563 lines (1427 loc) · 60.5 KB
/
Consensus.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Cardano.Node.Tracing.Tracers.Consensus
( severityChainSyncClientEvent
, namesForChainSyncClientEvent
, docChainSyncClientEvent
, severityChainSyncServerEvent
, namesForChainSyncServerEvent
, docChainSyncServerEvent
, severityBlockFetchDecision
, namesForBlockFetchDecision
, docBlockFetchDecision
, severityBlockFetchClient
, namesForBlockFetchClient
, docBlockFetchClient
, severityBlockFetchServer
, namesForBlockFetchServer
, docBlockFetchServer
, severityTxInbound
, namesForTxInbound
, docTxInbound
, severityTxOutbound
, namesForTxOutbound
, docTxOutbound
, severityLocalTxSubmissionServer
, namesForLocalTxSubmissionServer
, docLocalTxSubmissionServer
, severityMempool
, namesForMempool
, docMempool
, TraceStartLeadershipCheckPlus (..)
, ForgeTracerType
, forgeTracerTransform
, severityForge
, namesForForge
, docForge
, namesForBlockchainTime
, severityBlockchainTime
, docBlockchainTime
, namesForKeepAliveClient
, severityKeepAliveClient
, docKeepAliveClient
) where
import Control.Monad.Class.MonadTime (Time (..))
import Data.Aeson (ToJSON, Value (Number, String), toJSON, (.=))
import Data.SOP.Strict
import qualified Data.Text as Text
import Data.Time (DiffTime)
import Text.Show
import Cardano.Logging
import Cardano.Node.Queries (HasKESInfo (..))
import Cardano.Node.Tracing.Era.Byron ()
import Cardano.Node.Tracing.Era.Shelley ()
import Cardano.Node.Tracing.Formatting ()
import Cardano.Node.Tracing.Render
import Cardano.Node.Tracing.Tracers.StartLeadershipCheck
import Cardano.Prelude hiding (All, Show, show)
import Cardano.Protocol.TPraos.OCert (KESPeriod (..))
import Ouroboros.Network.Block hiding (blockPrevHash)
import Ouroboros.Network.BlockFetch.ClientState (TraceLabelPeer (..))
import qualified Ouroboros.Network.BlockFetch.ClientState as BlockFetch
import Ouroboros.Network.BlockFetch.Decision
import Ouroboros.Network.DeltaQ (GSV (..), PeerGSV (..))
import Ouroboros.Network.KeepAlive (TraceKeepAliveClient (..))
import Ouroboros.Network.TxSubmission.Inbound hiding (txId)
import Ouroboros.Network.TxSubmission.Outbound
import qualified Data.Aeson as Aeson
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.BlockchainTime (SystemStart (..))
import Ouroboros.Consensus.BlockchainTime.WallClock.Util (TraceBlockchainTimeEvent (..))
import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.Ledger.Inspect (LedgerEvent (..), LedgerUpdate, LedgerWarning)
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, GenTxId, HasTxId,
LedgerSupportsMempool, txForgetValidated, txId)
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Mempool.API (MempoolSize (..), TraceEventMempool (..))
import Ouroboros.Consensus.MiniProtocol.BlockFetch.Server
(TraceBlockFetchServerEvent (..))
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client
import Ouroboros.Consensus.MiniProtocol.ChainSync.Server
import Ouroboros.Consensus.MiniProtocol.LocalTxSubmission.Server
(TraceLocalTxSubmissionServerEvent (..))
import Ouroboros.Consensus.Node.Run (SerialiseNodeToNodeConstraints, estimateBlockSize)
import Ouroboros.Consensus.Node.Tracers
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
import Ouroboros.Consensus.Util.Enclose
instance LogFormatting a => LogFormatting (TraceLabelCreds a) where
forMachine dtal (TraceLabelCreds creds a) =
mconcat [ "credentials" .= toJSON creds
, "val" .= forMachine dtal a
]
-- TODO Trace label creds as well
forHuman (TraceLabelCreds _t a) = forHuman a
asMetrics (TraceLabelCreds _t a) = asMetrics a
instance (LogFormatting (LedgerUpdate blk), LogFormatting (LedgerWarning blk))
=> LogFormatting (LedgerEvent blk) where
forMachine dtal = \case
LedgerUpdate update -> forMachine dtal update
LedgerWarning warning -> forMachine dtal warning
tipToObject :: forall blk. ConvertRawHash blk => Tip blk -> Aeson.Object
tipToObject = \case
TipGenesis -> mconcat
[ "slot" .= toJSON (0 :: Int)
, "block" .= String "genesis"
, "blockNo" .= toJSON ((-1) :: Int)
]
Tip slot hash blockno -> mconcat
[ "slot" .= slot
, "block" .= String (renderHeaderHash (Proxy @blk) hash)
, "blockNo" .= blockno
]
--------------------------------------------------------------------------------
-- ChainSyncClient Tracer
--------------------------------------------------------------------------------
severityChainSyncClientEvent ::
BlockFetch.TraceLabelPeer peer (TraceChainSyncClientEvent blk) -> SeverityS
severityChainSyncClientEvent (BlockFetch.TraceLabelPeer _ e) =
severityChainSyncClientEvent' e
namesForChainSyncClientEvent ::
BlockFetch.TraceLabelPeer peer (TraceChainSyncClientEvent blk) -> [Text]
namesForChainSyncClientEvent (BlockFetch.TraceLabelPeer _ e) =
"ChainSyncClientEvent" : namesForChainSyncClientEvent' e
severityChainSyncClientEvent' :: TraceChainSyncClientEvent blk -> SeverityS
severityChainSyncClientEvent' TraceDownloadedHeader {} = Info
severityChainSyncClientEvent' TraceFoundIntersection {} = Info
severityChainSyncClientEvent' TraceRolledBack {} = Notice
severityChainSyncClientEvent' TraceException {} = Warning
severityChainSyncClientEvent' TraceTermination {} = Notice
namesForChainSyncClientEvent' :: TraceChainSyncClientEvent blk -> [Text]
namesForChainSyncClientEvent' TraceDownloadedHeader {} =
["DownloadedHeader"]
namesForChainSyncClientEvent' TraceFoundIntersection {} =
["FoundIntersection"]
namesForChainSyncClientEvent' TraceRolledBack {} =
["RolledBack"]
namesForChainSyncClientEvent' TraceException {} =
["Exception"]
namesForChainSyncClientEvent' TraceTermination {} =
["Termination"]
instance (ConvertRawHash blk, LedgerSupportsProtocol blk)
=> LogFormatting (TraceChainSyncClientEvent blk) where
forHuman (TraceDownloadedHeader pt) =
"While following a candidate chain, we rolled forward by downloading a\
\ header. " <> showT (headerPoint pt)
forHuman (TraceRolledBack tip) =
"While following a candidate chain, we rolled back to the given point: "
<> showT tip
forHuman (TraceException exc) =
"An exception was thrown by the Chain Sync Client. "
<> showT exc
forHuman TraceFoundIntersection {} =
"We found an intersection between our chain fragment and the\
\ candidate's chain."
forHuman (TraceTermination res) =
"The client has terminated. " <> showT res
forMachine _dtal (TraceDownloadedHeader h) =
mconcat [ "kind" .= String "DownloadedHeader"
, tipToObject (tipFromHeader h)
]
forMachine dtal (TraceRolledBack tip) =
mconcat [ "kind" .= String "RolledBack"
, "tip" .= forMachine dtal tip ]
forMachine _dtal (TraceException exc) =
mconcat [ "kind" .= String "Exception"
, "exception" .= String (Text.pack $ show exc) ]
forMachine _dtal TraceFoundIntersection {} =
mconcat [ "kind" .= String "FoundIntersection" ]
forMachine _dtal (TraceTermination reason) =
mconcat [ "kind" .= String "Termination"
, "reason" .= String (Text.pack $ show reason) ]
docChainSyncClientEvent ::
Documented (BlockFetch.TraceLabelPeer peer (TraceChainSyncClientEvent blk))
docChainSyncClientEvent =
addDocumentedNamespace
["ChainSyncClientEvent"]
docChainSyncClientEvent'
docChainSyncClientEvent' ::
Documented (BlockFetch.TraceLabelPeer peer (TraceChainSyncClientEvent blk))
docChainSyncClientEvent' = Documented [
DocMsg
["DownloadedHeader"]
[]
"While following a candidate chain, we rolled forward by downloading a\
\ header."
, DocMsg
["RolledBack"]
[]
"While following a candidate chain, we rolled back to the given point."
, DocMsg
["FoundIntersection"]
[]
"We found an intersection between our chain fragment and the\
\ candidate's chain."
, DocMsg
["Exception"]
[]
"An exception was thrown by the Chain Sync Client."
, DocMsg
["Termination"]
[]
"The client has terminated."
]
--------------------------------------------------------------------------------
-- ChainSyncServer Tracer
--------------------------------------------------------------------------------
severityChainSyncServerEvent :: TraceChainSyncServerEvent blk -> SeverityS
severityChainSyncServerEvent (TraceChainSyncServerUpdate _tip _upd _blocking enclosing) =
case enclosing of
RisingEdge -> Info
FallingEdgeWith () -> Debug
namesForChainSyncServerEvent :: TraceChainSyncServerEvent blk -> [Text]
namesForChainSyncServerEvent ev =
"ChainSyncServerEvent" : namesForChainSyncServerEvent' ev
namesForChainSyncServerEvent' :: TraceChainSyncServerEvent blk -> [Text]
namesForChainSyncServerEvent' (TraceChainSyncServerUpdate _tip _update NonBlocking _enclosing) =
["ServerRead"]
namesForChainSyncServerEvent' (TraceChainSyncServerUpdate _tip _update Blocking _enclosing) =
["ServerReadBlocked"]
instance ConvertRawHash blk
=> LogFormatting (TraceChainSyncServerEvent blk) where
forMachine _dtal (TraceChainSyncServerUpdate tip (AddBlock _hdr) NonBlocking enclosing) =
mconcat $
[ "kind" .= String "ChainSyncServerRead.AddBlock"
, tipToObject tip
]
<> [ "risingEdge" .= True | RisingEdge <- [enclosing] ]
forMachine _dtal (TraceChainSyncServerUpdate tip (RollBack _pt) NonBlocking enclosing) =
mconcat $
[ "kind" .= String "ChainSyncServerRead.RollBack"
, tipToObject tip
]
<> [ "risingEdge" .= True | RisingEdge <- [enclosing] ]
forMachine _dtal (TraceChainSyncServerUpdate tip (AddBlock _pt) Blocking enclosing) =
mconcat $
[ "kind" .= String "ChainSyncServerReadBlocked.AddBlock"
, tipToObject tip
]
<> [ "risingEdge" .= True | RisingEdge <- [enclosing] ]
forMachine _dtal (TraceChainSyncServerUpdate tip (RollBack _pt) Blocking enclosing) =
mconcat $
[ "kind" .= String "ChainSyncServerReadBlocked.RollBack"
, tipToObject tip
]
<> [ "risingEdge" .= True | RisingEdge <- [enclosing] ]
asMetrics (TraceChainSyncServerUpdate _tip (AddBlock _hdr) _blocking FallingEdge) =
[CounterM "cardano.node.chainSync.rollForward" Nothing]
asMetrics _ = []
docChainSyncServerEvent :: Documented (TraceChainSyncServerEvent blk)
docChainSyncServerEvent =
addDocumentedNamespace
["ChainSyncServerEvent", "ServerRead"]
docChainSyncServerEvent'
docChainSyncServerEvent' :: Documented (TraceChainSyncServerEvent blk)
docChainSyncServerEvent' = Documented [
DocMsg
["ServerRead"]
[]
"A server read has occurred, either for an add block or a rollback"
, DocMsg
["ServerReadBlocked"]
[]
"A server read has blocked, either for an add block or a rollback"
, DocMsg
["RollForward"]
[("cardano.node.chainSync.rollForward", "")]
"Roll forward to the given point."
, DocMsg
["RollBackward"]
[]
""
]
--------------------------------------------------------------------------------
-- BlockFetchDecision Tracer
--------------------------------------------------------------------------------
severityBlockFetchDecision ::
[BlockFetch.TraceLabelPeer peer (FetchDecision [Point header])]
-> SeverityS
severityBlockFetchDecision [] = Info
severityBlockFetchDecision l = maximum $
map (\(BlockFetch.TraceLabelPeer _ a) -> fetchDecisionSeverity a) l
where
fetchDecisionSeverity :: FetchDecision a -> SeverityS
fetchDecisionSeverity fd =
case fd of
Left FetchDeclineChainNotPlausible -> Debug
Left FetchDeclineChainNoIntersection -> Notice
Left FetchDeclineAlreadyFetched -> Debug
Left FetchDeclineInFlightThisPeer -> Debug
Left FetchDeclineInFlightOtherPeer -> Debug
Left FetchDeclinePeerShutdown -> Info
Left FetchDeclinePeerSlow -> Info
Left FetchDeclineReqsInFlightLimit {} -> Info
Left FetchDeclineBytesInFlightLimit {} -> Info
Left FetchDeclinePeerBusy {} -> Info
Left FetchDeclineConcurrencyLimit {} -> Info
Right _ -> Info
namesForBlockFetchDecision ::
[BlockFetch.TraceLabelPeer peer (FetchDecision [Point header])]
-> [Text]
namesForBlockFetchDecision _ = []
instance (LogFormatting peer, Show peer) =>
LogFormatting [TraceLabelPeer peer (FetchDecision [Point header])] where
forMachine DMinimal _ = mempty
forMachine _ [] = mconcat
[ "kind" .= String "EmptyPeersFetch"]
forMachine _ xs = mconcat
[ "kind" .= String "PeersFetch"
, "peers" .= toJSON
(foldl' (\acc x -> forMachine DDetailed x : acc) [] xs) ]
asMetrics peers = [IntM "cardano.node.connectedPeers" (fromIntegral (length peers))]
instance (LogFormatting peer, Show peer, LogFormatting a)
=> LogFormatting (TraceLabelPeer peer a) where
forMachine dtal (TraceLabelPeer peerid a) =
mconcat [ "peer" .= forMachine dtal peerid ] <> forMachine dtal a
forHuman (TraceLabelPeer peerid a) = "Peer is " <> showT peerid
<> ". " <> forHuman a
asMetrics (TraceLabelPeer _peerid a) = asMetrics a
instance LogFormatting (FetchDecision [Point header]) where
forMachine _dtal (Left decline) =
mconcat [ "kind" .= String "FetchDecision declined"
, "declined" .= String (showT decline)
]
forMachine _dtal (Right results) =
mconcat [ "kind" .= String "FetchDecision results"
, "length" .= String (showT $ length results)
]
docBlockFetchDecision ::
Documented [BlockFetch.TraceLabelPeer remotePeer (FetchDecision [Point (Header blk)])]
docBlockFetchDecision = Documented [
DocMsg
[]
[("cardano.node.connectedPeers", "Number of connected peers")]
"Throughout the decision making process we accumulate reasons to decline\
\ to fetch any blocks. This message carries the intermediate and final\
\ results."
]
--------------------------------------------------------------------------------
-- BlockFetchClient Tracer
--------------------------------------------------------------------------------
severityBlockFetchClient ::
BlockFetch.TraceLabelPeer peer (BlockFetch.TraceFetchClientState header)
-> SeverityS
severityBlockFetchClient (BlockFetch.TraceLabelPeer _p bf) = severityBlockFetchClient' bf
severityBlockFetchClient' ::
BlockFetch.TraceFetchClientState header
-> SeverityS
severityBlockFetchClient' BlockFetch.AddedFetchRequest {} = Info
severityBlockFetchClient' BlockFetch.AcknowledgedFetchRequest {} = Info
severityBlockFetchClient' BlockFetch.SendFetchRequest {} = Info
severityBlockFetchClient' BlockFetch.StartedFetchBatch {} = Info
severityBlockFetchClient' BlockFetch.CompletedBlockFetch {} = Info
severityBlockFetchClient' BlockFetch.CompletedFetchBatch {} = Info
severityBlockFetchClient' BlockFetch.RejectedFetchBatch {} = Info
severityBlockFetchClient' BlockFetch.ClientTerminating {} = Notice
namesForBlockFetchClient ::
BlockFetch.TraceLabelPeer peer (BlockFetch.TraceFetchClientState header)
-> [Text]
namesForBlockFetchClient (BlockFetch.TraceLabelPeer _p bf) = namesForBlockFetchClient' bf
namesForBlockFetchClient' ::
BlockFetch.TraceFetchClientState header
-> [Text]
namesForBlockFetchClient' BlockFetch.AddedFetchRequest {} =
["AddedFetchRequest"]
namesForBlockFetchClient' BlockFetch.AcknowledgedFetchRequest {} =
["AcknowledgedFetchRequest"]
namesForBlockFetchClient' BlockFetch.SendFetchRequest {} =
["SendFetchRequest"]
namesForBlockFetchClient' BlockFetch.StartedFetchBatch {} =
["StartedFetchBatch"]
namesForBlockFetchClient' BlockFetch.CompletedFetchBatch {} =
["CompletedFetchBatch"]
namesForBlockFetchClient' BlockFetch.CompletedBlockFetch {} =
["CompletedBlockFetch"]
namesForBlockFetchClient' BlockFetch.RejectedFetchBatch {} =
["RejectedFetchBatch"]
namesForBlockFetchClient' BlockFetch.ClientTerminating {} =
["ClientTerminating"]
instance LogFormatting (BlockFetch.TraceFetchClientState header) where
forMachine _dtal BlockFetch.AddedFetchRequest {} =
mconcat [ "kind" .= String "AddedFetchRequest" ]
forMachine _dtal BlockFetch.AcknowledgedFetchRequest {} =
mconcat [ "kind" .= String "AcknowledgedFetchRequest" ]
forMachine _dtal BlockFetch.SendFetchRequest {} =
mconcat [ "kind" .= String "SendFetchRequest" ]
forMachine _dtal BlockFetch.CompletedBlockFetch {} =
mconcat [ "kind" .= String "CompletedBlockFetch" ]
forMachine _dtal BlockFetch.CompletedFetchBatch {} =
mconcat [ "kind" .= String "CompletedFetchBatch" ]
forMachine _dtal BlockFetch.StartedFetchBatch {} =
mconcat [ "kind" .= String "StartedFetchBatch" ]
forMachine _dtal BlockFetch.RejectedFetchBatch {} =
mconcat [ "kind" .= String "RejectedFetchBatch" ]
forMachine _dtal BlockFetch.ClientTerminating {} =
mconcat [ "kind" .= String "ClientTerminating" ]
docBlockFetchClient ::
Documented (BlockFetch.TraceLabelPeer remotePeer (BlockFetch.TraceFetchClientState (Header blk)))
docBlockFetchClient = addDocumentedNamespace [] docBlockFetchClient'
docBlockFetchClient' ::
Documented (BlockFetch.TraceLabelPeer remotePeer (BlockFetch.TraceFetchClientState (Header blk)))
docBlockFetchClient' = Documented [
DocMsg
["AddedFetchRequest"]
[]
"The block fetch decision thread has added a new fetch instruction\
\ consisting of one or more individual request ranges."
,
DocMsg
["AcknowledgedFetchRequest"]
[]
"Mark the point when the fetch client picks up the request added\
\ by the block fetch decision thread. Note that this event can happen\
\ fewer times than the 'AddedFetchRequest' due to fetch request merging."
,
DocMsg
["SendFetchRequest"]
[]
"Mark the point when fetch request for a fragment is actually sent\
\ over the wire."
,
DocMsg
["StartedFetchBatch"]
[]
"Mark the start of receiving a streaming batch of blocks. This will\
\ be followed by one or more 'CompletedBlockFetch' and a final\
\ 'CompletedFetchBatch'"
,
DocMsg
["CompletedFetchBatch"]
[]
"Mark the successful end of receiving a streaming batch of blocks"
,
DocMsg
["CompletedBlockFetch"]
[]
"Mark the successful end of receiving a streaming batch of blocks."
,
DocMsg
["RejectedFetchBatch"]
[]
"If the other peer rejects our request then we have this event\
\ instead of 'StartedFetchBatch' and 'CompletedFetchBatch'."
,
DocMsg
["ClientTerminating"]
[]
"The client is terminating. Log the number of outstanding\
\ requests."
]
--------------------------------------------------------------------------------
-- BlockFetchServer Tracer
--------------------------------------------------------------------------------
severityBlockFetchServer ::
TraceBlockFetchServerEvent blk
-> SeverityS
severityBlockFetchServer _ = Info
namesForBlockFetchServer ::
TraceBlockFetchServerEvent blk
-> [Text]
namesForBlockFetchServer TraceBlockFetchServerSendBlock {} = ["SendBlock"]
instance ConvertRawHash blk => LogFormatting (TraceBlockFetchServerEvent blk) where
forMachine _dtal (TraceBlockFetchServerSendBlock blk) =
mconcat [ "kind" .= String "BlockFetchServer"
, "block" .= String (renderChainHash
@blk
(renderHeaderHash (Proxy @blk))
$ pointHash blk)]
-- TODO JNF
asMetrics (TraceBlockFetchServerSendBlock _p) =
[CounterM "cardano.node.served.block" Nothing]
docBlockFetchServer ::
Documented (TraceBlockFetchServerEvent blk)
docBlockFetchServer = addDocumentedNamespace [] docBlockFetchServer'
docBlockFetchServer' ::
Documented (TraceBlockFetchServerEvent blk)
docBlockFetchServer' = Documented [
DocMsg
["SendBlock"]
[("cardano.node.served.block", "")]
"The server sent a block to the peer."
]
--------------------------------------------------------------------------------
-- TxInbound Tracer
--------------------------------------------------------------------------------
severityTxInbound ::
BlockFetch.TraceLabelPeer peer (TraceTxSubmissionInbound (GenTxId blk) (GenTx blk))
-> SeverityS
severityTxInbound (BlockFetch.TraceLabelPeer _p ti) = severityTxInbound' ti
severityTxInbound' ::
TraceTxSubmissionInbound (GenTxId blk) (GenTx blk)
-> SeverityS
severityTxInbound' TraceTxSubmissionCollected {} = Debug
severityTxInbound' TraceTxSubmissionProcessed {} = Debug
severityTxInbound' TraceTxInboundTerminated = Notice
severityTxInbound' TraceTxInboundCannotRequestMoreTxs {} = Debug
severityTxInbound' TraceTxInboundCanRequestMoreTxs {} = Debug
namesForTxInbound ::
BlockFetch.TraceLabelPeer peer (TraceTxSubmissionInbound (GenTxId blk) (GenTx blk))
-> [Text]
namesForTxInbound (BlockFetch.TraceLabelPeer _p ti) = namesForTxInbound' ti
namesForTxInbound' ::
TraceTxSubmissionInbound (GenTxId blk) (GenTx blk)
-> [Text]
namesForTxInbound' (TraceTxSubmissionCollected _) =
["TxSubmissionCollected"]
namesForTxInbound' (TraceTxSubmissionProcessed _) =
["TxSubmissionProcessed"]
namesForTxInbound' TraceTxInboundTerminated =
["TxInboundTerminated"]
namesForTxInbound' TraceTxInboundCanRequestMoreTxs {} =
["TxInboundCanRequestMoreTxs"]
namesForTxInbound' TraceTxInboundCannotRequestMoreTxs {} =
["TxInboundCannotRequestMoreTxs"]
instance LogFormatting (TraceTxSubmissionInbound txid tx) where
forMachine _dtal (TraceTxSubmissionCollected count) =
mconcat
[ "kind" .= String "TraceTxSubmissionCollected"
, "count" .= toJSON count
]
forMachine _dtal (TraceTxSubmissionProcessed processed) =
mconcat
[ "kind" .= String "TraceTxSubmissionProcessed"
, "accepted" .= toJSON (ptxcAccepted processed)
, "rejected" .= toJSON (ptxcRejected processed)
]
forMachine _dtal TraceTxInboundTerminated =
mconcat
[ "kind" .= String "TraceTxInboundTerminated"
]
forMachine _dtal (TraceTxInboundCanRequestMoreTxs count) =
mconcat
[ "kind" .= String "TraceTxInboundCanRequestMoreTxs"
, "count" .= toJSON count
]
forMachine _dtal (TraceTxInboundCannotRequestMoreTxs count) =
mconcat
[ "kind" .= String "TraceTxInboundCannotRequestMoreTxs"
, "count" .= toJSON count
]
asMetrics (TraceTxSubmissionCollected count)=
[CounterM "cardano.node.submissions.submitted" (Just count)]
asMetrics (TraceTxSubmissionProcessed processed) =
[ CounterM "cardano.node.submissions.accepted"
(Just (ptxcAccepted processed))
, CounterM "cardano.node.submissions.rejected"
(Just (ptxcRejected processed))
]
asMetrics _ = []
docTxInbound ::
Documented (BlockFetch.TraceLabelPeer remotePeer
(TraceTxSubmissionInbound txid tx))
docTxInbound = addDocumentedNamespace [] docTxInbound'
docTxInbound' ::
Documented (BlockFetch.TraceLabelPeer remotePeer
(TraceTxSubmissionInbound txid tx))
docTxInbound' = Documented [
DocMsg
["TxSubmissionCollected"]
[ ("cardano.node.submissions.submitted", "")]
"Number of transactions just about to be inserted."
,
DocMsg
["TxSubmissionProcessed"]
[ ("cardano.node.submissions.accepted", "")
, ("cardano.node.submissions.rejected", "")
]
"Just processed transaction pass/fail breakdown."
,
DocMsg
["TxInboundTerminated"]
[]
"Server received 'MsgDone'."
,
DocMsg
["TxInboundCanRequestMoreTxs"]
[]
"There are no replies in flight, but we do know some more txs we\
\ can ask for, so lets ask for them and more txids."
,
DocMsg
["TxInboundCannotRequestMoreTxs"]
[]
"There's no replies in flight, and we have no more txs we can\
\ ask for so the only remaining thing to do is to ask for more\
\ txids. Since this is the only thing to do now, we make this a\
\ blocking call."
]
--------------------------------------------------------------------------------
-- TxOutbound Tracer
--------------------------------------------------------------------------------
severityTxOutbound ::
BlockFetch.TraceLabelPeer peer (TraceTxSubmissionOutbound (GenTxId blk) (GenTx blk))
-> SeverityS
severityTxOutbound (BlockFetch.TraceLabelPeer _p _ti) = Info
namesForTxOutbound ::
BlockFetch.TraceLabelPeer peer (TraceTxSubmissionOutbound (GenTxId blk) (GenTx blk))
-> [Text]
namesForTxOutbound (BlockFetch.TraceLabelPeer _p ti) = namesForTxOutbound' ti
namesForTxOutbound' ::
TraceTxSubmissionOutbound (GenTxId blk) (GenTx blk)
-> [Text]
namesForTxOutbound' TraceTxSubmissionOutboundRecvMsgRequestTxs {} =
["TxSubmissionOutboundRecvMsgRequest"]
namesForTxOutbound' TraceTxSubmissionOutboundSendMsgReplyTxs {} =
["TxSubmissionOutboundSendMsgReply"]
namesForTxOutbound' TraceControlMessage {} =
["ControlMessage"]
instance (Show txid, Show tx)
=> LogFormatting (TraceTxSubmissionOutbound txid tx) where
forMachine DDetailed (TraceTxSubmissionOutboundRecvMsgRequestTxs txids) =
mconcat
[ "kind" .= String "TraceTxSubmissionOutboundRecvMsgRequestTxs"
, "txIds" .= String (Text.pack $ show txids)
]
forMachine _dtal (TraceTxSubmissionOutboundRecvMsgRequestTxs _txids) =
mconcat
[ "kind" .= String "TraceTxSubmissionOutboundRecvMsgRequestTxs"
]
forMachine DDetailed (TraceTxSubmissionOutboundSendMsgReplyTxs txs) =
mconcat
[ "kind" .= String "TraceTxSubmissionOutboundSendMsgReplyTxs"
, "txs" .= String (Text.pack $ show txs)
]
forMachine _dtal (TraceTxSubmissionOutboundSendMsgReplyTxs _txs) =
mconcat
[ "kind" .= String "TraceTxSubmissionOutboundSendMsgReplyTxs"
]
forMachine _dtal (TraceControlMessage _msg) =
mconcat
[ "kind" .= String "TraceControlMessage"
]
docTxOutbound :: forall remotePeer txid tx.
Documented (BlockFetch.TraceLabelPeer remotePeer
(TraceTxSubmissionOutbound txid tx))
docTxOutbound = addDocumentedNamespace [] docTxOutbound'
docTxOutbound' :: forall remotePeer txid tx.
Documented (BlockFetch.TraceLabelPeer remotePeer
(TraceTxSubmissionOutbound txid tx))
docTxOutbound' = Documented [
DocMsg
["RecvMsgRequest"]
[]
"The IDs of the transactions requested."
,
DocMsg
["SendMsgReply"]
[]
"The transactions to be sent in the response."
,
DocMsg
["ControlMessage"]
[]
""
]
--------------------------------------------------------------------------------
-- TxSubmissionServer Tracer
--------------------------------------------------------------------------------
severityLocalTxSubmissionServer ::
TraceLocalTxSubmissionServerEvent blk
-> SeverityS
severityLocalTxSubmissionServer _ = Info
namesForLocalTxSubmissionServer ::
TraceLocalTxSubmissionServerEvent blk
-> [Text]
namesForLocalTxSubmissionServer TraceReceivedTx {} = ["ReceivedTx"]
instance LogFormatting (TraceLocalTxSubmissionServerEvent blk) where
forMachine _dtal (TraceReceivedTx _gtx) =
mconcat [ "kind" .= String "ReceivedTx" ]
docLocalTxSubmissionServer :: Documented (TraceLocalTxSubmissionServerEvent blk)
docLocalTxSubmissionServer =
addDocumentedNamespace [] docLocalTxSubmissionServer'
docLocalTxSubmissionServer' :: Documented (TraceLocalTxSubmissionServerEvent blk)
docLocalTxSubmissionServer' = Documented [
DocMsg
["ReceivedTx"]
[]
"A transaction was received."
]
--------------------------------------------------------------------------------
-- Mempool Tracer
--------------------------------------------------------------------------------
severityMempool ::
TraceEventMempool blk
-> SeverityS
severityMempool _ = Info
namesForMempool :: TraceEventMempool blk -> [Text]
namesForMempool TraceMempoolAddedTx {} = ["AddedTx"]
namesForMempool TraceMempoolRejectedTx {} = ["RejectedTx"]
namesForMempool TraceMempoolRemoveTxs {} = ["RemoveTxs"]
namesForMempool TraceMempoolManuallyRemovedTxs {} = ["ManuallyRemovedTxs"]
instance
( Show (ApplyTxErr blk)
, LogFormatting (ApplyTxErr blk)
, LogFormatting (GenTx blk)
, ToJSON (GenTxId blk)
, LedgerSupportsMempool blk
) => LogFormatting (TraceEventMempool blk) where
forMachine dtal (TraceMempoolAddedTx tx _mpSzBefore mpSzAfter) =
mconcat
[ "kind" .= String "TraceMempoolAddedTx"
, "tx" .= forMachine dtal (txForgetValidated tx)
, "mempoolSize" .= forMachine dtal mpSzAfter
]
forMachine dtal (TraceMempoolRejectedTx tx txApplyErr mpSz) =
mconcat
[ "kind" .= String "TraceMempoolRejectedTx"
, "err" .= forMachine dtal txApplyErr
, "tx" .= forMachine dtal tx
, "mempoolSize" .= forMachine dtal mpSz
]
forMachine dtal (TraceMempoolRemoveTxs txs mpSz) =
mconcat
[ "kind" .= String "TraceMempoolRemoveTxs"
, "txs" .= map (forMachine dtal . txForgetValidated) txs
, "mempoolSize" .= forMachine dtal mpSz
]
forMachine dtal (TraceMempoolManuallyRemovedTxs txs0 txs1 mpSz) =
mconcat
[ "kind" .= String "TraceMempoolManuallyRemovedTxs"
, "txsRemoved" .= txs0
, "txsInvalidated" .= map (forMachine dtal . txForgetValidated) txs1
, "mempoolSize" .= forMachine dtal mpSz
]
asMetrics (TraceMempoolAddedTx _tx _mpSzBefore mpSz) =
[ IntM "cardano.node.txsInMempool" (fromIntegral $ msNumTxs mpSz)
, IntM "cardano.node.mempoolBytes" (fromIntegral $ msNumBytes mpSz)
]
asMetrics (TraceMempoolRejectedTx _tx _txApplyErr mpSz) =
[ IntM "cardano.node.txsInMempool" (fromIntegral $ msNumTxs mpSz)
, IntM "cardano.node.mempoolBytes" (fromIntegral $ msNumBytes mpSz)
]
asMetrics (TraceMempoolRemoveTxs _txs mpSz) =
[ IntM "cardano.node.txsInMempool" (fromIntegral $ msNumTxs mpSz)
, IntM "cardano.node.mempoolBytes" (fromIntegral $ msNumBytes mpSz)
]
asMetrics (TraceMempoolManuallyRemovedTxs [] _txs1 mpSz) =
[ IntM "cardano.node.txsInMempool" (fromIntegral $ msNumTxs mpSz)
, IntM "cardano.node.mempoolBytes" (fromIntegral $ msNumBytes mpSz)
]
asMetrics (TraceMempoolManuallyRemovedTxs txs _txs1 mpSz) =
[ IntM "cardano.node.txsInMempool" (fromIntegral $ msNumTxs mpSz)
, IntM "cardano.node.mempoolBytes" (fromIntegral $ msNumBytes mpSz)
, CounterM "cardano.node.txsProcessedNum" (Just (fromIntegral $ length txs))
]
instance LogFormatting MempoolSize where
forMachine _dtal MempoolSize{msNumTxs, msNumBytes} =
mconcat
[ "numTxs" .= msNumTxs
, "bytes" .= msNumBytes
]
docMempool :: forall blk. Documented (TraceEventMempool blk)
docMempool = addDocumentedNamespace [] docMempool'
docMempool' :: forall blk. Documented (TraceEventMempool blk)
docMempool' = Documented [
DocMsg
["AddedTx"]
[ ("cardano.node.txsInMempool","Transactions in mempool")
, ("cardano.node.mempoolBytes", "Byte size of the mempool")
]
"New, valid transaction that was added to the Mempool."
, DocMsg
["RejectedTx"]
[ ("cardano.node.txsInMempool","Transactions in mempool")
, ("cardano.node.mempoolBytes", "Byte size of the mempool")
]
"New, invalid transaction thas was rejected and thus not added to\
\ the Mempool."
, DocMsg
["RemoveTxs"]
[ ("cardano.node.txsInMempool","Transactions in mempool")
, ("cardano.node.mempoolBytes", "Byte size of the mempool")
]
"Previously valid transactions that are no longer valid because of\
\ changes in the ledger state. These transactions have been removed\
\ from the Mempool."
, DocMsg
["ManuallyRemovedTxs"]
[ ("cardano.node.txsInMempool","Transactions in mempool")
, ("cardano.node.mempoolBytes", "Byte size of the mempool")
, ("cardano.node.txsProcessedNum", "")
]
"Transactions that have been manually removed from the Mempool."
]
--------------------------------------------------------------------------------
-- ForgeEvent Tracer
--------------------------------------------------------------------------------
severityForge :: ForgeTracerType blk -> SeverityS
severityForge (Left t) = severityForge' t
severityForge (Right t) = severityForge''' t
severityForge' :: TraceLabelCreds (TraceForgeEvent blk) -> SeverityS
severityForge' (TraceLabelCreds _t e) = severityForge'' e
severityForge'' :: TraceForgeEvent blk -> SeverityS
severityForge'' TraceStartLeadershipCheck {} = Info
severityForge'' TraceSlotIsImmutable {} = Error
severityForge'' TraceBlockFromFuture {} = Error
severityForge'' TraceBlockContext {} = Debug
severityForge'' TraceNoLedgerState {} = Error
severityForge'' TraceLedgerState {} = Debug
severityForge'' TraceNoLedgerView {} = Error
severityForge'' TraceLedgerView {} = Debug
severityForge'' TraceForgeStateUpdateError {} = Error
severityForge'' TraceNodeCannotForge {} = Error
severityForge'' TraceNodeNotLeader {} = Info
severityForge'' TraceNodeIsLeader {} = Info
severityForge'' TraceForgeTickedLedgerState {} = Debug
severityForge'' TraceForgingMempoolSnapshot {} = Debug
severityForge'' TraceForgedBlock {} = Info
severityForge'' TraceDidntAdoptBlock {} = Error
severityForge'' TraceForgedInvalidBlock {} = Error
severityForge'' TraceAdoptedBlock {} = Info
severityForge''' :: TraceLabelCreds TraceStartLeadershipCheckPlus -> SeverityS
severityForge''' _ = Info
namesForForge :: ForgeTracerType blk -> [Text]
namesForForge (Left t) = namesForForge' t
namesForForge (Right t) = namesForForge''' t
namesForForge' :: TraceLabelCreds (TraceForgeEvent blk) -> [Text]
namesForForge' (TraceLabelCreds _t e) = namesForForge'' e
namesForForge'' :: TraceForgeEvent blk -> [Text]
namesForForge'' TraceStartLeadershipCheck {} = ["StartLeadershipCheck"]
namesForForge'' TraceSlotIsImmutable {} = ["SlotIsImmutable"]
namesForForge'' TraceBlockFromFuture {} = ["BlockFromFuture"]
namesForForge'' TraceBlockContext {} = ["BlockContext"]
namesForForge'' TraceNoLedgerState {} = ["NoLedgerState"]
namesForForge'' TraceLedgerState {} = ["LedgerState"]
namesForForge'' TraceNoLedgerView {} = ["NoLedgerView"]
namesForForge'' TraceLedgerView {} = ["LedgerView"]
namesForForge'' TraceForgeStateUpdateError {} = ["ForgeStateUpdateError"]
namesForForge'' TraceNodeCannotForge {} = ["NodeCannotForge"]
namesForForge'' TraceNodeNotLeader {} = ["NodeNotLeader"]
namesForForge'' TraceNodeIsLeader {} = ["NodeIsLeader"]
namesForForge'' TraceForgeTickedLedgerState {} = ["ForgeTickedLedgerState"]
namesForForge'' TraceForgingMempoolSnapshot {} = ["ForgingMempoolSnapshot"]
namesForForge'' TraceForgedBlock {} = ["ForgedBlock"]
namesForForge'' TraceDidntAdoptBlock {} = ["DidntAdoptBlock"]
namesForForge'' TraceForgedInvalidBlock {} = ["ForgedInvalidBlock"]
namesForForge'' TraceAdoptedBlock {} = ["AdoptedBlock"]
namesForForge''' :: TraceLabelCreds TraceStartLeadershipCheckPlus -> [Text]
namesForForge''' (TraceLabelCreds _ TraceStartLeadershipCheckPlus {}) =
["StartLeadershipCheckPlus"]
instance ( tx ~ GenTx blk
, ConvertRawHash blk
, GetHeader blk
, HasHeader blk
, HasKESInfo blk
, HasTxId (GenTx blk)
, LedgerSupportsProtocol blk
, LedgerSupportsMempool blk
, SerialiseNodeToNodeConstraints blk
, Show (ForgeStateUpdateError blk)
, Show (CannotForge blk)
, Show (TxId (GenTx blk))
, LogFormatting (InvalidBlockReason blk)
, LogFormatting (CannotForge blk)
, LogFormatting (ForgeStateUpdateError blk))
=> LogFormatting (TraceForgeEvent blk) where
forMachine _dtal (TraceStartLeadershipCheck slotNo) =
mconcat
[ "kind" .= String "TraceStartLeadershipCheck"
, "slot" .= toJSON (unSlotNo slotNo)
]
forMachine dtal (TraceSlotIsImmutable slotNo tipPoint tipBlkNo) =
mconcat
[ "kind" .= String "TraceSlotIsImmutable"
, "slot" .= toJSON (unSlotNo slotNo)
, "tip" .= renderPointForDetails dtal tipPoint
, "tipBlockNo" .= toJSON (unBlockNo tipBlkNo)
]
forMachine _dtal (TraceBlockFromFuture currentSlot tip) =
mconcat
[ "kind" .= String "TraceBlockFromFuture"
, "current slot" .= toJSON (unSlotNo currentSlot)
, "tip" .= toJSON (unSlotNo tip)
]
forMachine dtal (TraceBlockContext currentSlot tipBlkNo tipPoint) =
mconcat
[ "kind" .= String "TraceBlockContext"
, "current slot" .= toJSON (unSlotNo currentSlot)
, "tip" .= renderPointForDetails dtal tipPoint