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

Genesis milestone 13: documentation / performance optimization #1113

Merged
merged 37 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
30da324
Make the LoP follow the GSM states
Niols Mar 19, 2024
a6901c5
Only select chains whose tip is in the loe fragment
facundominguez May 3, 2024
1708b34
Don't retrigger chain selection if the tip of the loe fragment doesn'…
facundominguez May 3, 2024
d6d84f3
Increase amount of tries in the Uniform tests and enable CSJ in all o…
facundominguez May 7, 2024
fade4d9
Allow to specify tests with multiple honest peers
Niols May 6, 2024
3ec40c2
Add some adversaries to the “happy path” test
Niols May 10, 2024
6191884
Edit documentation of LoE and GDD
facundominguez May 7, 2024
94b89f3
Explain more the shrinking choice of test 'serve adversarial branches…
facundominguez May 14, 2024
7286de2
NodeKernel: integrate GSM and LoE
amesgen Apr 4, 2024
3f952fe
Automated watcher of CSJ state invariants
Niols May 16, 2024
1cf7129
Allow to disable *all* Genesis components individually
amesgen May 16, 2024
c3c9a96
Simplify the honest peer shrinking function
nbacquey May 13, 2024
e6d057b
Avoid reconstructing the candidateSuffixes in densityDisconnect
facundominguez May 21, 2024
c0799e1
Rename `PeersSchedule` into `PointSchedule` and make it a newtype
Niols May 15, 2024
02c6884
Skip List/Map conversions in GDD governor
facundominguez May 20, 2024
2ef3173
Only get the successors of the immutable tip when reprocessing chain …
facundominguez May 24, 2024
4551ab4
Add changelog fragments
amesgen May 31, 2024
9011106
Rework `followsLoEFrag` into `trimToLoE`
Niols May 21, 2024
8adac16
Refactor `PointSchedule` to support test end time
nbacquey May 23, 2024
461f165
Fix grammar in comments
facundominguez Jul 10, 2024
f2763da
Fix comments in LeakyBucket.hs
facundominguez Jul 10, 2024
47cc624
Expand HAA acronym
facundominguez Jul 10, 2024
1fe1b10
Remove redundant do keyword
facundominguez Jul 10, 2024
4db1b7a
Replace Bool with isomorphic and more telling datatypes in CSJ test
facundominguez Jul 10, 2024
a50026e
Fix double quotes and make Note visible in haddock
facundominguez Jul 10, 2024
f6105ba
Update haddock comments in the Governor module
facundominguez Jul 10, 2024
20d86b3
Elaborate on the meaning of the type parameter of LoE
facundominguez Jul 10, 2024
f133483
Remove redundant parenthesis
facundominguez Jul 10, 2024
302b9d8
Fix formatting in haddock comment
facundominguez Jul 10, 2024
bb3f5a0
Please hlint
facundominguez Jul 11, 2024
39d7d4d
Adapt to change of type in maximalCandidates.
facundominguez Jul 11, 2024
32a2fd0
LeakyBucket: assert `timeToWaitMicroseconds > 0`
Niols Jul 11, 2024
d4cbcb8
LeakyBucket: wrap `leak` in `forever` for clarity
Niols Jul 11, 2024
1af233e
fixup! LeakyBucket: assert `timeToWaitMicroseconds > 0`
amesgen Jul 11, 2024
7d02b4c
ChainSync client state: `cschGsmCallback` -> `cschOnGsmStateChanged`
amesgen Jul 11, 2024
01d4594
changelog: use consistent grammar
amesgen Jul 11, 2024
53ea76c
Make types and comments a bit more precise for the leak thread
facundominguez Jul 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Node.InitStorage
import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (..))
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Storage.ChainDB.API (LoELimit (..))
import qualified Ouroboros.Consensus.Storage.ChainDB.Impl.Paths as Paths
import Ouroboros.Consensus.Storage.Common (BlockComponent (..))
import Ouroboros.Consensus.Storage.ImmutableDB (ImmutableDB,
Expand Down Expand Up @@ -175,7 +174,7 @@ immutalise bcfg tracer immDB volDB = do

succsOf <- atomically $ VolatileDB.filterByPredecessor volDB
let candidates =
Paths.maximalCandidates succsOf LoEUnlimited (tipToPoint immTip)
Paths.maximalCandidates succsOf Nothing (tipToPoint immTip)
candidatesAndTipHdrs <- for candidates $ \candidate -> do
tipHdr <-
VolatileDB.getKnownBlockComponent volDB GetHeader (NE.last candidate)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Breaking

- Integrated all Genesis components into the NodeKernel. In particular,
`RunNodeArgs` now has a new field

```haskell
rnGenesisConfig :: GenesisConfig
```

This can be set to `Ouroboros.Consensus.Node.Genesis.disableGenesisConfig` to
keep the Praos behavior, or to `enableGenesisConfigDefault` to enable Genesis
with preliminary parameter choices.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ library
Ouroboros.Consensus.Node.Exit
Ouroboros.Consensus.Node.ExitPolicy
Ouroboros.Consensus.Node.GSM
Ouroboros.Consensus.Node.Genesis
Ouroboros.Consensus.Node.Recovery
Ouroboros.Consensus.Node.RethrowPolicy
Ouroboros.Consensus.Node.Tracers
Expand Down Expand Up @@ -242,6 +243,7 @@ test-suite consensus-test
Test.Consensus.Network.AnchoredFragment.Extras
Test.Consensus.Node
Test.Consensus.PeerSimulator.BlockFetch
Test.Consensus.PeerSimulator.CSJInvariants
Test.Consensus.PeerSimulator.ChainSync
Test.Consensus.PeerSimulator.Config
Test.Consensus.PeerSimulator.Handlers
Expand All @@ -266,6 +268,7 @@ test-suite consensus-test
Test.Consensus.PointSchedule.SinglePeer
Test.Consensus.PointSchedule.SinglePeer.Indices
Test.Consensus.PointSchedule.Tests
Test.Util.PartialAccessors
Test.Util.TersePrinting

build-depends:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import qualified Codec.CBOR.Decoding as CBOR
import Codec.CBOR.Encoding (Encoding)
import qualified Codec.CBOR.Encoding as CBOR
import Codec.CBOR.Read (DeserialiseFailure)
import Control.Concurrent.Class.MonadSTM.Strict.TVar as TVar.Unchecked
import qualified Control.Concurrent.Class.MonadSTM.Strict.TVar as TVar.Unchecked
import Control.Monad.Class.MonadTime.SI (MonadTime)
import Control.Monad.Class.MonadTimer.SI (MonadTimer)
import Control.Tracer
Expand Down Expand Up @@ -570,6 +570,7 @@ mkApps kernel Tracers {..} mkCodecs ByteLimits {..} genChainSyncTimeout lopBucke
(contramap (TraceLabelPeer them) (Node.chainSyncClientTracer (getTracers kernel)))
(CsClient.defaultChainDbView (getChainDB kernel))
(getChainSyncHandles kernel)
(getGsmState kernel)
them
version
lopBucketConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ import Ouroboros.Consensus.Fragment.InFuture (CheckInFuture,
ClockSkew)
import qualified Ouroboros.Consensus.Fragment.InFuture as InFuture
import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (..))
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client
(CSJConfig (..), ChainSyncLoPBucketConfig (..))
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck as InFutureCheck
import qualified Ouroboros.Consensus.Network.NodeToClient as NTC
import qualified Ouroboros.Consensus.Network.NodeToNode as NTN
import Ouroboros.Consensus.Node.DbLock
import Ouroboros.Consensus.Node.DbMarker
import Ouroboros.Consensus.Node.ErrorPolicy
import Ouroboros.Consensus.Node.ExitPolicy
import Ouroboros.Consensus.Node.Genesis (GenesisConfig (..),
GenesisNodeKernelArgs, mkGenesisNodeKernelArgs)
import Ouroboros.Consensus.Node.GSM (GsmNodeKernelArgs (..))
import qualified Ouroboros.Consensus.Node.GSM as GSM
import Ouroboros.Consensus.Node.InitStorage
Expand Down Expand Up @@ -193,6 +193,8 @@ data RunNodeArgs m addrNTN addrNTC blk (p2p :: Diffusion.P2P) = RunNodeArgs {
, rnPeerSharing :: PeerSharing

, rnGetUseBootstrapPeers :: STM m UseBootstrapPeers

, rnGenesisConfig :: GenesisConfig
}


Expand Down Expand Up @@ -249,11 +251,7 @@ data LowLevelRunNodeArgs m addrNTN addrNTC versionDataNTN versionDataNTC blk
-- | See 'NTN.ChainSyncTimeout'
, llrnChainSyncTimeout :: m NTN.ChainSyncTimeout

-- | See 'CsClient.ChainSyncLoPBucketConfig'
, llrnChainSyncLoPBucketConfig :: ChainSyncLoPBucketConfig

-- | See 'CsClient.CSJConfig'
, llrnCSJConfig :: CSJConfig
, llrnGenesisConfig :: GenesisConfig

-- | How to run the data diffusion applications
--
Expand Down Expand Up @@ -413,6 +411,9 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
llrnMaxClockSkew
systemTime

(genesisArgs, setLoEinChainDbArgs) <-
mkGenesisNodeKernelArgs llrnGenesisConfig

let maybeValidateAll
| lastShutDownWasClean
= id
Expand All @@ -428,7 +429,8 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
initLedger
llrnMkHasFS
llrnChainDbArgsDefaults
( maybeValidateAll
( setLoEinChainDbArgs
. maybeValidateAll
. llrnCustomiseChainDbArgs
)

Expand Down Expand Up @@ -474,6 +476,7 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
gsmMarkerFileView
rnGetUseBootstrapPeers
llrnPublicPeerSelectionStateVar
genesisArgs
nodeKernel <- initNodeKernel nodeKernelArgs
rnNodeKernelHook registry nodeKernel

Expand Down Expand Up @@ -521,8 +524,8 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
(NTN.defaultCodecs codecConfig version encAddrNTN decAddrNTN)
NTN.byteLimits
llrnChainSyncTimeout
llrnChainSyncLoPBucketConfig
llrnCSJConfig
(gcChainSyncLoPBucketConfig llrnGenesisConfig)
(gcCSJConfig llrnGenesisConfig)
(reportMetric Diffusion.peerMetricsConfiguration peerMetrics)
(NTN.mkHandlers nodeKernelArgs nodeKernel)

Expand Down Expand Up @@ -629,7 +632,7 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
LedgerPeersConsensusInterface {
lpGetLatestSlot = getImmTipSlot kernel,
lpGetLedgerPeers = fromMaybe [] <$> getPeersFromCurrentLedger kernel (const True),
lpGetLedgerStateJudgement = getLedgerStateJudgement kernel
lpGetLedgerStateJudgement = GSM.gsmStateToLedgerJudgement <$> getGsmState kernel
},
Diffusion.daUpdateOutboundConnectionsState =
let varOcs = getOutboundConnectionsState kernel in \newOcs -> do
Expand Down Expand Up @@ -711,6 +714,7 @@ mkNodeKernelArgs ::
-> GSM.MarkerFileView m
-> STM m UseBootstrapPeers
-> StrictSTM.StrictTVar m (Diffusion.PublicPeerSelectionState addrNTN)
-> GenesisNodeKernelArgs m blk
-> m (NodeKernelArgs m addrNTN (ConnectionId addrNTC) blk)
mkNodeKernelArgs
registry
Expand All @@ -727,6 +731,7 @@ mkNodeKernelArgs
gsmMarkerFileView
getUseBootstrapPeers
publicPeerSelectionStateVar
genesisArgs
= do
let (kaRng, psRng) = split rng
return NodeKernelArgs
Expand All @@ -751,6 +756,7 @@ mkNodeKernelArgs
, keepAliveRng = kaRng
, peerSharingRng = psRng
, publicPeerSelectionStateVar
, genesisArgs
}

-- | We allow the user running the node to customise the 'NodeKernelArgs'
Expand Down Expand Up @@ -852,6 +858,7 @@ stdLowLevelRunNodeArgsIO ::
stdLowLevelRunNodeArgsIO RunNodeArgs{ rnProtocolInfo
, rnEnableP2P
, rnPeerSharing
, rnGenesisConfig
}
$(SafeWildCards.fields 'StdRunNodeArgs) = do
llrnBfcSalt <- stdBfcSaltIO
Expand All @@ -860,8 +867,7 @@ stdLowLevelRunNodeArgsIO RunNodeArgs{ rnProtocolInfo
pure LowLevelRunNodeArgs
{ llrnBfcSalt
, llrnChainSyncTimeout = fromMaybe Diffusion.defaultChainSyncTimeout srnChainSyncTimeout
, llrnChainSyncLoPBucketConfig = ChainSyncLoPBucketDisabled
, llrnCSJConfig = CSJDisabled
, llrnGenesisConfig = rnGenesisConfig
, llrnCustomiseHardForkBlockchainTimeArgs = id
, llrnGsmAntiThunderingHerd
, llrnKeepAliveRng
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ module Ouroboros.Consensus.Node.GSM (
-- * Auxiliaries
, TraceGsmEvent (..)
, gsmStateToLedgerJudgement
, initializationLedgerJudgement
, initializationGsmState
-- * Constructors
, realDurationUntilTooOld
, realGsmEntryPoints
, realMarkerFileView
-- * Re-exported
, module Ouroboros.Consensus.Node.GsmState
) where

import qualified Cardano.Slotting.Slot as Slot
Expand All @@ -43,6 +45,7 @@ import qualified Ouroboros.Consensus.HardFork.Abstract as HardFork
import qualified Ouroboros.Consensus.HardFork.History as HardFork
import qualified Ouroboros.Consensus.HardFork.History.Qry as Qry
import qualified Ouroboros.Consensus.Ledger.Basics as L
import Ouroboros.Consensus.Node.GsmState
import Ouroboros.Consensus.Storage.ChainDB.API (ChainDB)
import Ouroboros.Consensus.Util.NormalForm.StrictTVar (StrictTVar)
import qualified Ouroboros.Consensus.Util.NormalForm.StrictTVar as StrictSTM
Expand Down Expand Up @@ -80,19 +83,6 @@ data CandidateVersusSelection =
-- ^ Whether the candidate is better than the selection
deriving (Eq, Show)

-- | Current state of the Genesis State Machine
data GsmState =
PreSyncing
-- ^ We are syncing, and the Honest Availability Assumption is not
-- satisfied.
|
Syncing
-- ^ We are syncing, and the Honest Availability Assumption is satisfied.
|
CaughtUp
-- ^ We are caught-up.
deriving (Eq, Show, Read)

data GsmView m upstreamPeer selection chainSyncState = GsmView {
antiThunderingHerd :: Maybe StdGen
-- ^ An initial seed used to randomly increase 'minCaughtUpDuration' by up
Expand Down Expand Up @@ -168,34 +158,34 @@ data GsmEntryPoints m = GsmEntryPoints {

-----

-- | Determine the initial 'LedgerStateJudgment'
-- | Determine the initial 'GsmState'
--
-- Also initializes the persistent marker file.
initializationLedgerJudgement ::
initializationGsmState ::
( L.GetTip (L.LedgerState blk)
, Monad m
)
=> m (L.LedgerState blk)
-> Maybe (WrapDurationUntilTooOld m blk)
-- ^ 'Nothing' if @blk@ has no age limit
-> MarkerFileView m
-> m LedgerStateJudgement
initializationLedgerJudgement
-> m GsmState
initializationGsmState
getCurrentLedger
mbDurationUntilTooOld
markerFileView
= do
wasCaughtUp <- hasMarkerFile markerFileView
if not wasCaughtUp then pure TooOld else do
if not wasCaughtUp then pure PreSyncing else do
case mbDurationUntilTooOld of
Nothing -> return YoungEnough
Nothing -> return CaughtUp
Just wd -> do
sno <- L.getTipSlot <$> getCurrentLedger
getDurationUntilTooOld wd sno >>= \case
After{} -> return YoungEnough
After{} -> return CaughtUp
Already -> do
removeMarkerFile markerFileView
return TooOld
return PreSyncing

-- | For 'LedgerStateJudgement' as used in the Diffusion layer, there is no
-- difference between 'PreSyncing' and 'Syncing'.
Expand Down
Loading
Loading