-
Notifications
You must be signed in to change notification settings - Fork 1
Extend ForkHeight to manage Fork numbers #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7d02e2a
489728f
92fff2a
dd5a906
4e7fb56
e0f4b5f
e64444c
52c1a46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,7 @@ import qualified Pact.Utils.StableHashMap as SHM | |
|
|
||
| import Chainweb.BlockHeader | ||
| import Chainweb.BlockHeight | ||
| import Chainweb.ForkState (pact4ForkNumber) | ||
| import Chainweb.Logger | ||
| import qualified Chainweb.ChainId as Chainweb | ||
| import Chainweb.Mempool.Mempool (pact4RequestKeyToTransactionHash) | ||
|
|
@@ -371,7 +372,7 @@ applyCmd v logger gasLogger txFailuresCounter pdbenv miner gasModel txCtx txIdxI | |
| chainweb217Pact' = guardCtx chainweb217Pact txCtx | ||
| chainweb219Pact' = guardCtx chainweb219Pact txCtx | ||
| chainweb223Pact' = guardCtx chainweb223Pact txCtx | ||
| allVerifiers = verifiersAt v cid currHeight | ||
| allVerifiers = verifiersAt v cid pact4ForkNumber currHeight | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine with me, using |
||
| toEmptyPactError (PactError errty _ _ _) = PactError errty noInfo [] mempty | ||
|
|
||
| toOldListErr pe = pe { peDoc = listErrMsg } | ||
|
|
@@ -671,7 +672,8 @@ applyLocal logger gasLogger dbEnv gasModel txCtx spv cmdIn mc execConfig = | |
| currHeight = ctxCurrentBlockHeight txCtx | ||
| cid = V._chainId txCtx | ||
| v = _chainwebVersion txCtx | ||
| allVerifiers = verifiersAt v cid currHeight | ||
|
|
||
| allVerifiers = verifiersAt v cid pact4ForkNumber currHeight | ||
| -- Note [Throw out verifier proofs eagerly] | ||
| !verifiersWithNoProof = | ||
| (fmap . fmap) (\_ -> ()) verifiers | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ module Chainweb.Version | |
| -- * Properties of Chainweb Version | ||
| Fork(..) | ||
| , ForkHeight(..) | ||
| , succByHeight | ||
| , _ForkAtBlockHeight | ||
| , _ForkAtGenesis | ||
| , _ForkNever | ||
|
|
@@ -322,12 +323,54 @@ instance FromJSON Fork where | |
| instance FromJSONKey Fork where | ||
| fromJSONKey = FromJSONKeyTextParser $ either fail return . eitherFromText | ||
|
|
||
| data ForkHeight = ForkAtBlockHeight !BlockHeight | ForkAtGenesis | ForkNever | ||
| deriving stock (Generic, Eq, Ord, Show) | ||
| data ForkHeight = ForkAtForkNumber !ForkNumber | ForkAtBlockHeight !BlockHeight | ForkAtGenesis | ForkNever | ||
| deriving stock (Generic, Eq, Show) | ||
| deriving anyclass (Hashable, NFData) | ||
|
|
||
| instance Bounded ForkHeight where | ||
| minBound = ForkAtGenesis | ||
| maxBound = ForkNever | ||
|
|
||
| instance Ord ForkHeight where | ||
| compare ForkAtGenesis ForkAtGenesis = EQ | ||
| compare ForkNever ForkNever = EQ | ||
| compare (ForkAtForkNumber a) (ForkAtForkNumber b) = compare a b | ||
| compare (ForkAtBlockHeight a) (ForkAtBlockHeight b) = compare a b | ||
| compare ForkAtGenesis _ = LT | ||
| compare _ ForkAtGenesis = GT | ||
| compare ForkNever _ = GT | ||
| compare _ ForkNever = LT | ||
| compare (ForkAtForkNumber fn) (ForkAtBlockHeight _) | ||
| | fn == 0 = LT | ||
| | otherwise = GT | ||
| compare (ForkAtBlockHeight _) (ForkAtForkNumber fn) | ||
| | fn == 0 = GT | ||
| | otherwise = LT | ||
|
|
||
| -- We consider the following ordering for Forks: | ||
| -- - ForkAtGenesis | ||
| -- - ForkNumber = 0 (unusual case) | ||
edmundnoble marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -- - BlockHeight = 0 (unusual case) | ||
| -- - BlockHeight = 1 | ||
| -- .. | ||
| -- - BlockHeight = n | ||
| -- - ForkNumber = 1 | ||
| -- .. | ||
| -- - ForkNumber = n | ||
| -- - ForkNever | ||
| -- | ||
| -- During the LLC era, forks were triggered by block heights, with a fork number of 0 (called feature flag). | ||
| -- After version 3.1, forks are ONLY triggered by fork numbers, as soon as the fork number becomes equal to 1. | ||
| -- So the fork heights are sorted chronologically: first block heights, then fork numbers. | ||
|
|
||
|
|
||
| makePrisms ''ForkHeight | ||
|
|
||
| succByHeight :: ForkHeight -> ForkHeight | ||
| succByHeight (ForkAtBlockHeight x) = ForkAtBlockHeight $ succ x | ||
| succByHeight ForkNever = ForkNever | ||
| succByHeight _ = error "Only a Blockheight defined fork can be succ'ed" | ||
|
|
||
|
Comment on lines
+370
to
+373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: This being somewhat hacky is expected because the mechanism it's working on is also somewhat hacky. In future, |
||
| newtype ChainwebVersionName = | ||
| ChainwebVersionName { getChainwebVersionName :: T.Text } | ||
| deriving stock (Generic, Eq, Ord) | ||
|
|
@@ -491,9 +534,9 @@ data ChainwebVersion | |
| -- | ||
| -- NOTE: This is internal. For the actual size of the serialized header | ||
| -- use 'headerSizeBytes'. | ||
| , _versionMaxBlockGasLimit :: Rule BlockHeight (Maybe Natural) | ||
| , _versionMaxBlockGasLimit :: Rule ForkHeight (Maybe Natural) | ||
| -- ^ The maximum gas limit for an entire block. | ||
| , _versionSpvProofRootValidWindow :: Rule BlockHeight (Maybe Word64) | ||
| , _versionSpvProofRootValidWindow :: Rule ForkHeight (Maybe Word64) | ||
| -- ^ The minimum number of block headers a chainweb node should | ||
| -- retain in its history at all times. | ||
| , _versionBootstraps :: [PeerInfo] | ||
|
|
@@ -504,7 +547,7 @@ data ChainwebVersion | |
| -- ^ Whether to disable any core functionality. | ||
| , _versionDefaults :: VersionDefaults | ||
| -- ^ Version-specific defaults that can be overridden elsewhere. | ||
| , _versionVerifierPluginNames :: ChainMap (Rule BlockHeight (Set VerifierName)) | ||
| , _versionVerifierPluginNames :: ChainMap (Rule ForkHeight (Set VerifierName)) | ||
| -- ^ Verifier plugins that can be run to verify transaction contents. | ||
| , _versionQuirks :: VersionQuirks | ||
| -- ^ Modifications to behavior at particular blockheights | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have a TODO for renaming the current
minimumBlockHeaderHistorytoversionSpvProofRootValidWindowand adding a newminimumBlockHeaderHistorywhich is set toNothing(i.e. all history) for all existing versions for this to use.