Skip to content

Commit

Permalink
Limit pool garbage collection to once per epoch.
Browse files Browse the repository at this point in the history
Before this change, it was possible for garbage collection to happen
more than once per epoch, as any rollback would recreate the mutable
reference to the latest garbage collection epoch, causing the latest
garbage collection epoch value to be reset to zero.

This change adjusts the reference creation mechanism so that it only
happens once, on startup.
  • Loading branch information
jonathanknowles committed Sep 21, 2020
1 parent 770da72 commit bbd0cd6
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs
Expand Up @@ -463,19 +463,26 @@ monitorStakePools
-> NetworkLayer IO t (CardanoBlock sc)
-> DBLayer IO
-> IO ()
monitorStakePools tr gp nl db@DBLayer{..} = do
latestGarbageCollectionEpochRef <- mkLatestGarbageCollectionEpochRef
let forwardHandler = forward latestGarbageCollectionEpochRef
cursor <- initCursor
traceWith tr $ MsgStartMonitoring cursor
follow nl (contramap MsgFollow tr) cursor forwardHandler getHeader >>= \case
FollowInterrupted -> traceWith tr MsgHaltMonitoring
FollowFailure -> traceWith tr MsgCrashMonitoring
FollowRollback point -> do
traceWith tr $ MsgRollingBackTo point
liftIO . atomically $ rollbackTo point
monitorStakePools tr gp nl db
monitorStakePools tr gp nl DBLayer{..} =
monitor =<< mkLatestGarbageCollectionEpochRef
where
monitor latestGarbageCollectionEpochRef = loop
where
loop = do
cursor <- initCursor
traceWith tr $ MsgStartMonitoring cursor
let followTrace = contramap MsgFollow tr
let forwardHandler = forward latestGarbageCollectionEpochRef
follow nl followTrace cursor forwardHandler getHeader >>= \case
FollowInterrupted ->
traceWith tr MsgHaltMonitoring
FollowFailure ->
traceWith tr MsgCrashMonitoring
FollowRollback point -> do
traceWith tr $ MsgRollingBackTo point
liftIO . atomically $ rollbackTo point
loop

GenesisParameters
{ getGenesisBlockHash
, getEpochStability
Expand Down

0 comments on commit bbd0cd6

Please sign in to comment.