Skip to content

Commit

Permalink
PLT-1311 Add JSON-RPC querying of the stake pool delegation (SPD) by …
Browse files Browse the repository at this point in the history
…epoch in `marconi-sidechain`.

* Add indexing and JSON-RPC querying of the SPD by epoch in `marconi-sidechain`.

* Added golden test for JSON response of stake pool delegation by
  epoch

* Fixed resuming of Utxo indexer to include *all* possible chain points,
  not only the latest ones.

* Updated README of `marconi-sidechain` to include an example of request
  and response for the JSON-RPC server on that specific endpoint.
  • Loading branch information
koslambrou committed Mar 21, 2023
1 parent e1be99e commit a643fcd
Show file tree
Hide file tree
Showing 24 changed files with 579 additions and 251 deletions.
1 change: 1 addition & 0 deletions marconi-chain-index/marconi-chain-index.cabal
Expand Up @@ -61,6 +61,7 @@ library
Marconi.ChainIndex.Node.Client.GenesisConfig
Marconi.ChainIndex.Orphans
Marconi.ChainIndex.Types
Marconi.ChainIndex.Utils

--------------------
-- Local components
Expand Down
29 changes: 19 additions & 10 deletions marconi-chain-index/src/Marconi/ChainIndex/Indexers.hs
Expand Up @@ -28,7 +28,7 @@ import Control.Concurrent.STM.TChan (TChan, dupTChan, newBroadcastTChanIO, readT
import Control.Exception (catch)
import Control.Lens (view)
import Control.Lens.Operators ((^.))
import Control.Monad (forever, unless, void)
import Control.Monad (forever, void)
import Control.Monad.Trans.Except (runExceptT)
import Data.List (findIndex, foldl1', intersect)
import Data.Map (Map)
Expand Down Expand Up @@ -265,7 +265,7 @@ scriptTxWorker onInsert coordinator path = do

epochStakepoolSizeWorker_
:: FilePath
-> (Storable.StorableEvent EpochSPDHandle -> IO ())
-> ((Storable.State EpochSPDHandle, Storable.StorableEvent EpochSPDHandle) -> IO ())
-> Word64 -- Security param
-> Coordinator
-> TChan (ChainSyncEvent (BlockInMode CardanoMode))
Expand Down Expand Up @@ -295,7 +295,7 @@ epochStakepoolSizeWorker_
chainSyncEvent <- atomically $ readTChan ch

newLedgerState <- case chainSyncEvent of
RollForward blockInMode@(C.BlockInMode (C.Block (C.BlockHeader slotNo bh bn) _) _) _ct -> do
RollForward blockInMode@(C.BlockInMode (C.Block (C.BlockHeader slotNo bh bn) _) _) chainTip -> do
-- Compute new LedgerState given block and old LedgerState
let newLedgerState =
O.lrResult
Expand All @@ -305,12 +305,21 @@ epochStakepoolSizeWorker_
currentLedgerState
let newEpochNo = EpochSPD.getEpochNo newLedgerState

-- If the currentLedgerState has a different epochNo than the newLedgerState, this
-- means that we need to index currentLedgerState
unless (maybeEpochNo == newEpochNo) $ do
let storableEvent = EpochSPD.toStorableEvent currentLedgerState slotNo bh bn
modifyMVar_ indexerMVar $ Storable.insert storableEvent
onInsert storableEvent
-- If the block is rollbackable, we always store the LedgerState. If the block is
-- immutable, we only store it right before a new epoch.
-- let isLastEventOfEpoch = maybeEpochNo /= newEpochNo
let isLastEventOfEpoch = maybeEpochNo /= newEpochNo
let storableEvent =
EpochSPD.toStorableEvent
currentLedgerState
slotNo
bh
bn
chainTip
securityParam
isLastEventOfEpoch
newIndexer <- modifyMVar indexerMVar $ \idx -> fmap (\newIdx -> (newIdx, newIdx)) $ Storable.insert storableEvent idx
onInsert (newIndexer, storableEvent) -- refresh the query STM/CPS with new storage pointers/counters state

pure newLedgerState

Expand Down Expand Up @@ -341,7 +350,7 @@ epochStakepoolSizeWorker_

epochStakepoolSizeWorker
:: FilePath
-> (Storable.StorableEvent EpochSPDHandle -> IO ())
-> ((Storable.State EpochSPDHandle, Storable.StorableEvent EpochSPDHandle) -> IO ())
-> Worker
epochStakepoolSizeWorker nodeConfigPath onInsert coordinator path = do
workerChannel <- atomically . dupTChan $ _channel coordinator
Expand Down

0 comments on commit a643fcd

Please sign in to comment.