Skip to content

Commit

Permalink
keep feature flag validation disabled (#929)
Browse files Browse the repository at this point in the history
* keep feature flag validation disabled

* add useful test for feature flag validation
  • Loading branch information
larskuhtz authored Feb 18, 2020
1 parent 5874272 commit 16a279d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/Chainweb/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -684,24 +684,24 @@ slowEpochGuard Mainnet01 h = h < 80000
slowEpochGuard _ _ = False
{-# INLINE slowEpochGuard #-}

-- | Skip validation of feature flags for block heights up to 340000.
-- | Skip validation of feature flags.
--
-- Unused feature flag bits are supposed to be set to 0. This was not enforced
-- in chainweb-node versions <= 1.5. There is a large number of blocks in the
-- history of mainnet before 2020-02-20, that have non-zero feature flags. In
-- order to prepare future use of fleature flag feature flag validation will
-- start at block height 340000.
-- Unused feature flag bits are supposed to be set to 0. This isn't enforced
-- currently (chainweb-node versions <= 1.6). There is a large number of blocks
-- in the history of mainnet before 2020-02-20, that have non-zero feature
-- flags.
--
-- This guard grandfathers the this behavior up to block height 340000.
--
-- Blockheight 340000 is expected to occur on mainnet01 on 2019-02-24.
-- This guard permits the use of the last 64 bits of a block header as a nonce
-- value for all blogs which pass this guard.
--
skipFeatureFlagValidationGuard
:: ChainwebVersion
-> BlockHeight
-- ^ height of header
-> Bool
skipFeatureFlagValidationGuard Mainnet01 h = h < 340000
skipFeatureFlagValidationGuard Mainnet01 _ = True
skipFeatureFlagValidationGuard Development _ = True
skipFeatureFlagValidationGuard Testnet04 _ = True
skipFeatureFlagValidationGuard _ _ = False

-- | Preserve Pact bugs pre 1.6 chainweb version
Expand Down
14 changes: 7 additions & 7 deletions test/Chainweb/Test/BlockHeader/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import Test.Tasty.HUnit
import Chainweb.BlockHeader
import Chainweb.BlockHeader.Genesis
import Chainweb.BlockHeader.Validation
import Chainweb.BlockHeight
import Chainweb.Graph
import Chainweb.Test.Orphans.Internal ({- Arbitrary BlockHeader -})
import Chainweb.Time
import Chainweb.Utils
Expand All @@ -40,10 +42,8 @@ import Chainweb.Version

tests :: TestTree
tests = testGroup "Chainweb.Test.Blockheader.Validation"
[ prop_featureFlag Mainnet01
, prop_featureFlag Testnet04
, prop_featureFlag Development
, prop_validateMainnet
[ prop_validateMainnet
, prop_featureFlag (Test petersonChainGraph) 10
]

-- -------------------------------------------------------------------------- --
Expand All @@ -52,9 +52,9 @@ tests = testGroup "Chainweb.Test.Blockheader.Validation"
-- There is an input for which the rule fails.
--

prop_featureFlag :: ChainwebVersion -> TestTree
prop_featureFlag v = testCase ("Invalid feature flags fail validation for " <> sshow v) $ do
hdr <- (blockHeight .~ 400000)
prop_featureFlag :: ChainwebVersion -> BlockHeight -> TestTree
prop_featureFlag v h = testCase ("Invalid feature flags fail validation for " <> sshow v) $ do
hdr <- (blockHeight .~ h)
. (blockFlags .~ fromJuste (decode "1"))
. (blockChainwebVersion .~ v)
<$> generate arbitrary
Expand Down

0 comments on commit 16a279d

Please sign in to comment.