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

chainChoice should not loop forever on singletonChainGraph #1746

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/Chainweb/CutDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ processCuts conf logFun headerStore payloadStore cutHashesStore queue cutVar = d
--
isOld x = do
curHashes <- cutToCutHashes Nothing <$> readTVarIO cutVar
-- are all chains in the current cut ahead of or equal to this new cut in height?
let r = all (>= (0 :: Int)) $ (HM.unionWith (-) `on` (fmap (int . _bhwhHeight) . _cutHashes)) curHashes x
when r $ loggc Debug x "skip old cut"
return r
Expand Down
13 changes: 11 additions & 2 deletions src/Chainweb/Miner/Coordinator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand Down Expand Up @@ -41,6 +42,7 @@ module Chainweb.Miner.Coordinator
, publish
) where

import Control.Concurrent (threadDelay)
import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TVar
import Control.DeepSeq (NFData)
Expand Down Expand Up @@ -71,6 +73,7 @@ import Chainweb.Cut hiding (join)
import Chainweb.Cut.Create
import Chainweb.Cut.CutHashes
import Chainweb.CutDB
import Chainweb.Graph (singletonChainGraph)
import Chainweb.Logger (Logger, logFunction)
import Chainweb.Logging.Miner
import Chainweb.Miner.Config
Expand Down Expand Up @@ -224,8 +227,14 @@ chainChoice c choice = case choice of
where
loop :: ChainId -> IO ChainId
loop cid = do
new <- randomChainIdAt c (minChainHeight c)
bool (pure new) (loop cid) $ new == cid
if _chainGraph c == singletonChainGraph
then do
let millisecondInMicros = 1_000
threadDelay millisecondInMicros
chessai marked this conversation as resolved.
Show resolved Hide resolved
return cid
else do
new <- randomChainIdAt c (minChainHeight c)
bool (pure new) (loop cid) $ new == cid

-- | Accepts a "solved" `BlockHeader` from some external source (e.g. a remote
-- mining client), attempts to reassociate it with the current best `Cut`, and
Expand Down