Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit dc20839

Browse files
authored
Merge pull request input-output-hk/cardano-sl#3437 from input-output-hk/ruhatch/CDEC-509
[CDEC-509] Remove HasGeneratedSecrets
2 parents 013a4a5 + d52bfd1 commit dc20839

File tree

7 files changed

+94
-55
lines changed

7 files changed

+94
-55
lines changed

server/Main.hs

+27-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import Pos.Chain.Ssc (SscParams)
1616
import Pos.Chain.Txp (TxpConfiguration)
1717
import qualified Pos.Client.CLI as CLI
1818
import Pos.Context (ncUserSecret)
19-
import Pos.Core (epochSlots)
19+
import Pos.Core (Config (..), configGeneratedSecretsThrow, epochSlots)
20+
import Pos.Core.Genesis (GeneratedSecrets)
2021
import Pos.Crypto (ProtocolMagic)
2122
import Pos.DB.DB (initNodeDBs)
2223
import Pos.DB.Txp (txpGlobalSettings)
@@ -170,25 +171,37 @@ actionWithNewWallet pm txpConfig sscParams nodeParams ntpConfig params =
170171
loggerName = lpDefaultName . bpLoggingParams . npBaseParams $ nodeParams
171172

172173
-- | Runs an edge node plus its wallet backend API.
173-
startEdgeNode :: HasCompileInfo
174-
=> WalletStartupOptions
175-
-> IO ()
174+
startEdgeNode :: HasCompileInfo => WalletStartupOptions -> IO ()
176175
startEdgeNode wso =
177-
withConfigurations blPath conf $ \pm txpConfig ntpConfig -> do
178-
(sscParams, nodeParams) <- getParameters txpConfig ntpConfig
179-
case wsoWalletBackendParams wso of
180-
WalletLegacy legacyParams ->
181-
actionWithWallet pm txpConfig sscParams nodeParams ntpConfig legacyParams
182-
WalletNew newParams ->
183-
actionWithNewWallet pm txpConfig sscParams nodeParams ntpConfig newParams
176+
withConfigurations blPath conf $ \coreConfig txpConfig ntpConfig -> do
177+
generatedSecrets <- configGeneratedSecretsThrow coreConfig
178+
(sscParams, nodeParams) <- getParameters generatedSecrets
179+
txpConfig
180+
ntpConfig
181+
case wsoWalletBackendParams wso of
182+
WalletLegacy legacyParams -> actionWithWallet
183+
(configProtocolMagic coreConfig)
184+
txpConfig
185+
sscParams
186+
nodeParams
187+
ntpConfig
188+
legacyParams
189+
WalletNew newParams -> actionWithNewWallet
190+
(configProtocolMagic coreConfig)
191+
txpConfig
192+
sscParams
193+
nodeParams
194+
ntpConfig
195+
newParams
184196
where
185197
getParameters :: HasConfigurations
186-
=> TxpConfiguration
198+
=> GeneratedSecrets
199+
-> TxpConfiguration
187200
-> NtpConfiguration
188201
-> IO (SscParams, NodeParams)
189-
getParameters txpConfig ntpConfig = do
202+
getParameters generatedSecrets txpConfig ntpConfig = do
190203

191-
currentParams <- CLI.getNodeParams defaultLoggerName (wsoNodeArgs wso) nodeArgs
204+
currentParams <- CLI.getNodeParams defaultLoggerName (wsoNodeArgs wso) nodeArgs generatedSecrets
192205
let vssSK = fromJust $ npUserSecret currentParams ^. usVss
193206
let gtParams = CLI.gtSscParams (wsoNodeArgs wso) vssSK (npBehaviorConfig currentParams)
194207

test/unit/Test/Spec/CoinSelection.hs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# OPTIONS_GHC -fno-warn-orphans #-}
22
{-# LANGUAGE TupleSections #-}
33
{-# LANGUAGE ViewPatterns #-}
4+
45
module Test.Spec.CoinSelection (
56
spec
67
) where
@@ -25,7 +26,8 @@ import qualified Text.Tabl as Tabl
2526

2627
import Pos.Binary.Class (Bi (encode), toLazyByteString)
2728
import qualified Pos.Chain.Txp as Core
28-
import Pos.Core (Coeff (..), TxSizeLinear (..), unsafeIntegerToCoin)
29+
import Pos.Core as Core (Coeff (..), Config (..), TxSizeLinear (..),
30+
unsafeIntegerToCoin)
2931
import qualified Pos.Core as Core
3032
import Pos.Core.Attributes (mkAttributes)
3133
import Pos.Crypto (SecretKey)
@@ -417,10 +419,13 @@ genMaxInputTx estimator = do
417419
-- Now build the transaction, attempting to make the encoded size of the transaction
418420
-- as large as possible.
419421
bimap pretty ((,maxTxSize) . encodedSize) <$> (
420-
withDefConfiguration $ \pm -> do
422+
withDefConfiguration $ \coreConfig -> do
421423
key <- arbitrary
422424
inputs <- replicateM maxInputs ((,) <$> genIn <*> genOutAux)
423-
mkTx pm key (NE.fromList inputs) (NE.fromList [output]) [])
425+
mkTx (configProtocolMagic coreConfig)
426+
key
427+
(NE.fromList inputs)
428+
(NE.fromList [output]) [])
424429

425430
genMaxTxSize :: Gen Byte
426431
genMaxTxSize = fromBytes <$> choose (4000, 100000)
@@ -488,7 +493,7 @@ payRestrictInputsTo :: Word64
488493
-> Policy
489494
-> Gen RunResult
490495
payRestrictInputsTo maxInputs genU genP feeFunction adjustOptions bal amount policy =
491-
withDefConfiguration $ \pm -> do
496+
withDefConfiguration $ \coreConfig -> do
492497
utxo <- genU bal
493498
payee <- genP utxo amount
494499
key <- arbitrary
@@ -501,7 +506,11 @@ payRestrictInputsTo maxInputs genU genP feeFunction adjustOptions bal amount pol
501506
Left e -> return (utxo, payee, Left (STB e))
502507
Right (CoinSelFinalResult inputs outputs coins) -> do
503508
change <- genChange utxo payee coins
504-
txAux <- mkTx pm key inputs outputs change
509+
txAux <- mkTx (configProtocolMagic coreConfig)
510+
key
511+
inputs
512+
outputs
513+
change
505514
return (utxo, payee, bimap STB identity txAux)
506515

507516
pay :: (InitialBalance -> Gen Core.Utxo)

test/unit/Test/Spec/Fixture.hs

+11-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Universum
1616

1717
import System.Wlog (Severity)
1818

19+
import Pos.Core (Config (..))
20+
1921
import Test.Pos.Configuration (withDefConfiguration)
2022
import Test.QuickCheck (arbitrary, frequency)
2123
import Test.QuickCheck.Monadic (PropertyM, pick)
@@ -67,10 +69,15 @@ withActiveWalletFixture prepareFixtures cc = do
6769
generateFixtures <- prepareFixtures
6870
liftIO $ Keystore.bracketTestKeystore $ \keystore -> do
6971
WalletLayer.Kernel.bracketPassiveWallet devNull keystore mockNodeStateDef $ \passiveLayer passiveWallet -> do
70-
withDefConfiguration $ \pm -> do
71-
WalletLayer.Kernel.bracketActiveWallet pm passiveLayer passiveWallet diffusion $ \activeLayer activeWallet -> do
72-
fixtures <- generateFixtures keystore activeWallet
73-
cc keystore activeLayer activeWallet fixtures
72+
withDefConfiguration $ \coreConfig -> do
73+
WalletLayer.Kernel.bracketActiveWallet
74+
(configProtocolMagic coreConfig)
75+
passiveLayer
76+
passiveWallet
77+
diffusion
78+
$ \activeLayer activeWallet -> do
79+
fixtures <- generateFixtures keystore activeWallet
80+
cc keystore activeLayer activeWallet fixtures
7481
where
7582
diffusion :: Kernel.WalletDiffusion
7683
diffusion = Kernel.WalletDiffusion {

test/unit/Test/Spec/Kernel.hs

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import qualified Cardano.Wallet.Kernel.Keystore as Keystore
1616
import Cardano.Wallet.Kernel.NodeStateAdaptor (mockNodeStateDef)
1717
import qualified Cardano.Wallet.Kernel.Read as Kernel
1818

19-
import Pos.Core (Coeff (..), TxSizeLinear (..))
19+
import Pos.Core (Coeff (..), Config (..), TxSizeLinear (..))
2020
import Pos.Core.Chrono
2121

2222
import Test.Infrastructure.Generator
@@ -267,11 +267,12 @@ bracketPassiveWallet postHook = do
267267

268268
-- | Initialize active wallet in a manner suitable for generator-based testing
269269
bracketActiveWallet :: (Kernel.ActiveWallet -> IO a) -> IO a
270-
bracketActiveWallet test =
271-
withDefConfiguration $ \pm -> do
272-
bracketPassiveWallet $ \passive ->
273-
Kernel.bracketActiveWallet pm passive diffusion $ \active ->
274-
test active
270+
bracketActiveWallet test = withDefConfiguration $ \coreConfig -> do
271+
bracketPassiveWallet $ \passive ->
272+
Kernel.bracketActiveWallet (configProtocolMagic coreConfig)
273+
passive
274+
diffusion
275+
test
275276

276277
-- TODO: Decide what we want to do with submitted transactions
277278
diffusion :: Kernel.WalletDiffusion

test/unit/Test/Spec/TxMetaScenarios.hs

+7-8
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ import Pos.Core.Slotting (EpochIndex (..), LocalSlotIndex (..),
3636
SlotId (..))
3737
import Pos.Util (withCompileInfo)
3838

39-
40-
import Ntp.Client (NtpStatus (..))
41-
4239
import Test.Hspec
4340
import Test.Infrastructure.Genesis
4441
import Test.Pos.Configuration (withDefConfiguration,
@@ -395,7 +392,7 @@ nodeStParams1 =
395392
, mockNodeStateSlotStart = const $ Right getSomeTimestamp
396393
, mockNodeStateSecurityParameter = SecurityParameter 2160
397394
, mockNodeStateNextEpochSlotDuration = fromMicroseconds 200
398-
, mockNodeStateNtpStatus = NtpSyncPending
395+
, mockNodeStateNtpDrift = const (V1.TimeInfo Nothing)
399396
}
400397

401398
nodeStParams2 :: MockNodeStateParams
@@ -408,7 +405,7 @@ nodeStParams2 =
408405
, mockNodeStateSlotStart = const $ Right getSomeTimestamp
409406
, mockNodeStateSecurityParameter = SecurityParameter 2160
410407
, mockNodeStateNextEpochSlotDuration = fromMicroseconds 200
411-
, mockNodeStateNtpStatus = NtpSyncPending
408+
, mockNodeStateNtpDrift = const (V1.TimeInfo Nothing)
412409
}
413410

414411
-- | Initialize active wallet in a manner suitable for generator-based testing.
@@ -418,10 +415,12 @@ nodeStParams2 =
418415
-- there for better testing.
419416
bracketActiveWalletTxMeta :: MockNodeStateParams -> (Kernel.ActiveWallet -> IO a) -> IO a
420417
bracketActiveWalletTxMeta stateParams test =
421-
withDefConfiguration $ \pm -> do
418+
withDefConfiguration $ \coreConfig -> do
422419
bracketPassiveWalletTxMeta stateParams $ \passive ->
423-
Kernel.bracketActiveWallet pm passive diffusion $ \active ->
424-
test active
420+
Kernel.bracketActiveWallet (configProtocolMagic coreConfig)
421+
passive
422+
diffusion
423+
$ \active -> test active
425424

426425
-- | Initialize passive wallet in a manner suitable for the unit tests
427426
bracketPassiveWalletTxMeta :: MockNodeStateParams -> (Kernel.PassiveWallet -> IO a) -> IO a

test/unit/UTxO/Context.hs

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DeriveAnyClass #-}
2+
23
{-# OPTIONS_GHC -fno-warn-orphans #-}
34

45
-- | Context needed for the translation between DSL and Cardano types
@@ -50,7 +51,7 @@ import Pos.Chain.Block (BlockHeader (..), GenesisBlock, HeaderHash,
5051
blockHeaderHash, genesisBlock0, _gbHeader)
5152
import Pos.Chain.Lrc
5253
import Pos.Chain.Txp
53-
import Pos.Core
54+
import Pos.Core as Core
5455
import Pos.Core.Delegation (ProxySKHeavy)
5556
import Pos.Core.Genesis (GeneratedSecrets (..), GenesisData (..),
5657
GenesisDelegation (..), PoorSecret (..), RichSecrets (..))
@@ -88,20 +89,29 @@ data CardanoContext = CardanoContext {
8889
, ccEpochSlots :: SlotCount
8990
}
9091

91-
initCardanoContext :: HasConfiguration => ProtocolMagic -> CardanoContext
92-
initCardanoContext ccMagic = CardanoContext{..}
92+
initCardanoContext
93+
:: HasConfiguration
94+
=> Core.Config
95+
-> CardanoContext
96+
initCardanoContext coreConfig = CardanoContext
97+
{ ccStakes = genesisStakes
98+
, ccBlock0 = ccBlock0
99+
, ccData = genesisData
100+
, ccUtxo = ccUtxo
101+
, ccSecrets = fromMaybe (error "initCardanoContext: no secrets") $
102+
configGeneratedSecrets coreConfig
103+
, ccMagic = configProtocolMagic coreConfig
104+
, ccInitLeaders = ccLeaders
105+
, ccBalances = utxoToAddressCoinPairs ccUtxo
106+
, ccHash0 = (blockHeaderHash . BlockHeaderGenesis . _gbHeader) ccBlock0
107+
, ccEpochSlots = epochSlots
108+
}
93109
where
94-
ccLeaders = genesisLeaders epochSlots
95-
ccStakes = genesisStakes
96-
ccBlock0 = genesisBlock0 ccMagic (GenesisHash genesisHash) ccLeaders
97-
ccData = genesisData
98-
ccUtxo = unGenesisUtxo genesisUtxo
99-
ccSecrets = fromMaybe (error "initCardanoContext: no secrets") $
100-
generatedSecrets
101-
ccInitLeaders = ccLeaders
102-
ccBalances = utxoToAddressCoinPairs ccUtxo
103-
ccHash0 = (blockHeaderHash . BlockHeaderGenesis . _gbHeader) ccBlock0
104-
ccEpochSlots = epochSlots
110+
ccLeaders = genesisLeaders epochSlots
111+
ccBlock0 = genesisBlock0 (configProtocolMagic coreConfig)
112+
(GenesisHash genesisHash)
113+
ccLeaders
114+
ccUtxo = unGenesisUtxo genesisUtxo
105115

106116
{-------------------------------------------------------------------------------
107117
More explicit representation of the various actors in the genesis block

test/unit/UTxO/Translate.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ instance Monad m => MonadGState (TranslateT e m) where
102102
-- pure exceptions.
103103
runTranslateT :: Monad m => Exception e => TranslateT e m a -> m a
104104
runTranslateT (TranslateT ta) =
105-
withDefConfiguration $ \pm ->
105+
withDefConfiguration $ \coreConfig ->
106106
withDefUpdateConfiguration $
107107
let env :: TranslateEnv
108108
env = TranslateEnv {
109-
teContext = initContext (initCardanoContext pm)
110-
, teConfig = Dict
111-
, teUpdate = Dict
109+
teContext = initContext (initCardanoContext coreConfig)
110+
, teConfig = Dict
111+
, teUpdate = Dict
112112
}
113113
in do ma <- runReaderT (runExceptT ta) env
114114
case ma of

0 commit comments

Comments
 (0)