Skip to content
Merged
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
10 changes: 1 addition & 9 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ jobs:
id: tag
shell: bash
run: |
if [ "${GITHUB_REF/refs\/tags\//}" == "refs/heads/main" ]; then
echo "value=$GIT_SHA" >> $GITHUB_OUTPUT
else
echo "value=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
fi
echo "value=$GIT_SHA" >> $GITHUB_OUTPUT
env:
GIT_SHA: ${{ github.sha }}

Expand All @@ -57,10 +53,6 @@ jobs:
${{ runner.os }}-${{ runner.arch }}-build-
${{ runner.os }}-${{ runner.arch }}-

- name: ❓ Check cache
run: |
find ~/.local

- name: 🚄 Prepare OS
if: ${{ matrix.os == 'macos' }}
run: |
Expand Down
59 changes: 58 additions & 1 deletion src/Cardano/Tools/DB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-orphans #-}


module Cardano.Tools.DB
( StandardBlock,
StandardPoint,
Expand All @@ -20,6 +21,8 @@ module Cardano.Tools.DB
DBError (..),
DB,
DBTrace,
LedgerDbBackend(..),
LedgerDbConfig(..),
SlotNo,
Hash,
asInteger,
Expand All @@ -34,6 +37,7 @@ module Cardano.Tools.DB
makeSlot,
mkPoint,
listBlocks,
parseLedgerDbConfig,
toBytestring,
)
where
Expand All @@ -45,7 +49,7 @@ import Cardano.Slotting.Slot (SlotNo (..), WithOrigin (..))
import Cardano.Tools.DBAnalyser.Block.Cardano (Args (CardanoBlockArgs))
import Cardano.Tools.DBAnalyser.HasAnalysis (mkProtocolInfo)
import Control.Tracer (Tracer (..))
import Data.Aeson (FromJSON (..), ToJSON, object, toJSON, withObject, (.:), (.=))
import Data.Aeson (FromJSON (..), ToJSON, object, toJSON, withObject, (.:), (.=), eitherDecodeFileStrict', Value (Object))
import qualified Data.ByteString.Base16 as Hex
import qualified Data.ByteString.Lazy as LBS
import Data.String (IsString (fromString))
Expand Down Expand Up @@ -76,6 +80,9 @@ import Ouroboros.Consensus.Util.ResourceRegistry (withRegistry)
import Ouroboros.Network.AnchoredSeq (lookupByMeasure)
import qualified Ouroboros.Network.AnchoredSeq as Seq
import Text.Read (readMaybe)
import qualified Data.Aeson.Types as Aeson
import qualified Data.Aeson.KeyMap as KeyMap
import Data.Aeson.Types (fromJSON)

type StandardBlock = CardanoBlock StandardCrypto

Expand Down Expand Up @@ -241,3 +248,53 @@ getSnapshot db slot = do
pure $ Found $ serialize (toEnum 10) $ shelleyLedgerState state
_other -> pure (Err UnknownStateType)
_other -> pure (Err NotFound)


-- # LedgerDb Configuration
-- We need to read the node's config file to get its LedgerDB options
-- There is no way to parse the node config without pulling in cardano-node code and dependencies,
-- which defeats the purpose of this code.

data LedgerDbConfig = LedgerDbConfig
{ backend :: LedgerDbBackend,
numOfDiskSnapshots :: Int,
queryBatchSize :: Int,
snapshotInterval :: Int
}
deriving (Eq, Show)

data LedgerDbBackend = V2InMemory
deriving (Eq, Show)

newtype LedgerDbConfigError = LedgerDbConfigError String
deriving (Eq, Show)

instance FromJSON LedgerDbConfig where
parseJSON = withObject "LedgerDbConfig" $ \v ->
LedgerDbConfig
<$> v .: "Backend"
<*> v .: "NumOfDiskSnapshots"
<*> v .: "QueryBatchSize"
<*> v .: "SnapshotInterval"

instance FromJSON LedgerDbBackend where
parseJSON "V2InMemory" = pure V2InMemory
parseJSON _ = fail "Unsupported LedgerDbBackend"

parseLedgerDbConfig :: FilePath -> IO (Either LedgerDbConfigError LedgerDbConfig)
parseLedgerDbConfig nodeConfig = do
eitherDecodeFileStrict' nodeConfig >>= \case
Left _ ->
undefined
Right (Object config) ->
case KeyMap.lookup "LedgerDB" config of
Nothing ->
undefined
Just value ->
case fromJSON value of
Aeson.Error err ->
fail err
Aeson.Success v ->
pure (Right v)
Right _ ->
undefined
146 changes: 146 additions & 0 deletions test-data/config/mainnet-config-bp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"AlonzoGenesisFile": "mainnet-alonzo-genesis.json",
"AlonzoGenesisHash": "7e94a15f55d1e82d10f09203fa1d40f8eede58fd8066542cf6566008068ed874",
"ByronGenesisFile": "mainnet-byron-genesis.json",
"ByronGenesisHash": "5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb",
"CheckpointsFile": "mainnet-checkpoints.json",
"CheckpointsFileHash": "3e6dee5bae7acc6d870187e72674b37c929be8c66e62a552cf6a876b1af31ade",
"ConsensusMode": "PraosMode",
"ConwayGenesisFile": "mainnet-conway-genesis.json",
"ConwayGenesisHash": "15a199f895e461ec0ffc6dd4e4028af28a492ab4e806d39cb674c88f7643ef62",
"EnableP2P": true,
"LastKnownBlockVersion-Alt": 0,
"LastKnownBlockVersion-Major": 3,
"LastKnownBlockVersion-Minor": 0,
"LedgerDB": {
"Backend": "V2InMemory",
"NumOfDiskSnapshots": 2,
"QueryBatchSize": 100000,
"SnapshotInterval": 4320
},
"MaxKnownMajorProtocolVersion": 2,
"MinNodeVersion": "10.4.0",
"PeerSharing": false,
"Protocol": "Cardano",
"RequiresNetworkMagic": "RequiresNoMagic",
"ShelleyGenesisFile": "mainnet-shelley-genesis.json",
"ShelleyGenesisHash": "1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81",
"TargetNumberOfKnownPeers": 100,
"TargetNumberOfRootPeers": 100,
"TraceOptionForwarder": {
"connQueueSize": 64,
"disconnQueueSize": 128,
"maxReconnectDelay": 30
},
"TraceOptionMetricsPrefix": "cardano.node.metrics.",
"TraceOptionPeerFrequency": 2000,
"TraceOptionResourceFrequency": 1000,
"TraceOptions": {
"": {
"backends": [
"EKGBackend",
"Forwarder",
"PrometheusSimple suffix 127.0.0.1 12798",
"Stdout HumanFormatColoured"
],
"detail": "DNormal",
"severity": "Notice"
},
"BlockFetch.Client.CompletedBlockFetch": {
"maxFrequency": 2.0
},
"BlockFetch.Decision": {
"severity": "Silence"
},
"ChainDB": {
"severity": "Info"
},
"ChainDB.AddBlockEvent.AddBlockValidation": {
"severity": "Silence"
},
"ChainDB.AddBlockEvent.AddBlockValidation.ValidCandidate": {
"maxFrequency": 2.0
},
"ChainDB.AddBlockEvent.AddedBlockToQueue": {
"maxFrequency": 2.0
},
"ChainDB.AddBlockEvent.AddedBlockToVolatileDB": {
"maxFrequency": 2.0
},
"ChainDB.CopyToImmutableDBEvent.CopiedBlockToImmutableDB": {
"maxFrequency": 2.0
},
"ChainDB.LedgerEvent.Forker": {
"severity": "Silence"
},
"ChainSync.Client": {
"severity": "Warning"
},
"Forge.Loop": {
"severity": "Info"
},
"Forge.StateInfo": {
"severity": "Info"
},
"Mempool": {
"severity": "Silence"
},
"Mempool.AttemptAdd": {
"severity": "Silence"
},
"Mempool.LedgerFound": {
"severity": "Silence"
},
"Mempool.LedgerNotFound": {
"severity": "Silence"
},
"Mempool.SyncNotNeeded": {
"severity": "Silence"
},
"Net.ConnectionManager.Remote": {
"severity": "Info"
},
"Net.ConnectionManager.Remote.ConnectionManagerCounters": {
"severity": "Silence"
},
"Net.ErrorPolicy": {
"severity": "Info"
},
"Net.ErrorPolicy.Local": {
"severity": "Info"
},
"Net.InboundGovernor": {
"severity": "Warning"
},
"Net.InboundGovernor.Remote": {
"severity": "Info"
},
"Net.Mux.Remote": {
"severity": "Info"
},
"Net.PeerSelection": {
"severity": "Silence"
},
"Net.Subscription.DNS": {
"severity": "Info"
},
"Net.Subscription.IP": {
"severity": "Info"
},
"Resources": {
"severity": "Silence"
},
"Startup.DiffusionInit": {
"severity": "Info"
}
},
"TurnOnLogMetrics": true,
"TurnOnLogging": true,
"UseTraceDispatcher": true,
"defaultBackends": [],
"defaultScribes": [],
"minSeverity": "Critical",
"options": {},
"setupBackends": [],
"setupScribes": []
}
15 changes: 14 additions & 1 deletion test/Cardano/Tools/DBServer/OptionsSpec.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module Cardano.Tools.DBServer.OptionsSpec where

import Cardano.Tools.DB
( LedgerDbConfig(..), LedgerDbBackend(..), parseLedgerDbConfig )
import Cardano.Tools.DBServer.Options (Options (..), ServeOptions (..), parseArgs)
import Data.String (IsString (..))
import Network.Wai.Handler.Warp (HostPreference)
import Test.Hspec (Spec, describe, it, shouldBe)
import Test.Hspec (Spec, describe, it, shouldBe, shouldReturn)
import Test.Hspec.QuickCheck (prop)
import Test.QuickCheck (Arbitrary (..), elements, (===))

Expand All @@ -20,6 +22,17 @@ spec = do
show (fromString "*" :: HostPreference) `shouldBe` "HostAny"
show (fromString "0.0.0.0" :: HostPreference) `shouldBe` "Host \"0.0.0.0\""

describe "Config files" $ do
it "Can read configuration file" $ do
let ledgerDbConfig = LedgerDbConfig {
backend = V2InMemory,
numOfDiskSnapshots = 2,
queryBatchSize = 100000,
snapshotInterval = 4320
}
parseLedgerDbConfig "test-data/config/mainnet-config-bp.json" `shouldReturn` Right ledgerDbConfig


newtype SomeHost = SomeHost String
deriving (Show, Eq)

Expand Down