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

Commit 06b4f09

Browse files
committed
[CDEC-509] Remove HasGeneratedSecrets
1 parent 830b316 commit 06b4f09

File tree

44 files changed

+598
-419
lines changed

Some content is hidden

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

44 files changed

+598
-419
lines changed

auxx/Main.hs

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import Ntp.Client (NtpConfiguration)
1818
import Pos.Chain.Txp (TxpConfiguration)
1919
import qualified Pos.Client.CLI as CLI
2020
import Pos.Context (NodeContext (..))
21-
import Pos.Core (ConfigurationError, epochSlots)
21+
import Pos.Core as Core (Config (..), ConfigurationError,
22+
configGeneratedSecretsThrow, epochSlots)
2223
import Pos.Crypto (ProtocolMagic)
2324
import Pos.DB.DB (initNodeDBs)
2425
import Pos.DB.Txp (txpGlobalSettings)
@@ -102,12 +103,14 @@ action opts@AuxxOptions {..} command = do
102103
runWithoutNode :: PrintAction IO -> IO ()
103104
runWithoutNode printAction = printAction "Mode: light" >> rawExec Nothing Nothing Nothing opts Nothing command
104105

105-
runWithConfig :: HasConfigurations => PrintAction IO -> ProtocolMagic -> TxpConfiguration -> NtpConfiguration -> IO ()
106-
runWithConfig printAction pm txpConfig ntpConfig = do
106+
runWithConfig :: HasConfigurations => PrintAction IO -> Core.Config -> TxpConfiguration -> NtpConfiguration -> IO ()
107+
runWithConfig printAction coreConfig txpConfig ntpConfig = do
107108
printAction "Mode: with-config"
108109
CLI.printInfoOnStart aoCommonNodeArgs ntpConfig txpConfig
110+
generatedSecrets <- configGeneratedSecretsThrow coreConfig
109111
(nodeParams, tempDbUsed) <-
110-
correctNodeParams opts =<< CLI.getNodeParams loggerName cArgs nArgs
112+
correctNodeParams opts =<<
113+
CLI.getNodeParams loggerName cArgs nArgs generatedSecrets
111114

112115
let toRealMode :: AuxxMode a -> RealMode EmptyMempoolExt a
113116
toRealMode auxxAction = do
@@ -121,12 +124,13 @@ action opts@AuxxOptions {..} command = do
121124
(npUserSecret nodeParams ^. usVss)
122125
sscParams = CLI.gtSscParams cArgs vssSK (npBehaviorConfig nodeParams)
123126

127+
let pm = configProtocolMagic coreConfig
124128
bracketNodeResources nodeParams sscParams (txpGlobalSettings pm txpConfig) (initNodeDBs pm epochSlots) $ \nr ->
125129
let NodeContext {..} = nrContext nr
126130
modifier = if aoStartMode == WithNode
127131
then runNodeWithSinglePlugin pm txpConfig nr
128132
else identity
129-
auxxModeAction = modifier (auxxPlugin pm txpConfig opts command)
133+
auxxModeAction = modifier (auxxPlugin coreConfig txpConfig opts command)
130134
in runRealMode pm txpConfig nr $ \diffusion ->
131135
toRealMode (auxxModeAction (hoistDiffusion realModeToAuxx toRealMode diffusion))
132136

auxx/src/Command/Proc.hs

+46-36
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ import Pos.Chain.Txp (TxpConfiguration)
2121
import Pos.Chain.Update (BlockVersionModifier (..))
2222
import Pos.Client.KeyStorage (addSecretKey, getSecretKeysPlain)
2323
import Pos.Client.Txp.Balances (getBalance)
24-
import Pos.Core (AddrStakeDistribution (..), Address, StakeholderId,
25-
addressHash, mkMultiKeyDistr, unsafeGetCoin)
24+
import Pos.Core as Core (AddrStakeDistribution (..), Address,
25+
Config (..), StakeholderId, addressHash,
26+
configGeneratedSecretsThrow, mkMultiKeyDistr,
27+
unsafeGetCoin)
2628
import Pos.Core.Common (AddrAttributes (..), AddrSpendingData (..),
2729
makeAddress)
28-
import Pos.Core.Configuration (genesisSecretKeys)
2930
import Pos.Core.Delegation (HeavyDlgIndex (..))
31+
import Pos.Core.Genesis (gsSecretKeys)
3032
import Pos.Core.Txp (TxOut (..))
3133
import Pos.Core.Update (SoftwareVersion (..))
32-
import Pos.Crypto (ProtocolMagic, PublicKey, emptyPassphrase,
33-
encToPublic, fullPublicKeyF, hashHexF, noPassEncrypt,
34-
safeCreatePsk, unsafeCheatingHashCoerce, withSafeSigner)
34+
import Pos.Crypto (PublicKey, emptyPassphrase, encToPublic,
35+
fullPublicKeyF, hashHexF, noPassEncrypt, safeCreatePsk,
36+
unsafeCheatingHashCoerce, withSafeSigner)
3537
import Pos.DB.Class (MonadGState (..))
3638
import Pos.Infra.Diffusion.Types (Diffusion (..))
3739
import Pos.Util.UserSecret (WalletUserSecret (..), readUserSecret,
@@ -64,13 +66,13 @@ import Repl (PrintAction)
6466

6567
createCommandProcs ::
6668
forall m. (MonadIO m, CanLog m, HasLoggerName m)
67-
=> Maybe ProtocolMagic
69+
=> Maybe Core.Config
6870
-> Maybe TxpConfiguration
6971
-> Maybe (Dict (MonadAuxxMode m))
7072
-> PrintAction m
7173
-> Maybe (Diffusion m)
7274
-> [CommandProc m]
73-
createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights . fix $ \commands -> [
75+
createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = rights . fix $ \commands -> [
7476

7577
return CommandProc
7678
{ cpName = "L"
@@ -212,7 +214,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
212214
},
213215

214216
let name = "send-to-all-genesis" in
215-
needsProtocolMagic name >>= \pm ->
217+
needsCoreConfig name >>= \coreConfig ->
216218
needsDiffusion name >>= \diffusion ->
217219
needsAuxxMode name >>= \Dict ->
218220
return CommandProc
@@ -226,7 +228,11 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
226228
stagpTpsSentFile <- getArg tyFilePath "file"
227229
return Tx.SendToAllGenesisParams{..}
228230
, cpExec = \stagp -> do
229-
Tx.sendToAllGenesis pm diffusion stagp
231+
secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow coreConfig
232+
Tx.sendToAllGenesis (configProtocolMagic coreConfig)
233+
secretKeys
234+
diffusion
235+
stagp
230236
return ValueUnit
231237
, cpHelp = "create and send transactions from all genesis addresses \
232238
\ for <duration> seconds, <delay> in ms. <conc> is the \
@@ -247,7 +253,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
247253
},
248254

249255
let name = "send" in
250-
needsProtocolMagic name >>= \pm ->
256+
needsCoreConfig name >>= \coreConfig ->
251257
needsDiffusion name >>= \diffusion ->
252258
needsAuxxMode name >>= \Dict ->
253259
return CommandProc
@@ -257,14 +263,14 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
257263
(,) <$> getArg tyInt "i"
258264
<*> getArgSome tyTxOut "out"
259265
, cpExec = \(i, outputs) -> do
260-
Tx.send pm diffusion i outputs
266+
Tx.send (configProtocolMagic coreConfig) diffusion i outputs
261267
return ValueUnit
262268
, cpHelp = "send from #i to specified transaction outputs \
263269
\ (use 'tx-out' to build them)"
264270
},
265271

266272
let name = "vote" in
267-
needsProtocolMagic name >>= \pm ->
273+
needsCoreConfig name >>= \coreConfig ->
268274
needsDiffusion name >>= \diffusion ->
269275
needsAuxxMode name >>= \Dict ->
270276
return CommandProc
@@ -275,7 +281,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
275281
<*> getArg tyBool "agree"
276282
<*> getArg tyHash "up-id"
277283
, cpExec = \(i, decision, upId) -> do
278-
Update.vote pm diffusion i decision upId
284+
Update.vote (configProtocolMagic coreConfig) diffusion i decision upId
279285
return ValueUnit
280286
, cpHelp = "send vote for update proposal <up-id> and \
281287
\ decision <agree> ('true' or 'false'), \
@@ -331,7 +337,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
331337
},
332338

333339
let name = "propose-update" in
334-
needsProtocolMagic name >>= \pm ->
340+
needsCoreConfig name >>= \coreConfig ->
335341
needsDiffusion name >>= \diffusion ->
336342
needsAuxxMode name >>= \Dict ->
337343
return CommandProc
@@ -353,7 +359,8 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
353359
-- FIXME: confuses existential/universal. A better solution
354360
-- is to have two ValueHash constructors, one with universal and
355361
-- one with existential (relevant via singleton-style GADT) quantification.
356-
ValueHash . unsafeCheatingHashCoerce <$> Update.propose pm diffusion params
362+
ValueHash . unsafeCheatingHashCoerce
363+
<$> Update.propose (configProtocolMagic coreConfig) diffusion params
357364
, cpHelp = "propose an update with one positive vote for it \
358365
\ using secret key #i"
359366
},
@@ -369,7 +376,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
369376
},
370377

371378
let name = "delegate-heavy" in
372-
needsProtocolMagic name >>= \pm ->
379+
needsCoreConfig name >>= \coreConfig ->
373380
needsDiffusion name >>= \diffusion ->
374381
needsAuxxMode name >>= \Dict ->
375382
return CommandProc
@@ -385,7 +392,10 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
385392
withSafeSigner issuerSk (pure emptyPassphrase) $ \case
386393
Nothing -> logError "Invalid passphrase"
387394
Just ss -> do
388-
let psk = safeCreatePsk pm ss delegatePk (HeavyDlgIndex curEpoch)
395+
let psk = safeCreatePsk (configProtocolMagic coreConfig)
396+
ss
397+
delegatePk
398+
(HeavyDlgIndex curEpoch)
389399
if dry
390400
then do
391401
printAction $
@@ -403,7 +413,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
403413
},
404414

405415
let name = "generate-blocks" in
406-
needsProtocolMagic name >>= \pm ->
416+
needsCoreConfig name >>= \coreConfig ->
407417
needsAuxxMode name >>= \Dict ->
408418
needsTxpConfig name >>= \txpConfig ->
409419
return CommandProc
@@ -414,22 +424,23 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
414424
bgoSeed <- getArgOpt tyInt "seed"
415425
return GenBlocksParams{..}
416426
, cpExec = \params -> do
417-
generateBlocks pm txpConfig params
427+
generateBlocks (configProtocolMagic coreConfig) txpConfig params
418428
return ValueUnit
419429
, cpHelp = "generate <n> blocks"
420430
},
421431

422432
let name = "add-key-pool" in
433+
needsCoreConfig name >>= \coreConfig ->
423434
needsAuxxMode name >>= \Dict ->
424435
return CommandProc
425436
{ cpName = name
426437
, cpArgumentPrepare = identity
427438
, cpArgumentConsumer = getArgMany tyInt "i"
428439
, cpExec = \is -> do
429440
when (null is) $ logWarning "Not adding keys from pool (list is empty)"
430-
let secrets = fromMaybe (error "Secret keys are unknown") genesisSecretKeys
441+
secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow coreConfig
431442
forM_ is $ \i -> do
432-
key <- evaluateNF $ secrets !! i
443+
key <- evaluateNF $ secretKeys !! i
433444
addSecretKey $ noPassEncrypt key
434445
return ValueUnit
435446
, cpHelp = ""
@@ -458,7 +469,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
458469
},
459470

460471
let name = "rollback" in
461-
needsProtocolMagic name >>= \pm ->
472+
needsCoreConfig name >>= \coreConfig ->
462473
needsAuxxMode name >>= \Dict ->
463474
return CommandProc
464475
{ cpName = name
@@ -468,7 +479,9 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
468479
rpDumpPath <- getArg tyFilePath "dump-file"
469480
pure RollbackParams{..}
470481
, cpExec = \RollbackParams{..} -> do
471-
Rollback.rollbackAndDump pm rpNum rpDumpPath
482+
Rollback.rollbackAndDump (configProtocolMagic coreConfig)
483+
rpNum
484+
rpDumpPath
472485
return ValueUnit
473486
, cpHelp = ""
474487
},
@@ -513,18 +526,15 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
513526
, cpHelp = "display this message"
514527
}]
515528
where
516-
needsAuxxMode :: Name -> Either UnavailableCommand (Dict (MonadAuxxMode m))
517-
needsAuxxMode name =
518-
maybe (Left $ UnavailableCommand name "AuxxMode is not available") Right hasAuxxMode
519-
needsDiffusion :: Name -> Either UnavailableCommand (Diffusion m)
520-
needsDiffusion name =
521-
maybe (Left $ UnavailableCommand name "Diffusion layer is not available") Right mDiffusion
522-
needsProtocolMagic :: Name -> Either UnavailableCommand ProtocolMagic
523-
needsProtocolMagic name =
524-
maybe (Left $ UnavailableCommand name "ProtocolMagic is not available") Right mpm
525-
needsTxpConfig :: Name -> Either UnavailableCommand TxpConfiguration
526-
needsTxpConfig name =
527-
maybe (Left $ UnavailableCommand name "TxpConfiguration is not available") Right mTxpConfig
529+
needsData :: Maybe a -> Text -> Name -> Either UnavailableCommand a
530+
needsData mData msg name = maybe
531+
(Left $ UnavailableCommand name (msg <> " is not available"))
532+
Right
533+
mData
534+
needsAuxxMode = needsData hasAuxxMode "AuxxMode"
535+
needsDiffusion = needsData mDiffusion "Diffusion layer"
536+
needsCoreConfig = needsData mCoreConfig "Core.Config"
537+
needsTxpConfig = needsData mTxpConfig "TxpConfiguration"
528538

529539
procConst :: Applicative m => Name -> Value -> CommandProc m
530540
procConst name value =

auxx/src/Command/Tx.hs

+6-7
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ import Pos.Core (IsBootstrapEraAddr (..), Timestamp (..),
4343
deriveFirstHDAddress, makePubKeyAddress, mkCoin)
4444
import Pos.Core.Conc (concurrently, currentTime, delay,
4545
forConcurrently, modifySharedAtomic, newSharedAtomic)
46-
import Pos.Core.Configuration (genesisBlockVersionData,
47-
genesisSecretKeys)
46+
import Pos.Core.Configuration (genesisBlockVersionData)
4847
import Pos.Core.Txp (TxAux (..), TxIn (TxInUtxo), TxOut (..),
4948
TxOutAux (..), txaF)
5049
import Pos.Core.Update (BlockVersionData (..))
51-
import Pos.Crypto (EncryptedSecretKey, ProtocolMagic, emptyPassphrase,
52-
encToPublic, fakeSigner, hash, safeToPublic, toPublic,
53-
withSafeSigners)
50+
import Pos.Crypto (EncryptedSecretKey, ProtocolMagic, SecretKey,
51+
emptyPassphrase, encToPublic, fakeSigner, hash,
52+
safeToPublic, toPublic, withSafeSigners)
5453
import Pos.Infra.Diffusion.Types (Diffusion (..))
5554
import Pos.Util.UserSecret (usWallet, userSecret, wusRootKey)
5655
import Pos.Util.Util (maybeThrow)
@@ -87,12 +86,12 @@ addTxSubmit =
8786
sendToAllGenesis
8887
:: forall m. MonadAuxxMode m
8988
=> ProtocolMagic
89+
-> [SecretKey]
9090
-> Diffusion m
9191
-> SendToAllGenesisParams
9292
-> m ()
93-
sendToAllGenesis pm diffusion (SendToAllGenesisParams genesisTxsPerThread txsPerThread conc delay_ tpsSentFile) = do
93+
sendToAllGenesis pm keysToSend diffusion (SendToAllGenesisParams genesisTxsPerThread txsPerThread conc delay_ tpsSentFile) = do
9494
let genesisSlotDuration = fromIntegral (toMicroseconds $ bvdSlotDuration genesisBlockVersionData) `div` 1000000 :: Int
95-
keysToSend = fromMaybe (error "Genesis secret keys are unknown") genesisSecretKeys
9695
tpsMVar <- newSharedAtomic $ TxCount 0 conc
9796
startTime <- show . toInteger . getTimestamp . Timestamp <$> currentTime
9897
bracket (openFile tpsSentFile WriteMode) (liftIO . hClose) $ \h -> do

auxx/src/Plugin.hs

+19-15
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import System.IO (hFlush, stdout)
2323
import System.Wlog (CanLog, HasLoggerName, logInfo)
2424

2525
import Pos.Chain.Txp (TxpConfiguration, genesisUtxo, unGenesisUtxo)
26+
import Pos.Core as Core (Config)
2627
import Pos.Core.Conc (delay)
27-
import Pos.Crypto (AHash (..), ProtocolMagic, fullPublicKeyF,
28-
hashHexF)
28+
import Pos.Crypto (AHash (..), fullPublicKeyF, hashHexF)
2929
import Pos.Infra.Diffusion.Types (Diffusion)
3030

3131
import AuxxOptions (AuxxOptions (..))
@@ -42,49 +42,49 @@ import Repl (PrintAction, WithCommandAction (..))
4242

4343
auxxPlugin ::
4444
MonadAuxxMode m
45-
=> ProtocolMagic
45+
=> Core.Config
4646
-> TxpConfiguration
4747
-> AuxxOptions
4848
-> Either WithCommandAction Text
4949
-> Diffusion m
5050
-> m ()
51-
auxxPlugin pm txpConfig auxxOptions repl = \diffusion -> do
51+
auxxPlugin coreConfig txpConfig auxxOptions repl = \diffusion -> do
5252
logInfo $ sformat ("Length of genesis utxo: " %int)
5353
(length $ unGenesisUtxo genesisUtxo)
54-
rawExec (Just pm) (Just txpConfig) (Just Dict) auxxOptions (Just diffusion) repl
54+
rawExec (Just coreConfig) (Just txpConfig) (Just Dict) auxxOptions (Just diffusion) repl
5555

5656
rawExec ::
5757
( MonadIO m
5858
, MonadCatch m
5959
, CanLog m
6060
, HasLoggerName m
6161
)
62-
=> Maybe ProtocolMagic
62+
=> Maybe Core.Config
6363
-> Maybe TxpConfiguration
6464
-> Maybe (Dict (MonadAuxxMode m))
6565
-> AuxxOptions
6666
-> Maybe (Diffusion m)
6767
-> Either WithCommandAction Text
6868
-> m ()
69-
rawExec pm txpConfig mHasAuxxMode AuxxOptions{..} mDiffusion = \case
69+
rawExec mCoreConfig txpConfig mHasAuxxMode AuxxOptions{..} mDiffusion = \case
7070
Left WithCommandAction{..} -> do
7171
printAction "... the auxx plugin is ready"
72-
forever $ withCommand $ runCmd pm txpConfig mHasAuxxMode mDiffusion printAction
73-
Right cmd -> runWalletCmd pm txpConfig mHasAuxxMode mDiffusion cmd
72+
forever $ withCommand $ runCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion printAction
73+
Right cmd -> runWalletCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion cmd
7474

7575
runWalletCmd ::
7676
( MonadIO m
7777
, CanLog m
7878
, HasLoggerName m
7979
)
80-
=> Maybe ProtocolMagic
80+
=> Maybe Core.Config
8181
-> Maybe TxpConfiguration
8282
-> Maybe (Dict (MonadAuxxMode m))
8383
-> Maybe (Diffusion m)
8484
-> Text
8585
-> m ()
86-
runWalletCmd pm txpConfig mHasAuxxMode mDiffusion line = do
87-
runCmd pm txpConfig mHasAuxxMode mDiffusion printAction line
86+
runWalletCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion line = do
87+
runCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion printAction line
8888
printAction "Command execution finished"
8989
printAction " " -- for exit by SIGPIPE
9090
liftIO $ hFlush stdout
@@ -100,15 +100,19 @@ runCmd ::
100100
, CanLog m
101101
, HasLoggerName m
102102
)
103-
=> Maybe ProtocolMagic
103+
=> Maybe Core.Config
104104
-> Maybe TxpConfiguration
105105
-> Maybe (Dict (MonadAuxxMode m))
106106
-> Maybe (Diffusion m)
107107
-> PrintAction m
108108
-> Text
109109
-> m ()
110-
runCmd pm txpConfig mHasAuxxMode mDiffusion printAction line = do
111-
let commandProcs = createCommandProcs pm txpConfig mHasAuxxMode printAction mDiffusion
110+
runCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion printAction line = do
111+
let commandProcs = createCommandProcs mCoreConfig
112+
txpConfig
113+
mHasAuxxMode
114+
printAction
115+
mDiffusion
112116
parse = withExceptT Lang.ppParseError . ExceptT . return . Lang.parse
113117
resolveCommandProcs =
114118
withExceptT Lang.ppResolveErrors . ExceptT . return .

0 commit comments

Comments
 (0)