From 66038f42285c757c0bfcd5ed3d8cdf72fadc21b4 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 2 Jul 2020 08:43:37 +0000 Subject: [PATCH] Assign precedence values to pool certificates extracted from Shelley blocks. --- .../src/Cardano/Wallet/Shelley/Pools.hs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs index d5fc060dfe9..7e92c06a141 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs @@ -53,7 +53,6 @@ import Cardano.Wallet.Primitive.Types , PoolId , PoolRegistrationCertificate (..) , PoolRetirementCertificate (..) - , Precedence (..) , ProtocolParameters , SlotId , SlotLength (..) @@ -362,13 +361,26 @@ monitorStakePools tr gp nl db@DBLayer{..} = do liftIO $ traceWith tr $ MsgErrProduction e Right () -> pure () - forM_ registrations $ \case - Registration cert -> do + + -- A Shelley block can contain multiple certificates relating to + -- the same pool. + -- + -- The order in which certificates appear within a block determines + -- their precedence relative to one another. + -- + -- Certificates that appear later in a block have higher precedence + -- than certificates that appear earlier. + -- + -- TODO: Insert link to the specification to justify this decision. + -- + let precedences = [minBound ..] + forM_ (registrations `zip` precedences) $ \case + (Registration cert, precedence) -> do liftIO $ traceWith tr $ MsgStakePoolRegistration cert - putPoolRegistration (slot, minBound) cert - Retirement cert -> do + putPoolRegistration (slot, precedence) cert + (Retirement cert, precedence) -> do liftIO $ traceWith tr $ MsgStakePoolRetirement cert - putPoolRetirement (slot, minBound) cert + putPoolRetirement (slot, precedence) cert pure Continue monitorMetadata