| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Util.AnchoredFragment
Description
Utility functions on anchored fragments
Intended for qualified import > import qualified Ouroboros.Consensus.Util.AnchoredFragment as AF
Synopsis
- compareAnchoredFragments ∷ (BlockSupportsProtocol blk, HasCallStack, GetHeader1 h, HasHeader (h blk), HeaderHash (h blk) ~ HeaderHash blk) ⇒ BlockConfig blk → PerasWeightSnapshot blk → AnchoredFragment (h blk) → AnchoredFragment (h blk) → Ordering
- compareHeadBlockNo ∷ HasHeader b ⇒ AnchoredFragment b → AnchoredFragment b → Ordering
- cross ∷ HasHeader block ⇒ AnchoredFragment block → AnchoredFragment block → Maybe (Point block, AnchoredFragment block)
- forksAtMostKWeight ∷ (StandardHash blk, HasHeader b, HeaderHash blk ~ HeaderHash b) ⇒ PerasWeightSnapshot blk → PerasWeight → AnchoredFragment b → AnchoredFragment b → Bool
- preferAnchoredCandidate ∷ (BlockSupportsProtocol blk, HasCallStack, GetHeader1 h, GetHeader1 h', HeaderHash (h blk) ~ HeaderHash blk, HeaderHash (h blk) ~ HeaderHash (h' blk), HasHeader (h blk), HasHeader (h' blk)) ⇒ BlockConfig blk → PerasWeightSnapshot blk → AnchoredFragment (h blk) → AnchoredFragment (h' blk) → Bool
- stripCommonPrefix ∷ (Functor f, Foldable f, HasHeader blk) ⇒ Anchor blk → f (AnchoredFragment blk) → (AnchoredFragment blk, f (AnchoredFragment blk))
Documentation
compareAnchoredFragments ∷ (BlockSupportsProtocol blk, HasCallStack, GetHeader1 h, HasHeader (h blk), HeaderHash (h blk) ~ HeaderHash blk) ⇒ BlockConfig blk → PerasWeightSnapshot blk → AnchoredFragment (h blk) → AnchoredFragment (h blk) → Ordering Source #
Compare two (potentially empty!) AnchoredFragments.
PRECONDITION: The fragments must intersect.
Usage note: the primary user of this function is the chain database when sorting fragments that are preferred over our selection. It establishes the precondition in the following way: It will only compare candidate fragments that it has previously verified are preferable to our current chain. Since these fragments intersect with our current chain, we can enlarge them to all be anchored in the immutable tip. Therefore, they intersect pairwise.
compareHeadBlockNo ∷ HasHeader b ⇒ AnchoredFragment b → AnchoredFragment b → Ordering Source #
Compare the headBlockNo, which is a measure of the length of the chain,
of two anchored fragments.
A fragment with a head is always "greater" than one without. When both
fragments have no head (i.e. are empty), they are EQ.
Note that an EBB can share its BlockNo with another regular block. If
such an EBB is the head of one fragment and the regular block with the same
BlockNo is the head of the other fragment, then this function will say
they are EQ, while in fact one fragment should be preferred over the
other.
This is not a big deal as we won't be seeing new EBBs, so they will not be
the head of a fragment very often anyway, only when catching up. As soon as
a new block/header is added to the fragment, the right decision will be
made again (GT or LT).
cross ∷ HasHeader block ⇒ AnchoredFragment block → AnchoredFragment block → Maybe (Point block, AnchoredFragment block) Source #
If the two fragments c1 and c2 intersect, return the intersection
point and join the prefix of c1 before the intersection with the suffix
of c2 after the intersection. The resulting fragment has the same
anchor as c1 and the same head as c2.
Arguments
| ∷ (StandardHash blk, HasHeader b, HeaderHash blk ~ HeaderHash b) | |
| ⇒ PerasWeightSnapshot blk | |
| → PerasWeight | By how much weight can we roll back our chain at most? |
| → AnchoredFragment b | Our chain |
| → AnchoredFragment b | Their chain |
| → Bool | Indicates whether their chain forks at most the given the amount of
weight. Returns |
Check that we can switch from ours to theirs by rolling back our chain
by at most k weight.
If ours and cand do not intersect, this returns False. If they do
intersect, then we check that the suffix of ours after the intersection has
total weight at most k.
preferAnchoredCandidate Source #
Arguments
| ∷ (BlockSupportsProtocol blk, HasCallStack, GetHeader1 h, GetHeader1 h', HeaderHash (h blk) ~ HeaderHash blk, HeaderHash (h blk) ~ HeaderHash (h' blk), HasHeader (h blk), HasHeader (h' blk)) | |
| ⇒ BlockConfig blk | |
| → PerasWeightSnapshot blk | Peras weights used to judge this chain. |
| → AnchoredFragment (h blk) | Our chain |
| → AnchoredFragment (h' blk) | Candidate |
| → Bool |
Lift preferCandidate to AnchoredFragment
PRECONDITION: The fragments must intersect.
Usage note: the primary user of this function is the chain database. It
establishes the precondition when comparing a candidate fragment to our
current chain in the following way: The fragment is guaranteed (by the chain
sync client) to intersect with our chain (indeed, within at most k blocks
from our tip, although the exact distance does not matter for
compareAnchoredFragments).
stripCommonPrefix ∷ (Functor f, Foldable f, HasHeader blk) ⇒ Anchor blk → f (AnchoredFragment blk) → (AnchoredFragment blk, f (AnchoredFragment blk)) Source #
Strip the common prefix of multiple fragments.
PRECONDITION: all fragments have the given anchor as their anchor.