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

Integrate ledger snapshot checksum #6047

Draft
wants to merge 3 commits into
base: release/10.1.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ allow-newer:
-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.
source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-consensus
-- use branch geo2a/issue-892-checksum-snaphot-file-release-ouroboros-consensus-0.21.0.0-backport
tag: bc9f10c0a
--sha256: JGuQlFgW46mck545klipsiajhkr9A51JYXVRvmr0KYI=
subdir:
ouroboros-consensus
ouroboros-consensus-cardano
ouroboros-consensus-diffusion
ouroboros-consensus-protocol
sop-extras
strict-sop-core
20 changes: 15 additions & 5 deletions cardano-node/src/Cardano/Node/Configuration/POM.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

Expand Down Expand Up @@ -35,8 +37,8 @@ import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Mempool (MempoolCapacityBytesOverride (..))
import Ouroboros.Consensus.Node (NodeDatabasePaths (..))
import qualified Ouroboros.Consensus.Node as Consensus (NetworkP2PMode (..))
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (NumOfDiskSnapshots (..),
SnapshotInterval (..))
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (Flag (..),
NumOfDiskSnapshots (..), SnapshotInterval (..), pattern DoDiskSnapshotChecksum)
import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..), DiffusionMode (..))
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))

Expand Down Expand Up @@ -103,9 +105,10 @@ data NodeConfiguration
, ncProtocolConfig :: !NodeProtocolConfiguration

-- Node parameters, not protocol-specific:
, ncDiffusionMode :: !DiffusionMode
, ncNumOfDiskSnapshots :: !NumOfDiskSnapshots
, ncSnapshotInterval :: !SnapshotInterval
, ncDiffusionMode :: !DiffusionMode
, ncNumOfDiskSnapshots :: !NumOfDiskSnapshots
, ncSnapshotInterval :: !SnapshotInterval
, ncDoDiskSnapshotChecksum :: !(Flag "DoDiskSnapshotChecksum")

-- | During the development and integration of new network protocols
-- (node-to-node and node-to-client) we wish to be able to test them
Expand Down Expand Up @@ -188,6 +191,7 @@ data PartialNodeConfiguration
, pncDiffusionMode :: !(Last DiffusionMode )
, pncNumOfDiskSnapshots :: !(Last NumOfDiskSnapshots)
, pncSnapshotInterval :: !(Last SnapshotInterval)
, pncDoDiskSnapshotChecksum :: !(Last (Flag "DoDiskSnapshotChecksum"))
, pncExperimentalProtocolsEnabled :: !(Last Bool)

-- BlockFetch configuration
Expand Down Expand Up @@ -250,6 +254,8 @@ instance FromJSON PartialNodeConfiguration where
<- Last . fmap RequestedNumOfDiskSnapshots <$> v .:? "NumOfDiskSnapshots"
pncSnapshotInterval
<- Last . fmap RequestedSnapshotInterval <$> v .:? "SnapshotInterval"
pncDoDiskSnapshotChecksum
<- Last <$> v .:? "DoDiskSnapshotChecksum"
pncExperimentalProtocolsEnabled <- fmap Last $ do
mValue <- v .:? "ExperimentalProtocolsEnabled"

Expand Down Expand Up @@ -329,6 +335,7 @@ instance FromJSON PartialNodeConfiguration where
, pncDiffusionMode
, pncNumOfDiskSnapshots
, pncSnapshotInterval
, pncDoDiskSnapshotChecksum
, pncExperimentalProtocolsEnabled
, pncMaxConcurrencyBulkSync
, pncMaxConcurrencyDeadline
Expand Down Expand Up @@ -500,6 +507,7 @@ defaultPartialNodeConfiguration =
, pncDiffusionMode = Last $ Just InitiatorAndResponderDiffusionMode
, pncNumOfDiskSnapshots = Last $ Just DefaultNumOfDiskSnapshots
, pncSnapshotInterval = Last $ Just DefaultSnapshotInterval
, pncDoDiskSnapshotChecksum = Last $ Just DoDiskSnapshotChecksum
, pncExperimentalProtocolsEnabled = Last $ Just False
, pncTopologyFile = Last . Just $ TopologyFile "configuration/cardano/mainnet-topology.json"
, pncProtocolFiles = mempty
Expand Down Expand Up @@ -552,6 +560,7 @@ makeNodeConfiguration pnc = do
diffusionMode <- lastToEither "Missing DiffusionMode" $ pncDiffusionMode pnc
numOfDiskSnapshots <- lastToEither "Missing NumOfDiskSnapshots" $ pncNumOfDiskSnapshots pnc
snapshotInterval <- lastToEither "Missing SnapshotInterval" $ pncSnapshotInterval pnc
doDiskSnapshotChecksum <- lastToEither "Missing DoDiskSnapshotChecksum" $ pncDoDiskSnapshotChecksum pnc
shutdownConfig <- lastToEither "Missing ShutdownConfig" $ pncShutdownConfig pnc
socketConfig <- lastToEither "Missing SocketConfig" $ pncSocketConfig pnc

Expand Down Expand Up @@ -621,6 +630,7 @@ makeNodeConfiguration pnc = do
, ncDiffusionMode = diffusionMode
, ncNumOfDiskSnapshots = numOfDiskSnapshots
, ncSnapshotInterval = snapshotInterval
, ncDoDiskSnapshotChecksum = doDiskSnapshotChecksum
, ncExperimentalProtocolsEnabled = experimentalProtocols
, ncMaxConcurrencyBulkSync = getLast $ pncMaxConcurrencyBulkSync pnc
, ncMaxConcurrencyDeadline = getLast $ pncMaxConcurrencyDeadline pnc
Expand Down
10 changes: 8 additions & 2 deletions cardano-node/src/Cardano/Node/Orphans.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE StandaloneDeriving #-}

Expand All @@ -8,6 +10,7 @@ module Cardano.Node.Orphans () where

import Cardano.Api ()

import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (Flag(..))
import Ouroboros.Consensus.Node
import qualified Data.Text as Text
import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..))
Expand Down Expand Up @@ -46,11 +49,14 @@ instance FromJSON AcceptedConnectionsLimit where
<*> v .: "delay"

instance FromJSON NodeDatabasePaths where
parseJSON o@(Object{})=
withObject "NodeDatabasePaths"
parseJSON o@(Object{})=
withObject "NodeDatabasePaths"
(\v -> MultipleDbPaths
<$> v .: "ImmutableDbPath"
<*> v .: "VolatileDbPath"
) o
parseJSON (String s) = return . OnePathForAllDbs $ Text.unpack s
parseJSON _ = fail "NodeDatabasePaths must be an object or a string"

deriving newtype instance FromJSON (Flag symbol)
deriving newtype instance ToJSON (Flag symbol)
1 change: 1 addition & 0 deletions cardano-node/src/Cardano/Node/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ nodeRunParser = do
, pncDiffusionMode = mempty
, pncNumOfDiskSnapshots = numOfDiskSnapshots
, pncSnapshotInterval = snapshotInterval
, pncDoDiskSnapshotChecksum = mempty
, pncExperimentalProtocolsEnabled = mempty
, pncProtocolFiles = Last $ Just ProtocolFilepaths
{ byronCertFile
Expand Down
4 changes: 3 additions & 1 deletion cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExplicitNamespaces #-}
Expand Down Expand Up @@ -63,7 +64,7 @@ import Cardano.Tracing.Config (TraceOptions (..), TraceSelection (..))
import Cardano.Tracing.Tracers
import qualified Ouroboros.Consensus.Config as Consensus
import Ouroboros.Consensus.Config.SupportsNode (ConfigSupportsNode (..))
import Ouroboros.Consensus.Node (DiskPolicyArgs (..), NetworkP2PMode (..),
import Ouroboros.Consensus.Node (DiskPolicyArgs (..), pattern DoDiskSnapshotChecksum, pattern NoDoDiskSnapshotChecksum, NetworkP2PMode (..),
NodeDatabasePaths (..), RunNodeArgs (..), StdRunNodeArgs (..))
import qualified Ouroboros.Consensus.Node as Node (NodeDatabasePaths (..), getChainDB, run)
import Ouroboros.Consensus.Node.Genesis
Expand Down Expand Up @@ -650,6 +651,7 @@ handleSimpleNode blockType runP p2pMode tracers nc onKernel = do
DiskPolicyArgs
(ncSnapshotInterval nc)
(ncNumOfDiskSnapshots nc)
(ncDoDiskSnapshotChecksum nc)

--------------------------------------------------------------------------------
-- SIGHUP Handlers
Expand Down
35 changes: 29 additions & 6 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,21 +1507,35 @@ instance ( StandardHash blk
, ConvertRawHash blk)
=> LogFormatting (LedgerDB.TraceSnapshotEvent blk) where
forHuman (LedgerDB.TookSnapshot snap pt RisingEdge) =
"Taking ledger snapshot " <> showT snap <>
" at " <> renderRealPointAsPhrase pt
Text.unwords [ "Taking ledger snapshot"
, showT snap
, "at"
, renderRealPointAsPhrase pt
]
forHuman (LedgerDB.TookSnapshot snap pt (FallingEdgeWith t)) =
"Took ledger snapshot " <> showT snap <>
" at " <> renderRealPointAsPhrase pt <> ", duration: " <> showT t
Text.unwords [ "Took ledger snapshot"
, showT snap
, "at"
, renderRealPointAsPhrase pt
, ", duration:"
, showT t
]
forHuman (LedgerDB.DeletedSnapshot snap) =
"Deleted old snapshot " <> showT snap
Text.unwords ["Deleted old snapshot", showT snap]
forHuman (LedgerDB.InvalidSnapshot snap failure) =
"Invalid snapshot " <> showT snap <> showT failure <> context
Text.unwords [ "Invalid snapshot"
, showT snap
, showT failure
, context
]
where
context = case failure of
LedgerDB.InitFailureRead{} ->
" This is most likely an expected change in the serialization format,"
geo2a marked this conversation as resolved.
Show resolved Hide resolved
<> " which currently requires a chain replay"
_ -> ""
forHuman (LedgerDB.SnapshotMissingChecksum snap) =
"Checksum file is missing for snapshot " <> showT snap

forMachine dtals (LedgerDB.TookSnapshot snap pt enclosedTiming) =
mconcat [ "kind" .= String "TookSnapshot"
Expand All @@ -1535,15 +1549,21 @@ instance ( StandardHash blk
mconcat [ "kind" .= String "InvalidSnapshot"
, "snapshot" .= forMachine dtals snap
, "failure" .= show failure ]
forMachine dtals (LedgerDB.SnapshotMissingChecksum snap) =
mconcat [ "kind" .= String "SnapshotMissingChecksum"
, "snapshot" .= forMachine dtals snap
]

instance MetaTrace (LedgerDB.TraceSnapshotEvent blk) where
namespaceFor LedgerDB.TookSnapshot {} = Namespace [] ["TookSnapshot"]
namespaceFor LedgerDB.DeletedSnapshot {} = Namespace [] ["DeletedSnapshot"]
namespaceFor LedgerDB.InvalidSnapshot {} = Namespace [] ["InvalidSnapshot"]
namespaceFor LedgerDB.SnapshotMissingChecksum {} = Namespace [] ["SnapshotMissingChecksum"]

severityFor (Namespace _ ["TookSnapshot"]) _ = Just Info
severityFor (Namespace _ ["DeletedSnapshot"]) _ = Just Debug
severityFor (Namespace _ ["InvalidSnapshot"]) _ = Just Error
severityFor (Namespace _ ["SnapshotMissingChecksum"]) _ = Just Warning
severityFor _ _ = Nothing

documentFor (Namespace _ ["TookSnapshot"]) = Just $ mconcat
Expand All @@ -1555,12 +1575,15 @@ instance MetaTrace (LedgerDB.TraceSnapshotEvent blk) where
"A snapshot was deleted from the disk."
documentFor (Namespace _ ["InvalidSnapshot"]) = Just
"An on disk snapshot was invalid. Unless it was suffixed, it will be deleted"
documentFor (Namespace _ ["SnapshotMissingChecksum"]) = Just
"Checksum file was missing for snapshot."
documentFor _ = Nothing

allNamespaces =
[ Namespace [] ["TookSnapshot"]
, Namespace [] ["DeletedSnapshot"]
, Namespace [] ["InvalidSnapshot"]
, Namespace [] ["SnapshotMissingChecksum"]
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ instance HasSeverityAnnotation (ChainDB.TraceEvent blk) where
LedgerDB.TookSnapshot {} -> Info
LedgerDB.DeletedSnapshot {} -> Debug
LedgerDB.InvalidSnapshot {} -> Error
LedgerDB.SnapshotMissingChecksum {} -> Warning

getSeverityAnnotation (ChainDB.TraceCopyToImmutableDBEvent ev) = case ev of
ChainDB.CopiedBlockToImmutableDB {} -> Debug
Expand Down Expand Up @@ -615,6 +616,8 @@ instance ( ConvertRawHash blk
" This is most likely an expected change in the serialization format,"
<> " which currently requires a chain replay"
_ -> ""
LedgerDB.SnapshotMissingChecksum snap ->
"Checksum file is missing for snapshot " <> showT snap

LedgerDB.TookSnapshot snap pt RisingEdge ->
"Taking ledger snapshot " <> showT snap <>
Expand Down Expand Up @@ -1101,6 +1104,10 @@ instance ( ConvertRawHash blk
mconcat [ "kind" .= String "TraceSnapshotEvent.InvalidSnapshot"
, "snapshot" .= toObject verb snap
, "failure" .= show failure ]
LedgerDB.SnapshotMissingChecksum snap ->
mconcat [ "kind" .= String "TraceSnapshotEvent.SnapshotMissingChecksum"
, "snapshot" .= toObject verb snap
]

toObject verb (ChainDB.TraceCopyToImmutableDBEvent ev) = case ev of
ChainDB.CopiedBlockToImmutableDB pt ->
Expand Down
6 changes: 5 additions & 1 deletion cardano-node/test/Test/Cardano/Node/POM.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TemplateHaskell #-}

module Test.Cardano.Node.POM
Expand All @@ -15,7 +16,7 @@ import Cardano.Tracing.Config (PartialTraceOptions (..), defaultPartia
import Ouroboros.Consensus.Node (NodeDatabasePaths (..))
import qualified Ouroboros.Consensus.Node as Consensus (NetworkP2PMode (..))
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (NumOfDiskSnapshots (..),
SnapshotInterval (..))
SnapshotInterval (..), pattern DoDiskSnapshotChecksum)
import Ouroboros.Network.Block (SlotNo (..))
import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..),
DiffusionMode (InitiatorAndResponderDiffusionMode))
Expand Down Expand Up @@ -119,6 +120,7 @@ testPartialYamlConfig =
, pncDiffusionMode = Last Nothing
, pncNumOfDiskSnapshots = Last Nothing
, pncSnapshotInterval = mempty
, pncDoDiskSnapshotChecksum = Last . Just $ DoDiskSnapshotChecksum
, pncExperimentalProtocolsEnabled = Last Nothing
, pncMaxConcurrencyBulkSync = Last Nothing
, pncMaxConcurrencyDeadline = Last Nothing
Expand Down Expand Up @@ -161,6 +163,7 @@ testPartialCliConfig =
, pncDiffusionMode = mempty
, pncNumOfDiskSnapshots = Last Nothing
, pncSnapshotInterval = Last . Just . RequestedSnapshotInterval $ secondsToDiffTime 100
, pncDoDiskSnapshotChecksum = Last . Just $ DoDiskSnapshotChecksum
, pncExperimentalProtocolsEnabled = Last $ Just True
, pncProtocolFiles = Last . Just $ ProtocolFilepaths Nothing Nothing Nothing Nothing Nothing Nothing
, pncValidateDB = Last $ Just True
Expand Down Expand Up @@ -205,6 +208,7 @@ eExpectedConfig = do
, ncDiffusionMode = InitiatorAndResponderDiffusionMode
, ncNumOfDiskSnapshots = DefaultNumOfDiskSnapshots
, ncSnapshotInterval = RequestedSnapshotInterval $ secondsToDiffTime 100
, ncDoDiskSnapshotChecksum = DoDiskSnapshotChecksum
, ncExperimentalProtocolsEnabled = True
, ncMaxConcurrencyBulkSync = Nothing
, ncMaxConcurrencyDeadline = Nothing
Expand Down
Loading