ouroboros-consensus-0.18.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Consensus.Fragment.Diff

Description

Intended for qualified import

import Ouroboros.Consensus.Fragment.Diff (ChainDiff (..))
import qualified Ouroboros.Consensus.Fragment.Diff as Diff
Synopsis

Documentation

data ChainDiff b Source #

A diff of a chain (fragment).

Typical instantiations of the type argument b: a block type blk, Header blk, HeaderFields, ..., anything that supports HasHeader.

Note: we allow the suffix to be shorter than the number of blocks to roll back. In other words, applying a ChainDiff can result in a chain shorter than the chain to which the diff was applied.

Constructors

ChainDiff 

Fields

Instances

Instances details
(StandardHash b, Show b) ⇒ Show (ChainDiff b) Source # 
Instance details

Defined in Ouroboros.Consensus.Fragment.Diff

Methods

showsPrecIntChainDiff b → ShowS #

showChainDiff b → String #

showList ∷ [ChainDiff b] → ShowS #

(StandardHash b, Eq b) ⇒ Eq (ChainDiff b) Source # 
Instance details

Defined in Ouroboros.Consensus.Fragment.Diff

Methods

(==)ChainDiff b → ChainDiff b → Bool #

(/=)ChainDiff b → ChainDiff b → Bool #

Queries

getAnchorPointChainDiff b → Point b Source #

Return the anchor point of the new suffix

getTipHasHeader b ⇒ ChainDiff b → Point b Source #

Return the tip of the new suffix

rollbackExceedsSuffixHasHeader b ⇒ ChainDiff b → Bool Source #

Return True iff applying the ChainDiff to a chain C will result in a chain shorter than C, i.e., the number of blocks to roll back is greater than the length of the new elements in the suffix to add.

Constructors

diff Source #

Arguments

∷ (HasHeader b, HasHeader b', HeaderHash b ~ HeaderHash b', HasCallStack) 
AnchoredFragment b'

Current chain

AnchoredFragment b

Candidate chain

ChainDiff b 

Diff a candidate chain with the current chain.

If the candidate fragment is shorter than the current chain, Nothing is returned (this would violate the invariant of ChainDiff).

PRECONDITION: the candidate fragment must intersect with the current chain fragment.

extendAnchoredFragment b → ChainDiff b Source #

Make an extension-only (no rollback) ChainDiff.

Application

applyHasHeader b ⇒ AnchoredFragment b → ChainDiff b → Maybe (AnchoredFragment b) Source #

Apply the ChainDiff on the given chain fragment.

The fragment is first rolled back a number of blocks before appending the new suffix.

If the ChainDiff doesn't fit (anchor point mismatch), Nothing is returned.

The returned fragment will have the same anchor point as the given fragment.

Manipulation

appendHasHeader b ⇒ ChainDiff b → b → ChainDiff b Source #

Append a b to a ChainDiff.

PRECONDITION: it must fit onto the end of the suffix.

mapM ∷ ∀ a b m. (HasHeader b, HeaderHash a ~ HeaderHash b, Monad m) ⇒ (a → m b) → ChainDiff a → m (ChainDiff b) Source #

takeWhileOldestHasHeader b ⇒ (b → Bool) → ChainDiff b → ChainDiff b Source #

Return the longest prefix of the suffix matching the given predicate, starting from the left, i.e., the "oldest" blocks.

If the new suffix is shorter than the diff's rollback, return Nothing.

truncate ∷ (HasHeader b, HasCallStack) ⇒ Point b → ChainDiff b → ChainDiff b Source #

Truncate the diff by rolling back the new suffix to the given point.

PRECONDITION: the given point must correspond to one of the new blocks/headers of the new suffix or its anchor (i.e, withinFragmentBounds pt (getSuffix diff)).

If the length of the truncated suffix is shorter than the rollback, Nothing is returned.