Skip to content

Commit 6d5873a

Browse files
Merge #1806
1806: Remove duplicate transaction check from tryAddTxs in mempool r=intricate a=intricate Closes #1801 Co-authored-by: Luke Nadur <[email protected]>
2 parents ea83018 + e291414 commit 6d5873a

File tree

7 files changed

+24
-38
lines changed

7 files changed

+24
-38
lines changed

cabal.project

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,29 +207,29 @@ source-repository-package
207207
source-repository-package
208208
type: git
209209
location: https://github.com/input-output-hk/cardano-ledger
210-
tag: 1b0d9ff9c7e201f0877ccec2a992c58e2b19c5ec
211-
--sha256: 05vlmhxqsjn2y8ff864mm0jjbkl9pmb5qscbhwk6nrngqvxg00ys
210+
tag: 90b14c056059d0082cb2641f9c77cb1b097be329
211+
--sha256: 029lqlf33a3vvy933fil8qglv3hjaprankllr80h0acspqjzahk0
212212
subdir: cardano-ledger
213213

214214
source-repository-package
215215
type: git
216216
location: https://github.com/input-output-hk/cardano-ledger
217-
tag: 1b0d9ff9c7e201f0877ccec2a992c58e2b19c5ec
218-
--sha256: 05vlmhxqsjn2y8ff864mm0jjbkl9pmb5qscbhwk6nrngqvxg00ys
217+
tag: 90b14c056059d0082cb2641f9c77cb1b097be329
218+
--sha256: 029lqlf33a3vvy933fil8qglv3hjaprankllr80h0acspqjzahk0
219219
subdir: crypto
220220

221221
source-repository-package
222222
type: git
223223
location: https://github.com/input-output-hk/cardano-ledger
224-
tag: 1b0d9ff9c7e201f0877ccec2a992c58e2b19c5ec
225-
--sha256: 05vlmhxqsjn2y8ff864mm0jjbkl9pmb5qscbhwk6nrngqvxg00ys
224+
tag: 90b14c056059d0082cb2641f9c77cb1b097be329
225+
--sha256: 029lqlf33a3vvy933fil8qglv3hjaprankllr80h0acspqjzahk0
226226
subdir: cardano-ledger/test
227227

228228
source-repository-package
229229
type: git
230230
location: https://github.com/input-output-hk/cardano-ledger
231-
tag: 1b0d9ff9c7e201f0877ccec2a992c58e2b19c5ec
232-
--sha256: 05vlmhxqsjn2y8ff864mm0jjbkl9pmb5qscbhwk6nrngqvxg00ys
231+
tag: 90b14c056059d0082cb2641f9c77cb1b097be329
232+
--sha256: 029lqlf33a3vvy933fil8qglv3hjaprankllr80h0acspqjzahk0
233233
subdir: crypto/test
234234

235235
source-repository-package

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ module Ouroboros.Consensus.Mempool.API (
1717
, HasTxId(..)
1818
, GenTxId
1919
, MempoolAddTxResult (..)
20-
, isTxAddedOrAlreadyInMempool
21-
, isTxRejected
20+
, isMempoolTxAdded
21+
, isMempoolTxRejected
2222
, MempoolSize (..)
2323
, TraceEventMempool(..)
2424
, HasTxs(..)
@@ -235,26 +235,20 @@ data Mempool m blk idx = Mempool {
235235
data MempoolAddTxResult blk
236236
= MempoolTxAdded
237237
-- ^ The transaction was added to the mempool.
238-
| MempoolTxAlreadyInMempool
239-
-- ^ The transaction already exists within the mempool and therefore could
240-
-- not be added.
241-
--
242-
-- Note that we don't treat this like an error/rejection case.
243238
| MempoolTxRejected !(ApplyTxErr blk)
244239
-- ^ The transaction was rejected and could not be added to the mempool
245240
-- for the specified reason.
246241

247242
deriving instance Eq (ApplyTxErr blk) => Eq (MempoolAddTxResult blk)
248243
deriving instance Show (ApplyTxErr blk) => Show (MempoolAddTxResult blk)
249244

250-
isTxAddedOrAlreadyInMempool :: MempoolAddTxResult blk -> Bool
251-
isTxAddedOrAlreadyInMempool MempoolTxAdded = True
252-
isTxAddedOrAlreadyInMempool MempoolTxAlreadyInMempool = True
253-
isTxAddedOrAlreadyInMempool _ = False
245+
isMempoolTxAdded :: MempoolAddTxResult blk -> Bool
246+
isMempoolTxAdded MempoolTxAdded = True
247+
isMempoolTxAdded _ = False
254248

255-
isTxRejected :: MempoolAddTxResult blk -> Bool
256-
isTxRejected (MempoolTxRejected _) = True
257-
isTxRejected _ = False
249+
isMempoolTxRejected :: MempoolAddTxResult blk -> Bool
250+
isMempoolTxRejected (MempoolTxRejected _) = True
251+
isMempoolTxRejected _ = False
258252

259253
-- | Wrapper around 'implTryAddTxs' that blocks until all transaction have
260254
-- either been added to the Mempool or rejected.

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,6 @@ implTryAddTxs mpEnv = go []
273273
join $ atomically $ readTVar mpEnvStateVar >>= tryAdd
274274
where
275275
tryAdd is
276-
-- This transaction already exists within the mempool.
277-
-- Note that we don't treat this as an error/rejection case.
278-
| implSnapshotHasTx is (txId firstTx)
279-
= return $ go
280-
((firstTx, MempoolTxAdded):acc)
281-
toAdd'
282-
283276
-- No space in the Mempool.
284277
| let firstTxSize = txSize firstTx
285278
curSize = msNumBytes $ isMempoolSize is

ouroboros-consensus/src/Ouroboros/Consensus/MiniProtocol/LocalTxSubmission/Server.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ localTxSubmissionServer tracer mempool =
3434
case res of
3535
[(_tx, addTxRes)] -> case addTxRes of
3636
MempoolTxAdded -> return (Nothing, server)
37-
MempoolTxAlreadyInMempool -> return (Nothing, server)
3837
MempoolTxRejected addTxErr -> return (Just addTxErr, server)
3938
-- The output list of addTxs has the same length as the input list.
4039
_ -> error "addTxs: unexpected result"

ouroboros-consensus/src/Ouroboros/Consensus/NodeKernel.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,6 @@ getMempoolWriter
630630
getMempoolWriter mempool = Inbound.TxSubmissionMempoolWriter
631631
{ Inbound.txId = txId
632632
, mempoolAddTxs = \txs ->
633-
map (txId . fst) . filter (isTxAddedOrAlreadyInMempool . snd) <$>
633+
map (txId . fst) . filter (isMempoolTxAdded . snd) <$>
634634
addTxs mempool txs
635635
}

ouroboros-consensus/test-consensus/Test/Consensus/Mempool.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ prop_Mempool_addTxs_result setup =
114114
withTestMempool (testSetup setup) $ \TestMempool { mempool } -> do
115115
result <- addTxs mempool (allTxs setup)
116116
return $ counterexample (ppTxs (txs setup)) $
117-
[(tx, isTxAddedOrAlreadyInMempool res) | (tx, res) <- result] ===
118-
[(testTx, valid) | (testTx, valid) <- txs setup]
117+
[(tx, isMempoolTxAdded res) | (tx, res) <- result] ===
118+
[(testTx, valid) | (testTx, valid) <- txs setup]
119119

120120
-- | Test that invalid transactions are never added to the 'Mempool'.
121121
prop_Mempool_InvalidTxsNeverAdded :: TestSetupWithTxs -> Property
@@ -186,13 +186,13 @@ prop_Mempool_Capacity (MempoolCapTestSetup testSetupWithTxs) =
186186
MempoolCapacityBytes capacity = testMempoolCap testSetup
187187

188188
-- | Convert 'MempoolAddTxResult' into a 'Bool':
189-
-- isTxAddedOrAlreadyInMempool -> True, isTxRejected -> False.
189+
-- isMempoolTxAdded -> True, isMempoolTxRejected -> False.
190190
blindErrors
191191
:: ([(GenTx TestBlock, MempoolAddTxResult blk)], [GenTx TestBlock])
192192
-> ([(GenTx TestBlock, Bool)], [GenTx TestBlock])
193193
blindErrors (processed, toAdd) = (processed', toAdd)
194194
where
195-
processed' = [ (tx, isTxAddedOrAlreadyInMempool txAddRes)
195+
processed' = [ (tx, isMempoolTxAdded txAddRes)
196196
| (tx, txAddRes) <- processed ]
197197

198198
expectedResult
@@ -670,8 +670,8 @@ withTestMempool setup@TestSetup { testLedgerState, testInitialTxs, testMempoolCa
670670
result <- addTxs mempool testInitialTxs
671671
-- the invalid transactions are reported in the same order they were
672672
-- added, so the first error is not the result of a cascade
673-
whenJust (find (isTxRejected . snd) result) $ \(invalidTx, _) -> error $
674-
"Invalid initial transaction: " <> condense invalidTx
673+
whenJust (find (isMempoolTxRejected . snd) result) $ \(invalidTx, _) ->
674+
error $ "Invalid initial transaction: " <> condense invalidTx
675675

676676
-- Clear the trace
677677
atomically $ writeTVar varEvents []

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extra-deps:
6565
- gray-code-0.3.1
6666

6767
- git: https://github.com/input-output-hk/cardano-ledger
68-
commit: 1b0d9ff9c7e201f0877ccec2a992c58e2b19c5ec
68+
commit: 90b14c056059d0082cb2641f9c77cb1b097be329
6969
subdirs:
7070
- cardano-ledger
7171
- cardano-ledger/test

0 commit comments

Comments
 (0)