Skip to content

Commit

Permalink
UTXO-HD 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Jul 22, 2024
1 parent 2820a63 commit d07d123
Show file tree
Hide file tree
Showing 34 changed files with 1,458 additions and 339 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2024-04-24"
CABAL_CACHE_VERSION: "2024-04-28"

concurrency:
group: >
Expand Down Expand Up @@ -75,6 +75,19 @@ jobs:
with:
use-sodium-vrf: true # default is true

- name: Linux install lmdb
if: matrix.os == 'ubuntu-latest'
run: sudo apt install liblmdb-dev

- name: Mac install lmdb
if: matrix.os == 'macos-latest'
run: brew install lmdb

- name: Windows install lmdb
if: matrix.os == 'windows-latest'
shell: 'C:/msys64/usr/bin/bash.exe -e {0}'
run: /usr/bin/pacman --noconfirm -S mingw-w64-x86_64-lmdb

- uses: actions/checkout@v4

- name: Cabal update
Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
/cabal.project.old
configuration/defaults/simpleview/genesis/
configuration/defaults/liveview/genesis/
dist-newstyle
dist-newstyle/
dist-profiled/
dist-*
dist/
*~
\#*
Expand All @@ -20,12 +18,13 @@ dist/
result*
/launch-*
stack.yaml.lock
.ghcid

/.cache
/db
/db-[0-9]
/logs
/mainnet
/mainnet*
/profile
/launch_*
/state-*
Expand Down
29 changes: 29 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,32 @@ allow-newer: katip:Win32
-- 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
tag: 2149c2f2c81089074eb575497e3785b6180f6062
--sha256: sha256-lR9eVgUtcKs4cxajRnnKIhg91vYW2vbs/Hs/XhaVC5w=
subdir:
ouroboros-consensus
ouroboros-consensus-cardano
ouroboros-consensus-diffusion
ouroboros-consensus-protocol
sop-extras
strict-sop-core

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-api
tag: 651092c0c06866b7eab4e2261b3f28fbe8a74542
--sha256: sha256-5SEGngIqEjXXBsjiZXWkrwMgYVXajuBCIeCDC4h7r+k=
subdir:
cardano-api

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-cli
tag: bd4c66e7921a85d5626b2761e4cd7b41af770b31
--sha256: sha256-5evW3riN5k8ctsA3hUOvnxoVnvw0A+0J4y1c4/bGSK8=
subdir:
cardano-cli
4 changes: 4 additions & 0 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ library
exposed-modules: Cardano.Node.Configuration.Logging
Cardano.Node.Configuration.NodeAddress
Cardano.Node.Configuration.POM
Cardano.Node.Configuration.LedgerDB
Cardano.Node.Configuration.Socket
Cardano.Node.Configuration.Topology
Cardano.Node.Configuration.TopologyP2P
Expand Down Expand Up @@ -204,6 +205,9 @@ library
, stm
, strict-sop-core
, strict-stm
, sop-core
, sop-extras
, text >= 2.0
, time
, trace-dispatcher ^>= 2.5.8
, trace-forward ^>= 2.2.6
Expand Down
103 changes: 103 additions & 0 deletions cardano-node/src/Cardano/Node/Configuration/LedgerDB.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Node.Configuration.LedgerDB (
LedgerDbSelectorFlag(..)
, Gigabytes
, toBytes
, defaultLMDBLimits
, selectorToArgs
) where

import Ouroboros.Consensus.Storage.LedgerDB.Impl.Args
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Args as V1
import Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB (LMDBLimits (..))
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as V2
import Ouroboros.Consensus.Util.Args

import qualified Data.Aeson.Types as Aeson (FromJSON)
import Data.SOP.Dict

-- | Choose the LedgerDB Backend
--
-- As of UTxO-HD, the LedgerDB now uses either an in-memory backend or LMDB to
-- keep track of differences in the UTxO set.
--
-- - 'InMemory': uses more memory than the minimum requirements but is somewhat
-- faster.
-- - 'LMDB': uses less memory but is somewhat slower.
--
-- See 'Ouroboros.Consnesus.Storage.LedgerDB.OnDisk.BackingStoreSelector'.
data LedgerDbSelectorFlag =
V1LMDB (Maybe Gigabytes) -- ^ A map size can be specified, this is the maximum
-- disk space the LMDB database can fill. If not
-- provided, the default of 16GB will be used.
| V1InMemory
| V2InMemory
deriving (Eq, Show)

-- | A number of gigabytes.
newtype Gigabytes = Gigabytes Int
deriving stock (Eq, Show)
deriving newtype (Read, Aeson.FromJSON)

-- | Convert a number of Gigabytes to the equivalent number of bytes.
toBytes :: Gigabytes -> Int
toBytes (Gigabytes x) = x * 1024 * 1024 * 1024

-- | Recommended settings for the LMDB backing store.
--
-- === @'lmdbMapSize'@
-- The default @'LMDBLimits'@ uses an @'lmdbMapSize'@ of @1024 * 1024 * 1024 * 16@
-- bytes, or 16 Gigabytes. @'lmdbMapSize'@ sets the size of the memory map
-- that is used internally by the LMDB backing store, and is also the
-- maximum size of the on-disk database. 16 GB should be sufficient for the
-- medium term, i.e., it is sufficient until a more performant alternative to
-- the LMDB backing store is implemented, which will probably replace the LMDB
-- backing store altogether.
--
-- Note(jdral): It is recommended not to set the @'lmdbMapSize'@ to a value
-- that is much smaller than 16 GB through manual configuration: the node will
-- die with a fatal error as soon as the database size exceeds the
-- @'lmdbMapSize'@. If this fatal error were to occur, we would expect that
-- the node can continue normal operation if it is restarted with a higher
-- @'lmdbMapSize'@ configured. Nonetheless, this situation should be avoided.
--
-- === @'lmdbMaxDatabases'@
-- The @'lmdbMaxDatabases'@ is set to 10, which means that the LMDB backing
-- store will allow up @<= 10@ internal databases. We say /internal/
-- databases, since they are not exposed outside the backing store interface,
-- such that from the outside view there is just one /logical/ database.
-- Two of these internal databases are reserved for normal operation of the
-- backing store, while the remaining databases will be used to store ledger
-- tables. At the moment, there is at most one ledger table that will be
-- stored in an internal database: the UTxO. Nonetheless, we set
-- @'lmdbMaxDatabases'@ to @10@ in order to future-proof these limits.
--
-- === @'lmdbMaxReaders'@
-- The @'lmdbMaxReaders'@ limit sets the maximum number of threads that can
-- read from the LMDB database. Currently, there should only be a single reader
-- active. Again, we set @'lmdbMaxReaders'@ to @16@ in order to future-proof
-- these limits.
--
-- === References
-- For more information about LMDB limits, one should inspect:
-- * The @lmdb-simple@ and @haskell-lmdb@ forked repositories.
-- * The official LMDB API documentation at
-- <http://www.lmdb.tech/doc/group__mdb.html>.
defaultLMDBLimits :: LMDBLimits
defaultLMDBLimits = LMDBLimits {
lmdbMapSize = 16 * 1024 * 1024 * 1024
, lmdbMaxDatabases = 10
, lmdbMaxReaders = 16
}

selectorToArgs :: LedgerDbSelectorFlag -> V1.FlushFrequency -> V1.QueryBatchSize -> Complete LedgerDbFlavorArgs IO
selectorToArgs V1InMemory a b = LedgerDbFlavorArgsV1 $ V1.V1Args a b V1.InMemoryBackingStoreArgs
selectorToArgs V2InMemory _ _ = LedgerDbFlavorArgsV2 $ V2.V2Args V2.InMemoryHandleArgs
selectorToArgs (V1LMDB l) a b=
LedgerDbFlavorArgsV1
$ V1.V1Args a b
$ V1.LMDBBackingStoreArgs (maybe id (\ll lim -> lim { lmdbMapSize = toBytes ll }) l defaultLMDBLimits) Dict
Loading

0 comments on commit d07d123

Please sign in to comment.