Skip to content

Commit

Permalink
WIP: drafting the bootstrap GSM
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrisby committed Jan 31, 2024
1 parent 948cf9a commit 4de0c49
Show file tree
Hide file tree
Showing 13 changed files with 703 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ library
Ouroboros.Consensus.Node.ErrorPolicy
Ouroboros.Consensus.Node.Exit
Ouroboros.Consensus.Node.ExitPolicy
Ouroboros.Consensus.Node.GSM
Ouroboros.Consensus.Node.Recovery
Ouroboros.Consensus.Node.RethrowPolicy
Ouroboros.Consensus.Node.Tracers
Expand All @@ -69,6 +70,7 @@ library
build-depends:
, base >=4.14 && <4.19
, bytestring >=0.10 && <0.12
, cardano-slotting
, cborg ^>=0.2.2
, containers >=0.5 && <0.7
, contra-tracer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,9 @@ mkApps kernel Tracers {..} mkCodecs ByteLimits {..} genChainSyncTimeout ReportPe
(contramap (TraceLabelPeer them) (Node.chainSyncClientTracer (getTracers kernel)))
(CsClient.defaultChainDbView (getChainDB kernel))
(getNodeCandidates kernel)
(getNodeIdlers kernel)
them
version $ \varCandidate -> do
version $ \varCandidate (startIdling, stopIdling) -> do
chainSyncTimeout <- genChainSyncTimeout
(r, trailing) <-
runPipelinedPeerWithLimits
Expand All @@ -588,6 +589,8 @@ mkApps kernel Tracers {..} mkCodecs ByteLimits {..} genChainSyncTimeout ReportPe
, CsClient.controlMessageSTM
, CsClient.headerMetricsTracer = TraceLabelPeer them `contramap` reportHeader
, CsClient.varCandidate
, CsClient.startIdling
, CsClient.stopIdling
}
return (ChainSyncInitiatorResult r, trailing)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import Data.Hashable (Hashable)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe, isNothing)
import Data.Time (NominalDiffTime)
import Data.Typeable (Typeable)
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.BlockchainTime hiding (getSystemStart)
Expand All @@ -81,6 +82,8 @@ import Ouroboros.Consensus.Node.DbLock
import Ouroboros.Consensus.Node.DbMarker
import Ouroboros.Consensus.Node.ErrorPolicy
import Ouroboros.Consensus.Node.ExitPolicy
import Ouroboros.Consensus.Node.GSM (GsmNodeKernelArgs (..))
import qualified Ouroboros.Consensus.Node.GSM as GSM
import Ouroboros.Consensus.Node.InitStorage
import Ouroboros.Consensus.Node.NetworkProtocolVersion
import Ouroboros.Consensus.Node.ProtocolInfo
Expand Down Expand Up @@ -130,7 +133,7 @@ import System.FilePath ((</>))
import System.FS.API (SomeHasFS (..))
import System.FS.API.Types
import System.FS.IO (ioHasFS)
import System.Random (StdGen, newStdGen, randomIO, randomRIO)
import System.Random (StdGen, newStdGen, split, randomIO, randomRIO)

{-------------------------------------------------------------------------------
The arguments to the Consensus Layer node functionality
Expand Down Expand Up @@ -254,6 +257,10 @@ data LowLevelRunNodeArgs m addrNTN addrNTC versionDataNTN versionDataNTC blk
-- | node-to-client protocol versions to run.
, llrnNodeToClientVersions :: Map NodeToClientVersion (BlockNodeToClientVersion blk)

-- | If the volatile tip is older than this, then the node will exit the
-- @CaughtUp@ state.
, llrnMaxCaughtUpAge :: NominalDiffTime

-- | Maximum clock skew
, llrnMaxClockSkew :: ClockSkew
}
Expand Down Expand Up @@ -364,8 +371,15 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
, ChainDB.cdbVolatileDbValidation = ValidateAll
}

chainDB <- openChainDB registry inFuture cfg initLedger
llrnChainDbArgsDefaults customiseChainDbArgs'
let finalChainDbArgs =
mkFinalChainDbArgs
registry
inFuture
cfg
initLedger
llrnChainDbArgsDefaults
customiseChainDbArgs'
chainDB <- ChainDB.openDB finalChainDbArgs

continueWithCleanChainDB chainDB $ do
btime <-
Expand All @@ -384,17 +398,28 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
, hfbtMaxClockRewind = secondsToNominalDiffTime 20
}

nodeKernelArgs <-
fmap (nodeKernelArgsEnforceInvariants . llrnCustomiseNodeKernelArgs) $
mkNodeKernelArgs
registry
llrnBfcSalt
llrnKeepAliveRng
cfg
rnTraceConsensus
btime
(InFutureCheck.realHeaderInFutureCheck llrnMaxClockSkew systemTime)
chainDB
nodeKernelArgs <- do
durationUntilTooOld <- GSM.realDurationUntilTooOld
(configLedger cfg)
(ledgerState <$> ChainDB.getCurrentLedger chainDB)
llrnMaxCaughtUpAge
systemTime
let gsmMarkerFileView =
case ChainDB.cdbHasFSGsmDB finalChainDbArgs of
SomeHasFS x -> GSM.realMarkerFileView chainDB x
fmap (nodeKernelArgsEnforceInvariants . llrnCustomiseNodeKernelArgs)
$ mkNodeKernelArgs
registry
llrnBfcSalt
llrnKeepAliveRng
cfg
rnTraceConsensus
btime
(InFutureCheck.realHeaderInFutureCheck llrnMaxClockSkew systemTime)
chainDB
llrnMaxCaughtUpAge
(Just durationUntilTooOld)
gsmMarkerFileView
nodeKernel <- initNodeKernel nodeKernelArgs
rnNodeKernelHook registry nodeKernel

Expand Down Expand Up @@ -600,13 +625,25 @@ openChainDB
-- ^ Customise the 'ChainDbArgs'
-> m (ChainDB m blk)
openChainDB registry inFuture cfg initLedger defArgs customiseArgs =
ChainDB.openDB args
where
args :: ChainDbArgs Identity m blk
args = customiseArgs $
mkChainDbArgs registry inFuture cfg initLedger
(nodeImmutableDbChunkInfo (configStorage cfg))
defArgs
ChainDB.openDB
$ mkFinalChainDbArgs registry inFuture cfg initLedger defArgs customiseArgs

mkFinalChainDbArgs
:: forall m blk. (RunNode blk, IOLike m)
=> ResourceRegistry m
-> CheckInFuture m blk
-> TopLevelConfig blk
-> ExtLedgerState blk
-- ^ Initial ledger
-> ChainDbArgs Defaults m blk
-> (ChainDbArgs Identity m blk -> ChainDbArgs Identity m blk)
-- ^ Customise the 'ChainDbArgs'
-> ChainDbArgs Identity m blk
mkFinalChainDbArgs registry inFuture cfg initLedger defArgs customiseArgs =
customiseArgs $
mkChainDbArgs registry inFuture cfg initLedger
(nodeImmutableDbChunkInfo (configStorage cfg))
defArgs

mkChainDbArgs
:: forall m blk. (RunNode blk, IOLike m)
Expand Down Expand Up @@ -645,6 +682,9 @@ mkNodeKernelArgs
-> BlockchainTime m
-> InFutureCheck.SomeHeaderInFutureCheck m blk
-> ChainDB m blk
-> NominalDiffTime
-> Maybe (GSM.WrapDurationUntilTooOld m blk)
-> GSM.MarkerFileView m
-> m (NodeKernelArgs m addrNTN (ConnectionId addrNTC) blk)
mkNodeKernelArgs
registry
Expand All @@ -655,6 +695,9 @@ mkNodeKernelArgs
btime
chainSyncFutureCheck
chainDB
maxCaughtUpAge
gsmDurationUntilTooOld
gsmMarkerFileView
= do
return NodeKernelArgs
{ tracers
Expand All @@ -669,6 +712,12 @@ mkNodeKernelArgs
, miniProtocolParameters = defaultMiniProtocolParameters
, blockFetchConfiguration = defaultBlockFetchConfiguration
, keepAliveRng
, gsmArgs = GsmNodeKernelArgs {
gsmAntiThunderingHerd = snd (split keepAliveRng)
, gsmDurationUntilTooOld
, gsmMarkerFileView
, gsmMinCaughtUpDuration = maxCaughtUpAge
}
}
where
defaultBlockFetchConfiguration :: BlockFetchConfiguration
Expand Down Expand Up @@ -879,6 +928,7 @@ stdLowLevelRunNodeArgsIO RunNodeArgs{ rnProtocolInfo
(supportedNodeToClientVersions (Proxy @blk))
, llrnWithCheckedDB =
stdWithCheckedDB (Proxy @blk) srnDatabasePath networkMagic
, llrnMaxCaughtUpAge = secondsToNominalDiffTime $ 20 * 60 -- 20 min
, llrnMaxClockSkew =
InFuture.defaultClockSkew
}
Expand Down
Loading

0 comments on commit 4de0c49

Please sign in to comment.