Skip to content

Commit 96bedc0

Browse files
committed
Log on duplicate keys
1 parent dc1a87b commit 96bedc0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Chainweb/Pact5/Backend/ChainwebPactDb.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import Pact.Core.Serialise qualified as Pact
130130
import Pact.Core.StableEncoding (encodeStable)
131131
import Pact.Types.Persistence qualified as Pact4
132132
import Prelude hiding (concat, log)
133+
import System.LogLevel
133134

134135
data InternalDbException = InternalDbException CallStack Text
135136
instance Show InternalDbException where show = displayException
@@ -566,7 +567,8 @@ doWriteRow wt d k v = case d of
566567
doKeys
567568
:: forall k v logger
568569
-- ^ the highest block we should be reading writes from
569-
. Pact.Domain k v Pact.CoreBuiltin Pact.Info
570+
. Logger logger
571+
=> Pact.Domain k v Pact.CoreBuiltin Pact.Info
570572
-> BlockHandler logger [k]
571573
doKeys d = do
572574
dbKeys <- getDbKeys
@@ -598,10 +600,16 @@ doKeys d = do
598600
v <- view blockHandlerVersion
599601
cid <- view blockHandlerChainId
600602
bh <- view blockHandlerBlockHeight
601-
if chainweb230Pact v cid bh
603+
let preResult = sort (memKeys ++ parsedKeys)
602604
-- the read-cache contains duplicate keys that we need to remove.
603-
then return $ fmap head $ group $ sort (memKeys ++ parsedKeys)
604-
else return $ sort (memKeys ++ parsedKeys)
605+
let postResult = fmap head $ group $ sort (memKeys ++ parsedKeys)
606+
when (postResult /= preResult) $ do
607+
lgr <- view blockHandlerLogger
608+
liftIO $ logFunctionText lgr Warn $ "duplicate keys in domain " <> sshow d
609+
return $
610+
if chainweb230Pact v cid bh
611+
then postResult
612+
else preResult
605613

606614
where
607615

0 commit comments

Comments
 (0)