Skip to content

Commit

Permalink
Trace forkSyncStateOnTipPointChange (#1280)
Browse files Browse the repository at this point in the history
# Description

Trace when forkSyncStateOnTipPointChange completes an iteration.
This provides insight into how much time is spent syncing the mempool
after a new block has been adopted.
  • Loading branch information
amesgen authored Oct 11, 2024
2 parents 92a8330 + 7af37a7 commit c1a681d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Breaking

- Add TraceMempoolSynced to TraceEventMempool for tracing mempool sync time.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import qualified Ouroboros.Consensus.Mempool.TxSeq as TxSeq
import Ouroboros.Consensus.Storage.ChainDB (ChainDB)
import qualified Ouroboros.Consensus.Storage.ChainDB.API as ChainDB
import Ouroboros.Consensus.Util (repeatedly)
import Ouroboros.Consensus.Util.Enclose (EnclosingTimed)
import Ouroboros.Consensus.Util.IOLike hiding (newMVar)

{-------------------------------------------------------------------------------
Expand Down Expand Up @@ -556,6 +557,10 @@ data TraceEventMempool blk
-- transactions.
MempoolSize
-- ^ The current size of the Mempool.
| TraceMempoolSynced
-- ^ Emitted when the mempool is adjusted after the tip has changed.
EnclosingTimed
-- ^ How long the sync operation took.

deriving instance ( Eq (GenTx blk)
, Eq (Validated (GenTx blk))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Ouroboros.Consensus.Mempool.Init (

import Control.Monad (void)
import Control.Tracer
import Data.Functor.Contravariant ((>$<))
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.HeaderValidation
import Ouroboros.Consensus.Ledger.Abstract
Expand All @@ -18,6 +19,7 @@ import Ouroboros.Consensus.Mempool.Capacity
import Ouroboros.Consensus.Mempool.Impl.Common
import Ouroboros.Consensus.Mempool.Query
import Ouroboros.Consensus.Mempool.Update
import Ouroboros.Consensus.Util.Enclose
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Consensus.Util.ResourceRegistry
import Ouroboros.Consensus.Util.STM (Watcher (..), forkLinkedWatcher)
Expand Down Expand Up @@ -68,7 +70,9 @@ forkSyncStateOnTipPointChange registry menv =
}
where
action :: Point blk -> m ()
action _tipPoint = void $ implSyncWithLedger menv
action _tipPoint =
encloseTimedWith (TraceMempoolSynced >$< mpEnvTracer menv) $
void $ implSyncWithLedger menv

-- Using the tip ('Point') allows for quicker equality checks
getCurrentTip :: STM m (Point blk)
Expand Down

0 comments on commit c1a681d

Please sign in to comment.