Skip to content

Commit

Permalink
Merge #1468
Browse files Browse the repository at this point in the history
1468: Calculate default mempool capacity as 2x the ledger max block size r=edsko a=intricate

Closes #1467 

Co-authored-by: Luke Nadur <[email protected]>
  • Loading branch information
iohk-bors[bot] and intricate authored Jan 22, 2020
2 parents 5c90d6e + b61dca1 commit e539f76
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ouroboros-consensus/src/Ouroboros/Consensus/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Ouroboros.Consensus.Node
, NodeArgs (..)
, NodeKernel (..)
, MaxBlockSizeOverride (..)
, MempoolCapacityBytesOverride (..)
, IPSubscriptionTarget (..)
, DnsSubscriptionTarget (..)
, ConnectionId (..)
Expand Down Expand Up @@ -55,7 +56,6 @@ import Ouroboros.Consensus.Block (BlockProtocol)
import Ouroboros.Consensus.BlockchainTime
import Ouroboros.Consensus.ChainSyncClient (ClockSkew (..))
import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (..))
import Ouroboros.Consensus.Mempool (MempoolCapacityBytes (..))
import Ouroboros.Consensus.Node.DbMarker
import Ouroboros.Consensus.Node.ErrorPolicy
import Ouroboros.Consensus.Node.ProtocolInfo
Expand Down Expand Up @@ -279,7 +279,7 @@ mkNodeArgs registry cfg initState tracers btime chainDB isProducer = NodeArgs
, blockMatchesHeader = nodeBlockMatchesHeader
, maxUnackTxs = 100 -- TODO
, maxBlockSize = NoOverride
, mempoolCap = MempoolCapacityBytes 128_000 -- TODO
, mempoolCap = NoMempoolCapacityBytesOverride
, chainSyncPipelining = pipelineDecisionLowHighMark 200 300 -- TODO
}
where
Expand Down
35 changes: 32 additions & 3 deletions ouroboros-consensus/src/Ouroboros/Consensus/NodeKernel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Ouroboros.Consensus.NodeKernel (
NodeKernel (..)
, BlockProduction (..)
, MaxBlockSizeOverride (..)
, MempoolCapacityBytesOverride (..)
, NodeArgs (..)
, TraceForgeEvent (..)
, initNodeKernel
Expand Down Expand Up @@ -138,6 +139,15 @@ data MaxBlockSizeOverride
| MaxBlockBodySize !Word32
-- ^ Use the following maximum size in bytes for the block body.

-- | An override for the default 'MempoolCapacityBytes' which is 2x the
-- maximum block size from the protocol parameters in the ledger.
data MempoolCapacityBytesOverride
= NoMempoolCapacityBytesOverride
-- ^ Use 2x the maximum block size from the protocol parameters in the
-- ledger.
| MempoolCapacityBytesOverride !MempoolCapacityBytes
-- ^ Use the following 'MempoolCapacityBytes'.

-- | Arguments required when initializing a node
data NodeArgs m peer blk = NodeArgs {
tracers :: Tracers m peer blk
Expand All @@ -152,7 +162,7 @@ data NodeArgs m peer blk = NodeArgs {
, blockMatchesHeader :: Header blk -> blk -> Bool
, maxUnackTxs :: Word16
, maxBlockSize :: MaxBlockSizeOverride
, mempoolCap :: MempoolCapacityBytes
, mempoolCap :: MempoolCapacityBytesOverride
, chainSyncPipelining :: MkPipelineDecision
}

Expand Down Expand Up @@ -217,7 +227,7 @@ initInternalState
, ProtocolLedgerView blk
, Ord peer
, NoUnexpectedThunks peer
, ApplyTx blk
, RunNode blk
)
=> NodeArgs m peer blk
-> m (InternalState m peer blk)
Expand All @@ -226,10 +236,22 @@ initInternalState NodeArgs { tracers, chainDB, registry, cfg,
initState, mempoolCap } = do
varCandidates <- newTVarM mempty
varState <- newTVarM initState
mpCap <- atomically $ do
-- If no override is provided, calculate the default mempool capacity as
-- 2x the current ledger's maximum block size.
--
-- It's worth noting that even though the ledger's maximum block size is
-- a dynamic value (it can be changed via an update proposal), we only
-- calculate the default mempool capacity once here. i.e. if the
-- ledger's maximum block size changes during runtime, the mempool
-- capacity /will not/ automatically adapt. The mempool capacity would
-- only be calculated again upon restarting the node.
ledger <- ledgerState <$> ChainDB.getCurrentLedger chainDB
pure (mempoolCapacity ledger)
mempool <- openMempool registry
(chainDBLedgerInterface chainDB)
(ledgerConfigView cfg)
mempoolCap
mpCap
(mempoolTracer tracers)

fetchClientRegistry <- newFetchClientRegistry
Expand All @@ -242,6 +264,13 @@ initInternalState NodeArgs { tracers, chainDB, registry, cfg,
cfg chainDB getCandidates blockFetchSize blockMatchesHeader btime

return IS {..}
where
mempoolCapacity :: LedgerState blk -> MempoolCapacityBytes
mempoolCapacity ledger = case mempoolCap of
NoMempoolCapacityBytesOverride -> noOverride
MempoolCapacityBytesOverride mcb -> mcb
where
noOverride = MempoolCapacityBytes (nodeMaxBlockSize ledger * 2)

initBlockFetchConsensusInterface
:: forall m peer blk. (IOLike m, SupportedBlock blk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ runThreadNetwork ThreadNetworkArgs
, blockMatchesHeader = nodeBlockMatchesHeader
, maxUnackTxs = 1000 -- TODO
, maxBlockSize = NoOverride
, mempoolCap = MempoolCapacityBytes 3000 -- TODO
, mempoolCap = NoMempoolCapacityBytesOverride
, chainSyncPipelining = pipelineDecisionLowHighMark 2 4
}

Expand Down

0 comments on commit e539f76

Please sign in to comment.