-
Notifications
You must be signed in to change notification settings - Fork 23
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
Full rework of the BlockFetch logic for bulk sync mode #1179
Open
Niols
wants to merge
29
commits into
main
Choose a base branch
from
blockfetch/milestone-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,287
−438
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b93c379
Introduce a collection of chainsync handles that synchronizes a map a…
facundominguez b1c0bf8
Implement a call to rotate dynamos in CSJ
facundominguez c4bfa37
Specify the order in which to start the peers
Niols c594c09
Add a BlockFetch leashing attack test
Niols 6926278
Accomodate for changes to BlockFetch
Niols 73187ba
Track the last time the ChainDB thread was starved
Niols 17b251e
Add explicit tracing events for CSJ
Niols 0d3fc28
ChainDB: let the BlockFetch client add blocks asynchronously
facundominguez 0f5d073
Update Genesis configuration
nbacquey 028883a
Set the jump size to smaller size for byron
facundominguez b7fa122
Limit the rate at which GDD is evaluated
facundominguez 08be124
Documentation edits for CSJ
facundominguez e27a73c
ChainSync client: disconnect if stuck and not better than selection
amesgen 8a3a1f3
Update tests
Niols dc5f6f7
Don't let GDD drop candidates that do not intersect with the selection
facundominguez db529b3
Introduce `peersOnlyAdversary` and classify abnormal test peers as ad…
nbacquey 17ca1f7
Document all tests that did not have documentation
Niols 5c7a545
Depend on the ouroboros-network fork with the latest blockfetch
facundominguez 122ab88
lint: stylish-haskell
nbacquey 62605ad
Add changelog fragments
amesgen db26d58
Please hlint
facundominguez 061bf1a
Fix `dropElemsAt` implementation
nbacquey 17b9d3c
Adjust stalling test to have more kills by LoP
facundominguez d6a37c4
Document prop_blockFetchLeashingAttack
Niols 4c00401
Disable blockfetch timeouts in uniform tests
facundominguez 754ef99
Groom comments and counterexample messages.
facundominguez dadb808
Drop random points from adversarial schedules in the time limited lea…
facundominguez 9af756e
Please hlint again
facundominguez 13c93e6
Update configuration after recovering BulkSync in ouroboros-network
facundominguez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions
3
...-consensus-diffusion/changelog.d/20240807_100458_alexander.esgen_milestone_1.md
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,3 @@ | ||
### Breaking | ||
|
||
- Adapted to Genesis-related changes in `ouroboros-consensus` ([#1179](https://github.com/IntersectMBO/ouroboros-consensus/pull/1179)). |
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 | ||||
---|---|---|---|---|---|---|
@@ -1,24 +1,32 @@ | ||||||
{-# LANGUAGE DeriveGeneric #-} | ||||||
{-# LANGUAGE DeriveTraversable #-} | ||||||
{-# LANGUAGE DerivingStrategies #-} | ||||||
{-# LANGUAGE LambdaCase #-} | ||||||
{-# LANGUAGE NamedFieldPuns #-} | ||||||
{-# LANGUAGE NumericUnderscores #-} | ||||||
{-# LANGUAGE RecordWildCards #-} | ||||||
{-# LANGUAGE ScopedTypeVariables #-} | ||||||
|
||||||
module Ouroboros.Consensus.Node.Genesis ( | ||||||
-- * 'GenesisConfig' | ||||||
GenesisConfig (..) | ||||||
, GenesisConfigFlags (..) | ||||||
, LoEAndGDDConfig (..) | ||||||
, defaultGenesisConfigFlags | ||||||
, disableGenesisConfig | ||||||
, enableGenesisConfigDefault | ||||||
, mkGenesisConfig | ||||||
-- * NodeKernel helpers | ||||||
, GenesisNodeKernelArgs (..) | ||||||
, LoEAndGDDNodeKernelArgs (..) | ||||||
, mkGenesisNodeKernelArgs | ||||||
, setGetLoEFragment | ||||||
) where | ||||||
|
||||||
import Control.Monad (join) | ||||||
import Data.Maybe (fromMaybe) | ||||||
import Data.Traversable (for) | ||||||
import GHC.Generics (Generic) | ||||||
import Ouroboros.Consensus.Block | ||||||
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client | ||||||
(CSJConfig (..), CSJEnabledConfig (..), | ||||||
|
@@ -32,51 +40,121 @@ import Ouroboros.Consensus.Util.Args | |||||
import Ouroboros.Consensus.Util.IOLike | ||||||
import Ouroboros.Network.AnchoredFragment (AnchoredFragment) | ||||||
import qualified Ouroboros.Network.AnchoredFragment as AF | ||||||
import Ouroboros.Network.BlockFetch | ||||||
(GenesisBlockFetchConfiguration (..)) | ||||||
|
||||||
-- | Whether to en-/disable the Limit on Eagerness and the Genesis Density | ||||||
-- Disconnector. | ||||||
data LoEAndGDDConfig a = | ||||||
LoEAndGDDEnabled !a | ||||||
| LoEAndGDDDisabled | ||||||
deriving stock (Show, Functor, Foldable, Traversable) | ||||||
deriving stock (Eq, Generic, Show, Functor, Foldable, Traversable) | ||||||
|
||||||
-- | Aggregating the various configs for Genesis-related subcomponents. | ||||||
data GenesisConfig = GenesisConfig { | ||||||
gcChainSyncLoPBucketConfig :: !ChainSyncLoPBucketConfig | ||||||
data GenesisConfig = GenesisConfig | ||||||
{ gcBlockFetchConfig :: !GenesisBlockFetchConfiguration | ||||||
, gcChainSyncLoPBucketConfig :: !ChainSyncLoPBucketConfig | ||||||
, gcCSJConfig :: !CSJConfig | ||||||
, gcLoEAndGDDConfig :: !(LoEAndGDDConfig ()) | ||||||
, gcLoEAndGDDConfig :: !(LoEAndGDDConfig LoEAndGDDParams) | ||||||
} deriving stock (Eq, Generic, Show) | ||||||
|
||||||
-- | Genesis configuration flags and low-level args, as parsed from config file or CLI | ||||||
data GenesisConfigFlags = GenesisConfigFlags | ||||||
{ gcfEnableCSJ :: Bool | ||||||
, gcfEnableLoEAndGDD :: Bool | ||||||
, gcfEnableLoP :: Bool | ||||||
, gcfBlockFetchGracePeriod :: Maybe Integer | ||||||
, gcfBucketCapacity :: Maybe Integer | ||||||
, gcfBucketRate :: Maybe Integer | ||||||
, gcfCSJJumpSize :: Maybe Integer | ||||||
, gcfGDDRateLimit :: Maybe DiffTime | ||||||
} deriving stock (Eq, Generic, Show) | ||||||
|
||||||
defaultGenesisConfigFlags :: GenesisConfigFlags | ||||||
defaultGenesisConfigFlags = GenesisConfigFlags | ||||||
{ gcfEnableCSJ = True | ||||||
, gcfEnableLoEAndGDD = True | ||||||
, gcfEnableLoP = True | ||||||
, gcfBlockFetchGracePeriod = Nothing | ||||||
, gcfBucketCapacity = Nothing | ||||||
, gcfBucketRate = Nothing | ||||||
, gcfCSJJumpSize = Nothing | ||||||
, gcfGDDRateLimit = Nothing | ||||||
} | ||||||
|
||||||
-- TODO justification/derivation from other parameters | ||||||
enableGenesisConfigDefault :: GenesisConfig | ||||||
enableGenesisConfigDefault = GenesisConfig { | ||||||
gcChainSyncLoPBucketConfig = ChainSyncLoPBucketEnabled ChainSyncLoPBucketEnabledConfig { | ||||||
csbcCapacity = 100_000 -- number of tokens | ||||||
, csbcRate = 500 -- tokens per second leaking, 1/2ms | ||||||
} | ||||||
, gcCSJConfig = CSJEnabled CSJEnabledConfig { | ||||||
csjcJumpSize = 3 * 2160 * 20 -- mainnet forecast range | ||||||
} | ||||||
, gcLoEAndGDDConfig = LoEAndGDDEnabled () | ||||||
} | ||||||
enableGenesisConfigDefault = mkGenesisConfig $ Just $ defaultGenesisConfigFlags | ||||||
|
||||||
-- | Disable all Genesis components, yielding Praos behavior. | ||||||
disableGenesisConfig :: GenesisConfig | ||||||
disableGenesisConfig = GenesisConfig { | ||||||
gcChainSyncLoPBucketConfig = ChainSyncLoPBucketDisabled | ||||||
disableGenesisConfig = mkGenesisConfig Nothing | ||||||
|
||||||
mkGenesisConfig :: Maybe GenesisConfigFlags -> GenesisConfig | ||||||
mkGenesisConfig Nothing = -- disable Genesis | ||||||
GenesisConfig | ||||||
{ gcBlockFetchConfig = GenesisBlockFetchConfiguration | ||||||
{ gbfcGracePeriod = 0 -- no grace period when Genesis is disabled | ||||||
} | ||||||
, gcChainSyncLoPBucketConfig = ChainSyncLoPBucketDisabled | ||||||
, gcCSJConfig = CSJDisabled | ||||||
, gcLoEAndGDDConfig = LoEAndGDDDisabled | ||||||
} | ||||||
mkGenesisConfig (Just GenesisConfigFlags{..}) = | ||||||
GenesisConfig | ||||||
{ gcBlockFetchConfig = GenesisBlockFetchConfiguration | ||||||
{ gbfcGracePeriod | ||||||
} | ||||||
, gcChainSyncLoPBucketConfig = if gcfEnableLoP | ||||||
then ChainSyncLoPBucketEnabled ChainSyncLoPBucketEnabledConfig | ||||||
{ csbcCapacity | ||||||
, csbcRate | ||||||
} | ||||||
else ChainSyncLoPBucketDisabled | ||||||
, gcCSJConfig = if gcfEnableCSJ | ||||||
then CSJEnabled CSJEnabledConfig | ||||||
{ csjcJumpSize | ||||||
} | ||||||
else CSJDisabled | ||||||
, gcLoEAndGDDConfig = if gcfEnableLoEAndGDD | ||||||
then LoEAndGDDEnabled LoEAndGDDParams{lgpGDDRateLimit} | ||||||
else LoEAndGDDDisabled | ||||||
} | ||||||
where | ||||||
-- TODO justification/derivation from other parameters | ||||||
defaultBlockFetchGracePeriod = 10 -- seconds | ||||||
defaultCapacity = 100_000 -- number of tokens | ||||||
defaultRate = 500 -- tokens per second leaking, 1/2ms | ||||||
-- 3 * 2160 * 20 works in more recent ranges of slots, but causes syncing to | ||||||
-- block in byron. | ||||||
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.
Suggested change
|
||||||
defaultCSJJumpSize = 2 * 2160 | ||||||
defaultGDDRateLimit = 1.0 -- seconds | ||||||
|
||||||
gbfcGracePeriod = fromInteger $ fromMaybe defaultBlockFetchGracePeriod gcfBlockFetchGracePeriod | ||||||
csbcCapacity = fromInteger $ fromMaybe defaultCapacity gcfBucketCapacity | ||||||
csbcRate = fromInteger $ fromMaybe defaultRate gcfBucketRate | ||||||
csjcJumpSize = fromInteger $ fromMaybe defaultCSJJumpSize gcfCSJJumpSize | ||||||
lgpGDDRateLimit = fromMaybe defaultGDDRateLimit gcfGDDRateLimit | ||||||
|
||||||
newtype LoEAndGDDParams = LoEAndGDDParams | ||||||
{ -- | How often to evaluate GDD. 0 means as soon as possible. | ||||||
-- Otherwise, no faster than once every T seconds, where T is the | ||||||
-- value of the field. | ||||||
lgpGDDRateLimit :: DiffTime | ||||||
} deriving stock (Eq, Generic, Show) | ||||||
|
||||||
-- | Genesis-related arguments needed by the NodeKernel initialization logic. | ||||||
data GenesisNodeKernelArgs m blk = GenesisNodeKernelArgs { | ||||||
gnkaLoEAndGDDArgs :: !(LoEAndGDDConfig (LoEAndGDDNodeKernelArgs m blk)) | ||||||
} | ||||||
|
||||||
data LoEAndGDDNodeKernelArgs m blk = LoEAndGDDNodeKernelArgs { | ||||||
-- | A TVar containing an action that returns the 'ChainDB.GetLoEFragment' | ||||||
-- action. We use this extra indirection to update this action after we | ||||||
-- opened the ChainDB (which happens before we initialize the NodeKernel). | ||||||
-- After that, this TVar will not be modified again. | ||||||
gnkaGetLoEFragment :: !(LoEAndGDDConfig (StrictTVar m (ChainDB.GetLoEFragment m blk))) | ||||||
lgnkaLoEFragmentTVar :: !(StrictTVar m (ChainDB.GetLoEFragment m blk)) | ||||||
, lgnkaGDDRateLimit :: DiffTime | ||||||
} | ||||||
|
||||||
-- | Create the initial 'GenesisNodeKernelArgs" (with a temporary | ||||||
-- 'ChainDB.GetLoEFragment' that will be replaced via 'setGetLoEFragment') and a | ||||||
-- function to update the 'ChainDbArgs' accordingly. | ||||||
|
@@ -87,20 +165,24 @@ mkGenesisNodeKernelArgs :: | |||||
, Complete ChainDbArgs m blk -> Complete ChainDbArgs m blk | ||||||
) | ||||||
mkGenesisNodeKernelArgs gcfg = do | ||||||
gnkaGetLoEFragment <- for (gcLoEAndGDDConfig gcfg) $ \() -> | ||||||
newTVarIO $ pure $ | ||||||
gnkaLoEAndGDDArgs <- for (gcLoEAndGDDConfig gcfg) $ \p -> do | ||||||
loeFragmentTVar <- newTVarIO $ pure $ | ||||||
-- Use the most conservative LoE fragment until 'setGetLoEFragment' | ||||||
-- is called. | ||||||
ChainDB.LoEEnabled $ AF.Empty AF.AnchorGenesis | ||||||
let updateChainDbArgs = case gnkaGetLoEFragment of | ||||||
pure LoEAndGDDNodeKernelArgs | ||||||
{ lgnkaLoEFragmentTVar = loeFragmentTVar | ||||||
, lgnkaGDDRateLimit = lgpGDDRateLimit p | ||||||
} | ||||||
let updateChainDbArgs = case gnkaLoEAndGDDArgs of | ||||||
LoEAndGDDDisabled -> id | ||||||
LoEAndGDDEnabled varGetLoEFragment -> \cfg -> | ||||||
LoEAndGDDEnabled lgnkArgs -> \cfg -> | ||||||
cfg { ChainDB.cdbsArgs = | ||||||
(ChainDB.cdbsArgs cfg) { ChainDB.cdbsLoE = getLoEFragment } | ||||||
} | ||||||
where | ||||||
getLoEFragment = join $ readTVarIO varGetLoEFragment | ||||||
pure (GenesisNodeKernelArgs {gnkaGetLoEFragment}, updateChainDbArgs) | ||||||
getLoEFragment = join $ readTVarIO $ lgnkaLoEFragmentTVar lgnkArgs | ||||||
pure (GenesisNodeKernelArgs{gnkaLoEAndGDDArgs}, updateChainDbArgs) | ||||||
|
||||||
-- | Set 'gnkaGetLoEFragment' to the actual logic for determining the current | ||||||
-- LoE fragment. | ||||||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might help to add comments and examples of these flags and their effect on the node's behaviour. It will surely help whoever integrates this with the CLI/Node.