Skip to content

Commit

Permalink
Remove ill-defined LoELimit
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed May 7, 2024
1 parent bc33a4a commit 8953864
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ module Ouroboros.Consensus.Storage.ChainDB.API (
-- * Genesis
, GetLoEFragment
, LoE (..)
, LoELimit (..)
) where

import Control.Monad (void)
import Data.Typeable (Typeable)
import Data.Word (Word64)
import GHC.Generics (Generic)
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.HeaderStateHistory
Expand Down Expand Up @@ -895,8 +893,3 @@ data LoE a =
deriving (Eq, Show, Generic, NoThunks, Functor, Foldable, Traversable)

type GetLoEFragment m blk = LoE (m (AnchoredFragment (Header blk)))

data LoELimit =
LoELimit Word64
|
LoEUnlimited
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Data.Maybe (isJust, isNothing)
import Data.Maybe.Strict (StrictMaybe (..), strictMaybeToMaybe)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Word (Word64)
import GHC.Stack (HasCallStack)
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
Expand All @@ -59,7 +60,7 @@ import Ouroboros.Consensus.Ledger.Inspect
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Storage.ChainDB.API (AddBlockPromise (..),
AddBlockResult (..), BlockComponent (..), ChainType (..),
InvalidBlockReason (..), LoE (..), LoELimit (..))
InvalidBlockReason (..), LoE (..))
import Ouroboros.Consensus.Storage.ChainDB.API.Types.InvalidBlockPunishment
(InvalidBlockPunishment, noPunishment)
import qualified Ouroboros.Consensus.Storage.ChainDB.API.Types.InvalidBlockPunishment as InvalidBlockPunishment
Expand Down Expand Up @@ -175,9 +176,7 @@ initialChainSelection immutableDB volatileDB lgrDB tracer cfg varInvalid
suffixesAfterI :: [NonEmpty (HeaderHash blk)]
suffixesAfterI = Paths.maximalCandidates succsOf limit (AF.anchorToPoint i)
where
limit = case loE of
LoEEnabled _ -> LoELimit k
LoEDisabled -> LoEUnlimited
limit = k <$ loE

constructChain ::
NonEmpty (HeaderHash blk)
Expand Down Expand Up @@ -649,7 +648,7 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ do
-- ^ The current chain and ledger
-> LoE (AnchoredFragment (Header blk))
-- ^ LoE fragment
-> LoELimit
-> LoE Word64
-- ^ How many extra blocks to select after @b@ at most.
-> m (Point blk)
addToCurrentChain succsOf curChainAndLedger loeFrag maxExtra = do
Expand Down Expand Up @@ -732,7 +731,7 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ do
-- ^ The current chain (anchored at @i@) and ledger
-> LoE (AnchoredFragment (Header blk))
-- ^ LoE fragment
-> LoELimit
-> LoE Word64
-- ^ How many extra blocks to select after @b@ at most.
-> ChainDiff (HeaderFields blk)
-- ^ Header fields for @(x,b]@
Expand Down Expand Up @@ -805,23 +804,23 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ do
-> AnchoredFragment x
-- ^ The fragment with the new block @b@ as its tip, with the same
-- anchor as @curChain@.
-> Maybe LoELimit
-> Maybe (LoE Word64)
computeLoEMaxExtra (LoEEnabled loeFrag) newBlockFrag =
-- Both fragments are on the same chain
if loeSuffixLength == 0 || rollback == 0 then
if rollback > k + loeSuffixLength
then Nothing
else Just $ LoELimit $ k + loeSuffixLength - rollback
else Just $ LoEEnabled $ k + loeSuffixLength - rollback
else
if rollback > k
then Nothing
else Just $ LoELimit $ k - rollback
else Just $ LoEEnabled $ k - rollback
where
d = Diff.diff newBlockFrag loeFrag
rollback = Diff.getRollback d
loeSuffixLength = fromIntegral $ AF.length (Diff.getSuffix d)
computeLoEMaxExtra LoEDisabled _ =
Just LoEUnlimited
Just LoEDisabled

mkSelectionChangedInfo ::
AnchoredFragment (Header blk) -- ^ old chain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ maximalCandidates ::
forall blk.
(ChainHash blk -> Set (HeaderHash blk))
-- ^ @filterByPredecessor@
-> LoELimit -- ^ Max length of any candidate
-> LoE Word64 -- ^ Max length of any candidate
-> Point blk -- ^ @B@
-> [NonEmpty (HeaderHash blk)]
-- ^ Each element in the list is a list of hashes from which we can
Expand All @@ -85,7 +85,7 @@ maximalCandidates succsOf loeLimit b = mapMaybe (NE.nonEmpty . applyLoE) $ go (p
, candidate <- go (BlockHash next)
]
applyLoE
| LoELimit limit <- loeLimit
| LoEEnabled limit <- loeLimit
= take (fromIntegral limit)
| otherwise
= id
Expand All @@ -104,7 +104,7 @@ extendWithSuccessors ::
forall blk. HasHeader blk
=> (ChainHash blk -> Set (HeaderHash blk))
-> LookupBlockInfo blk
-> LoELimit -- ^ Max extra length for any suffix
-> LoE Word64 -- ^ Max extra length for any suffix
-> ChainDiff (HeaderFields blk)
-> NonEmpty (ChainDiff (HeaderFields blk))
extendWithSuccessors succsOf lookupBlockInfo loeLimit diff =
Expand Down

0 comments on commit 8953864

Please sign in to comment.