@@ -315,6 +315,8 @@ instance Show ValidationFailure where
315315 InvalidFeatureFlags -> " The block has an invalid feature flag value"
316316 InvalidBraiding -> " The block is not braided correctly into the chainweb"
317317 InvalidAdjacentVersion -> " An adjancent parent has a chainweb version that does not match the version of the validated header"
318+ IncorrectForkNumber -> " The block has an incorrect fork number"
319+ InvalidForkVotes -> " The block has an invalid fork vote count"
318320
319321-- | An enumeration of possible validation failures for a block header.
320322--
@@ -374,13 +376,29 @@ data ValidationFailureType
374376 | InvalidAdjacentVersion
375377 -- ^ An adjacent parent has chainweb version that does not match the
376378 -- version of the validated header.
379+ | IncorrectForkNumber
380+ -- ^ The block has an incorrect fork number. At the beginning of a fork
381+ -- epoch the fork number is the fork number of the parent plus one if
382+ -- the fork vote count of the parent is at least 2/3 of the total number
383+ -- of blocks in a fork epoch. Otherwise the number must be equal to the
384+ -- fork number of the parent. Note, that the fork number is determined
385+ -- deterministically from the parent block. It increases monotonically
386+ -- at most once per fork epoch.
387+ | InvalidForkVotes
388+ -- ^ The block has an invalid fork vote count. At the beginning of an
389+ -- fork epoch the fork vote count must be zero. Otherwise, the fork vote
390+ -- count must be equal to the fork vote of the parent block or one more
391+ -- than that. The fork vote count increases monotonically within an fork
392+ -- epoch in steps of zero or one. The step size at each block is
393+ -- non-deterministic. It is reset to zero at the beginning of a new fork
394+ -- epoch.
377395 deriving (Show , Eq , Ord )
378396
379397instance Exception ValidationFailure
380398
381399-- | The list of validation failures that are definite and independent of any
382400-- external context. A block for which validation fails with one of these
383- -- failures must be dicarded .
401+ -- failures must be discarded .
384402--
385403-- No node on the chainweb-web network should propgate blocks with these
386404-- failures. If a block is received that causes a definite validation failures
@@ -401,6 +419,8 @@ definiteValidationFailures =
401419 , IncorrectGenesisParent
402420 , IncorrectGenesisTarget
403421 , IncorrectPayloadHash
422+ , IncorrectForkNumber
423+ , InvalidForkVotes
404424 ]
405425
406426-- | Predicate that checks whether a validation failure is definite.
@@ -631,6 +651,7 @@ validateIntrinsic t b = concat
631651 , [ BlockInTheFuture | not (prop_block_current t b)]
632652 , [ InvalidFeatureFlags | not (prop_block_featureFlags b)]
633653 , [ AdjacentChainMismatch | not (prop_block_adjacent_chainIds b) ]
654+ , [ InvalidForkVotes | not (prop_block_forkVotesReset b) ]
634655 ]
635656
636657-- | Validate properties of a block with respect to a given parent.
@@ -653,6 +674,8 @@ validateInductiveChainStep s = concat
653674 , [ VersionMismatch | not (prop_block_chainwebVersion s) ]
654675 , [ IncorrectWeight | not (prop_block_weight s) ]
655676 , [ ChainMismatch | not (prop_block_chainId s) ]
677+ , [ InvalidForkVotes | not (prop_block_forkVotesIncrement s) ]
678+ , [ IncorrectForkNumber | not (prop_block_forkNumber s)
656679 ]
657680
658681validateInductiveWebStep
@@ -718,6 +741,11 @@ prop_block_adjacent_chainIds b
718741 | isGenesisBlockHeader b = _chainGraph b
719742 | otherwise = chainGraphAt (_chainwebVersion b) (view blockHeight b - 1 )
720743
744+ prop_block_forkVotesReset :: BlockHeader -> Bool
745+ prop_block_forkVotesReset b
746+ | isForkEpochStartBlockHeader b = view blockForkVotes b == 0
747+ | otherwise = True
748+
721749-- -------------------------------------------------------------------------- --
722750-- Inductive BlockHeader Properties
723751-- -------------------------------------------------------------------------- --
@@ -745,6 +773,14 @@ prop_block_chainId :: ChainStep -> Bool
745773prop_block_chainId (ChainStep (ParentHeader p) b)
746774 = view blockChainId p == view blockChainId b
747775
776+ prop_block_forkVotesIncrement :: ChainStep -> Bool
777+ prop_block_forkVotesIncrement (ChainStep (ParentHeader p) b)
778+ | isForkEpochStartBlockHeader b = votes == 0
779+ | otherwise = fv == parentVotes || votes == parentVotes + 1
780+ where
781+ votes = view blockForkVotes b
782+ parentVotes = view blockForkVotes p
783+
748784-- -------------------------------------------------------------------------- --
749785-- Multi chain inductive properties
750786
0 commit comments