Skip to content

Commit

Permalink
Write per-slot pool delegation certificates to the database.
Browse files Browse the repository at this point in the history
When restoring blocks.

Additionally, write a log entry for each certificate discovered.
  • Loading branch information
jonathanknowles committed Nov 28, 2019
1 parent 931bc9e commit 66a085d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,13 @@ restoreBlocks ctx wid blocks nodeTip = db & \DBLayer{..} -> do
<*> withNoSuchWallet wid (readWalletMeta $ PrimaryKey wid)
let bp = blockchainParameters cp
let (filteredBlocks, cps) = NE.unzip $ applyBlocks @s blocks cp
let slotPoolDelegations =
[ (slotId, poolId)
| let slots = view #slotId . view #header <$> blocks
, let delegations = view #delegations <$> filteredBlocks
, (slotId, poolIds) <- NE.toList $ NE.zip slots delegations
, poolId <- poolIds
]
let txs = fold $ view #transactions <$> filteredBlocks
let k = bp ^. #getEpochStability
let localTip = currentTip $ NE.last cps
Expand All @@ -583,6 +590,11 @@ restoreBlocks ctx wid blocks nodeTip = db & \DBLayer{..} -> do
liftIO $ logCheckpoint cp'
putCheckpoint (PrimaryKey wid) cp'

mapExceptT atomically $
forM_ slotPoolDelegations $ \delegation@(slotId, poolId) -> do
liftIO $ logDelegation delegation
putDelegationCertificate (PrimaryKey wid) poolId slotId

mapExceptT atomically $ do
liftIO $ logCheckpoint cp
putCheckpoint (PrimaryKey wid) (NE.last cps)
Expand Down Expand Up @@ -610,6 +622,14 @@ restoreBlocks ctx wid blocks nodeTip = db & \DBLayer{..} -> do
logCheckpoint cp = logInfo tr $
"Creating checkpoint at " <> pretty (currentTip cp)

logDelegation :: (SlotId, PoolId) -> IO ()
logDelegation (slotId, poolId) = logInfo tr $ mconcat
[ "Discovered delegation to pool "
, pretty poolId
, " within slot "
, pretty slotId
]

-- | Remove an existing wallet. Note that there's no particular work to
-- be done regarding the restoration worker as it will simply terminate
-- on the next tick when noticing that the corresponding wallet is gone.
Expand Down

0 comments on commit 66a085d

Please sign in to comment.