Skip to content

Fix queryPoolFetchRetry #1353

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

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cardano-db-sync/app/test-http-get-json-metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ queryTestOfflineData = do
)
pure . organise $ map (convert . unValue4) res
where
convert :: (Text, Text, ByteString, PoolHashId) -> (PoolHashId, TestOffline)
convert :: (Text, PoolUrl, ByteString, PoolHashId) -> (PoolHashId, TestOffline)
convert (tname, url, hash, poolId) =
( poolId
, TestOffline
{ toTicker = tname
, toUrl = PoolUrl url
, toUrl = url
, toHash = PoolMetaHash hash
}
)
Expand Down
4 changes: 2 additions & 2 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Cardano.Api.Shelley (
import Cardano.BM.Trace (Trace, logDebug, logInfo, logWarning)
import Cardano.Crypto.Hash (hashToBytes)
import qualified Cardano.Crypto.Hashing as Crypto
import Cardano.Db (DbLovelace (..), DbWord64 (..))
import Cardano.Db (DbLovelace (..), DbWord64 (..), PoolUrl (..))
import qualified Cardano.Db as DB
import Cardano.DbSync.Api
import Cardano.DbSync.Cache
Expand Down Expand Up @@ -540,7 +540,7 @@ insertMetaDataRef poolId txId md =
lift . DB.insertPoolMetadataRef $
DB.PoolMetadataRef
{ DB.poolMetadataRefPoolId = poolId
, DB.poolMetadataRefUrl = Ledger.urlToText (Shelley._poolMDUrl md)
, DB.poolMetadataRefUrl = PoolUrl $ Ledger.urlToText (Shelley._poolMDUrl md)
, DB.poolMetadataRefHash = Shelley._poolMDHash md
, DB.poolMetadataRefRegisteredTxId = txId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Network.HTTP.Client (HttpException (..))
import qualified Network.HTTP.Client as Http
import qualified Network.HTTP.Types as Http

-- |Fetch error for the HTTP client fetching the pool offline metadata.
-- | Fetch error for the HTTP client fetching the pool offline metadata.
data FetchError
= FEHashMismatch !PoolUrl !Text !Text
| FEDataTooLong !PoolUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Cardano.DbSync.Era.Shelley.Offline.Query (
) where

import Cardano.Db (
EntityField (PoolHashId, PoolHashView, PoolMetadataRefHash, PoolMetadataRefId, PoolMetadataRefPoolId, PoolMetadataRefUrl, PoolOfflineDataPmrId, PoolOfflineFetchErrorFetchTime, PoolOfflineFetchErrorId, PoolOfflineFetchErrorPmrId, PoolOfflineFetchErrorPoolId, PoolOfflineFetchErrorRetryCount),
EntityField (PoolHashId, PoolMetadataRefHash, PoolMetadataRefId, PoolMetadataRefPoolId, PoolMetadataRefUrl, PoolOfflineDataPmrId, PoolOfflineFetchErrorFetchTime, PoolOfflineFetchErrorId, PoolOfflineFetchErrorPmrId, PoolOfflineFetchErrorPoolId, PoolOfflineFetchErrorRetryCount),
PoolHash,
PoolHashId,
PoolMetaHash (PoolMetaHash),
Expand All @@ -15,7 +15,7 @@ import Cardano.Db (
PoolOfflineData,
PoolOfflineFetchError,
PoolOfflineFetchErrorId,
PoolUrl (PoolUrl),
PoolUrl,
)
import Cardano.DbSync.Era.Shelley.Offline.FetchQueue (newRetry, retryAgain)
import Cardano.DbSync.Types (PoolFetchRetry (..))
Expand Down Expand Up @@ -92,13 +92,13 @@ queryNewPoolFetch now = do
pure $ max_ (pmr ^. PoolMetadataRefId)

convert ::
(Value PoolHashId, Value PoolMetadataRefId, Value Text, Value ByteString) ->
(Value PoolHashId, Value PoolMetadataRefId, Value PoolUrl, Value ByteString) ->
PoolFetchRetry
convert (Value phId, Value pmrId, Value url, Value pmh) =
PoolFetchRetry
{ pfrPoolHashId = phId
, pfrReferenceId = pmrId
, pfrPoolUrl = PoolUrl url
, pfrPoolUrl = url
, pfrPoolMDHash = Just $ PoolMetaHash pmh
, pfrRetry = newRetry now
}
Expand All @@ -120,7 +120,7 @@ queryPoolFetchRetry _now = do
pure
( pofe ^. PoolOfflineFetchErrorFetchTime
, pofe ^. PoolOfflineFetchErrorPmrId
, ph ^. PoolHashView
, pmr ^. PoolMetadataRefUrl
, pmr ^. PoolMetadataRefHash
, ph ^. PoolHashId
, pofe ^. PoolOfflineFetchErrorRetryCount
Expand All @@ -138,13 +138,13 @@ queryPoolFetchRetry _now = do
pure $ max_ (pofe ^. PoolOfflineFetchErrorId)

convert ::
(Value UTCTime, Value PoolMetadataRefId, Value Text, Value ByteString, Value PoolHashId, Value Word) ->
(Value UTCTime, Value PoolMetadataRefId, Value PoolUrl, Value ByteString, Value PoolHashId, Value Word) ->
PoolFetchRetry
convert (Value time, Value pmrId, Value url, Value pmh, Value phId, Value rCount) =
PoolFetchRetry
{ pfrPoolHashId = phId
, pfrReferenceId = pmrId
, pfrPoolUrl = PoolUrl url
, pfrPoolUrl = url
, pfrPoolMDHash = Just $ PoolMetaHash pmh
, pfrRetry = retryAgain (Time.utcTimeToPOSIXSeconds time) rCount
}
5 changes: 4 additions & 1 deletion cardano-db/src/Cardano/Db/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
module Cardano.Db.Schema where

import Cardano.Db.Schema.Orphans ()
import Cardano.Db.Schema.Types (
PoolUrl,
)
import Cardano.Db.Types (
DbInt65,
DbLovelace,
Expand Down Expand Up @@ -220,7 +223,7 @@ share

PoolMetadataRef
poolId PoolHashId noreference
url Text
url PoolUrl sqltype=varchar
hash ByteString sqltype=hash32type
registeredTxId TxId noreference -- Only used for rollback.
UniquePoolMetadataRef poolId url hash
Expand Down
10 changes: 10 additions & 0 deletions cardano-db/src/Cardano/Db/Schema/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

module Cardano.Db.Schema.Orphans () where

import Cardano.Db.Schema.Types (
PoolUrl (..),
)
import Cardano.Db.Types (
DbInt65 (..),
DbLovelace (..),
Expand Down Expand Up @@ -73,6 +76,13 @@ instance PersistField DbWord64 where
fromPersistValue x =
Left $ mconcat ["Failed to parse Haskell type DbWord64: ", Text.pack (show x)]

instance PersistField PoolUrl where
toPersistValue = PersistText . unPoolUrl
fromPersistValue (PersistText txt) = Right $ PoolUrl txt
fromPersistValue (PersistByteString bs) = Right $ PoolUrl (Text.decodeLatin1 bs)
fromPersistValue x =
Left $ mconcat ["Failed to parse Haskell type PoolUrl: ", Text.pack (show x)]

instance PersistField RewardSource where
toPersistValue = PersistText . showRewardSource
fromPersistValue (PersistLiteral bs) = Right $ readRewardSource (Text.decodeLatin1 bs)
Expand Down
2 changes: 1 addition & 1 deletion cardano-db/test/Test/IO/Cardano/Db/Insert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ poolMetadataRef :: TxId -> PoolHashId -> PoolMetadataRef
poolMetadataRef txid phid =
PoolMetadataRef
{ poolMetadataRefPoolId = phid
, poolMetadataRefUrl = "best.pool.com"
, poolMetadataRefUrl = PoolUrl "best.pool.com"
, poolMetadataRefHash = mkHash 32 '4'
, poolMetadataRefRegisteredTxId = txid
}
Expand Down