Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 58414fb

Browse files
authored
Merge pull request #3285 from input-output-hk/mhuesch/CDEC-451-sq
[CDEC-451] Remove `Mockable`
2 parents a32086e + 58d7d91 commit 58414fb

File tree

94 files changed

+222
-2204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+222
-2204
lines changed

auxx/Main.hs

+8-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import System.Wlog (LoggerName, logInfo)
1414
import qualified Pos.Client.CLI as CLI
1515
import Pos.Context (NodeContext (..))
1616
import Pos.Core (ConfigurationError, epochSlots)
17-
import Pos.Core.Mockable (Production (..), runProduction)
1817
import Pos.Crypto (ProtocolMagic)
1918
import Pos.DB.DB (initNodeDBs)
2019
import Pos.Infra.Diffusion.Types (Diffusion, hoistDiffusion)
@@ -43,12 +42,12 @@ loggerName = "auxx"
4342

4443
-- 'NodeParams' obtained using 'CLI.getNodeParams' are not perfect for
4544
-- Auxx, so we need to adapt them slightly.
46-
correctNodeParams :: AuxxOptions -> NodeParams -> Production (NodeParams, Bool)
45+
correctNodeParams :: AuxxOptions -> NodeParams -> IO (NodeParams, Bool)
4746
correctNodeParams AuxxOptions {..} np = do
4847
(dbPath, isTempDbUsed) <- case npDbPathM np of
4948
Nothing -> do
50-
tempDir <- liftIO $ Temp.getCanonicalTemporaryDirectory
51-
dbPath <- liftIO $ Temp.createTempDirectory tempDir "nodedb"
49+
tempDir <- Temp.getCanonicalTemporaryDirectory
50+
dbPath <- Temp.createTempDirectory tempDir "nodedb"
5251
logInfo $ sformat ("Temporary db created: "%shown) dbPath
5352
return (dbPath, True)
5453
Just dbPath -> do
@@ -81,7 +80,7 @@ runNodeWithSinglePlugin ::
8180
runNodeWithSinglePlugin pm nr plugin =
8281
runNode pm nr [plugin]
8382

84-
action :: HasCompileInfo => AuxxOptions -> Either WithCommandAction Text -> Production ()
83+
action :: HasCompileInfo => AuxxOptions -> Either WithCommandAction Text -> IO ()
8584
action opts@AuxxOptions {..} command = do
8685
let pa = either printAction (const putText) command
8786
case aoStartMode of
@@ -95,10 +94,10 @@ action opts@AuxxOptions {..} command = do
9594
_ -> withConfigurations Nothing conf (runWithConfig pa)
9695

9796
where
98-
runWithoutNode :: PrintAction Production -> Production ()
97+
runWithoutNode :: PrintAction IO -> IO ()
9998
runWithoutNode printAction = printAction "Mode: light" >> rawExec Nothing Nothing opts Nothing command
10099

101-
runWithConfig :: HasConfigurations => PrintAction Production -> NtpConfiguration -> ProtocolMagic -> Production ()
100+
runWithConfig :: HasConfigurations => PrintAction IO -> NtpConfiguration -> ProtocolMagic -> IO ()
102101
runWithConfig printAction ntpConfig pm = do
103102
printAction "Mode: with-config"
104103
CLI.printInfoOnStart aoCommonNodeArgs ntpConfig
@@ -117,7 +116,7 @@ action opts@AuxxOptions {..} command = do
117116
(npUserSecret nodeParams ^. usVss)
118117
sscParams = CLI.gtSscParams cArgs vssSK (npBehaviorConfig nodeParams)
119118

120-
bracketNodeResources nodeParams sscParams (txpGlobalSettings pm) (initNodeDBs pm epochSlots) $ \nr -> Production $
119+
bracketNodeResources nodeParams sscParams (txpGlobalSettings pm) (initNodeDBs pm epochSlots) $ \nr ->
121120
let NodeContext {..} = nrContext nr
122121
modifier = if aoStartMode == WithNode
123122
then runNodeWithSinglePlugin pm nr
@@ -146,7 +145,7 @@ main = withCompileInfo $ do
146145
loggingParams = disableConsoleLog $
147146
CLI.loggingParams loggerName (aoCommonNodeArgs opts)
148147
loggerBracket loggingParams . logException "auxx" $ do
149-
let runAction a = runProduction $ action opts a
148+
let runAction a = action opts a
150149
case aoAction opts of
151150
Repl -> withAuxxRepl $ \c -> runAction (Left c)
152151
Cmd cmd -> runAction (Right cmd)

auxx/cardano-sl-auxx.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ library
8888
, time-units
8989
, transformers
9090
, universum >= 0.1.11
91+
, unliftio
9192
, unordered-containers
9293
, validation
9394

auxx/src/Command/Tx.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Command.Tx
1212

1313
import Universum
1414

15+
import qualified Control.Concurrent.MVar as Conc
1516
import Control.Concurrent.STM.TQueue (newTQueue, tryReadTQueue,
1617
writeTQueue)
1718
import Control.Exception.Safe (Exception (..), try)
@@ -31,6 +32,7 @@ import Formatting (build, int, sformat, shown, stext, (%))
3132
import System.Environment (lookupEnv)
3233
import System.IO (BufferMode (LineBuffering), hClose, hSetBuffering)
3334
import System.Wlog (logError, logInfo)
35+
import UnliftIO (MonadUnliftIO)
3436

3537
import Pos.Client.KeyStorage (getSecretKeysPlain)
3638
import Pos.Client.Txp.Balances (getOwnUtxoForPk)
@@ -39,11 +41,10 @@ import Pos.Client.Txp.Util (createTx)
3941
import Pos.Core (BlockVersionData (bvdSlotDuration),
4042
IsBootstrapEraAddr (..), Timestamp (..),
4143
deriveFirstHDAddress, makePubKeyAddress, mkCoin)
44+
import Pos.Core.Conc (concurrently, currentTime, delay,
45+
forConcurrently, modifySharedAtomic, newSharedAtomic)
4246
import Pos.Core.Configuration (genesisBlockVersionData,
4347
genesisSecretKeys)
44-
import Pos.Core.Mockable (Mockable, SharedAtomic, SharedAtomicT,
45-
concurrently, currentTime, delay, forConcurrently,
46-
modifySharedAtomic, newSharedAtomic)
4748
import Pos.Core.Txp (TxAux (..), TxIn (TxInUtxo), TxOut (..),
4849
TxOutAux (..), txaF)
4950
import Pos.Crypto (EncryptedSecretKey, ProtocolMagic, emptyPassphrase,
@@ -77,7 +78,7 @@ data TxCount = TxCount
7778
-- How many threads are still sending transactions.
7879
, _txcThreads :: !Int }
7980

80-
addTxSubmit :: Mockable SharedAtomic m => SharedAtomicT m TxCount -> m ()
81+
addTxSubmit :: MonadUnliftIO m => Conc.MVar TxCount -> m ()
8182
addTxSubmit =
8283
flip modifySharedAtomic
8384
(\(TxCount submitted sending) ->

auxx/src/Mode.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import Pos.Core (Address, HasConfiguration, HasPrimaryKey (..),
4444
largestPubKeyAddressBoot, largestPubKeyAddressSingleKey,
4545
makePubKeyAddress, siEpoch)
4646
import Pos.Core.JsonLog (CanJsonLog (..))
47-
import Pos.Core.Mockable (Production)
4847
import Pos.Core.Reporting (HasMisbehaviorMetrics (..),
4948
MonadReporting (..))
5049
import Pos.Core.Slotting (HasSlottingVar (..), MonadSlotsData)
@@ -70,7 +69,7 @@ import Pos.Util.LoggerName (HasLoggerName' (..))
7069
import Pos.Util.UserSecret (HasUserSecret (..))
7170
import Pos.WorkMode (EmptyMempoolExt, RealMode, RealModeContext (..))
7271

73-
type AuxxMode = ReaderT AuxxContext Production
72+
type AuxxMode = ReaderT AuxxContext IO
7473

7574
class (m ~ AuxxMode, HasConfigurations, HasCompileInfo) => MonadAuxxMode m
7675
instance (HasConfigurations, HasCompileInfo) => MonadAuxxMode AuxxMode

auxx/src/Plugin.hs

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Formatting (float, int, sformat, (%))
2121
import System.IO (hFlush, stdout)
2222
import System.Wlog (CanLog, HasLoggerName, logInfo)
2323

24-
import Pos.Core.Mockable (Delay, Mockable, delay)
24+
import Pos.Core.Conc (delay)
2525
import Pos.Crypto (AHash (..), ProtocolMagic, fullPublicKeyF,
2626
hashHexF)
2727
import Pos.Infra.Diffusion.Types (Diffusion)
@@ -40,7 +40,7 @@ import Repl (PrintAction, WithCommandAction (..))
4040
{-# ANN module ("HLint: ignore Reduce duplication" :: Text) #-}
4141

4242
auxxPlugin ::
43-
(MonadAuxxMode m, Mockable Delay m)
43+
MonadAuxxMode m
4444
=> ProtocolMagic
4545
-> AuxxOptions
4646
-> Either WithCommandAction Text
@@ -56,7 +56,6 @@ rawExec ::
5656
, MonadCatch m
5757
, CanLog m
5858
, HasLoggerName m
59-
, Mockable Delay m
6059
)
6160
=> Maybe ProtocolMagic
6261
-> Maybe (Dict (MonadAuxxMode m))
@@ -74,7 +73,6 @@ runWalletCmd ::
7473
( MonadIO m
7574
, CanLog m
7675
, HasLoggerName m
77-
, Mockable Delay m
7876
)
7977
=> Maybe ProtocolMagic
8078
-> Maybe (Dict (MonadAuxxMode m))

block/src/Pos/Block/BListener.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Control.Monad.Trans (MonadTrans (..))
1616

1717
import Pos.Block.Types (Blund)
1818
import Pos.Core.Chrono (NE, NewestFirst (..), OldestFirst (..))
19-
import Pos.Core.Mockable (SharedAtomicT)
2019
import Pos.DB.BatchOp (SomeBatchOp)
2120

2221
class Monad m => MonadBListener m where
@@ -29,8 +28,7 @@ class Monad m => MonadBListener m where
2928
onRollbackBlocks :: NewestFirst NE Blund -> m SomeBatchOp
3029

3130
instance {-# OVERLAPPABLE #-}
32-
( MonadBListener m, Monad m, MonadTrans t, Monad (t m)
33-
, SharedAtomicT m ~ SharedAtomicT (t m) ) =>
31+
( MonadBListener m, Monad m, MonadTrans t, Monad (t m)) =>
3432
MonadBListener (t m)
3533
where
3634
onApplyBlocks = lift . onApplyBlocks

block/src/Pos/Block/Logic/Internal.hs

-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import Pos.Core (ComponentBlock (..), IsGenesisHeader, epochIndexL,
4343
mainBlockUpdatePayload)
4444
import Pos.Core.Block (Block, GenesisBlock, MainBlock)
4545
import Pos.Core.Chrono (NE, NewestFirst (..), OldestFirst (..))
46-
import Pos.Core.Mockable (CurrentTime, Mockable)
4746
import Pos.Core.Reporting (MonadReporting)
4847
import Pos.Crypto (ProtocolMagic)
4948
import Pos.DB (MonadDB, MonadDBRead, MonadGState, SomeBatchOp (..))
@@ -105,8 +104,6 @@ type MonadBlockApply ctx m
105104
, MonadMask m
106105
-- Needed to embed custom logic.
107106
, MonadBListener m
108-
-- Needed for rollback
109-
, Mockable CurrentTime m
110107
)
111108

112109
type MonadMempoolNormalization ctx m
@@ -123,7 +120,6 @@ type MonadMempoolNormalization ctx m
123120
, MonadReporting m
124121
-- 'MonadRandom' for crypto.
125122
, Rand.MonadRandom m
126-
, Mockable CurrentTime m
127123
, HasSscConfiguration
128124
)
129125

block/src/Pos/Block/Lrc.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Pos.Core (Coin, EpochIndex, EpochOrSlot (..), SharedSeed,
3131
StakeholderId, blkSecurityParam, crucialSlot, epochIndexL,
3232
epochSlots, getEpochOrSlot)
3333
import Pos.Core.Chrono (NE, NewestFirst (..), toOldestFirst)
34-
import Pos.Core.Mockable (forConcurrently)
34+
import Pos.Core.Conc (forConcurrently)
3535
import Pos.Core.Reporting (HasMisbehaviorMetrics (..),
3636
MisbehaviorMetrics (..))
3737
import Pos.Core.Slotting (MonadSlots)

client/src/Pos/Client/Txp/History.hs

-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import Pos.Core.Block (Block, MainBlock, mainBlockSlot,
4343
mainBlockTxPayload)
4444
import Pos.Core.Block.Constructors (genesisBlock0)
4545
import Pos.Core.JsonLog (CanJsonLog (..))
46-
import Pos.Core.Mockable (CurrentTime, Mockable)
4746
import Pos.Crypto (ProtocolMagic, WithHash (..), withHash)
4847
import Pos.DB (MonadDBRead, MonadGState)
4948
import Pos.DB.Block (getBlock)
@@ -208,7 +207,6 @@ type TxHistoryEnv ctx m =
208207
, MonadTxpMem (MempoolExt m) ctx m
209208
, HasLens' ctx StateLock
210209
, HasLens' ctx (StateLockMetrics MemPoolModifyReason)
211-
, Mockable CurrentTime m
212210
, HasNodeType ctx
213211
, CanJsonLog m
214212
)

client/src/Pos/Client/Txp/Network.hs

-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import Pos.Communication.Message ()
2626
import Pos.Communication.Types (InvOrDataTK)
2727
import Pos.Core (Address, Coin, makeRedeemAddress, mkCoin,
2828
unsafeAddCoin)
29-
import Pos.Core.Mockable (MonadMockable)
3029
import Pos.Core.Txp (TxAux (..), TxId, TxMsgContents (..), TxOut (..),
3130
TxOutAux (..), txaF)
3231
import Pos.Crypto (ProtocolMagic, RedeemSecretKey, SafeSigner, hash,
@@ -41,7 +40,6 @@ type TxMode m
4140
= ( MinWorkMode m
4241
, MonadBalances m
4342
, MonadTxHistory m
44-
, MonadMockable m
4543
, MonadMask m
4644
, MonadThrow m
4745
, TxCreateMode m

core/cardano-sl-core.cabal

+4-15
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,9 @@ library
5757
Pos.Core.JsonLog.JsonLogT
5858
Pos.Core.JsonLog.LogEvents
5959

60-
-- Mockable (moved from networking in
61-
-- the `sinbin` shuffle). All modules
62-
-- must be exposed so that `networking`
63-
-- can import & re-export them.
64-
Pos.Core.Mockable
65-
Pos.Core.Mockable.Channel
66-
Pos.Core.Mockable.Class
67-
Pos.Core.Mockable.Concurrent
68-
Pos.Core.Mockable.CurrentTime
69-
Pos.Core.Mockable.Instances
70-
Pos.Core.Mockable.Monad
71-
Pos.Core.Mockable.Production
72-
Pos.Core.Mockable.SharedAtomic
73-
Pos.Core.Mockable.SharedExclusive
74-
Pos.Core.Mockable.Metrics
60+
-- Concurrency operations, previously
61+
-- in `Mockable`.
62+
Pos.Core.Conc
7563

7664
Pos.Core.Reporting
7765

@@ -262,6 +250,7 @@ library
262250
, transformers-base
263251
, transformers-lift
264252
, universum
253+
, unliftio
265254
, unliftio-core
266255
, unordered-containers
267256
, vector

0 commit comments

Comments
 (0)