Skip to content
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

[WIP] Genesis benchmarks #1209

Draft
wants to merge 76 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
1369102
Introduce a collection of chainsync handles that synchronizes a map a…
facundominguez May 27, 2024
e3be2f1
Implement a call to rotate dynamos in CSJ
facundominguez May 27, 2024
3c42b51
Comment formatting
facundominguez Jun 26, 2024
407db3b
Rename `varHandles` to `readHandles` for consistency
Niols Jun 27, 2024
92ff252
Mention that the objector also gets demoted
Niols Jun 27, 2024
d7d7acc
Specify the order in which to start the peers
Niols Jun 19, 2024
705daf4
Add a BlockFetch leashing attack test
Niols Jun 18, 2024
8bd6815
Switch peer simulator to `FetchModeBulkSync`
Niols Jun 5, 2024
31705f2
Track the last time the ChainDB thread was starved
Niols Jun 20, 2024
b20f711
Plug `rotateDynamo` into `BlockFetchConsensusInterface`
Niols Jun 26, 2024
e894140
Change how last starvation is recorded
Niols Jun 27, 2024
ebc49ce
Revert "GSM: use diffusion layer info for HAA"
facundominguez Jun 20, 2024
7beffdc
Fix starvation detection; improve tracing
Niols Jul 5, 2024
d3dbdf8
Follow changes of tracing in peer simulator
Niols Jul 5, 2024
b0946d3
Follow configurable grace period
Niols Jul 5, 2024
2d51933
Allow parameterizing whether chainsel starvation is handled
Niols Jul 5, 2024
90d613c
Trace the time at which starvation started
Niols Jul 5, 2024
50ac9b1
stylish haskell
Niols Jul 5, 2024
60d0d62
Follow change in trace chainselstarvationstarted
Niols Jul 8, 2024
1efae68
ChainDB: let the BlockFetch client add blocks asynchronously
Niols Jul 11, 2024
91bf46d
Some wiggle room for duplicate headers
Niols Jul 11, 2024
bc445da
Disable chainsel starvation in CSJ test
Niols Jul 5, 2024
e93b423
Depend on the ouroboros-network fork with the latest blockfetch
facundominguez Jul 11, 2024
5e5b37d
Accomodate for the addition of ChainSyncClientHandleCollection and gr…
facundominguez Jul 11, 2024
5aaa882
Follow removal of `bfcMaxConcurrencyBulkSync`
Niols Jul 12, 2024
7ac6a88
Only log starvations when they actually start
Niols Jul 12, 2024
956332f
Revert "ChainDB: let the BlockFetch client add blocks asynchronously"
Niols Jul 12, 2024
e742b01
Add explicit tracing events for CSJ
Niols Jul 15, 2024
a12cd89
Follow changes in blockfetch decision tracing
Niols Jul 15, 2024
eafa6a4
Move Genesis-specific BlockFetch config to GenesisConfig
nbacquey Jul 16, 2024
4500891
Add missing instances for TraceChainSetStarvationEvent
nbacquey Jul 17, 2024
ff5f040
Reapply "ChainDB: let the BlockFetch client add blocks asynchronously"
facundominguez Jul 18, 2024
ea486e7
Stop measuring starvation when blocks arrive
facundominguez Jul 19, 2024
8226db3
Introduce GenesisConfigFlags for interaction with config files/CLI
nbacquey Jul 22, 2024
eb8de6e
Add missing instances for Genesis configuration
nbacquey Jul 22, 2024
70f6713
Set the jump size to smaller size for byron
facundominguez Jul 23, 2024
315ea7e
export default Genesis config flags
nbacquey Jul 23, 2024
07dab6b
Fix ouroboros-consensus-diffusion:test:consensus-test
facundominguez Jul 23, 2024
8b510ce
Fix ouroboros-consensus:test:consensus-test
facundominguez Jul 23, 2024
d9ea987
Accomodate for the addition of ChainSyncClientHandleCollection and gr…
facundominguez Jul 11, 2024
6bb240e
Reapply "GSM: use diffusion layer info for HAA"
amesgen Jul 26, 2024
a8111f7
Limit the rate at which GDD is evaluated
facundominguez Jul 24, 2024
6961bd4
Edit note on Interactions with the BlockFetch logic
facundominguez Jul 24, 2024
b605fed
Accomodate for separate decision loop intervals for fetch modes
facundominguez Jul 25, 2024
7841fb5
fixup: Adding rate limit to GDD
facundominguez Jul 26, 2024
314616f
Set the default jump size to 2k
facundominguez Jul 25, 2024
889a149
Relax expectations of test blockFetch in the BulkSync case
facundominguez Jul 29, 2024
c93d7df
Set the GDD rate limit to 0 in the peer simulator
facundominguez Jul 30, 2024
bc2bb70
Accomodate for timer added in blockFetchLogic
facundominguez Jul 30, 2024
62981db
Have the peer simulator use the default grace period for chainsel sta…
facundominguez Jul 30, 2024
1c6498e
ChainSync client: disconnect if stuck and not better than selection
amesgen Jul 31, 2024
4c212aa
Shift point schedule times before giving the schedules to tests
facundominguez Jul 31, 2024
42b9ff4
Allow to run the decision logic once after the last tick in the block…
facundominguez Jul 31, 2024
e73e43a
Update LoP tests to run 1000 times each
facundominguez Aug 1, 2024
aeb3290
Run more repetitions of LoE tests
facundominguez Aug 1, 2024
1ff5343
Print timestamps for node restarts
facundominguez Aug 1, 2024
99edbed
Disable boring timeouts in the node restart test
facundominguez Aug 1, 2024
499a95d
Wait sufficiently long after restarting the node at the end of a test
facundominguez Aug 1, 2024
db3eb9f
Don't let GDD drop candidates that do not intersect with the selection
facundominguez Aug 1, 2024
8eb4ea2
Genesis tests: remove outdated comment
amesgen Aug 2, 2024
833d2ec
disableBoringTimeouts: don't consider `canAwaitTimeout` boring
amesgen Aug 2, 2024
83ff29e
Disable canAwaitTimeout again in the timed leashing attack
facundominguez Aug 2, 2024
3d65fb1
Document treatment of fragments with no intersection with the selecti…
facundominguez Aug 2, 2024
6a184e5
fixup! ChainSync client: disconnect if stuck and not better than sele…
amesgen Aug 2, 2024
c750764
Edit note on truncation of candidate fragments
facundominguez Aug 2, 2024
8eaf5dc
Expand the comments motivating DynamoInitState and ObjectorInitState
facundominguez Aug 2, 2024
c94e8ef
Expect CandidateTooSparse in gdd tests
facundominguez Aug 2, 2024
39b4877
Run CSJ and gdd tests more times by default
facundominguez Aug 5, 2024
0f22ff1
Add a notice about untracked delays in the node restart test
facundominguez Aug 5, 2024
ab33a03
Remove redundant empty window check from the GDD
facundominguez Aug 5, 2024
23542f9
fixup! ChainDB: let the BlockFetch client add blocks asynchronously
amesgen Aug 6, 2024
d15230e
Introduce `peersOnlyAdversary` and classify abnormal test peers as ad…
nbacquey Aug 6, 2024
bcb2c11
Document all tests that did not have documentation
Niols Aug 6, 2024
88c10cd
lint: stylish-haskell
nbacquey Aug 6, 2024
bfc0cac
Update `source-repository-package` to `blockfetch/milestone-1-rebased…
nbacquey Aug 6, 2024
f907373
Document prop_blockFetchLeashingAttack
Niols Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ import: ./asserts.cabal
if(os(windows))
constraints:
bitvec -simd

source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-network
tag: fcb842fcd6f32b43a7cdf18a4301c1659a8bb879
--sha256: kjwUrduwwxC+5QRQNJa4stEBzz7kqDJyyHOgGMfDw7s=
subdir:
ouroboros-network
ouroboros-network-api
ouroboros-network-protocols
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ data LowLevelRunNodeArgs m addrNTN addrNTC versionDataNTN versionDataNTC blk
--
-- See 'stdLowLevelRunNodeArgsIO'.
data StdRunNodeArgs m blk (p2p :: Diffusion.P2P) = StdRunNodeArgs
{ srnBfcMaxConcurrencyBulkSync :: Maybe Word
, srnBfcMaxConcurrencyDeadline :: Maybe Word
{ srnBfcMaxConcurrencyDeadline :: Maybe Word
, srnChainDbValidateOverride :: Bool
-- ^ If @True@, validate the ChainDB on init no matter what
, srnDiskPolicyArgs :: DiskPolicyArgs
Expand Down Expand Up @@ -938,9 +937,6 @@ stdLowLevelRunNodeArgsIO RunNodeArgs{ rnProtocolInfo
maybe id
(\mc bfc -> bfc { bfcMaxConcurrencyDeadline = mc })
srnBfcMaxConcurrencyDeadline
. maybe id
(\mc bfc -> bfc { bfcMaxConcurrencyBulkSync = mc })
srnBfcMaxConcurrencyBulkSync
modifyMempoolCapacityOverride =
maybe id
(\mc nka -> nka { mempoolCapacityOverride = mc })
Expand Down
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 (..),
Expand All @@ -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
, gcfBulkSyncGracePeriod :: 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
, gcfBulkSyncGracePeriod = 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
{ gbfcBulkSyncGracePeriod = 0 -- no grace period when Genesis is disabled
}
, gcChainSyncLoPBucketConfig = ChainSyncLoPBucketDisabled
, gcCSJConfig = CSJDisabled
, gcLoEAndGDDConfig = LoEAndGDDDisabled
}
mkGenesisConfig (Just GenesisConfigFlags{..}) =
GenesisConfig
{ gcBlockFetchConfig = GenesisBlockFetchConfiguration
{ gbfcBulkSyncGracePeriod
}
, 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
defaultBulkSyncGracePeriod = 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.
defaultCSJJumpSize = 2 * 2160
defaultGDDRateLimit = 1.0 -- seconds

gbfcBulkSyncGracePeriod = fromInteger $ fromMaybe defaultBulkSyncGracePeriod gcfBulkSyncGracePeriod
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.
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ import Ouroboros.Consensus.MiniProtocol.BlockFetch.Server
(TraceBlockFetchServerEvent)
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client
(InvalidBlockReason, TraceChainSyncClientEvent)
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.Jumping as CSJumping
import Ouroboros.Consensus.MiniProtocol.ChainSync.Server
(TraceChainSyncServerEvent)
import Ouroboros.Consensus.MiniProtocol.LocalTxSubmission.Server
(TraceLocalTxSubmissionServerEvent (..))
import Ouroboros.Consensus.Node.GSM (TraceGsmEvent)
import Ouroboros.Network.Block (Tip)
import Ouroboros.Network.BlockFetch (FetchDecision,
TraceFetchClientState, TraceLabelPeer)
import Ouroboros.Network.BlockFetch (TraceFetchClientState,
TraceLabelPeer)
import Ouroboros.Network.BlockFetch.Decision.Trace
(TraceDecisionEvent)
import Ouroboros.Network.KeepAlive (TraceKeepAliveClient)
import Ouroboros.Network.TxSubmission.Inbound
(TraceTxSubmissionInbound)
Expand All @@ -53,7 +56,7 @@ data Tracers' remotePeer localPeer blk f = Tracers
{ chainSyncClientTracer :: f (TraceLabelPeer remotePeer (TraceChainSyncClientEvent blk))
, chainSyncServerHeaderTracer :: f (TraceLabelPeer remotePeer (TraceChainSyncServerEvent blk))
, chainSyncServerBlockTracer :: f (TraceChainSyncServerEvent blk)
, blockFetchDecisionTracer :: f [TraceLabelPeer remotePeer (FetchDecision [Point (Header blk)])]
, blockFetchDecisionTracer :: f (TraceDecisionEvent remotePeer (Header blk))
, blockFetchClientTracer :: f (TraceLabelPeer remotePeer (TraceFetchClientState (Header blk)))
, blockFetchServerTracer :: f (TraceLabelPeer remotePeer (TraceBlockFetchServerEvent blk))
, txInboundTracer :: f (TraceLabelPeer remotePeer (TraceTxSubmissionInbound (GenTxId blk) (GenTx blk)))
Expand All @@ -67,6 +70,7 @@ data Tracers' remotePeer localPeer blk f = Tracers
, consensusErrorTracer :: f SomeException
, gsmTracer :: f (TraceGsmEvent (Tip blk))
, gddTracer :: f (TraceGDDEvent remotePeer blk)
, csjTracer :: f (CSJumping.TraceEvent remotePeer)
}

instance (forall a. Semigroup (f a))
Expand All @@ -89,6 +93,7 @@ instance (forall a. Semigroup (f a))
, consensusErrorTracer = f consensusErrorTracer
, gsmTracer = f gsmTracer
, gddTracer = f gddTracer
, csjTracer = f csjTracer
}
where
f :: forall a. Semigroup a
Expand Down Expand Up @@ -119,6 +124,7 @@ nullTracers = Tracers
, consensusErrorTracer = nullTracer
, gsmTracer = nullTracer
, gddTracer = nullTracer
, csjTracer = nullTracer
}

showTracers :: ( Show blk
Expand Down Expand Up @@ -152,6 +158,7 @@ showTracers tr = Tracers
, consensusErrorTracer = showTracing tr
, gsmTracer = showTracing tr
, gddTracer = showTracing tr
, csjTracer = showTracing tr
}

{-------------------------------------------------------------------------------
Expand Down
Loading