Skip to content

Commit

Permalink
Only log reward balances when they change
Browse files Browse the repository at this point in the history
E.g.:
[cardano-wallet.network:Info:860] [2021-03-30 11:52:36.01 UTC] Reward observer: New values: {c72a6827: 0.000000, eb220e40: 1000000.000000, fb3c13a2: 1000000.000000}
  • Loading branch information
Anviking committed Apr 15, 2021
1 parent af6498b commit d4f85e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/shelley/src/Cardano/Wallet/Shelley/Network.hs
Expand Up @@ -841,6 +841,7 @@ newRewardBalanceFetcher tr readNodeTip queryRewardQ = do
data ObserverLog key value
= MsgWillFetch (Set key)
| MsgDidFetch (Map key value)
| MsgDidChange (Map key value)
| MsgAddedObserver key
| MsgRemovedObserver key
deriving (Eq, Show)
Expand All @@ -855,6 +856,10 @@ instance (Ord key, Buildable key, Buildable value)
[ "Did fetch values "
, fmt $ mapF m
]
toText (MsgDidChange m) = mconcat
[ "New values: "
, fmt $ mapF m
]
toText (MsgAddedObserver key) = mconcat
[ "Started observing values for key "
, pretty key
Expand All @@ -876,7 +881,7 @@ instance (Ord key, Buildable key, Buildable value)
--
-- If it returns @Just values@, the cache will be set to @values@.
newObserver
:: forall m key value env. (MonadSTM m, Ord key)
:: forall m key value env. (MonadSTM m, Ord key, Eq value)
=> Tracer m (ObserverLog key value)
-> (env -> Set key -> m (Maybe (Map key value)))
-> m (Observer m key value, env -> m ())
Expand Down Expand Up @@ -914,13 +919,16 @@ newObserver tr fetch = do
-> m ()
refresh cacheVar observedKeysVar env = do
keys <- atomically $ readTVar observedKeysVar
oldValues <- atomically $ readTVar cacheVar
traceWith tr $ MsgWillFetch keys
mvalues <- fetch env keys

case mvalues of
Nothing -> pure ()
Just values -> do
traceWith tr $ MsgDidFetch values
when (oldValues /= values) $
traceWith tr $ MsgDidChange values
atomically $ writeTVar cacheVar values

-- | Return a function to run an action only if its single parameter has changed
Expand Down Expand Up @@ -1206,7 +1214,7 @@ instance ToText NetworkLayerLog where
MsgInterpreter interpreter ->
"Updated the history interpreter: " <> T.pack (show interpreter)
MsgInterpreterLog msg -> toText msg
MsgObserverLog msg -> toText msg
MsgObserverLog msg -> "Reward observer: " <> toText msg

instance HasPrivacyAnnotation NetworkLayerLog
instance HasSeverityAnnotation NetworkLayerLog where
Expand All @@ -1226,7 +1234,6 @@ instance HasSeverityAnnotation NetworkLayerLog where
MsgProtocolParameters{} -> Info
MsgLocalStateQueryError{} -> Error
MsgLocalStateQueryEraMismatch{} -> Debug
MsgGetRewardAccountBalance{} -> Info
MsgAccountDelegationAndRewards{} -> Info
MsgDestroyCursor{} -> Notice
MsgWillQueryRewardsForStake{} -> Info
Expand All @@ -1240,6 +1247,8 @@ instance HasSeverityAnnotation NetworkLayerLog where
| isSlowQuery qry dt -> Notice
| otherwise -> Debug
MsgInterpreterLog msg -> getSeverityAnnotation msg
MsgGetRewardAccountBalance{} -> Debug
MsgObserverLog (MsgDidChange _) -> Info
MsgObserverLog{} -> Debug


Expand Down
Expand Up @@ -128,6 +128,7 @@ spec = describe "NetworkLayer regression test #1708" $ do
[ MsgAddedObserver k
, MsgWillFetch $ Set.singleton k
, MsgDidFetch $ Map.singleton k v
, MsgDidChange $ Map.singleton k v
]

describe "calling startObserving a second time" $ do
Expand Down

0 comments on commit d4f85e7

Please sign in to comment.