Skip to content

Commit 31a1bef

Browse files
authored
LSM trees initial integration (#1572)
# Description Integrate the LSM trees as a new backend for the LedgerDB.
2 parents 6f7a489 + c99ccd4 commit 31a1bef

File tree

39 files changed

+1243
-247
lines changed

39 files changed

+1243
-247
lines changed

cabal.project

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ repository cardano-haskell-packages
1414
-- update either of these.
1515
index-state:
1616
-- Bump this if you need newer packages from Hackage
17-
, hackage.haskell.org 2025-09-11T01:58:40Z
17+
, hackage.haskell.org 2025-09-26T20:57:57Z
1818
-- Bump this if you need newer packages from CHaP
19-
, cardano-haskell-packages 2025-09-24T15:29:30Z
19+
, cardano-haskell-packages 2025-10-01T14:54:25Z
2020

2121
packages:
2222
ouroboros-consensus
@@ -49,3 +49,38 @@ if impl (ghc >= 9.12)
4949
allow-newer:
5050
-- https://github.com/kapralVV/Unique/issues/11
5151
, Unique:hashable
52+
53+
if impl (ghc >= 9.10)
54+
allow-newer:
55+
-- https://github.com/phadej/regression-simple/pull/14
56+
, regression-simple:base
57+
58+
source-repository-package
59+
type: git
60+
location: https://github.com/IntersectMBO/cardano-ledger
61+
tag: fb09078fa55015c881303a2ddb609c024cec258f
62+
--sha256: sha256-9Y9CRiyMn0AWD+C4aNVMaJgrj3FDAYfCX4VrLvtoMaI=
63+
subdir:
64+
eras/allegra/impl
65+
eras/alonzo/impl
66+
eras/alonzo/test-suite
67+
eras/babbage/impl
68+
eras/conway/impl
69+
eras/dijkstra/impl
70+
eras/mary/impl
71+
eras/shelley/impl
72+
eras/shelley/test-suite
73+
eras/shelley-ma/test-suite
74+
libs/cardano-ledger-api
75+
libs/cardano-ledger-core
76+
libs/cardano-ledger-binary
77+
libs/cardano-protocol-tpraos
78+
libs/non-integral
79+
libs/small-steps
80+
libs/cardano-data
81+
libs/set-algebra
82+
libs/vector-map
83+
eras/byron/chain/executable-spec
84+
eras/byron/ledger/executable-spec
85+
eras/byron/ledger/impl
86+
eras/byron/crypto

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/haskell.nix

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,13 @@ in
8989
nativeBuildInputs = [
9090
final.fd
9191
final.cabal-docspec
92-
(hsPkgs.ghcWithPackages
93-
(ps: [ ps.latex-svg-image ] ++ lib.filter (p: p ? components.library)
94-
(lib.attrValues (haskell-nix.haskellLib.selectProjectPackages ps))))
92+
(hsPkgs.shellFor {
93+
withHoogle = false;
94+
exactDeps = true;
95+
packages = _: [ ];
96+
additional = (ps: [ ps.latex-svg-image ] ++ lib.filter (p: p ? components.library)
97+
(lib.attrValues (haskell-nix.haskellLib.selectProjectPackages ps)));
98+
}).ghc
9599
final.texliveFull
96100
];
97101

ouroboros-consensus-cardano/app/DBAnalyser/Parsers.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ parseDBAnalyserConfig =
4646
[ flag' V1InMem $
4747
mconcat
4848
[ long "v1-in-mem"
49-
, help "use v1 in-memory backing store"
49+
, help "use v1 in-memory backing store [deprecated]"
5050
]
5151
, flag' V1LMDB $
5252
mconcat
@@ -55,9 +55,14 @@ parseDBAnalyserConfig =
5555
]
5656
, flag' V2InMem $
5757
mconcat
58-
[ long "v2-in-mem"
58+
[ long "in-mem"
5959
, help "use v2 in-memory backend"
6060
]
61+
, flag' V2LSM $
62+
mconcat
63+
[ long "lsm"
64+
, help "use v2 LSM backend"
65+
]
6166
]
6267

6368
parseSelectDB :: Parser SelectDB

ouroboros-consensus-cardano/app/snapshot-converter.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB
3838
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.DbChangelog as V1
3939
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Lock as V1
4040
import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Snapshots as V1
41+
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory as InMemory
4142
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory as V2
4243
import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq as V2
4344
import Ouroboros.Consensus.Util.CRC
@@ -199,7 +200,7 @@ load config@Config{inpath = pathToDiskSnapshot -> Just (fs@(SomeHasFS hasFS), pa
199200
checkSnapshotFileStructure Mem path fs
200201
(ls, _) <- withExceptT SnapshotError $ V2.loadSnapshot nullTracer rr ccfg fs ds
201202
let h = V2.currentHandle ls
202-
(V2.state h,) <$> Trans.lift (V2.readAll (V2.tables h))
203+
(V2.state h,) <$> Trans.lift (V2.readAll (V2.tables h) (V2.state h))
203204
LMDB -> do
204205
checkSnapshotFileStructure LMDB path fs
205206
((dbch, k, bstore), _) <-
@@ -240,7 +241,7 @@ store config@Config{outpath = pathToDiskSnapshot -> Just (fs@(SomeHasFS hasFS),
240241
Mem -> do
241242
lseq <- V2.empty state tbs $ V2.newInMemoryLedgerTablesHandle nullTracer fs
242243
let h = V2.currentHandle lseq
243-
Monad.void $ V2.implTakeSnapshot ccfg nullTracer fs suffix h
244+
Monad.void $ InMemory.implTakeSnapshot ccfg nullTracer fs suffix h
244245
LMDB -> do
245246
chlog <- newTVarIO (V1.empty state)
246247
lock <- V1.mkLedgerDBLock
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Patch
10+
11+
- A bullet item for the Patch category.
12+
13+
-->
14+
<!--
15+
### Non-Breaking
16+
17+
- A bullet item for the Non-Breaking category.
18+
19+
-->
20+
<!--
21+
### Breaking
22+
23+
- A bullet item for the Breaking category.
24+
25+
-->
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
### Patch
9+
10+
- Bump ledger dependencies:
11+
- `cardano-ledger-allegra` 1.8 → 1.9
12+
- `cardano-ledger-alonzo` 1.14 → 1.15
13+
- `cardano-ledger-api` 1.12 → 1.13
14+
- `cardano-ledger-conway` 1.20 → 1.21
15+
- `cardano-ledger-core` 1.18 → 1.19
16+
- `cardano-ledger-dijkstra` 0.1 → 0.2
17+
18+
<!--
19+
### Non-Breaking
20+
21+
- A bullet item for the Non-Breaking category.
22+
23+
-->
24+
<!--
25+
### Breaking
26+
27+
- A bullet item for the Breaking category.
28+
29+
-->

ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ library
139139
cardano-crypto,
140140
cardano-crypto-class ^>=2.2,
141141
cardano-crypto-wrapper,
142-
cardano-ledger-allegra ^>=1.8,
143-
cardano-ledger-alonzo ^>=1.14,
144-
cardano-ledger-api ^>=1.12,
142+
cardano-ledger-allegra ^>=1.9,
143+
cardano-ledger-alonzo ^>=1.15,
144+
cardano-ledger-api ^>=1.13,
145145
cardano-ledger-babbage ^>=1.12,
146146
cardano-ledger-binary ^>=1.7,
147147
cardano-ledger-byron ^>=1.2,
148-
cardano-ledger-conway ^>=1.20,
149-
cardano-ledger-core ^>=1.18,
150-
cardano-ledger-dijkstra ^>=0.1,
148+
cardano-ledger-conway ^>=1.21,
149+
cardano-ledger-core ^>=1.19,
150+
cardano-ledger-dijkstra ^>=0.2,
151151
cardano-ledger-mary ^>=1.9,
152152
cardano-ledger-shelley ^>=1.17,
153153
cardano-prelude,
@@ -593,6 +593,7 @@ library unstable-cardano-tools
593593
ouroboros-network-api,
594594
ouroboros-network-framework ^>=0.19,
595595
ouroboros-network-protocols,
596+
random,
596597
resource-registry,
597598
singletons,
598599
sop-core,

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Block.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ mkShelleyBlock ::
165165
mkShelleyBlock raw =
166166
ShelleyBlock
167167
{ shelleyBlockRaw = raw
168-
, shelleyBlockHeaderHash = pHeaderHash $ SL.bheader raw
168+
, shelleyBlockHeaderHash = pHeaderHash $ SL.blockHeader raw
169169
}
170170

171171
class
@@ -200,7 +200,7 @@ instance
200200
instance ShelleyCompatible proto era => GetHeader (ShelleyBlock proto era) where
201201
getHeader (ShelleyBlock rawBlk hdrHash) =
202202
ShelleyHeader
203-
{ shelleyHeaderRaw = SL.bheader rawBlk
203+
{ shelleyHeaderRaw = SL.blockHeader rawBlk
204204
, shelleyHeaderHash = hdrHash
205205
}
206206

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Ledger.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ applyHelper f cfg blk stBefore = do
629629
globals
630630
tickedShelleyLedgerState
631631
( let b = shelleyBlockRaw blk
632-
h' = mkHeaderView (SL.bheader b)
633-
in SL.Block h' (SL.bbody b)
632+
h' = mkHeaderView (SL.blockHeader b)
633+
in SL.Block h' (SL.blockBody b)
634634
)
635635

636636
let track ::

0 commit comments

Comments
 (0)