Skip to content

Commit aa2f968

Browse files
committed
ChainDB: expose PerasCertDB functionality
1 parent 1a52d8a commit aa2f968

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/API.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import Ouroboros.Consensus.Storage.LedgerDB
9090
, ReadOnlyForker'
9191
, Statistics
9292
)
93+
import Ouroboros.Consensus.Storage.PerasCertDB.API (PerasWeightSnapshot)
9394
import Ouroboros.Consensus.Storage.Serialisation
9495
import Ouroboros.Consensus.Util.CallStack
9596
import Ouroboros.Consensus.Util.IOLike
@@ -386,6 +387,10 @@ data ChainDB m blk = ChainDB
386387
, getStatistics :: m (Maybe Statistics)
387388
-- ^ Get statistics from the LedgerDB, in particular the number of entries
388389
-- in the tables.
390+
, addPerasCert :: PerasCert blk -> m ()
391+
-- ^ TODO
392+
, getPerasWeightSnapshot :: STM m (PerasWeightSnapshot blk)
393+
-- ^ TODO
389394
, closeDB :: m ()
390395
-- ^ Close the ChainDB
391396
--

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ openDBInternal args launchBgTasks = runWithTempRegistry $ do
276276
, getHeaderStateHistory = getEnvSTM h Query.getHeaderStateHistory
277277
, getReadOnlyForkerAtPoint = getEnv2 h Query.getReadOnlyForkerAtPoint
278278
, getStatistics = getEnv h Query.getStatistics
279+
, addPerasCert = getEnv1 h $ \cdb@CDB{..} cert -> do
280+
PerasCertDB.addCert cdbPerasCertDB cert
281+
-- TODO trigger chain selection in a more efficient way
282+
waitChainSelectionPromise =<< ChainSel.triggerChainSelectionAsync cdb
283+
, getPerasWeightSnapshot = getEnvSTM h Query.getPerasWeightSnapshot
279284
}
280285
addBlockTestFuse <- newFuse "test chain selection"
281286
copyTestFuse <- newFuse "test copy to immutable db"

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/Query.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Ouroboros.Consensus.Storage.ChainDB.Impl.Query
1818
, getIsValid
1919
, getMaxSlotNo
2020
, getPastLedger
21+
, getPerasWeightSnapshot
2122
, getReadOnlyForkerAtPoint
2223
, getStatistics
2324
, getTipBlock
@@ -52,6 +53,8 @@ import Ouroboros.Consensus.Storage.ChainDB.Impl.Types
5253
import Ouroboros.Consensus.Storage.ImmutableDB (ImmutableDB)
5354
import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmutableDB
5455
import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB
56+
import qualified Ouroboros.Consensus.Storage.PerasCertDB as PerasCertDB
57+
import Ouroboros.Consensus.Storage.PerasCertDB.API (PerasWeightSnapshot)
5558
import Ouroboros.Consensus.Storage.VolatileDB (VolatileDB)
5659
import qualified Ouroboros.Consensus.Storage.VolatileDB as VolatileDB
5760
import Ouroboros.Consensus.Util (eitherToMaybe)
@@ -262,6 +265,9 @@ getReadOnlyForkerAtPoint CDB{..} = LedgerDB.getReadOnlyForker cdbLedgerDB
262265
getStatistics :: IOLike m => ChainDbEnv m blk -> m (Maybe LedgerDB.Statistics)
263266
getStatistics CDB{..} = LedgerDB.getTipStatistics cdbLedgerDB
264267

268+
getPerasWeightSnapshot :: ChainDbEnv m blk -> STM m (PerasWeightSnapshot blk)
269+
getPerasWeightSnapshot CDB{..} = PerasCertDB.getWeightSnapshot cdbPerasCertDB
270+
265271
{-------------------------------------------------------------------------------
266272
Unifying interface over the immutable DB and volatile DB, but independent
267273
of the ledger DB. These functions therefore do not require the entire

0 commit comments

Comments
 (0)