Skip to content

Commit 7446f7b

Browse files
committed
Add "Mithril" named LedgerDB configuration
1 parent 507437c commit 7446f7b

3 files changed

Lines changed: 40 additions & 14 deletions

File tree

cardano-node/src/Cardano/Node/Configuration/POM.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import Ouroboros.Consensus.Node.Genesis (GenesisConfig, GenesisConfigF
4848
import Ouroboros.Consensus.Storage.LedgerDB.Args (QueryBatchSize (..))
4949
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots (NumOfDiskSnapshots (..),
5050
SnapshotDelayRange (..), SnapshotFrequency (..), SnapshotFrequencyArgs (..),
51-
SnapshotPolicyArgs (..), defaultSnapshotPolicyArgs)
51+
SnapshotPolicyArgs (..), defaultSnapshotPolicyArgs, mithrilSnapshotPolicyArgs)
5252
import Ouroboros.Consensus.Util.Args (OverrideOrDefault (..))
5353
import Ouroboros.Consensus.Storage.LedgerDB.V1.Args (FlushFrequency (..))
5454
import Ouroboros.Network.Diffusion.Configuration as Configuration
@@ -67,6 +67,7 @@ import Data.Hashable (Hashable)
6767
import Data.Maybe
6868
import Data.Monoid (Last (..))
6969
import Data.Text (Text)
70+
import qualified Data.Text as Text
7071
import Data.Time.Clock (DiffTime, secondsToDiffTime)
7172
import Data.Yaml (decodeFileThrow)
7273
import GHC.Generics (Generic)
@@ -547,8 +548,16 @@ instance FromJSON PartialNodeConfiguration where
547548

548549
mSnapshotsVal <- o .:? "Snapshots"
549550
spArgs <- case mSnapshotsVal of
550-
Nothing -> parseSnapshotOpts o
551+
-- A named snapshot policy selects a predefined set of snapshot
552+
-- policy arguments as a whole.
553+
Just (String name) -> case name of
554+
"Mithril" -> pure mithrilSnapshotPolicyArgs
555+
_ -> fail $ "Unknown named ledger snapshot policy: " <> Text.unpack name
556+
<> ". Expected \"Mithril\" or an object with snapshot options."
557+
-- the modern case of the snapshot policy specified under the "Snapshots" key
551558
Just sv -> flip (withObject "Snapshots") sv parseSnapshotOpts
559+
-- the legacy case of the snapshot policy specified at the top-level
560+
Nothing -> parseSnapshotOpts o
552561

553562
qsize <- (fmap RequestedQueryBatchSize <$> o .:? "QueryBatchSize") .!= DefaultQueryBatchSize
554563
backend <- o .:? "Backend" .!= "V2InMemory"

cardano-node/test/Test/Cardano/Node/POM.hs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import Cardano.Rpc.Server.Config (makeRpcConfig)
2323
import Ouroboros.Consensus.Node (NodeDatabasePaths (..))
2424
import Ouroboros.Consensus.Node.Genesis (disableGenesisConfig)
2525
import Ouroboros.Consensus.Storage.LedgerDB.Args
26-
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots (defaultSnapshotPolicyArgs)
26+
import Ouroboros.Consensus.Storage.LedgerDB.Snapshots (defaultSnapshotPolicyArgs,
27+
mithrilSnapshotPolicyArgs)
2728
import Ouroboros.Network.Block (SlotNo (..))
2829
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
2930
import Ouroboros.Network.TxSubmission.Inbound.V2.Types
@@ -316,17 +317,31 @@ prop_legacySnapshotFormat_POM =
316317
legacyConfig :: PartialNodeConfiguration <- evalEither $ eitherDecode legacyJson
317318
newConfig :: PartialNodeConfiguration <- evalEither $ eitherDecode newJson
318319
pncLedgerDbConfig legacyConfig === pncLedgerDbConfig newConfig
319-
where
320-
dummyRequiredValues :: LBS.ByteString
321-
dummyRequiredValues = mconcat
322-
[ "\"ByronGenesisFile\": \"x\""
323-
, ", \"ShelleyGenesisFile\": \"x\""
324-
, ", \"AlonzoGenesisFile\": \"x\""
325-
, ", \"ConwayGenesisFile\": \"x\""
326-
, ", \"LastKnownBlockVersion-Major\": 0"
327-
, ", \"LastKnownBlockVersion-Minor\": 0"
328-
, ", \"LastKnownBlockVersion-Alt\": 0"
329-
]
320+
321+
-- | Test that the named \"Mithril\" snapshot policy selects
322+
-- 'mithrilSnapshotPolicyArgs' as a whole.
323+
prop_mithrilSnapshotPolicy_POM :: Property
324+
prop_mithrilSnapshotPolicy_POM =
325+
withTests 1 . Hedgehog.property $ do
326+
let json = "{ " <> dummyRequiredValues <> ", "
327+
<> "\"LedgerDB\": {"
328+
<> " \"Backend\": \"V2InMemory\","
329+
<> " \"Snapshots\": \"Mithril\""
330+
<> "} }"
331+
config :: PartialNodeConfiguration <- evalEither $ eitherDecode json
332+
getLast (pncLedgerDbConfig config) ===
333+
Just (LedgerDbConfiguration mithrilSnapshotPolicyArgs DefaultQueryBatchSize V2InMemory noDeprecatedOptions)
334+
335+
dummyRequiredValues :: LBS.ByteString
336+
dummyRequiredValues = mconcat
337+
[ "\"ByronGenesisFile\": \"x\""
338+
, ", \"ShelleyGenesisFile\": \"x\""
339+
, ", \"AlonzoGenesisFile\": \"x\""
340+
, ", \"ConwayGenesisFile\": \"x\""
341+
, ", \"LastKnownBlockVersion-Major\": 0"
342+
, ", \"LastKnownBlockVersion-Minor\": 0"
343+
, ", \"LastKnownBlockVersion-Alt\": 0"
344+
]
330345

331346
-- -----------------------------------------------------------------------------
332347

configuration/cardano/mainnet-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ LedgerDB:
8888
# QueryUTxOByAddress), the store will be read in batches of this size.
8989
QueryBatchSize: 100000
9090

91+
# Instead of an object with individual options, a predefined snapshot
92+
# policy can be selected by name, e.g. `Snapshots: Mithril`.
9193
Snapshots:
9294
# The time interval between snapshots, in seconds.
9395
SnapshotInterval: 4320

0 commit comments

Comments
 (0)