Skip to content
Merged
27 changes: 18 additions & 9 deletions src/Chainweb/Version/Registry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ unregisterVersion v = do
then error "You cannot unregister mainnet or testnet04 versions"
else atomicModifyIORef' versionMap $ \m -> (HM.delete (_versionCode v) m, ())

validateNoHeightAfterChainweb31' :: ChainwebVersion -> ForkHeight -> Either String ()
validateNoHeightAfterChainweb31' v fh =
validateNoHeightAfterChainweb31 :: ChainwebVersion -> ForkHeight -> Either String ()
validateNoHeightAfterChainweb31 v fh =
case (fork31Height, fh) of
(Just (ForkAtBlockHeight refAth), ForkAtBlockHeight ath) ->
if ath > (refAth + 1)
Expand All @@ -89,12 +89,21 @@ validateNoHeightAfterChainweb31' v fh =
where
fork31Height = v ^? versionForks . at Chainweb31 . _Just . atChain (unsafeChainId 0)

validateNoHeightAfterChainweb31 :: ChainwebVersion -> Either String ()
validateNoHeightAfterChainweb31 v =
(mapM_ (mapM_ (validateNoHeightAfterChainweb31' v)) (v ^. versionForks))
>> (mapM_ (validateNoHeightAfterChainweb31' v . fst) $ ruleElems $ v ^. versionMaxBlockGasLimit)
>> (mapM_ (validateNoHeightAfterChainweb31' v . fst) $ ruleElems $ v ^. versionSpvProofRootValidWindow)
>> (mapM_ (mapM_ (validateNoHeightAfterChainweb31' v . fst) . ruleElems) $ v ^. versionVerifierPluginNames)
validateNoForkAtZero :: ForkHeight -> Either String ()
validateNoForkAtZero (ForkAtForkNumber atn)
| atn == 0 = Left ("ValidateSting: Fork Numbers can't be 0 ")
| otherwise = Right ()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete this case.

validateNoForkAtZero _ = Right ()


validateForkHeights :: ChainwebVersion -> Either String ()
validateForkHeights v =
(mapM_ (mapM_ doValidation) (v ^. versionForks))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be made a bit nicer in a follow-up with do instead of >>.

>> (mapM_ (doValidation . fst) $ ruleElems $ v ^. versionMaxBlockGasLimit)
>> (mapM_ (doValidation . fst) $ ruleElems $ v ^. versionSpvProofRootValidWindow)
>> (mapM_ (mapM_ (doValidation . fst) . ruleElems) $ v ^. versionVerifierPluginNames)
where
doValidation fh = validateNoHeightAfterChainweb31 v fh >> validateNoForkAtZero fh

validateVersion :: HasCallStack => ChainwebVersion -> IO ()
validateVersion v = do
Expand Down Expand Up @@ -125,7 +134,7 @@ validateVersion v = do
, [ "validateVersion: some pact upgrade has no transactions"
| any (any isUpgradeEmpty) (_versionUpgrades v) ]
, [ err
| Left err <- [validateNoHeightAfterChainweb31 v] ]
| Left err <- [validateForkHeights v] ]
-- TODO: check that pact 4/5 upgrades are only enabled when pact 4/5 is enabled
]
unless (null errors) $
Expand Down
Loading