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

[CDEC-509] Remove HasCoreConfiguration and HasConfiguration #3550

Merged
merged 3 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions auxx/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,25 @@ action opts@AuxxOptions {..} command = do
->
handle @_ @ConfigurationException (\_ -> runWithoutNode pa)
. handle @_ @ConfigurationError (\_ -> runWithoutNode pa)
$ withConfigurations Nothing conf (runWithConfig pa)
$ withConfigurations Nothing
cnaDumpGenesisDataPath
cnaDumpConfiguration
conf
(runWithConfig pa)
Light
-> runWithoutNode pa
_ -> withConfigurations Nothing conf (runWithConfig pa)
_ -> withConfigurations Nothing
cnaDumpGenesisDataPath
cnaDumpConfiguration
conf
(runWithConfig pa)
where
runWithoutNode :: PrintAction IO -> IO ()
runWithoutNode printAction = printAction "Mode: light" >> rawExec Nothing Nothing Nothing opts Nothing command

runWithConfig :: HasConfigurations => PrintAction IO -> Core.Config -> TxpConfiguration -> NtpConfiguration -> IO ()
runWithConfig printAction coreConfig txpConfig ntpConfig = do
runWithConfig printAction coreConfig txpConfig _ntpConfig = do
printAction "Mode: with-config"
CLI.printInfoOnStart aoCommonNodeArgs
(configGenesisData coreConfig)
ntpConfig
txpConfig
(nodeParams, tempDbUsed) <- (correctNodeParams opts . fst) =<< CLI.getNodeParams
loggerName
cArgs
Expand Down
21 changes: 9 additions & 12 deletions auxx/src/Mode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ import Pos.Client.Txp.History (MonadTxHistory (..),
getBlockHistoryDefault, getLocalHistoryDefault,
saveTxDefault)
import Pos.Context (HasNodeContext (..))
import Pos.Core (Address, HasConfiguration, HasPrimaryKey (..),
IsBootstrapEraAddr (..), SlotCount, deriveFirstHDAddress,
largestPubKeyAddressBoot, largestPubKeyAddressSingleKey,
makePubKeyAddress, siEpoch)
import Pos.Core (Address, HasPrimaryKey (..), IsBootstrapEraAddr (..),
SlotCount, deriveFirstHDAddress, largestPubKeyAddressBoot,
largestPubKeyAddressSingleKey, makePubKeyAddress, siEpoch)
import Pos.Core.JsonLog (CanJsonLog (..))
import Pos.Core.Reporting (HasMisbehaviorMetrics (..),
MonadReporting (..))
Expand Down Expand Up @@ -180,35 +179,34 @@ instance {-# OVERLAPPING #-} HasLoggerName AuxxMode where
instance {-# OVERLAPPING #-} CanJsonLog AuxxMode where
jsonLog = realModeToAuxx ... jsonLog

instance HasConfiguration => MonadDBRead AuxxMode where
instance MonadDBRead AuxxMode where
dbGet = realModeToAuxx ... dbGet
dbIterSource tag p =
transPipe (transResourceT realModeToAuxx) (dbIterSource tag p)
dbGetSerBlock = realModeToAuxx ... dbGetSerBlock
dbGetSerUndo = realModeToAuxx ... dbGetSerUndo
dbGetSerBlund = realModeToAuxx ... dbGetSerBlund

instance HasConfiguration => MonadDB AuxxMode where
instance MonadDB AuxxMode where
dbPut = realModeToAuxx ... dbPut
dbWriteBatch = realModeToAuxx ... dbWriteBatch
dbDelete = realModeToAuxx ... dbDelete
dbPutSerBlunds = realModeToAuxx ... dbPutSerBlunds

instance HasConfiguration => MonadGState AuxxMode where
instance MonadGState AuxxMode where
gsAdoptedBVData = realModeToAuxx ... gsAdoptedBVData

instance MonadBListener AuxxMode where
onApplyBlocks = realModeToAuxx ... onApplyBlocks
onRollbackBlocks = realModeToAuxx ... onRollbackBlocks

instance HasConfiguration => MonadBalances AuxxMode where
instance MonadBalances AuxxMode where
getOwnUtxos genesisData addrs = ifM isTempDbUsed
(getOwnUtxosGenesis genesisData addrs)
(getFilteredUtxo addrs)
getBalance = getBalanceFromUtxo

instance HasConfiguration =>
MonadTxHistory AuxxMode where
instance MonadTxHistory AuxxMode where
getBlockHistory = getBlockHistoryDefault
getLocalHistory = getLocalHistoryDefault
saveTx = saveTxDefault
Expand All @@ -233,8 +231,7 @@ instance MonadKeys AuxxMode where

type instance MempoolExt AuxxMode = EmptyMempoolExt

instance HasConfiguration =>
MonadTxpLocal AuxxMode where
instance MonadTxpLocal AuxxMode where
txpNormalize pm = withReaderT acRealModeContext . txNormalize pm
txpProcessTx coreConfig txpConfig = withReaderT acRealModeContext . txProcessTransaction coreConfig txpConfig

Expand Down
6 changes: 1 addition & 5 deletions client/src/Pos/Client/Txp/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import Pos.Core as Core (Address, Coin, Config (..), SlotCount,
integerToCoin, isRedeemAddress, mkCoin, sumCoins,
txSizeLinearMinValue, unsafeIntegerToCoin, unsafeSubCoin)
import Pos.Core.Attributes (mkAttributes)
import Pos.Core.Configuration (HasConfiguration)
import Pos.Core.Update (bvdTxFeePolicy)
import Pos.Crypto (ProtocolMagic, RedeemSecretKey, SafeSigner,
SignTag (SignRedeemTx, SignTx), deterministicKeyGen,
Expand Down Expand Up @@ -217,10 +216,7 @@ instance Arbitrary InputSelectionPolicy where
arbitrary = elements [minBound .. maxBound]

-- | Mode for creating transactions. We need to know fee policy.
type TxDistrMode m
= ( MonadGState m
, HasConfiguration
)
type TxDistrMode m = MonadGState m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, not worth doing in this PR but later we should go through the code base and killing completely useless type aliases like type X m = Y m.


type TxCreateMode m
= ( TxDistrMode m
Expand Down
17 changes: 1 addition & 16 deletions client/test/Test/Pos/Client/Txp/Mode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
module Test.Pos.Client.Txp.Mode
( TxpTestProperty
, TxpTestMode
, HasTxpConfigurations
, withBVData
) where

Expand All @@ -17,28 +16,14 @@ import qualified Data.ByteString as BS
import Test.QuickCheck (Testable (..), ioProperty)
import Test.QuickCheck.Monadic (PropertyM, monadic)

import Pos.Chain.Ssc (HasSscConfiguration)
import Pos.Chain.Update (HasUpdateConfiguration)
import Pos.Client.Txp.Addresses (MonadAddresses (..))
import Pos.Configuration (HasNodeConfiguration)
import Pos.Core (Address, HasConfiguration, makePubKeyAddressBoot)
import Pos.Core (Address, makePubKeyAddressBoot)
import Pos.Core.Update (BlockVersionData)
import Pos.Crypto (deterministicKeyGen)
import Pos.DB (MonadGState (..))

import Test.Pos.Core.Dummy (dummyBlockVersionData)

----------------------------------------------------------------------------
-- Configuration propagation
----------------------------------------------------------------------------

type HasTxpConfigurations =
( HasNodeConfiguration
, HasSscConfiguration
, HasConfiguration
, HasUpdateConfiguration
)

----------------------------------------------------------------------------
-- Mock for TxCreateMode
----------------------------------------------------------------------------
Expand Down
39 changes: 15 additions & 24 deletions client/test/Test/Pos/Client/Txp/UtilSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import Pos.Crypto (RedeemSecretKey, SafeSigner, SecretKey, decodeHash,
import Pos.DB (gsAdoptedBVData)
import Pos.Util.Util (leftToPanic)

import Test.Pos.Client.Txp.Mode (HasTxpConfigurations, TxpTestMode,
TxpTestProperty, withBVData)
import Test.Pos.Client.Txp.Mode (TxpTestMode, TxpTestProperty,
withBVData)
import Test.Pos.Configuration (withDefConfigurations)
import Test.Pos.Core.Dummy (dummyConfig)
import Test.Pos.Crypto.Arbitrary ()
Expand All @@ -59,7 +59,7 @@ spec = withDefConfigurations $ \_ _ _ ->
data TestFunctionWrapper
= forall prop. (Testable prop) => TestFunctionWrapper (InputSelectionPolicy -> prop)

createMTxSpec :: HasTxpConfigurations => Spec
createMTxSpec :: Spec
createMTxSpec = do
let inputSelectionPolicies =
[ ("Grouped inputs", OptimizeForSecurity)
Expand Down Expand Up @@ -114,16 +114,14 @@ createMTxSpec = do
"The amount of used inputs is as small as possible"

testCreateMTx
:: HasTxpConfigurations
=> CreateMTxParams
:: CreateMTxParams
-> TxpTestProperty (Either TxError (TxAux, NonEmpty TxOut))
testCreateMTx CreateMTxParams {..} = lift $
createMTx dummyConfig mempty cmpInputSelectionPolicy cmpUtxo (getSignerFromList cmpSigners)
cmpOutputs cmpAddrData

createMTxWorksWhenWeAreRichSpec
:: HasTxpConfigurations
=> InputSelectionPolicy
:: InputSelectionPolicy
-> TxpTestProperty ()
createMTxWorksWhenWeAreRichSpec inputSelectionPolicy =
forAllM gen $ \txParams@CreateMTxParams{..} -> do
Expand All @@ -135,8 +133,7 @@ createMTxWorksWhenWeAreRichSpec inputSelectionPolicy =
gen = makeManyAddressesToManyParams inputSelectionPolicy 1 1000000 1 1

stabilizationDoesNotFailSpec
:: HasTxpConfigurations
=> InputSelectionPolicy
:: InputSelectionPolicy
-> TxpTestProperty ()
stabilizationDoesNotFailSpec inputSelectionPolicy = do
forAllM gen $ \txParams@CreateMTxParams{..} -> do
Expand All @@ -149,8 +146,7 @@ stabilizationDoesNotFailSpec inputSelectionPolicy = do
gen = makeManyAddressesToManyParams inputSelectionPolicy 1 200000 1 1

feeIsNonzeroSpec
:: HasTxpConfigurations
=> InputSelectionPolicy
:: InputSelectionPolicy
-> TxpTestProperty ()
feeIsNonzeroSpec inputSelectionPolicy = do
forAllM gen $ \txParams@CreateMTxParams{..} -> do
Expand All @@ -165,8 +161,7 @@ feeIsNonzeroSpec inputSelectionPolicy = do
gen = makeManyAddressesToManyParams inputSelectionPolicy 1 100000 1 1

manyUtxoTo1Spec
:: HasTxpConfigurations
=> InputSelectionPolicy
:: InputSelectionPolicy
-> TxpTestProperty ()
manyUtxoTo1Spec inputSelectionPolicy = do
forAllM gen $ \txParams@CreateMTxParams{..} -> do
Expand All @@ -178,8 +173,7 @@ manyUtxoTo1Spec inputSelectionPolicy = do
gen = makeManyUtxoTo1Params inputSelectionPolicy 10 100000 1

manyAddressesTo1Spec
:: HasTxpConfigurations
=> InputSelectionPolicy
:: InputSelectionPolicy
-> TxpTestProperty ()
manyAddressesTo1Spec inputSelectionPolicy = do
forAllM gen $ \txParams@CreateMTxParams{..} -> do
Expand All @@ -191,8 +185,7 @@ manyAddressesTo1Spec inputSelectionPolicy = do
gen = makeManyAddressesToManyParams inputSelectionPolicy 10 100000 1 1

manyAddressesToManySpec
:: HasTxpConfigurations
=> InputSelectionPolicy
:: InputSelectionPolicy
-> TxpTestProperty ()
manyAddressesToManySpec inputSelectionPolicy = do
forAllM gen $ \txParams@CreateMTxParams{..} -> do
Expand All @@ -203,7 +196,7 @@ manyAddressesToManySpec inputSelectionPolicy = do
where
gen = makeManyAddressesToManyParams inputSelectionPolicy 10 100000 10 1

redemptionSpec :: HasTxpConfigurations => TxpTestProperty ()
redemptionSpec :: TxpTestProperty ()
redemptionSpec = do
forAllM genParams $ \(CreateRedemptionTxParams {..}) -> do
txOrError <- createRedemptionTx dummyProtocolMagic crpUtxo crpRsk crpOutputs
Expand All @@ -223,8 +216,7 @@ redemptionSpec = do
pure CreateRedemptionTxParams {..}

txWithRedeemOutputFailsSpec
:: HasTxpConfigurations
=> InputSelectionPolicy
:: InputSelectionPolicy
-> TxpTestProperty ()
txWithRedeemOutputFailsSpec inputSelectionPolicy = do
forAllM genParams $ \(CreateMTxParams {..}) -> do
Expand All @@ -244,8 +236,7 @@ txWithRedeemOutputFailsSpec inputSelectionPolicy = do
pure params{ cmpOutputs = one txOutAuxOutput }

feeForManyAddressesSpec
:: HasTxpConfigurations
=> InputSelectionPolicy
:: InputSelectionPolicy
-> Bool
-> TxpTestProperty ()
feeForManyAddressesSpec inputSelectionPolicy manyAddrs =
Expand Down Expand Up @@ -288,7 +279,7 @@ feeForManyAddressesSpec inputSelectionPolicy manyAddrs =
| otherwise = makeManyUtxoTo1Params inputSelectionPolicy


groupedPolicySpec :: HasTxpConfigurations => TxpTestProperty ()
groupedPolicySpec :: TxpTestProperty ()
groupedPolicySpec =
forAllM gen $ testCreateMTx >=> \case
Left err -> stopProperty $ pretty err
Expand All @@ -300,7 +291,7 @@ groupedPolicySpec =
utxoNum = 10
gen = makeManyUtxoTo1Params OptimizeForSecurity (fromIntegral utxoNum) 1000000 1

ungroupedPolicySpec :: HasTxpConfigurations => TxpTestProperty ()
ungroupedPolicySpec :: TxpTestProperty ()
ungroupedPolicySpec =
forAllM gen $ testCreateMTx >=> \case
Left err -> stopProperty $ pretty err
Expand Down
1 change: 0 additions & 1 deletion core/cardano-sl-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ library
Pos.Core.Genesis.NonAvvmBalances
Pos.Core.Genesis.ProtocolConstants
Pos.Core.Genesis.Spec
Pos.Core.Genesis.VssCertificatesMap
Pos.Core.Genesis.WStakeholders

-- Slotting
Expand Down
Loading