From 8e0b6dbb6136c8375b33e5506e2ae3afb5640d5a Mon Sep 17 00:00:00 2001 From: Edmund Noble Date: Mon, 6 Jan 2025 20:26:03 -0500 Subject: [PATCH] s/mempool{Insert,Lookup}5/mempool{Insert,Lookup}Pact5 --- test/lib/Chainweb/Test/Pact5/Utils.hs | 12 ++++----- .../Chainweb/Test/Pact5/PactServiceTest.hs | 26 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/lib/Chainweb/Test/Pact5/Utils.hs b/test/lib/Chainweb/Test/Pact5/Utils.hs index aa15d7375b..572f8b3f2f 100644 --- a/test/lib/Chainweb/Test/Pact5/Utils.hs +++ b/test/lib/Chainweb/Test/Pact5/Utils.hs @@ -18,8 +18,8 @@ module Chainweb.Test.Pact5.Utils , getTestLogger -- * Mempool - , mempoolInsert5 - , mempoolLookup5 + , mempoolInsertPact5 + , mempoolLookupPact5 -- * Resources , withTempSQLiteResource @@ -200,8 +200,8 @@ withRunPactService logger v cid pactQueue mempool webBHDb payloadDb pactServiceC -- | Insert a 'Pact5.Transaction' into the mempool. The mempool currently operates by default on -- 'Pact4.UnparsedTransaction's, so the txs have to be converted. -mempoolInsert5 :: MempoolBackend Pact4.UnparsedTransaction -> InsertType -> [Pact5.Transaction] -> IO () -mempoolInsert5 mp insertType txs = do +mempoolInsertPact5 :: MempoolBackend Pact4.UnparsedTransaction -> InsertType -> [Pact5.Transaction] -> IO () +mempoolInsertPact5 mp insertType txs = do let unparsedTxs :: [Pact4.UnparsedTransaction] unparsedTxs = flip map txs $ \tx -> case codecDecode Pact4.rawCommandCodec (codecEncode Pact5.payloadCodec tx) of @@ -210,8 +210,8 @@ mempoolInsert5 mp insertType txs = do mempoolInsert mp insertType $ Vector.fromList unparsedTxs -- | Looks up transactions in the mempool. Returns a set which indicates pending membership of the mempool. -mempoolLookup5 :: MempoolBackend Pact4.UnparsedTransaction -> Vector Pact5.Hash -> IO (HashSet Pact5.Hash) -mempoolLookup5 mp hashes = do +mempoolLookupPact5 :: MempoolBackend Pact4.UnparsedTransaction -> Vector Pact5.Hash -> IO (HashSet Pact5.Hash) +mempoolLookupPact5 mp hashes = do results <- mempoolLookup mp $ Vector.map (TransactionHash . Pact5.unHash) hashes return $ HashSet.fromList $ Vector.toList $ flip Vector.mapMaybe results $ \case Missing -> Nothing diff --git a/test/unit/Chainweb/Test/Pact5/PactServiceTest.hs b/test/unit/Chainweb/Test/Pact5/PactServiceTest.hs index 6b365dae49..778f08eec1 100644 --- a/test/unit/Chainweb/Test/Pact5/PactServiceTest.hs +++ b/test/unit/Chainweb/Test/Pact5/PactServiceTest.hs @@ -158,7 +158,7 @@ newBlockEmpty baseRdb = runResourceT $ do liftIO $ do cmd <- buildCwCmd v (transferCmd 1.0) _ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do - mempoolInsert5 mempool CheckedInsert [cmd] + mempoolInsertPact5 mempool CheckedInsert [cmd] -- -- Test that NewBlockEmpty ignores the mempool emptyBip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockEmpty (ParentHeader ph) pactQueue @@ -188,7 +188,7 @@ continueBlockSpec baseRdb = runResourceT $ do allAtOnceResults <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do -- insert all transactions - mempoolInsert5 mempool CheckedInsert [cmd1, cmd2, cmd3] + mempoolInsertPact5 mempool CheckedInsert [cmd1, cmd2, cmd3] -- construct a new block with all of said transactions bipAllAtOnce <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue @@ -207,14 +207,14 @@ continueBlockSpec baseRdb = runResourceT $ do revert fixture startCut continuedResults <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do mempoolClear mempool - mempoolInsert5 mempool CheckedInsert [cmd3] + mempoolInsertPact5 mempool CheckedInsert [cmd3] bipStart <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue - mempoolInsert5 mempool CheckedInsert [cmd2] + mempoolInsertPact5 mempool CheckedInsert [cmd2] bipContinued <- throwIfNoHistory =<< continueBlock bipStart pactQueue - mempoolInsert5 mempool CheckedInsert [cmd1] + mempoolInsertPact5 mempool CheckedInsert [cmd1] bipFinal <- throwIfNoHistory =<< continueBlock bipContinued pactQueue -- We must make progress on the same parent header @@ -263,7 +263,7 @@ newBlockTimeoutSpec baseRdb = runResourceT $ do } _ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do - mempoolInsert5 mempool CheckedInsert [tx2, timeoutTx, tx1] + mempoolInsertPact5 mempool CheckedInsert [tx2, timeoutTx, tx1] bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue -- Mempool orders by GasPrice. 'buildCwCmd' sets the gas price to the transfer amount. @@ -325,13 +325,13 @@ testNewBlockExcludesInvalid baseRdb = runResourceT $ do let pact4Hash = Pact5.Hash . Pact4.unHash . Pact4.toUntypedHash . Pact4._cmdHash _ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do - mempoolInsert5 mempool CheckedInsert [regularTx1] + mempoolInsertPact5 mempool CheckedInsert [regularTx1] bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue return $ finalizeBlock bip _ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do mempoolInsert mempool UncheckedInsert $ Vector.fromList [badParse, badSigs] - mempoolInsert5 mempool UncheckedInsert [badChain, badUnique, badFuture, badPast, badTxHash] + mempoolInsertPact5 mempool UncheckedInsert [badChain, badUnique, badFuture, badPast, badTxHash] bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue let expectedTxs = [] let actualTxs = Vector.toList $ Vector.map (unRequestKey . _crReqKey . snd) $ _transactionPairs $ _blockInProgressTransactions bip @@ -342,7 +342,7 @@ testNewBlockExcludesInvalid baseRdb = runResourceT $ do -- to disappear, because only the parent block is used to find txs to -- delete from the mempool let mempool = _fixtureMempools fixture ^?! atChain chain0 - mempoolInsert5 mempool CheckedInsert [badUnique, badFuture, badPast, badTxHash] + mempoolInsertPact5 mempool CheckedInsert [badUnique, badFuture, badPast, badTxHash] let badTxHashes = [ pact4Hash badParse @@ -352,7 +352,7 @@ testNewBlockExcludesInvalid baseRdb = runResourceT $ do , _cmdHash badTxHash , pact4Hash badSigs ] - inMempool <- mempoolLookup5 mempool (Vector.fromList badTxHashes) + inMempool <- mempoolLookupPact5 mempool (Vector.fromList badTxHashes) forM_ (zip [0 :: Word ..] badTxHashes) $ \(i, badHash) -> do assertBool ("bad tx [index = " <> sshow i <> ", hash = " <> sshow badTxHash <> "] should have been evicted from the mempool") $ not $ HashSet.member badHash inMempool @@ -367,7 +367,7 @@ lookupPactTxsSpec baseRdb = runResourceT $ do -- Depth 0 _ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do - mempoolInsert5 mempool CheckedInsert [cmd1, cmd2] + mempoolInsertPact5 mempool CheckedInsert [cmd1, cmd2] bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue return $ finalizeBlock bip @@ -418,7 +418,7 @@ failedTxsShouldGoIntoBlocks baseRdb = runResourceT $ do -- Depth 0 _ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do - mempoolInsert5 mempool CheckedInsert [cmd1, cmd2] + mempoolInsertPact5 mempool CheckedInsert [cmd1, cmd2] bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue let block = finalizeBlock bip assertEqual "block has 2 txs even though one of them failed" 2 (Vector.length $ _payloadWithOutputsTransactions block) @@ -460,7 +460,7 @@ advanceAllChainsWithTxs fixture txsPerChain = advanceAllChains fixture $ txsPerChain <&> \txs ph pactQueue mempool -> do mempoolClear mempool - mempoolInsert5 mempool CheckedInsert txs + mempoolInsertPact5 mempool CheckedInsert txs nb <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue return $ finalizeBlock nb