@@ -30,6 +30,7 @@ module Cardano.DbSync.Config.Types (
3030 TxOutConfig (.. ),
3131 UseTxOutAddress (.. ),
3232 ForceTxIn (.. ),
33+ LedgerBackend (.. ),
3334 LedgerInsertConfig (.. ),
3435 ShelleyInsertConfig (.. ),
3536 RewardsConfig (.. ),
@@ -150,6 +151,7 @@ data SyncNodeConfig = SyncNodeConfig
150151 , dncInsertOptions :: ! SyncInsertOptions
151152 , dncIpfsGateway :: [Text ]
152153 , dncSnapshotInterval :: ! SnapshotIntervalConfig
154+ , dncLedgerBackend :: ! LedgerBackend
153155 }
154156
155157data SyncPreConfig = SyncPreConfig
@@ -163,6 +165,7 @@ data SyncPreConfig = SyncPreConfig
163165 , pcInsertConfig :: ! SyncInsertConfig
164166 , pcIpfsGateway :: ! [Text ]
165167 , pcSnapshotInterval :: ! SnapshotIntervalConfig
168+ , pcLedgerBackend :: ! LedgerBackend
166169 }
167170 deriving (Show )
168171
@@ -224,6 +227,20 @@ newtype UseTxOutAddress = UseTxOutAddress {unUseTxOutAddress :: Bool}
224227 deriving (Eq , Show )
225228 deriving newtype (ToJSON , FromJSON )
226229
230+ -- | Choose the backend for storing ledger tables (UTxO set).
231+ -- 'LedgerBackendInMemory' keeps everything in RAM (current default).
232+ -- 'LedgerBackendLSM' uses LSM trees on disk for lower memory usage.
233+ data LedgerBackend
234+ = LedgerBackendInMemory
235+ | LedgerBackendLSM (Maybe FilePath )
236+ deriving (Eq , Show )
237+
238+ instance FromJSON LedgerBackend where
239+ parseJSON = Aeson. withText " LedgerBackend" $ \ case
240+ " inmemory" -> pure LedgerBackendInMemory
241+ " lsm" -> pure (LedgerBackendLSM Nothing )
242+ other -> fail $ " unexpected ledger_backend: " <> show other <> " . Expected \" inmemory\" or \" lsm\" ."
243+
227244data LedgerInsertConfig
228245 = LedgerEnable
229246 | LedgerDisable
@@ -423,6 +440,7 @@ parseGenSyncNodeConfig o =
423440 <*> o .:? " insert_options" .!= def
424441 <*> o .:? " ipfs_gateway" .!= [" https://ipfs.io/ipfs" ]
425442 <*> o .:? " snapshot_interval" .!= def
443+ <*> o .:? " ledger_backend" .!= LedgerBackendInMemory
426444
427445instance FromJSON SyncProtocol where
428446 parseJSON o =
0 commit comments