From fe138cca759b973c2b67c0b23cf5982e7d3ff4f3 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Mon, 20 Jan 2020 10:58:39 +0100 Subject: [PATCH 1/2] Log roll back attempts in pools monitoring When rolling back, we currently only log monitoring restarts, which can be somewhat confusing when done several times in a row: [pools-engine] Monitoring stake pools. Currently at f4260343-[1158372.5#220] [pools-engine] Monitoring stake pools. Currently at 20bd31a4-[1158372.1#216] [pools-engine] Monitoring stake pools. Currently at 437a7400-[1158371.6#212] [pools-engine] Monitoring stake pools. Currently at 5c874264-[1158371.2#208] Although this is typical of rollbacks, it's better to mention it explicitely to better track what the system is doing. --- lib/core/src/Cardano/Pool/Metrics.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/core/src/Cardano/Pool/Metrics.hs b/lib/core/src/Cardano/Pool/Metrics.hs index 25512e803f5..5cf932e859c 100644 --- a/lib/core/src/Cardano/Pool/Metrics.hs +++ b/lib/core/src/Cardano/Pool/Metrics.hs @@ -73,6 +73,7 @@ import Cardano.Wallet.Primitive.Types , PoolId , PoolOwner (..) , PoolRegistrationCertificate (..) + , SlotId ) import Control.Arrow ( first ) @@ -161,6 +162,7 @@ monitorStakePools tr nl db@DBLayer{..} = do follow nl trFollow cursor forward header >>= \case Nothing -> pure () Just point -> do + traceWith tr $ MsgRollingBackTo point liftIO . atomically $ rollbackTo point monitorStakePools tr nl db where @@ -514,6 +516,7 @@ data StakePoolLog | MsgFollow FollowLog | MsgStakeDistribution EpochNo | MsgStakePoolRegistration PoolRegistrationCertificate + | MsgRollingBackTo SlotId | MsgApplyError ErrMonitorStakePools deriving (Show, Eq) @@ -531,6 +534,7 @@ instance DefineSeverity StakePoolLog where MsgFollow msg -> defineSeverity msg MsgStakeDistribution _ -> Info MsgStakePoolRegistration _ -> Info + MsgRollingBackTo _ -> Info MsgApplyError e -> case e of ErrMonitorStakePoolsNetworkUnavailable{} -> Notice ErrMonitorStakePoolsNetworkTip{} -> Notice @@ -568,6 +572,8 @@ instance ToText StakePoolLog where "Writing stake-distribution for epoch " <> pretty ep MsgStakePoolRegistration pool -> "Discovered stake pool registration: " <> pretty pool + MsgRollingBackTo point -> + "Rolling back to " <> pretty point MsgApplyError e -> case e of ErrMonitorStakePoolsNetworkUnavailable{} -> "Network is not available." From 76bf85aa68403760a9e77e2df6de96322a5a1fbc Mon Sep 17 00:00:00 2001 From: KtorZ Date: Mon, 20 Jan 2020 11:34:43 +0100 Subject: [PATCH 2/2] increase network layer observation window's length --- lib/core/src/Cardano/Pool/Metrics.hs | 2 +- .../src/Cardano/Wallet/Jormungandr/Network.hs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/core/src/Cardano/Pool/Metrics.hs b/lib/core/src/Cardano/Pool/Metrics.hs index 5cf932e859c..95172128ee6 100644 --- a/lib/core/src/Cardano/Pool/Metrics.hs +++ b/lib/core/src/Cardano/Pool/Metrics.hs @@ -177,7 +177,7 @@ monitorStakePools tr nl db@DBLayer{..} = do readPoolRegistration poolId >>= \case Nothing -> putPoolRegistration sl0 r Just{} -> pure () - readPoolProductionCursor k + readPoolProductionCursor (max 100 k) forward :: NonEmpty Block diff --git a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs index 28e47fc8693..441ee5a82e2 100644 --- a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs +++ b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs @@ -301,9 +301,16 @@ mkRawNetworkLayer (block0, bp) batchSize st j = NetworkLayer _getAccountBalance } where - -- security parameter, the maximum number of unstable blocks + -- security parameter, the maximum number of unstable blocks. + -- When @k@ is too small, we use an arbitrary bigger (although still + -- reasonably sized) value to make sure that our observation window is + -- big-enough. This allows for re-syncing faster when connecting to a + -- network after a long period of time where the node might have drifted + -- completely. In theory, nodes can't switch to chains that are longer than + -- @k@ but in practice with Jörmungandr, nodes can make jumps longer than + -- that. k :: Quantity "block" Word32 - k = getEpochStability bp + k = (max 100) <$> getEpochStability bp genesis :: Hash "Genesis" genesis = getGenesisBlockHash bp