Skip to content

Commit d07d123

Browse files
committed
UTXO-HD 9.0
1 parent 2820a63 commit d07d123

File tree

34 files changed

+1458
-339
lines changed

34 files changed

+1458
-339
lines changed

.github/workflows/haskell.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
env:
4040
# Modify this value to "invalidate" the cabal cache.
41-
CABAL_CACHE_VERSION: "2024-04-24"
41+
CABAL_CACHE_VERSION: "2024-04-28"
4242

4343
concurrency:
4444
group: >
@@ -75,6 +75,19 @@ jobs:
7575
with:
7676
use-sodium-vrf: true # default is true
7777

78+
- name: Linux install lmdb
79+
if: matrix.os == 'ubuntu-latest'
80+
run: sudo apt install liblmdb-dev
81+
82+
- name: Mac install lmdb
83+
if: matrix.os == 'macos-latest'
84+
run: brew install lmdb
85+
86+
- name: Windows install lmdb
87+
if: matrix.os == 'windows-latest'
88+
shell: 'C:/msys64/usr/bin/bash.exe -e {0}'
89+
run: /usr/bin/pacman --noconfirm -S mingw-w64-x86_64-lmdb
90+
7891
- uses: actions/checkout@v4
7992

8093
- name: Cabal update

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
/cabal.project.old
88
configuration/defaults/simpleview/genesis/
99
configuration/defaults/liveview/genesis/
10-
dist-newstyle
11-
dist-newstyle/
12-
dist-profiled/
10+
dist-*
1311
dist/
1412
*~
1513
\#*
@@ -20,12 +18,13 @@ dist/
2018
result*
2119
/launch-*
2220
stack.yaml.lock
21+
.ghcid
2322

2423
/.cache
2524
/db
2625
/db-[0-9]
2726
/logs
28-
/mainnet
27+
/mainnet*
2928
/profile
3029
/launch_*
3130
/state-*

cabal.project

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,32 @@ allow-newer: katip:Win32
6464
-- IMPORTANT
6565
-- Do NOT add more source-repository-package stanzas here unless they are strictly
6666
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.
67+
68+
source-repository-package
69+
type: git
70+
location: https://github.com/IntersectMBO/ouroboros-consensus
71+
tag: 2149c2f2c81089074eb575497e3785b6180f6062
72+
--sha256: sha256-lR9eVgUtcKs4cxajRnnKIhg91vYW2vbs/Hs/XhaVC5w=
73+
subdir:
74+
ouroboros-consensus
75+
ouroboros-consensus-cardano
76+
ouroboros-consensus-diffusion
77+
ouroboros-consensus-protocol
78+
sop-extras
79+
strict-sop-core
80+
81+
source-repository-package
82+
type: git
83+
location: https://github.com/IntersectMBO/cardano-api
84+
tag: 651092c0c06866b7eab4e2261b3f28fbe8a74542
85+
--sha256: sha256-5SEGngIqEjXXBsjiZXWkrwMgYVXajuBCIeCDC4h7r+k=
86+
subdir:
87+
cardano-api
88+
89+
source-repository-package
90+
type: git
91+
location: https://github.com/IntersectMBO/cardano-cli
92+
tag: bd4c66e7921a85d5626b2761e4cd7b41af770b31
93+
--sha256: sha256-5evW3riN5k8ctsA3hUOvnxoVnvw0A+0J4y1c4/bGSK8=
94+
subdir:
95+
cardano-cli

cardano-node/cardano-node.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ library
7070
exposed-modules: Cardano.Node.Configuration.Logging
7171
Cardano.Node.Configuration.NodeAddress
7272
Cardano.Node.Configuration.POM
73+
Cardano.Node.Configuration.LedgerDB
7374
Cardano.Node.Configuration.Socket
7475
Cardano.Node.Configuration.Topology
7576
Cardano.Node.Configuration.TopologyP2P
@@ -204,6 +205,9 @@ library
204205
, stm
205206
, strict-sop-core
206207
, strict-stm
208+
, sop-core
209+
, sop-extras
210+
, text >= 2.0
207211
, time
208212
, trace-dispatcher ^>= 2.5.8
209213
, trace-forward ^>= 2.2.6
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{-# LANGUAGE DerivingStrategies #-}
2+
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
3+
4+
{-# OPTIONS_GHC -Wno-orphans #-}
5+
6+
module Cardano.Node.Configuration.LedgerDB (
7+
LedgerDbSelectorFlag(..)
8+
, Gigabytes
9+
, toBytes
10+
, defaultLMDBLimits
11+
, selectorToArgs
12+
) where
13+
14+
import Ouroboros.Consensus.Storage.LedgerDB.Impl.Args
15+
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Args as V1
16+
import Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB (LMDBLimits (..))
17+
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as V2
18+
import Ouroboros.Consensus.Util.Args
19+
20+
import qualified Data.Aeson.Types as Aeson (FromJSON)
21+
import Data.SOP.Dict
22+
23+
-- | Choose the LedgerDB Backend
24+
--
25+
-- As of UTxO-HD, the LedgerDB now uses either an in-memory backend or LMDB to
26+
-- keep track of differences in the UTxO set.
27+
--
28+
-- - 'InMemory': uses more memory than the minimum requirements but is somewhat
29+
-- faster.
30+
-- - 'LMDB': uses less memory but is somewhat slower.
31+
--
32+
-- See 'Ouroboros.Consnesus.Storage.LedgerDB.OnDisk.BackingStoreSelector'.
33+
data LedgerDbSelectorFlag =
34+
V1LMDB (Maybe Gigabytes) -- ^ A map size can be specified, this is the maximum
35+
-- disk space the LMDB database can fill. If not
36+
-- provided, the default of 16GB will be used.
37+
| V1InMemory
38+
| V2InMemory
39+
deriving (Eq, Show)
40+
41+
-- | A number of gigabytes.
42+
newtype Gigabytes = Gigabytes Int
43+
deriving stock (Eq, Show)
44+
deriving newtype (Read, Aeson.FromJSON)
45+
46+
-- | Convert a number of Gigabytes to the equivalent number of bytes.
47+
toBytes :: Gigabytes -> Int
48+
toBytes (Gigabytes x) = x * 1024 * 1024 * 1024
49+
50+
-- | Recommended settings for the LMDB backing store.
51+
--
52+
-- === @'lmdbMapSize'@
53+
-- The default @'LMDBLimits'@ uses an @'lmdbMapSize'@ of @1024 * 1024 * 1024 * 16@
54+
-- bytes, or 16 Gigabytes. @'lmdbMapSize'@ sets the size of the memory map
55+
-- that is used internally by the LMDB backing store, and is also the
56+
-- maximum size of the on-disk database. 16 GB should be sufficient for the
57+
-- medium term, i.e., it is sufficient until a more performant alternative to
58+
-- the LMDB backing store is implemented, which will probably replace the LMDB
59+
-- backing store altogether.
60+
--
61+
-- Note(jdral): It is recommended not to set the @'lmdbMapSize'@ to a value
62+
-- that is much smaller than 16 GB through manual configuration: the node will
63+
-- die with a fatal error as soon as the database size exceeds the
64+
-- @'lmdbMapSize'@. If this fatal error were to occur, we would expect that
65+
-- the node can continue normal operation if it is restarted with a higher
66+
-- @'lmdbMapSize'@ configured. Nonetheless, this situation should be avoided.
67+
--
68+
-- === @'lmdbMaxDatabases'@
69+
-- The @'lmdbMaxDatabases'@ is set to 10, which means that the LMDB backing
70+
-- store will allow up @<= 10@ internal databases. We say /internal/
71+
-- databases, since they are not exposed outside the backing store interface,
72+
-- such that from the outside view there is just one /logical/ database.
73+
-- Two of these internal databases are reserved for normal operation of the
74+
-- backing store, while the remaining databases will be used to store ledger
75+
-- tables. At the moment, there is at most one ledger table that will be
76+
-- stored in an internal database: the UTxO. Nonetheless, we set
77+
-- @'lmdbMaxDatabases'@ to @10@ in order to future-proof these limits.
78+
--
79+
-- === @'lmdbMaxReaders'@
80+
-- The @'lmdbMaxReaders'@ limit sets the maximum number of threads that can
81+
-- read from the LMDB database. Currently, there should only be a single reader
82+
-- active. Again, we set @'lmdbMaxReaders'@ to @16@ in order to future-proof
83+
-- these limits.
84+
--
85+
-- === References
86+
-- For more information about LMDB limits, one should inspect:
87+
-- * The @lmdb-simple@ and @haskell-lmdb@ forked repositories.
88+
-- * The official LMDB API documentation at
89+
-- <http://www.lmdb.tech/doc/group__mdb.html>.
90+
defaultLMDBLimits :: LMDBLimits
91+
defaultLMDBLimits = LMDBLimits {
92+
lmdbMapSize = 16 * 1024 * 1024 * 1024
93+
, lmdbMaxDatabases = 10
94+
, lmdbMaxReaders = 16
95+
}
96+
97+
selectorToArgs :: LedgerDbSelectorFlag -> V1.FlushFrequency -> V1.QueryBatchSize -> Complete LedgerDbFlavorArgs IO
98+
selectorToArgs V1InMemory a b = LedgerDbFlavorArgsV1 $ V1.V1Args a b V1.InMemoryBackingStoreArgs
99+
selectorToArgs V2InMemory _ _ = LedgerDbFlavorArgsV2 $ V2.V2Args V2.InMemoryHandleArgs
100+
selectorToArgs (V1LMDB l) a b=
101+
LedgerDbFlavorArgsV1
102+
$ V1.V1Args a b
103+
$ V1.LMDBBackingStoreArgs (maybe id (\ll lim -> lim { lmdbMapSize = toBytes ll }) l defaultLMDBLimits) Dict

0 commit comments

Comments
 (0)