Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit b1d66fd

Browse files
committed
Address issues from code review
1 parent ac96aa8 commit b1d66fd

File tree

6 files changed

+56
-37
lines changed

6 files changed

+56
-37
lines changed

src/Chainweb/CutDB.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ synchronizeProviders logger wbh providers c = do
530530
pLog Warn $ "resolveFork for failed"
531531
<> "; finfo: " <> encodeToText finfo
532532
<> "; failure: " <> sshow e
533-
-- pLog Error "It is recommend using --initial-block-height-limit to recover from fork manually."
534533
empty
535534
pLog Info $ "payload provider synced to "
536535
<> sshow (view blockHeight hdr)
@@ -707,17 +706,21 @@ processCuts conf logFun headerStore providers cutHashesStore queue cutVar cutPru
707706
-- During this final sync we also enable payload production.
708707
finfo <- forkInfoForHeader hdrStore bh Nothing Nothing True
709708

710-
-- Note, that this really should be super quick and
709+
-- Note, that this sync really should be super quick and
711710
-- should never fail.
712-
--
713-
-- FIXME: Can't we go to the merge cut directly?
714-
-- FIXME: we could we trigger this with only a
715-
-- single node in the system?
711+
-- TODO: It would be nicer to go to the merge cut directly.
716712
clog Info "Syncing paylooad provider with merged cut"
717713
resolveForkInfo clog (hdrStore ^?! ixg cid) NullCas provider Nothing finfo `catch`
718-
-- FIXME calling error is not OK!
719-
\(e :: SomeException) -> error
720-
$ "Failed to sync to merge cut (on chain " <> sshow cid <> "): " <> sshow e
714+
\(e :: SomeException) -> do
715+
clog Error
716+
$ "Failed to sync payload provider to the merge cut."
717+
<> " This should never happen. It may indicated a broken payload provider or a corrupted database."
718+
<> " Fork info: " <> encodeToText finfo
719+
<> " Failure: " <> sshow e
720+
throwM $ InternalInvariantViolation
721+
$ "Failed to sync payload provider to the merge cut."
722+
<> " This should never happen. It may indicated a broken payload provider or a corrupted database."
723+
<> " Failure: " <> sshow e
721724
_ -> return ()
722725
let cutDiff = cutDiffToTextShort curCut resultCut
723726
let currentCutIdMsg = T.unwords

src/Chainweb/Pact/PactService.hs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,7 @@ syncToFork logger serviceEnv hints forkInfo = do
540540
Checkpointer.setConsensusState sql forkInfo._forkInfoTargetState
541541
return (mempty, mempty, forkInfo._forkInfoTargetState)
542542
else do
543-
-- check if some past block had the target as its parent; if so, that
544-
-- means we can rewind to it
545-
--
546-
-- FIXME: why the parent? Why not the block itself?
547-
--
543+
-- check if the target is in our history
548544
latestBlockRewindable <-
549545
isJust <$> Checkpointer.lookupBlockHash sql (_latestBlockHash forkInfo._forkInfoTargetState)
550546

@@ -558,18 +554,11 @@ syncToFork logger serviceEnv hints forkInfo = do
558554
Checkpointer.setConsensusState sql forkInfo._forkInfoTargetState
559555
return (rewoundTxs, mempty, forkInfo._forkInfoTargetState)
560556
else do
561-
let traceBlockHashesAscending =
557+
let traceBlockHashesAscending = _forkInfoTraceBlockHashes forkInfo
562558

563-
-- Why do we drop the first entry? That seems fishy.
564-
drop 1 (unwrapParent . _evaluationCtxRankedParentHash <$> forkInfo._forkInfoTrace) <>
565-
[_syncStateRankedBlockHash forkInfo._forkInfoTargetState._consensusStateLatest]
566-
567-
-- FIXME: we sometimes get stuck in a loop with a fork into trace
568-
-- that is too short, i.e. the forkpoint is too far ahead.
569-
570-
logFunctionText logger Debug $ "playing blocks"
559+
logFunctionText logger Debug $ "playing blocks from fork info trace"
571560
<> "; from: " <> brief pactConsensusState
572-
<> "; target: " <> brief forkInfo._forkInfoTargetState
561+
<> "; target: " <> brief (_forkInfoTargetState forkInfo)
573562
<> "; trace: " <> brief traceBlockHashesAscending
574563

575564
findForkChainAscending (reverse $ zip forkInfo._forkInfoTrace traceBlockHashesAscending) >>= \case
@@ -595,7 +584,9 @@ syncToFork logger serviceEnv hints forkInfo = do
595584

596585
let unknownPayloads = NEL.filter (isNothing . snd) knownPayloads
597586
unless (null unknownPayloads)
598-
$ logFunctionText logger Debug $ "unknown blocks in context: " <> sshow (length unknownPayloads)
587+
$ logFunctionText logger Debug $ "unknown blocks in context"
588+
<> "; count: " <> sshow (length unknownPayloads)
589+
<> "; hashes: " <> brief (snd . fst <$> unknownPayloads)
599590

600591
runnableBlocks <- forM knownPayloads $ \((evalCtx, rankedBHash), maybePayload) -> do
601592
logFunctionText logger Debug $ "running block: " <> brief rankedBHash

src/Chainweb/PayloadProvider/EVM.hs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
{-# LANGUAGE UndecidableInstances #-}
2525

2626
{-# OPTIONS_GHC -Wprepositive-qualified-module #-}
27+
{-# LANGUAGE AllowAmbiguousTypes #-}
2728

2829
-- |
2930
-- Module: Chainweb.PayloadProvider.EVM
@@ -112,6 +113,7 @@ import Network.URI.Static
112113
import P2P.Session (ClientEnv)
113114
import P2P.TaskQueue
114115
import System.LogLevel
116+
import Servant.Client (ClientM)
115117

116118
-- -------------------------------------------------------------------------- --
117119
-- Payload Database
@@ -525,16 +527,7 @@ withEvmPayloadProvider logger c rdb mgr conf
525527
SomeChainIdT @c _ <- return $ someChainIdVal c
526528

527529
let pldCli = Rest.payloadClient @v @c @p
528-
529-
-- FIXME move the following two definitions elsewhere
530-
let payloadRankedPayloadHash pld = RankedBlockPayloadHash
531-
{ _rankedBlockPayloadHashHeight = int $ EVM._hdrNumber $ _payloadHeader pld
532-
, _rankedBlockPayloadHashHash = EVM._hdrPayloadHash $ _payloadHeader pld
533-
}
534-
let pldCliBatch rhs = do
535-
rs <- _payloadList <$> Rest.payloadBatchClient @v @c @p rhs
536-
let rs' = HM.fromList $ (\pld -> (payloadRankedPayloadHash pld, pld)) <$> rs
537-
return $ (`HM.lookup` rs') <$> rhs
530+
let pldCliBatch = mkPayloadBatchClient @v @c
538531

539532
genPld <- liftIO $ checkExecutionClient logger c engineCtx (EVM.ChainId (fromSNat ecid))
540533
liftIO $ logFunctionText logger Info $ "genesis payload block hash: " <> sshow (EVM._hdrPayloadHash genPld)
@@ -571,6 +564,17 @@ withEvmPayloadProvider logger c rdb mgr conf
571564
where
572565
pldStoreLogger = addLabel ("sub-component", "payloadStore") logger
573566

567+
mkPayloadBatchClient
568+
:: forall (v :: ChainwebVersionT) (c :: ChainIdT)
569+
. KnownChainwebVersionSymbol v
570+
=> KnownChainIdSymbol c
571+
=> [RankedBlockPayloadHash]
572+
-> ClientM [Maybe Payload]
573+
mkPayloadBatchClient rhs = do
574+
rs <- _payloadList <$> Rest.payloadBatchClient @v @c @(EvmProvider _) rhs
575+
let rs' = HM.fromList $ (\pld -> (_pldRankedBlockPayloadHash pld, pld)) <$> rs
576+
return $ (`HM.lookup` rs') <$> rhs
577+
574578
-- | Checks the availability of the Execution Client
575579
--
576580
-- - asserts API availability

src/Chainweb/PayloadProvider/P2P.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ data PayloadStore tbl a = PayloadStore
117117
-- could make it easier to limit concurrency across chains. If this is
118118
-- needed the ChainId parameter would have to be re-added.
119119
, _payloadStoreGetPayloadBatchClient :: !([RankedBlockPayloadHash] -> ClientM [Maybe a])
120+
-- ^ HTTP client for querying payloads in batches (provided by the
121+
-- PayloadProvider)
122+
--
123+
-- There is a default Payload REST API in
124+
-- "Chainweb.PayloadProvider.P2P.RestAPI" that can be used in common
125+
-- cases.
126+
--
127+
-- The same considerations apply as for '_payloadStoreGetPayloadClient'.
120128
}
121129

122130
-- FIXME: not sure whether the following instances are a good idea...

src/Chainweb/Sync/ForkInfo.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ resolveForkInfoForProviderState logg bhdb candidateHdrs provider hints finfo ppS
209209
-- error.
210210

211211
(forkBlocksDescendingStream S.:> forkPoint) <- S.toList
212+
213+
-- Note that this assumes that the parent of hdr is in the
214+
-- block header DB. With the current cut pipeline that is
215+
-- always the case, because we never validate a header for
216+
-- which the parent hasn't already been validated. In case
217+
-- that this changes in the future we need to adjust the
218+
-- branch diff to start from parent of the lowest processed
219+
-- block. That block would certainly be on the canonical
220+
-- chain, since we wouldn't validate block that aren't
221+
-- extending the current head.
222+
--
212223
$ branchDiff_ bhdb ppBlock hdr
213224

214225
let forkBlocksAscending = reverse

src/P2P/TaskQueue.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@ session_ limit q logFun env = E.mask $ \restore -> do
204204
return False
205205
| otherwise -> do
206206
logg task' Warn
207-
$ "task finally failed with: " <> sshow e <> " after " <> sshow attempts <> " attempts, limit: "
208-
<> sshow limit
207+
$ "task finally failed"
208+
<> "; attempts: " <> sshow attempts
209+
<> "; limit: " <> sshow limit
210+
<> "; failure: " <> sshow e
209211
putResult (_taskResult task') $! Left $! _taskFailures task'
210212

211213
logg task l m = logFun @T.Text l $ sshow (_taskId task) <> ": " <> m

0 commit comments

Comments
 (0)