Skip to content

Commit 15846cd

Browse files
committed
MempoolSize: added mxExUnits{Memory,Steps}
1 parent 47de2a2 commit 15846cd

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool/Capacity.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Data.Semigroup (stimes)
2727
import Data.Word (Word32)
2828
import GHC.Generics
2929
import NoThunks.Class
30+
import Numeric.Natural (Natural)
3031
import Ouroboros.Consensus.Ledger.Basics
3132
import Ouroboros.Consensus.Ledger.SupportsMempool
3233

@@ -89,15 +90,20 @@ newtype SemigroupViaMeasure a = SemigroupViaMeasure a
8990

9091
-- | The size of a mempool.
9192
data MempoolSize = MempoolSize
92-
{ msNumTxs :: !Word32
93+
{ msNumTxs :: !Word32
9394
-- ^ The number of transactions in the mempool.
94-
, msNumBytes :: !ByteSize32
95+
, msNumBytes :: !ByteSize32
9596
-- ^ The summed byte size of all the transactions in the mempool.
97+
, msExUnitsMemory :: !Natural
98+
-- ^ The execution memory units of all the transactions in the mempool.
99+
, msExUnitsSteps :: !Natural
100+
-- ^ The execution steps of all the transactions in the mempool.
96101
} deriving (Eq, Show, Generic, NoThunks)
97102

98103
instance Semigroup MempoolSize where
99-
MempoolSize xt xb <> MempoolSize yt yb = MempoolSize (xt + yt) (xb <> yb)
104+
MempoolSize xt xb xm xs <> MempoolSize yt yb ym ys = MempoolSize (xt + yt) (xb <> yb) (xm + ym) (xs + ys)
100105

101106
instance Monoid MempoolSize where
102-
mempty = MempoolSize { msNumTxs = 0, msNumBytes = ByteSize32 0 }
107+
mempty = MempoolSize { msNumTxs = 0, msNumBytes = ByteSize32 0,
108+
msExUnitsMemory = 0, msExUnitsSteps = 0 }
103109
mappend = (<>)

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool/Impl/Common.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,13 @@ deriving instance ( NoThunks (Validated (GenTx blk))
154154
-- the Mempool paired with their total size in bytes.
155155
isMempoolSize :: TxLimits blk => InternalState blk -> MempoolSize
156156
isMempoolSize is = MempoolSize {
157-
msNumTxs = fromIntegral $ length $ isTxs is
158-
, msNumBytes = txMeasureByteSize $ TxSeq.toSize $ isTxs is
159-
}
157+
msNumTxs = fromIntegral $ length $ isTxs is
158+
, msNumBytes = txMeasureByteSize size
159+
, msExUnitsMemory = txMeasureMetricExUnitsMemory size
160+
, msExUnitsSteps = txMeasureMetricExUnitsSteps size
161+
}
162+
where
163+
size = TxSeq.toSize (isTxs is)
160164

161165
initInternalState ::
162166
LedgerSupportsMempool blk

0 commit comments

Comments
 (0)