-
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 6 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 |
|---|---|---|
|
|
@@ -68,7 +68,7 @@ import "yet-another-logger" System.Logger hiding (Logger) | |
| import "yet-another-logger" System.Logger qualified as YAL | ||
| import "yet-another-logger" System.Logger.Backend.ColorOption (useColor) | ||
| import Chainweb.BlockHash | ||
| import Chainweb.BlockHeader (blockHeight, blockHash, blockPayloadHash) | ||
| import Chainweb.BlockHeader (blockHeight, blockForkNumber, blockHash, blockPayloadHash) | ||
| import Chainweb.BlockHeaderDB.Internal (BlockHeaderDb(..), RankedBlockHeader(..)) | ||
| import Chainweb.BlockHeight (BlockHeight(..)) | ||
| import Chainweb.Cut.CutHashes (cutIdToText) | ||
|
|
@@ -762,7 +762,7 @@ doCompactRocksDb logger cwVersion cids minBlockHeight srcDb targetDb = do | |
| iterLast it | ||
| iterValue it >>= \case | ||
| Nothing -> exitLog logger "Missing final payload. This is likely due to a corrupted database." | ||
| Just rbh -> pure (_getRankedBlockHeader rbh ^. blockHeight) | ||
| Just rbh -> pure $ _getRankedBlockHeader rbh | ||
|
|
||
| -- The header that we start at depends on whether or not | ||
| -- we have a minimal block header history window. | ||
|
|
@@ -772,7 +772,10 @@ doCompactRocksDb logger cwVersion cids minBlockHeight srcDb targetDb = do | |
| -- | ||
| -- On new enough chainweb versions, we want to only copy over | ||
| -- the minimal number of block headers. | ||
| case minimumBlockHeaderHistory cwVersion latestHeader of | ||
| -- Note, this behaviour may be dangerous in case of changes on the miniumum block history. | ||
kdafriend marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| -- | ||
| -- TODO = Option to prune headers history to the minimum should be enabled by flag. | ||
|
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. I'd rather have a TODO for renaming the current |
||
| case minimumBlockHeaderHistory cwVersion (latestHeader ^. blockForkNumber) (latestHeader ^. blockHeight) of | ||
| -- Go to the earliest possible entry. We migrate all BlockHeaders, for now. | ||
| -- They are needed for SPV. | ||
| -- | ||
|
|
@@ -791,16 +794,18 @@ doCompactRocksDb logger cwVersion cids minBlockHeight srcDb targetDb = do | |
| earliestHeader <- do | ||
| iterValue it >>= \case | ||
| Nothing -> exitLog logger "Missing first payload. This is likely due to a corrupted database." | ||
| Just rbh -> pure (_getRankedBlockHeader rbh ^. blockHeight) | ||
| Just rbh -> pure $ _getRankedBlockHeader rbh | ||
|
|
||
| -- Ensure that we log progress 100 times per chain | ||
| -- I just made this number up as something that felt somewhat sensible | ||
| let offset = (latestHeader - earliestHeader) `div` 100 | ||
| let headerProgressPoints = [earliestHeader + i * offset | i <- [1..100]] | ||
| let latestHeight = latestHeader ^. blockHeight | ||
| earliestHeight = earliestHeader ^. blockHeight | ||
| offset = (latestHeight - earliestHeight) `div` 100 | ||
| let headerProgressPoints = [earliestHeight + i * offset | i <- [1..100]] | ||
|
|
||
| let logHeaderProgress bHeight = do | ||
| when (bHeight `elem` headerProgressPoints) $ do | ||
| let percentDone = sshow $ 100 * fromIntegral @_ @Double (bHeight - earliestHeader) / fromIntegral @_ @Double (latestHeader - earliestHeader) | ||
| let percentDone = sshow $ 100 * fromIntegral @_ @Double (bHeight - earliestHeight) / fromIntegral @_ @Double (latestHeight - earliestHeight) | ||
| log' LL.Info $ percentDone <> "% done." | ||
|
|
||
| let go = do | ||
|
|
||
| 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. | ||
|
|
||
|
|
||
kdafriend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.