Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
67 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
ouroboros-network/src/Ouroboros/Network/AnchoredFragment/Completeness.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
-- | | ||
|
||
module Ouroboros.Network.AnchoredFragment.Completeness where | ||
|
||
import Prelude hiding (filter, head, last, length, map, null, splitAt) | ||
|
||
import GHC.Generics (Generic) | ||
import NoThunks.Class (NoThunks) | ||
|
||
import Ouroboros.Network.AnchoredFragment | ||
import Ouroboros.Network.Block | ||
|
||
-- | BlockFetch and ChainSync operate with 'AnchoredFragment's when dealing with | ||
-- candidate chains. For Ouroboros Genesis, we need to know whether or not the | ||
-- fragment represents the end of the remote chain, to make judgments about | ||
-- whether or not our perceived density is indeed the real density. | ||
-- | ||
-- Every fragment returned by ChainSync will be coupled with one of these tags, | ||
-- specifying if the ChainSync client thinks that the fragment is indeed | ||
-- complete. This flag will be used by the prefix selection algorithm to filter | ||
-- appropriate candidates to be provided to BlockFetch. | ||
data FragmentCompleteness = FragmentComplete | FragmentIncomplete | ||
deriving (Show, Generic, Eq, NoThunks) | ||
|
||
-- | Return a 'AF.FragmentCompleteness' for the given fragment assuming the | ||
-- provided tip is the one announced by the remote peer. | ||
-- | ||
-- This function will return 'Nothing' when the tip is at Genesis but the | ||
-- fragment isn't. This should be interpreted in the ChainSync protocol as a | ||
-- misbehaving of the server. | ||
isFragmentComplete :: | ||
( StandardHash blk | ||
, HasHeader blk) | ||
=> Tip blk | ||
-> AnchoredFragment blk | ||
-> Maybe FragmentCompleteness | ||
isFragmentComplete TipGenesis theirFrag = | ||
if pointHash (anchorPoint theirFrag) == GenesisHash | ||
then Just FragmentComplete | ||
else Nothing | ||
isFragmentComplete (Tip _ tipHash _) theirFrag = | ||
Just $ case headHash theirFrag of | ||
GenesisHash -> FragmentIncomplete | ||
BlockHash theHeadHash | ||
| theHeadHash == tipHash -> FragmentComplete | ||
| otherwise -> FragmentIncomplete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters