22{-# LANGUAGE ImportQualifiedPost #-}
33{-# LANGUAGE ScopedTypeVariables #-}
44
5+ -- TODO Remove this when checkFork' will be used for real
6+ {-# OPTIONS_GHC -Wno-unused-top-binds #-}
7+
58-- |
69-- Module: Chainweb.Version.Guards
710-- Copyright: Copyright © 2023 Kadena LLC.
@@ -70,6 +73,7 @@ import Chainweb.BlockHeight
7073import Chainweb.ChainId
7174import Chainweb.Pact4.Transaction qualified as Pact4
7275import Chainweb.Utils.Rule
76+ import Chainweb.ForkState
7377import Chainweb.Version
7478import Control.Lens
7579import Data.Word (Word64 )
@@ -86,32 +90,33 @@ import Pact.Types.Scheme (PPKScheme(ED25519, WebAuthn))
8690getForkHeight :: Fork -> ChainwebVersion -> ChainId -> ForkHeight
8791getForkHeight fork v cid = v ^?! versionForks . at fork . _Just . atChain cid
8892
93+ -- Check Fork by height
8994checkFork
90- :: (BlockHeight -> ForkHeight -> Bool )
95+ :: (ForkHeight -> ForkHeight -> Bool )
9196 -> Fork -> ChainwebVersion -> ChainId -> BlockHeight -> Bool
92- checkFork p f v cid h = p h (getForkHeight f v cid)
97+ checkFork p f v cid h = p (ForkAtBlockHeight h) (getForkHeight f v cid)
98+
99+ -- CheckFork by forkNumber
100+ checkFork'
101+ :: (ForkHeight -> ForkHeight -> Bool )
102+ -> Fork -> ChainwebVersion -> ChainId -> ForkNumber -> Bool
103+ checkFork' p f v cid fn = p (ForkAtForkNumber fn) (getForkHeight f v cid)
104+
93105
94- after :: BlockHeight -> ForkHeight -> Bool
95- after bh (ForkAtBlockHeight bh') = bh > bh'
96- after _ ForkAtGenesis = True
97- after _ ForkNever = False
106+ after :: ForkHeight -> ForkHeight -> Bool
107+ after = (>)
98108
99- atOrAfter :: BlockHeight -> ForkHeight -> Bool
100- atOrAfter bh (ForkAtBlockHeight bh') = bh >= bh'
101- atOrAfter _ ForkAtGenesis = True
102- atOrAfter _ ForkNever = False
109+ atOrAfter :: ForkHeight -> ForkHeight -> Bool
110+ atOrAfter = (>=)
103111
104- before :: BlockHeight -> ForkHeight -> Bool
105- before bh (ForkAtBlockHeight bh') = bh < bh'
106- before _ ForkAtGenesis = False
107- before _ ForkNever = True
112+ before :: ForkHeight -> ForkHeight -> Bool
113+ before = (<)
108114
109115-- Intended for forks that intend to run upgrades at exactly one height, and so
110116-- can't be "pre-activated" for genesis.
111- atNotGenesis :: BlockHeight -> ForkHeight -> Bool
112- atNotGenesis bh (ForkAtBlockHeight bh') = bh == bh'
117+ atNotGenesis :: ForkHeight -> ForkHeight -> Bool
113118atNotGenesis _ ForkAtGenesis = error " fork cannot be at genesis"
114- atNotGenesis _ ForkNever = False
119+ atNotGenesis fh fh' = fh == fh'
115120
116121-- -------------------------------------------------------------------------- --
117122-- Header Validation Guards
0 commit comments