Skip to content

Commit

Permalink
Extract Genesis-specific config params in their own type
Browse files Browse the repository at this point in the history
  • Loading branch information
nbacquey authored and facundominguez committed Jul 16, 2024
1 parent 33ffeb3 commit 7a84d64
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
4 changes: 3 additions & 1 deletion ouroboros-network/demo/chain-sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ clientBlockFetch sockAddrs maxSlotNo = withIOManager $ \iocp -> do
bfcMaxRequestsInflight = 10,
bfcDecisionLoopInterval = 0.01,
bfcSalt = 0,
bfcBulkSyncGracePeriod = 10 -- seconds
bfcGenesisBFConfig = GenesisBlockFetchConfiguration
{ gbfcBulkSyncGracePeriod = 10 -- seconds
}
})
>> return ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ blockFetchExample0 decisionTracer clientStateTracer clientMsgTracer
bfcMaxRequestsInflight = 10,
bfcDecisionLoopInterval = 0.01,
bfcSalt = 0,
bfcBulkSyncGracePeriod = 10 -- seconds
bfcGenesisBFConfig = GenesisBlockFetchConfiguration
{ gbfcBulkSyncGracePeriod = 10 -- seconds
}
})
>> return ()

Expand Down Expand Up @@ -247,7 +249,9 @@ blockFetchExample1 decisionTracer clientStateTracer clientMsgTracer
bfcMaxRequestsInflight = 10,
bfcDecisionLoopInterval = 0.01,
bfcSalt = 0,
bfcBulkSyncGracePeriod = 10 -- seconds
bfcGenesisBFConfig = GenesisBlockFetchConfiguration
{ gbfcBulkSyncGracePeriod = 10 -- seconds
}
})
>> return ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch =
bfcMaxRequestsInflight = 10,
bfcDecisionLoopInterval = 0.01,
bfcSalt = 0,
bfcBulkSyncGracePeriod = 10 -- seconds
bfcGenesisBFConfig = GenesisBlockFetchConfiguration
{ gbfcBulkSyncGracePeriod = 10 -- seconds
}
})

blockFetchPolicy :: NodeKernel BlockHeader Block s m
Expand Down
17 changes: 13 additions & 4 deletions ouroboros-network/src/Ouroboros/Network/BlockFetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module Ouroboros.Network.BlockFetch
( blockFetchLogic
, BlockFetchConfiguration (..)
, BlockFetchConsensusInterface (..)
, GenesisBlockFetchConfiguration (..)
-- ** Tracer types
, FetchDecision
, TraceFetchClientState (..)
Expand Down Expand Up @@ -141,12 +142,20 @@ data BlockFetchConfiguration =
-- | Salt used when comparing peers
bfcSalt :: !Int,

-- | Grace period when starting to talk to a peer in bulk sync mode
-- during which it is fine if the chain selection gets starved.
bfcBulkSyncGracePeriod :: !DiffTime
-- | Genesis-specific parameters
bfcGenesisBFConfig :: !GenesisBlockFetchConfiguration
}
deriving (Show)

-- | BlockFetch configuration parameters specific to Genesis.
data GenesisBlockFetchConfiguration =
GenesisBlockFetchConfiguration
{ -- | Grace period when starting to talk to a peer in bulk sync mode
-- during which it is fine if the chain selection gets starved.
gbfcBulkSyncGracePeriod :: !DiffTime
}
deriving (Show)

-- | Execute the block fetch logic. It monitors the current chain and candidate
-- chains. It decided which block bodies to fetch and manages the process of
-- fetching them, including making alternative decisions based on timeouts and
Expand Down Expand Up @@ -200,7 +209,7 @@ blockFetchLogic decisionTracer clientStateTracer
maxConcurrencyDeadline = bfcMaxConcurrencyDeadline,
decisionLoopInterval = bfcDecisionLoopInterval,
peerSalt = bfcSalt,
bulkSyncGracePeriod = bfcBulkSyncGracePeriod,
bulkSyncGracePeriod = gbfcBulkSyncGracePeriod bfcGenesisBFConfig,

plausibleCandidateChain,
compareCandidateChains,
Expand Down
17 changes: 10 additions & 7 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Ouroboros.Network.Diffusion.Configuration

import System.Random (randomRIO)

import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..))
import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..), GenesisBlockFetchConfiguration (..))
import Ouroboros.Network.ConnectionManager.Core (defaultProtocolIdleTimeout,
defaultResetTimeout, defaultTimeWaitTimeout)
import Ouroboros.Network.Diffusion (P2P (..))
Expand Down Expand Up @@ -90,12 +90,15 @@ defaultPeerSharing = PeerSharingDisabled
-- | Configuration for FetchDecisionPolicy.
defaultBlockFetchConfiguration :: Int -> BlockFetchConfiguration
defaultBlockFetchConfiguration bfcSalt =
BlockFetchConfiguration {
bfcMaxConcurrencyDeadline = 1,
bfcMaxRequestsInflight = fromIntegral $ blockFetchPipeliningMax defaultMiniProtocolParameters,
bfcDecisionLoopInterval = 0.01, -- 10ms
bfcBulkSyncGracePeriod = 10, -- seconds
bfcSalt }
BlockFetchConfiguration
{ bfcMaxConcurrencyDeadline = 1
, bfcMaxRequestsInflight = fromIntegral $ blockFetchPipeliningMax defaultMiniProtocolParameters
, bfcDecisionLoopInterval = 0.01 -- 10ms
, bfcGenesisBFConfig = GenesisBlockFetchConfiguration
{ gbfcBulkSyncGracePeriod = 10 -- seconds
}
, bfcSalt
}

defaultChainSyncTimeout :: IO ChainSyncTimeout
defaultChainSyncTimeout = do
Expand Down

0 comments on commit 7a84d64

Please sign in to comment.