33{-# LANGUAGE DeriveAnyClass #-}
44{-# LANGUAGE DeriveGeneric #-}
55{-# LANGUAGE DerivingStrategies #-}
6- {-# LANGUAGE FunctionalDependencies #-}
76{-# LANGUAGE FlexibleContexts #-}
87{-# LANGUAGE FlexibleInstances #-}
8+ {-# LANGUAGE FunctionalDependencies #-}
99{-# LANGUAGE GADTs #-}
1010{-# LANGUAGE GeneralizedNewtypeDeriving #-}
11+ {-# LANGUAGE ImportQualifiedPost #-}
12+ {-# LANGUAGE LambdaCase #-}
1113{-# LANGUAGE OverloadedStrings #-}
1214{-# LANGUAGE PatternSynonyms #-}
15+ {-# LANGUAGE QuantifiedConstraints #-}
1316{-# LANGUAGE RankNTypes #-}
1417{-# LANGUAGE ScopedTypeVariables #-}
18+ {-# LANGUAGE StandaloneDeriving #-}
1519{-# LANGUAGE TemplateHaskell #-}
1620{-# LANGUAGE TypeApplications #-}
1721{-# LANGUAGE TypeFamilies #-}
18- {-# LANGUAGE ViewPatterns #-}
19- {-# LANGUAGE StandaloneDeriving #-}
2022{-# LANGUAGE UndecidableInstances #-}
21- {-# LANGUAGE QuantifiedConstraints #-}
22- {-# LANGUAGE LambdaCase #-}
23+ {-# LANGUAGE ViewPatterns #-}
2324
2425-- |
2526-- Module: Chainweb.Version
@@ -75,6 +76,7 @@ module Chainweb.Version
7576 , versionVerifierPluginNames
7677 , versionQuirks
7778 , versionServiceDate
79+ , versionForkNumber
7880 , genesisBlockPayload
7981 , genesisBlockPayloadHash
8082 , genesisBlockTarget
@@ -151,27 +153,21 @@ module Chainweb.Version
151153import Control.DeepSeq
152154import Control.Lens hiding ((.=) , (<.>) , index )
153155import Control.Monad.Catch
154-
155156import Data.Aeson hiding (pairs )
156157import Data.Aeson.Types
157158import Data.Foldable
158159import Data.Hashable
159160import Data.HashMap.Strict (HashMap )
160- import qualified Data.HashMap.Strict as HM
161- import qualified Data.HashSet as HS
161+ import Data.HashMap.Strict qualified as HM
162+ import Data.HashSet qualified as HS
162163import Data.Set (Set )
163164import Data.Proxy
164- import qualified Data.Text as T
165+ import Data.Text qualified as T
165166import Data.Word
166-
167167import GHC.Generics (Generic )
168168import GHC.TypeLits
169169import GHC.Stack
170-
171- -- internal modules
172-
173170import Pact.Types.Runtime (Gas )
174-
175171import Chainweb.BlockCreationTime
176172import Chainweb.BlockHeight
177173import Chainweb.ChainId
@@ -181,17 +177,15 @@ import Chainweb.Graph
181177import Chainweb.HostAddress
182178import Chainweb.MerkleUniverse
183179import Chainweb.Payload
184- import qualified Chainweb.Pact4.Transaction as Pact4
185- import qualified Chainweb.Pact5.Transaction as Pact5
180+ import Chainweb.Pact4.Transaction qualified as Pact4
181+ import Chainweb.Pact5.Transaction qualified as Pact5
182+ import Chainweb.ForkState (ForkNumber )
186183import Chainweb.Utils
187184import Chainweb.Utils.Rule
188185import Chainweb.Utils.Serialization
189-
190- import Pact.Types.Verifier
191-
192186import Data.Singletons
193-
194187import P2P.Peer
188+ import Pact.Types.Verifier
195189
196190-- | Data type representing changes to block validation, whether in the payload
197191-- or in the header. Always add new forks at the end, not in the middle of the
@@ -393,8 +387,8 @@ pattern ForPact5 :: f Pact5 -> ForSomePactVersion f
393387pattern ForPact5 x = ForSomePactVersion Pact5T x
394388{-# COMPLETE ForPact4, ForPact5 #-}
395389data ForBothPactVersions f = ForBothPactVersions
396- { _forPact4 :: ( f Pact4 )
397- , _forPact5 :: ( f Pact5 )
390+ { _forPact4 :: f Pact4
391+ , _forPact5 :: f Pact5
398392 }
399393deriving stock instance (Eq (f Pact4 ), Eq (f Pact5 )) => Eq (ForBothPactVersions f )
400394deriving stock instance (Show (f Pact4 ), Show (f Pact5 )) => Show (ForBothPactVersions f )
@@ -435,7 +429,7 @@ instance NFData PactUpgrade where
435429pact4Upgrade :: [Pact4. Transaction ] -> PactUpgrade
436430pact4Upgrade txs = Pact4Upgrade txs False
437431
438- data TxIdxInBlock = TxBlockIdx Word
432+ newtype TxIdxInBlock = TxBlockIdx Word
439433 deriving stock (Eq , Ord , Show , Generic )
440434 deriving anyclass (Hashable , NFData )
441435
@@ -444,8 +438,8 @@ makePrisms ''TxIdxInBlock
444438-- The type of quirks, i.e. special validation behaviors that are in some
445439-- sense one-offs which can't be expressed as upgrade transactions and must be
446440-- preserved.
447- data VersionQuirks = VersionQuirks
448- { _quirkGasFees :: ! ( ChainMap (HashMap (BlockHeight , TxIdxInBlock ) Gas ) )
441+ newtype VersionQuirks = VersionQuirks
442+ { _quirkGasFees :: ChainMap (HashMap (BlockHeight , TxIdxInBlock ) Gas )
449443 }
450444 deriving stock (Show , Eq , Ord , Generic )
451445 deriving anyclass (NFData )
@@ -515,6 +509,22 @@ data ChainwebVersion
515509 -- ^ Modifications to behavior at particular blockheights
516510 , _versionServiceDate :: Maybe String
517511 -- ^ The node service date for this version.
512+ , _versionForkNumber :: ForkNumber
513+ -- ^ The current fork number for this version. Starting with
514+ -- chainweb-node version 2.33, fork numbers replace named forks. Fork
515+ -- numbers are monotonically increasing in steps of one. Protocol
516+ -- changes are guarded by minimum fork number. The fork number of a
517+ -- version specifies what forks are supported by a version of
518+ -- chainweb-node for a given chainweb version. Note, that it does /not/
519+ -- specify what forks are active. Forks are only active if the the fork
520+ -- number of the respective block header is at least the fork number of
521+ -- the respective fork.
522+ --
523+ -- Changes to the protocol are introduced by releasing a chainweb-node
524+ -- version that supports a fork number of the respecive change. Blocks
525+ -- that are produced by the new chainweb-node version will then raise
526+ -- the on-chain fork number in the block headers until the maximum
527+ -- supported number is reached.
518528 }
519529 deriving stock (Generic )
520530 deriving anyclass NFData
@@ -539,6 +549,7 @@ instance Ord ChainwebVersion where
539549 -- , _versionGenesis v `compare` _versionGenesis v'
540550 , _versionCheats v `compare` _versionCheats v'
541551 , _versionVerifierPluginNames v `compare` _versionVerifierPluginNames v'
552+ , _versionForkNumber v `compare` _versionForkNumber v'
542553 ]
543554
544555instance Eq ChainwebVersion where
@@ -722,7 +733,7 @@ genesisHeightAndGraph v c =
722733 -- the chain was in every graph down to the bottom,
723734 -- so the bottom has the genesis graph
724735 (False , z) -> ruleZipperHere z
725- (True , ( BetweenZipper _ above) )
736+ (True , BetweenZipper _ above)
726737 -- the chain is not in this graph, and there is no graph above
727738 -- which could have it
728739 | [] <- above -> missingChainError
0 commit comments