Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use QueryTip for local state queries #1053

Merged
merged 4 commits into from Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,11 @@ changes.

## [0.13.0] - UNRELEASED

- Added retries for local cardano-node queries. We witnessed these queries to
fail in case of a rollback so we ignore errors and retry for 5 times before
letting the query fail.


- **BREAKING** Changes to `hydra-plutus` scripts.

- Add option to draft a commit tx using inline datums.
Expand Down
18 changes: 15 additions & 3 deletions hydra-node/src/Hydra/Chain/CardanoClient.hs
Expand Up @@ -9,6 +9,7 @@ import Hydra.Prelude
import Hydra.Cardano.Api hiding (Block)

import qualified Cardano.Api.UTxO as UTxO
import Control.Tracer (showTracing, stdoutTracer, traceWith)
import qualified Data.Set as Set
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch)
import Test.QuickCheck (oneof)
Expand Down Expand Up @@ -317,12 +318,23 @@ queryStakePools networkId socket queryPoint =
in runQuery networkId socket queryPoint query >>= throwOnEraMismatch

-- | Throws at least 'QueryException' if query fails.
-- We don't expect the query to fail but this can easily happen in case of a
-- rollback. So what we do is retry 5 times and then give up.
runQuery :: NetworkId -> SocketPath -> QueryPoint -> QueryInMode CardanoMode a -> IO a
runQuery networkId socket point query =
queryNodeLocalState (localNodeConnectInfo networkId socket) maybePoint query >>= \case
Left err -> throwIO $ QueryAcquireException err
Right result -> pure result
let tracer = traceWith $ showTracing stdoutTracer
in go tracer 5
where
go tracer n =
queryNodeLocalState (localNodeConnectInfo networkId socket) maybePoint query >>= \case
Left err ->
if n == (0 :: Int)
then throwIO $ QueryAcquireException err
else do
tracer ("Retrying query... " ++ show n <> " Query: " <> show query)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make our logs non-JSON and hence it can only be temporary / blocks merging of this IMO.

threadDelay 1000000
go tracer (n - 1)
Right result -> pure result
maybePoint =
case point of
QueryTip -> Nothing
Expand Down