Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 153eeaf

Browse files
committed
add fork number field to chainweb version
1 parent 2c715eb commit 153eeaf

File tree

6 files changed

+44
-32
lines changed

6 files changed

+44
-32
lines changed

src/Chainweb/Version.hs

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
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
151153
import Control.DeepSeq
152154
import Control.Lens hiding ((.=), (<.>), index)
153155
import Control.Monad.Catch
154-
155156
import Data.Aeson hiding (pairs)
156157
import Data.Aeson.Types
157158
import Data.Foldable
158159
import Data.Hashable
159160
import 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
162163
import Data.Set(Set)
163164
import Data.Proxy
164-
import qualified Data.Text as T
165+
import Data.Text qualified as T
165166
import Data.Word
166-
167167
import GHC.Generics(Generic)
168168
import GHC.TypeLits
169169
import GHC.Stack
170-
171-
-- internal modules
172-
173170
import Pact.Types.Runtime (Gas)
174-
175171
import Chainweb.BlockCreationTime
176172
import Chainweb.BlockHeight
177173
import Chainweb.ChainId
@@ -181,17 +177,15 @@ import Chainweb.Graph
181177
import Chainweb.HostAddress
182178
import Chainweb.MerkleUniverse
183179
import 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)
186183
import Chainweb.Utils
187184
import Chainweb.Utils.Rule
188185
import Chainweb.Utils.Serialization
189-
190-
import Pact.Types.Verifier
191-
192186
import Data.Singletons
193-
194187
import 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
393387
pattern ForPact5 x = ForSomePactVersion Pact5T x
394388
{-# COMPLETE ForPact4, ForPact5 #-}
395389
data ForBothPactVersions f = ForBothPactVersions
396-
{ _forPact4 :: (f Pact4)
397-
, _forPact5 :: (f Pact5)
390+
{ _forPact4 :: f Pact4
391+
, _forPact5 :: f Pact5
398392
}
399393
deriving stock instance (Eq (f Pact4), Eq (f Pact5)) => Eq (ForBothPactVersions f)
400394
deriving stock instance (Show (f Pact4), Show (f Pact5)) => Show (ForBothPactVersions f)
@@ -435,7 +429,7 @@ instance NFData PactUpgrade where
435429
pact4Upgrade :: [Pact4.Transaction] -> PactUpgrade
436430
pact4Upgrade 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

544555
instance 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

src/Chainweb/Version/Development.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ devnet = ChainwebVersion
6565
(minBound, Set.fromList $ map VerifierName ["hyperlane_v3_message", "allow", "signed_list"])
6666
, _versionQuirks = noQuirks
6767
, _versionServiceDate = Nothing
68+
, _versionForkNumber = 0
6869
}

src/Chainweb/Version/Guards.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
{-# LANGUAGE BangPatterns #-}
21
{-# LANGUAGE GADTs #-}
32
{-# LANGUAGE ImportQualifiedPost #-}
4-
{-# LANGUAGE LambdaCase #-}
5-
{-# LANGUAGE OverloadedStrings #-}
63
{-# LANGUAGE ScopedTypeVariables #-}
74

85
-- |

src/Chainweb/Version/Mainnet.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ mainnet = ChainwebVersion
223223
, _disableMempoolSync = False
224224
}
225225
, _versionVerifierPluginNames = AllChains $
226-
(4_577_530, Set.fromList $ map VerifierName ["hyperlane_v3_message"]) `Above`
226+
(4_577_530, Set.fromList [VerifierName "hyperlane_v3_message"]) `Above`
227227
Bottom (minBound, mempty)
228228
, _versionQuirks = VersionQuirks
229229
{ _quirkGasFees = onChains
@@ -232,4 +232,5 @@ mainnet = ChainwebVersion
232232
]
233233
}
234234
, _versionServiceDate = Just "2026-01-07T00:00:00Z"
235+
, _versionForkNumber = 0
235236
}

src/Chainweb/Version/RecapDevelopment.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,5 @@ recapDevnet = ChainwebVersion
129129
Bottom (minBound, mempty)
130130
, _versionQuirks = noQuirks
131131
, _versionServiceDate = Nothing
132+
, _versionForkNumber = 0
132133
}

src/Chainweb/Version/Testnet04.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ testnet04 = ChainwebVersion
135135
Chainweb228Pact -> AllChains $ ForkAtBlockHeight $ BlockHeight 5_155_146 -- 2025-03-11 00:00:00+00:00
136136
Chainweb229Pact -> AllChains $ ForkAtBlockHeight $ BlockHeight 5_300_466 -- 2025-04-30 12:00:00+00:00
137137
Chainweb230Pact -> AllChains $ ForkAtBlockHeight $ BlockHeight 5_542_190 -- 2025-07-23 12:00:00+00:00
138-
Chainweb231Pact -> AllChains $ ForkAtBlockHeight $ BlockHeight 5_783_985 -- 2025-10-15 12:00:00+00:00
138+
Chainweb231Pact -> AllChains $ ForkAtBlockHeight $ BlockHeight 5_783_985 -- 2025-10-15 12:00:00+00:00
139139
Chainweb232Pact -> AllChains ForkNever
140140

141141
, _versionGraphs =
@@ -191,7 +191,7 @@ testnet04 = ChainwebVersion
191191
{ _disablePeerValidation = False
192192
, _disableMempoolSync = False
193193
}
194-
, _versionVerifierPluginNames = AllChains $ (4_100_681, Set.fromList $ map VerifierName ["hyperlane_v3_message"]) `Above`
194+
, _versionVerifierPluginNames = AllChains $ (4_100_681, Set.fromList [VerifierName "hyperlane_v3_message"]) `Above`
195195
Bottom (minBound, mempty)
196196
, _versionQuirks = VersionQuirks
197197
{ _quirkGasFees = onChains
@@ -200,4 +200,5 @@ testnet04 = ChainwebVersion
200200
]
201201
}
202202
, _versionServiceDate = Just "2026-01-07T00:00:00Z"
203+
, _versionForkNumber = 0
203204
}

0 commit comments

Comments
 (0)