Skip to content

Commit 6fc67a3

Browse files
committed
Mempool.Simple: use 0-based index
1 parent 78140b9 commit 6fc67a3

File tree

1 file changed

+8
-5
lines changed
  • ouroboros-network/src/Ouroboros/Network/TxSubmission/Mempool

1 file changed

+8
-5
lines changed

ouroboros-network/src/Ouroboros/Network/TxSubmission/Mempool/Simple.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ getReader :: forall tx txid m.
6060
-> Mempool m tx
6161
-> TxSubmissionMempoolReader txid tx Int m
6262
getReader getTxId getTxSize (Mempool mempool) =
63-
TxSubmissionMempoolReader { mempoolGetSnapshot, mempoolZeroIdx = 0 }
63+
-- Using `0`-based index. `mempoolZeroIdx = -1` so that
64+
-- `mempoolTxIdsAfter mempoolZeroIdx` returns all txs.
65+
TxSubmissionMempoolReader { mempoolGetSnapshot,
66+
mempoolZeroIdx = -1
67+
}
6468
where
6569
mempoolGetSnapshot :: STM m (MempoolSnapshot txid tx Int)
6670
mempoolGetSnapshot = getSnapshot <$> readTVar mempool
@@ -69,10 +73,9 @@ getReader getTxId getTxSize (Mempool mempool) =
6973
-> MempoolSnapshot txid tx Int
7074
getSnapshot seq =
7175
MempoolSnapshot {
72-
mempoolTxIdsAfter =
73-
\idx -> zipWith f [idx + 1 ..] (toList $ Seq.drop idx seq),
74-
-- why do I need to use `pred`?
75-
mempoolLookupTx = flip Seq.lookup seq . pred,
76+
mempoolTxIdsAfter = \idx -> zipWith f [idx + 1..]
77+
(toList $ Seq.drop (idx + 1) seq),
78+
mempoolLookupTx = \idx -> Seq.lookup idx seq,
7679
mempoolHasTx = \txid -> isJust $ find (\tx -> getTxId tx == txid) seq
7780
}
7881

0 commit comments

Comments
 (0)