Skip to content

Commit 63e68f2

Browse files
authored
Merge pull request #1353 from input-output-hk/erikd/issue-1347
Fix queryPoolFetchRetry
2 parents 07d3587 + 8625330 commit 63e68f2

File tree

7 files changed

+27
-14
lines changed

7 files changed

+27
-14
lines changed

Diff for: cardano-db-sync/app/test-http-get-json-metadata.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ queryTestOfflineData = do
147147
)
148148
pure . organise $ map (convert . unValue4) res
149149
where
150-
convert :: (Text, Text, ByteString, PoolHashId) -> (PoolHashId, TestOffline)
150+
convert :: (Text, PoolUrl, ByteString, PoolHashId) -> (PoolHashId, TestOffline)
151151
convert (tname, url, hash, poolId) =
152152
( poolId
153153
, TestOffline
154154
{ toTicker = tname
155-
, toUrl = PoolUrl url
155+
, toUrl = url
156156
, toHash = PoolMetaHash hash
157157
}
158158
)

Diff for: cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Cardano.Api.Shelley (
2626
import Cardano.BM.Trace (Trace, logDebug, logInfo, logWarning)
2727
import Cardano.Crypto.Hash (hashToBytes)
2828
import qualified Cardano.Crypto.Hashing as Crypto
29-
import Cardano.Db (DbLovelace (..), DbWord64 (..))
29+
import Cardano.Db (DbLovelace (..), DbWord64 (..), PoolUrl (..))
3030
import qualified Cardano.Db as DB
3131
import Cardano.DbSync.Api
3232
import Cardano.DbSync.Cache
@@ -540,7 +540,7 @@ insertMetaDataRef poolId txId md =
540540
lift . DB.insertPoolMetadataRef $
541541
DB.PoolMetadataRef
542542
{ DB.poolMetadataRefPoolId = poolId
543-
, DB.poolMetadataRefUrl = Ledger.urlToText (Shelley._poolMDUrl md)
543+
, DB.poolMetadataRefUrl = PoolUrl $ Ledger.urlToText (Shelley._poolMDUrl md)
544544
, DB.poolMetadataRefHash = Shelley._poolMDHash md
545545
, DB.poolMetadataRefRegisteredTxId = txId
546546
}

Diff for: cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Offline/Http.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Network.HTTP.Client (HttpException (..))
3232
import qualified Network.HTTP.Client as Http
3333
import qualified Network.HTTP.Types as Http
3434

35-
-- |Fetch error for the HTTP client fetching the pool offline metadata.
35+
-- | Fetch error for the HTTP client fetching the pool offline metadata.
3636
data FetchError
3737
= FEHashMismatch !PoolUrl !Text !Text
3838
| FEDataTooLong !PoolUrl

Diff for: cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Offline/Query.hs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Cardano.DbSync.Era.Shelley.Offline.Query (
66
) where
77

88
import Cardano.Db (
9-
EntityField (PoolHashId, PoolHashView, PoolMetadataRefHash, PoolMetadataRefId, PoolMetadataRefPoolId, PoolMetadataRefUrl, PoolOfflineDataPmrId, PoolOfflineFetchErrorFetchTime, PoolOfflineFetchErrorId, PoolOfflineFetchErrorPmrId, PoolOfflineFetchErrorPoolId, PoolOfflineFetchErrorRetryCount),
9+
EntityField (PoolHashId, PoolMetadataRefHash, PoolMetadataRefId, PoolMetadataRefPoolId, PoolMetadataRefUrl, PoolOfflineDataPmrId, PoolOfflineFetchErrorFetchTime, PoolOfflineFetchErrorId, PoolOfflineFetchErrorPmrId, PoolOfflineFetchErrorPoolId, PoolOfflineFetchErrorRetryCount),
1010
PoolHash,
1111
PoolHashId,
1212
PoolMetaHash (PoolMetaHash),
@@ -15,7 +15,7 @@ import Cardano.Db (
1515
PoolOfflineData,
1616
PoolOfflineFetchError,
1717
PoolOfflineFetchErrorId,
18-
PoolUrl (PoolUrl),
18+
PoolUrl,
1919
)
2020
import Cardano.DbSync.Era.Shelley.Offline.FetchQueue (newRetry, retryAgain)
2121
import Cardano.DbSync.Types (PoolFetchRetry (..))
@@ -92,13 +92,13 @@ queryNewPoolFetch now = do
9292
pure $ max_ (pmr ^. PoolMetadataRefId)
9393

9494
convert ::
95-
(Value PoolHashId, Value PoolMetadataRefId, Value Text, Value ByteString) ->
95+
(Value PoolHashId, Value PoolMetadataRefId, Value PoolUrl, Value ByteString) ->
9696
PoolFetchRetry
9797
convert (Value phId, Value pmrId, Value url, Value pmh) =
9898
PoolFetchRetry
9999
{ pfrPoolHashId = phId
100100
, pfrReferenceId = pmrId
101-
, pfrPoolUrl = PoolUrl url
101+
, pfrPoolUrl = url
102102
, pfrPoolMDHash = Just $ PoolMetaHash pmh
103103
, pfrRetry = newRetry now
104104
}
@@ -120,7 +120,7 @@ queryPoolFetchRetry _now = do
120120
pure
121121
( pofe ^. PoolOfflineFetchErrorFetchTime
122122
, pofe ^. PoolOfflineFetchErrorPmrId
123-
, ph ^. PoolHashView
123+
, pmr ^. PoolMetadataRefUrl
124124
, pmr ^. PoolMetadataRefHash
125125
, ph ^. PoolHashId
126126
, pofe ^. PoolOfflineFetchErrorRetryCount
@@ -138,13 +138,13 @@ queryPoolFetchRetry _now = do
138138
pure $ max_ (pofe ^. PoolOfflineFetchErrorId)
139139

140140
convert ::
141-
(Value UTCTime, Value PoolMetadataRefId, Value Text, Value ByteString, Value PoolHashId, Value Word) ->
141+
(Value UTCTime, Value PoolMetadataRefId, Value PoolUrl, Value ByteString, Value PoolHashId, Value Word) ->
142142
PoolFetchRetry
143143
convert (Value time, Value pmrId, Value url, Value pmh, Value phId, Value rCount) =
144144
PoolFetchRetry
145145
{ pfrPoolHashId = phId
146146
, pfrReferenceId = pmrId
147-
, pfrPoolUrl = PoolUrl url
147+
, pfrPoolUrl = url
148148
, pfrPoolMDHash = Just $ PoolMetaHash pmh
149149
, pfrRetry = retryAgain (Time.utcTimeToPOSIXSeconds time) rCount
150150
}

Diff for: cardano-db/src/Cardano/Db/Schema.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
module Cardano.Db.Schema where
1919

2020
import Cardano.Db.Schema.Orphans ()
21+
import Cardano.Db.Schema.Types (
22+
PoolUrl,
23+
)
2124
import Cardano.Db.Types (
2225
DbInt65,
2326
DbLovelace,
@@ -220,7 +223,7 @@ share
220223

221224
PoolMetadataRef
222225
poolId PoolHashId noreference
223-
url Text
226+
url PoolUrl sqltype=varchar
224227
hash ByteString sqltype=hash32type
225228
registeredTxId TxId noreference -- Only used for rollback.
226229
UniquePoolMetadataRef poolId url hash

Diff for: cardano-db/src/Cardano/Db/Schema/Orphans.hs

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
module Cardano.Db.Schema.Orphans () where
55

6+
import Cardano.Db.Schema.Types (
7+
PoolUrl (..),
8+
)
69
import Cardano.Db.Types (
710
DbInt65 (..),
811
DbLovelace (..),
@@ -73,6 +76,13 @@ instance PersistField DbWord64 where
7376
fromPersistValue x =
7477
Left $ mconcat ["Failed to parse Haskell type DbWord64: ", Text.pack (show x)]
7578

79+
instance PersistField PoolUrl where
80+
toPersistValue = PersistText . unPoolUrl
81+
fromPersistValue (PersistText txt) = Right $ PoolUrl txt
82+
fromPersistValue (PersistByteString bs) = Right $ PoolUrl (Text.decodeLatin1 bs)
83+
fromPersistValue x =
84+
Left $ mconcat ["Failed to parse Haskell type PoolUrl: ", Text.pack (show x)]
85+
7686
instance PersistField RewardSource where
7787
toPersistValue = PersistText . showRewardSource
7888
fromPersistValue (PersistLiteral bs) = Right $ readRewardSource (Text.decodeLatin1 bs)

Diff for: cardano-db/test/Test/IO/Cardano/Db/Insert.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ poolMetadataRef :: TxId -> PoolHashId -> PoolMetadataRef
181181
poolMetadataRef txid phid =
182182
PoolMetadataRef
183183
{ poolMetadataRefPoolId = phid
184-
, poolMetadataRefUrl = "best.pool.com"
184+
, poolMetadataRefUrl = PoolUrl "best.pool.com"
185185
, poolMetadataRefHash = mkHash 32 '4'
186186
, poolMetadataRefRegisteredTxId = txid
187187
}

0 commit comments

Comments
 (0)