Skip to content

Commit 7d82cf1

Browse files
facundominguezamesgen
authored andcommitted
Update configuration after recovering BulkSync in ouroboros-network
1 parent fd3da5d commit 7d82cf1

File tree

7 files changed

+99
-70
lines changed

7 files changed

+99
-70
lines changed

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ nonImmutableDbPath (MultipleDbPaths _ vol) = vol
317317
--
318318
-- See 'stdLowLevelRunNodeArgsIO'.
319319
data StdRunNodeArgs m blk (p2p :: Diffusion.P2P) = StdRunNodeArgs
320-
{ srnBfcMaxConcurrencyDeadline :: Maybe Word
320+
{ srnBfcMaxConcurrencyBulkSync :: Maybe Word
321+
, srnBfcMaxConcurrencyDeadline :: Maybe Word
321322
, srnChainDbValidateOverride :: Bool
322323
-- ^ If @True@, validate the ChainDB on init no matter what
323324
, srnDiskPolicyArgs :: DiskPolicyArgs
@@ -981,6 +982,9 @@ stdLowLevelRunNodeArgsIO RunNodeArgs{ rnProtocolInfo
981982
maybe id
982983
(\mc bfc -> bfc { bfcMaxConcurrencyDeadline = mc })
983984
srnBfcMaxConcurrencyDeadline
985+
. maybe id
986+
(\mc bfc -> bfc { bfcMaxConcurrencyBulkSync = mc })
987+
srnBfcMaxConcurrencyBulkSync
984988
modifyMempoolCapacityOverride =
985989
maybe id
986990
(\mc nka -> nka { mempoolCapacityOverride = mc })

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node/Genesis.hs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,26 @@ data GenesisConfig = GenesisConfig
6666

6767
-- | Genesis configuration flags and low-level args, as parsed from config file or CLI
6868
data GenesisConfigFlags = GenesisConfigFlags
69-
{ gcfEnableCSJ :: Bool
70-
, gcfEnableLoEAndGDD :: Bool
71-
, gcfEnableLoP :: Bool
72-
, gcfBulkSyncGracePeriod :: Maybe Integer
73-
, gcfBucketCapacity :: Maybe Integer
74-
, gcfBucketRate :: Maybe Integer
75-
, gcfCSJJumpSize :: Maybe Integer
76-
, gcfGDDRateLimit :: Maybe DiffTime
69+
{ gcfEnableCSJ :: Bool
70+
, gcfEnableLoEAndGDD :: Bool
71+
, gcfEnableLoP :: Bool
72+
, gcfBlockFetchGracePeriod :: Maybe Integer
73+
, gcfBucketCapacity :: Maybe Integer
74+
, gcfBucketRate :: Maybe Integer
75+
, gcfCSJJumpSize :: Maybe Integer
76+
, gcfGDDRateLimit :: Maybe DiffTime
7777
} deriving stock (Eq, Generic, Show)
7878

7979
defaultGenesisConfigFlags :: GenesisConfigFlags
8080
defaultGenesisConfigFlags = GenesisConfigFlags
81-
{ gcfEnableCSJ = True
82-
, gcfEnableLoEAndGDD = True
83-
, gcfEnableLoP = True
84-
, gcfBulkSyncGracePeriod = Nothing
85-
, gcfBucketCapacity = Nothing
86-
, gcfBucketRate = Nothing
87-
, gcfCSJJumpSize = Nothing
88-
, gcfGDDRateLimit = Nothing
81+
{ gcfEnableCSJ = True
82+
, gcfEnableLoEAndGDD = True
83+
, gcfEnableLoP = True
84+
, gcfBlockFetchGracePeriod = Nothing
85+
, gcfBucketCapacity = Nothing
86+
, gcfBucketRate = Nothing
87+
, gcfCSJJumpSize = Nothing
88+
, gcfGDDRateLimit = Nothing
8989
}
9090

9191
enableGenesisConfigDefault :: GenesisConfig
@@ -99,7 +99,7 @@ mkGenesisConfig :: Maybe GenesisConfigFlags -> GenesisConfig
9999
mkGenesisConfig Nothing = -- disable Genesis
100100
GenesisConfig
101101
{ gcBlockFetchConfig = GenesisBlockFetchConfiguration
102-
{ gbfcBulkSyncGracePeriod = 0 -- no grace period when Genesis is disabled
102+
{ gbfcGracePeriod = 0 -- no grace period when Genesis is disabled
103103
}
104104
, gcChainSyncLoPBucketConfig = ChainSyncLoPBucketDisabled
105105
, gcCSJConfig = CSJDisabled
@@ -109,7 +109,7 @@ mkGenesisConfig Nothing = -- disable Genesis
109109
mkGenesisConfig (Just GenesisConfigFlags{..}) =
110110
GenesisConfig
111111
{ gcBlockFetchConfig = GenesisBlockFetchConfiguration
112-
{ gbfcBulkSyncGracePeriod
112+
{ gbfcGracePeriod
113113
}
114114
, gcChainSyncLoPBucketConfig = if gcfEnableLoP
115115
then ChainSyncLoPBucketEnabled ChainSyncLoPBucketEnabledConfig
@@ -134,7 +134,7 @@ mkGenesisConfig (Just GenesisConfigFlags{..}) =
134134
-- The minimum amount of time during which the Genesis BlockFetch logic will
135135
-- download blocks from a specific peer (even if it is not performing well
136136
-- during that period).
137-
defaultBulkSyncGracePeriod = 10 -- seconds
137+
defaultBlockFetchGracePeriod = 10 -- seconds
138138

139139
-- LoP parameters. Empirically, it takes less than 1ms to validate a header,
140140
-- so leaking one token per 2ms is conservative. The capacity of 100_000
@@ -153,11 +153,11 @@ mkGenesisConfig (Just GenesisConfigFlags{..}) =
153153
-- Limiting the performance impact of the GDD.
154154
defaultGDDRateLimit = 1.0 -- seconds
155155

156-
gbfcBulkSyncGracePeriod = fromInteger $ fromMaybe defaultBulkSyncGracePeriod gcfBulkSyncGracePeriod
157-
csbcCapacity = fromInteger $ fromMaybe defaultCapacity gcfBucketCapacity
158-
csbcRate = fromInteger $ fromMaybe defaultRate gcfBucketRate
159-
csjcJumpSize = fromInteger $ fromMaybe defaultCSJJumpSize gcfCSJJumpSize
160-
lgpGDDRateLimit = fromMaybe defaultGDDRateLimit gcfGDDRateLimit
156+
gbfcGracePeriod = fromInteger $ fromMaybe defaultBlockFetchGracePeriod gcfBlockFetchGracePeriod
157+
csbcCapacity = fromInteger $ fromMaybe defaultCapacity gcfBucketCapacity
158+
csbcRate = fromInteger $ fromMaybe defaultRate gcfBucketRate
159+
csjcJumpSize = fromInteger $ fromMaybe defaultCSJJumpSize gcfCSJJumpSize
160+
lgpGDDRateLimit = fromMaybe defaultGDDRateLimit gcfGDDRateLimit
161161

162162
newtype LoEAndGDDParams = LoEAndGDDParams
163163
{ -- | How often to evaluate GDD. 0 means as soon as possible.

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/NodeKernel.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import Ouroboros.Network.AnchoredFragment (AnchoredFragment,
9595
import qualified Ouroboros.Network.AnchoredFragment as AF
9696
import Ouroboros.Network.Block (castTip, tipFromHeader)
9797
import Ouroboros.Network.BlockFetch
98+
import Ouroboros.Network.ConsensusMode (ConsensusMode (..))
9899
import Ouroboros.Network.Diffusion (PublicPeerSelectionState)
99100
import Ouroboros.Network.NodeToNode (ConnectionId,
100101
MiniProtocolParameters (..))
@@ -378,6 +379,7 @@ initInternalState NodeKernelArgs { tracers, chainDB, registry, cfg
378379
, mempoolCapacityOverride
379380
, gsmArgs, getUseBootstrapPeers
380381
, getDiffusionPipeliningSupport
382+
, genesisArgs
381383
} = do
382384
varGsmState <- do
383385
let GsmNodeKernelArgs {..} = gsmArgs
@@ -398,6 +400,7 @@ initInternalState NodeKernelArgs { tracers, chainDB, registry, cfg
398400

399401
slotForgeTimeOracle <- BlockFetchClientInterface.initSlotForgeTimeOracle cfg chainDB
400402
let readFetchMode = BlockFetchClientInterface.readFetchModeDefault
403+
(toConsensusMode $ gnkaLoEAndGDDArgs genesisArgs)
401404
btime
402405
(ChainDB.getCurrentChain chainDB)
403406
getUseBootstrapPeers
@@ -416,6 +419,11 @@ initInternalState NodeKernelArgs { tracers, chainDB, registry, cfg
416419
peerSharingRegistry <- newPeerSharingRegistry
417420

418421
return IS {..}
422+
where
423+
toConsensusMode :: forall a. LoEAndGDDConfig a -> ConsensusMode
424+
toConsensusMode = \case
425+
LoEAndGDDDisabled -> PraosMode
426+
LoEAndGDDEnabled _ -> GenesisMode
419427

420428
forkBlockForging ::
421429
forall m addrNTN addrNTC blk.

ouroboros-consensus-diffusion/src/unstable-diffusion-testlib/Test/ThreadNet/Network.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,10 +1013,11 @@ runThreadNetwork systemTime ThreadNetworkArgs
10131013
txSubmissionMaxUnacked = 1000 -- TODO ?
10141014
}
10151015
, blockFetchConfiguration = BlockFetchConfiguration {
1016-
bfcMaxConcurrencyDeadline = 2
1016+
bfcMaxConcurrencyBulkSync = 1
1017+
, bfcMaxConcurrencyDeadline = 2
10171018
, bfcMaxRequestsInflight = 10
1018-
, bfcDecisionLoopIntervalBulkSync = 0.0 -- Mock testsuite can use sub-second slot
1019-
, bfcDecisionLoopIntervalDeadline = 0.0 -- interval which doesn't play nice with
1019+
, bfcDecisionLoopIntervalPraos = 0.0 -- Mock testsuite can use sub-second slot
1020+
, bfcDecisionLoopIntervalGenesis = 0.0 -- interval which doesn't play nice with
10201021
-- blockfetch descision interval.
10211022
, bfcSalt = 0
10221023
, bfcGenesisBFConfig = gcBlockFetchConfig enableGenesisConfigDefault

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/BlockFetch.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ import Ouroboros.Consensus.Storage.ChainDB.API
3737
import Ouroboros.Consensus.Util (ShowProxy)
3838
import Ouroboros.Consensus.Util.IOLike
3939
import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..),
40-
FetchClientRegistry, FetchMode (..),
41-
GenesisBlockFetchConfiguration (..), blockFetchLogic,
42-
bracketFetchClient, bracketKeepAliveClient)
40+
FetchClientRegistry, GenesisBlockFetchConfiguration (..),
41+
blockFetchLogic, bracketFetchClient,
42+
bracketKeepAliveClient)
4343
import Ouroboros.Network.BlockFetch.Client (blockFetchClient)
44+
import Ouroboros.Network.BlockFetch.ConsensusInterface
45+
(FetchMode (..))
4446
import Ouroboros.Network.Channel (Channel)
4547
import Ouroboros.Network.ControlMessage (ControlMessageSTM)
4648
import Ouroboros.Network.Driver (runPeer)
@@ -93,13 +95,13 @@ startBlockFetchLogic enableChainSelStarvation registry tracer chainDb fetchClien
9395
-- do not serialize the blocks.
9496
(\_hdr -> 1000)
9597
slotForgeTime
96-
-- This is a syncing test, so we use 'FetchModeBulkSync'.
97-
(pure FetchModeBulkSync)
98+
-- This is a syncing test, so we use 'FetchModeGenesis'.
99+
(pure FetchModeGenesis)
98100
DiffusionPipeliningOn
99101

100102
bfcGenesisBFConfig = if enableChainSelStarvation
101103
then GenesisBlockFetchConfiguration
102-
{ gbfcBulkSyncGracePeriod =
104+
{ gbfcGracePeriod =
103105
if enableChainSelStarvation then
104106
10 -- default value for cardano-node at the time of writing
105107
else
@@ -110,10 +112,11 @@ startBlockFetchLogic enableChainSelStarvation registry tracer chainDb fetchClien
110112
-- Values taken from
111113
-- ouroboros-consensus-diffusion/src/unstable-diffusion-testlib/Test/ThreadNet/Network.hs
112114
blockFetchCfg = BlockFetchConfiguration
113-
{ bfcMaxConcurrencyDeadline = 50 -- unused because of @pure FetchModeBulkSync@ above
115+
{ bfcMaxConcurrencyBulkSync = 50
116+
, bfcMaxConcurrencyDeadline = 50 -- unused because of @pure FetchModeBulkSync@ above
114117
, bfcMaxRequestsInflight = 10
115-
, bfcDecisionLoopIntervalBulkSync = 0
116-
, bfcDecisionLoopIntervalDeadline = 0
118+
, bfcDecisionLoopIntervalPraos = 0
119+
, bfcDecisionLoopIntervalGenesis = 0
117120
, bfcSalt = 0
118121
, bfcGenesisBFConfig
119122
}

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/BlockFetch/ClientInterface.hs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import Ouroboros.Network.Block (MaxSlotNo)
4646
import Ouroboros.Network.BlockFetch.ConsensusInterface
4747
(BlockFetchConsensusInterface (..),
4848
ChainSelStarvation (..), FetchMode (..),
49-
FromConsensus (..))
49+
FromConsensus (..), PraosFetchMode (..), mkReadFetchMode)
50+
import Ouroboros.Network.ConsensusMode (ConsensusMode)
5051
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers,
5152
requiresBootstrapPeers)
5253
import Ouroboros.Network.PeerSelection.LedgerPeers.Type
@@ -142,37 +143,41 @@ initSlotForgeTimeOracle cfg chainDB = do
142143

143144
readFetchModeDefault ::
144145
(MonadSTM m, HasHeader blk)
145-
=> BlockchainTime m
146+
=> ConsensusMode
147+
-> BlockchainTime m
146148
-> STM m (AnchoredFragment blk)
147149
-> STM m UseBootstrapPeers
148150
-> STM m LedgerStateJudgement
149151
-> STM m FetchMode
150-
readFetchModeDefault btime getCurrentChain
151-
getUseBootstrapPeers getLedgerStateJudgement = do
152-
mCurSlot <- getCurrentSlot btime
153-
usingBootstrapPeers <- requiresBootstrapPeers <$> getUseBootstrapPeers
154-
<*> getLedgerStateJudgement
152+
readFetchModeDefault consensusMode btime getCurrentChain
153+
getUseBootstrapPeers getLedgerStateJudgement =
154+
mkReadFetchMode consensusMode getLedgerStateJudgement praosFetchMode
155+
where
156+
praosFetchMode = do
157+
mCurSlot <- getCurrentSlot btime
158+
usingBootstrapPeers <- requiresBootstrapPeers <$> getUseBootstrapPeers
159+
<*> getLedgerStateJudgement
155160

156-
-- This logic means that when the node is using bootstrap peers and is in
157-
-- TooOld state it will always return BulkSync. Otherwise if the node
158-
-- isn't using bootstrap peers (i.e. has them disabled it will use the old
159-
-- logic of returning BulkSync if behind 1000 slots
160-
case (usingBootstrapPeers, mCurSlot) of
161-
(True, _) -> return FetchModeBulkSync
162-
(False, CurrentSlotUnknown) -> return FetchModeBulkSync
163-
(False, CurrentSlot curSlot) -> do
164-
curChainSlot <- AF.headSlot <$> getCurrentChain
165-
let slotsBehind = case curChainSlot of
166-
-- There's nothing in the chain. If the current slot is 0, then
167-
-- we're 1 slot behind.
168-
Origin -> unSlotNo curSlot + 1
169-
NotOrigin slot -> unSlotNo curSlot - unSlotNo slot
170-
maxSlotsBehind = 1000
171-
return $ if slotsBehind < maxSlotsBehind
172-
-- When the current chain is near to "now", use deadline mode,
173-
-- when it is far away, use bulk sync mode.
174-
then FetchModeDeadline
175-
else FetchModeBulkSync
161+
-- This logic means that when the node is using bootstrap peers and is in
162+
-- TooOld state it will always return BulkSync. Otherwise if the node
163+
-- isn't using bootstrap peers (i.e. has them disabled it will use the old
164+
-- logic of returning BulkSync if behind 1000 slots
165+
case (usingBootstrapPeers, mCurSlot) of
166+
(True, _) -> return FetchModeBulkSync
167+
(False, CurrentSlotUnknown) -> return FetchModeBulkSync
168+
(False, CurrentSlot curSlot) -> do
169+
curChainSlot <- AF.headSlot <$> getCurrentChain
170+
let slotsBehind = case curChainSlot of
171+
-- There's nothing in the chain. If the current slot is 0, then
172+
-- we're 1 slot behind.
173+
Origin -> unSlotNo curSlot + 1
174+
NotOrigin slot -> unSlotNo curSlot - unSlotNo slot
175+
maxSlotsBehind = 1000
176+
return $ if slotsBehind < maxSlotsBehind
177+
-- When the current chain is near to "now", use deadline mode,
178+
-- when it is far away, use bulk sync mode.
179+
then FetchModeDeadline
180+
else FetchModeBulkSync
176181

177182
mkBlockFetchConsensusInterface ::
178183
forall m peer blk.

ouroboros-consensus/test/consensus-test/Test/Consensus/MiniProtocol/BlockFetch/Client.hs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..),
5757
bracketFetchClient, bracketKeepAliveClient,
5858
bracketSyncWithFetchClient, newFetchClientRegistry)
5959
import Ouroboros.Network.BlockFetch.Client (blockFetchClient)
60+
import Ouroboros.Network.BlockFetch.ConsensusInterface
61+
(PraosFetchMode (..))
6062
import Ouroboros.Network.ControlMessage (ControlMessage (..))
6163
import Ouroboros.Network.Mock.Chain (Chain)
6264
import qualified Ouroboros.Network.Mock.Chain as Chain
@@ -97,8 +99,9 @@ prop_blockFetch bfcts@BlockFetchClientTestSetup{..} =
9799
[ Map.keysSet bfcoBlockFetchResults === Map.keysSet peerUpdates
98100
, counterexample ("Fetched blocks per peer: " <> condense bfcoFetchedBlocks) $
99101
property $ case blockFetchMode of
100-
FetchModeDeadline -> all (> 0) bfcoFetchedBlocks
101-
FetchModeBulkSync -> any (> 0) bfcoFetchedBlocks
102+
PraosFetchMode FetchModeDeadline -> all (> 0) bfcoFetchedBlocks
103+
PraosFetchMode FetchModeBulkSync -> all (> 0) bfcoFetchedBlocks
104+
FetchModeGenesis -> any (> 0) bfcoFetchedBlocks
102105
]
103106
where
104107
BlockFetchClientOutcome{..} = runSimOrThrow $ runBlockFetchTest bfcts
@@ -361,18 +364,23 @@ instance Arbitrary BlockFetchClientTestSetup where
361364
peerUpdates <-
362365
Map.fromList . zip peerIds
363366
<$> replicateM numPeers (genUpdateSchedule blockFetchPipelining)
364-
blockFetchMode <- elements [FetchModeBulkSync, FetchModeDeadline]
367+
blockFetchMode <- elements
368+
[ PraosFetchMode FetchModeBulkSync
369+
, PraosFetchMode FetchModeDeadline
370+
, FetchModeGenesis
371+
]
365372
blockFetchCfg <- do
366373
let -- ensure that we can download blocks from all peers
374+
bfcMaxConcurrencyBulkSync = fromIntegral numPeers
367375
bfcMaxConcurrencyDeadline = fromIntegral numPeers
368376
-- This is used to introduce a minimal delay between BlockFetch
369377
-- logic iterations in case the monitored state vars change too
370378
-- fast, which we don't have to worry about in this test.
371-
bfcDecisionLoopIntervalBulkSync = 0
372-
bfcDecisionLoopIntervalDeadline = 0
379+
bfcDecisionLoopIntervalGenesis = 0
380+
bfcDecisionLoopIntervalPraos = 0
373381
bfcMaxRequestsInflight <- chooseEnum (2, 10)
374382
bfcSalt <- arbitrary
375-
gbfcBulkSyncGracePeriod <- fromIntegral <$> chooseInteger (5, 60)
383+
gbfcGracePeriod <- fromIntegral <$> chooseInteger (5, 60)
376384
let bfcGenesisBFConfig = GenesisBlockFetchConfiguration {..}
377385
pure BlockFetchConfiguration {..}
378386
pure BlockFetchClientTestSetup {..}

0 commit comments

Comments
 (0)