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

Commit 8d858b2

Browse files
committed
[CDEC-509] Remove HasGeneratedSecrets
1 parent 1453a90 commit 8d858b2

File tree

43 files changed

+601
-410
lines changed

Some content is hidden

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

43 files changed

+601
-410
lines changed

auxx/Main.hs

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ 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, epochSlots)
2222
import Pos.Crypto (ProtocolMagic)
2323
import Pos.DB.DB (initNodeDBs)
2424
import Pos.DB.Txp (txpGlobalSettings)
@@ -102,12 +102,16 @@ action opts@AuxxOptions {..} command = do
102102
runWithoutNode :: PrintAction IO -> IO ()
103103
runWithoutNode printAction = printAction "Mode: light" >> rawExec Nothing Nothing Nothing opts Nothing command
104104

105-
runWithConfig :: HasConfigurations => PrintAction IO -> ProtocolMagic -> TxpConfiguration -> NtpConfiguration -> IO ()
106-
runWithConfig printAction pm txpConfig ntpConfig = do
105+
runWithConfig :: HasConfigurations => PrintAction IO -> Core.Config -> TxpConfiguration -> NtpConfiguration -> IO ()
106+
runWithConfig printAction coreConfig txpConfig ntpConfig = do
107107
printAction "Mode: with-config"
108108
CLI.printInfoOnStart aoCommonNodeArgs ntpConfig txpConfig
109+
let generatedSecrets = fromMaybe
110+
(error "Main.action: GeneratedSecrets missing from config")
111+
(configGeneratedSecrets coreConfig)
109112
(nodeParams, tempDbUsed) <-
110-
correctNodeParams opts =<< CLI.getNodeParams loggerName cArgs nArgs
113+
correctNodeParams opts =<<
114+
CLI.getNodeParams loggerName cArgs nArgs generatedSecrets
111115

112116
let toRealMode :: AuxxMode a -> RealMode EmptyMempoolExt a
113117
toRealMode auxxAction = do
@@ -121,12 +125,13 @@ action opts@AuxxOptions {..} command = do
121125
(npUserSecret nodeParams ^. usVss)
122126
sscParams = CLI.gtSscParams cArgs vssSK (npBehaviorConfig nodeParams)
123127

128+
let pm = configProtocolMagic coreConfig
124129
bracketNodeResources nodeParams sscParams (txpGlobalSettings pm txpConfig) (initNodeDBs pm epochSlots) $ \nr ->
125130
let NodeContext {..} = nrContext nr
126131
modifier = if aoStartMode == WithNode
127132
then runNodeWithSinglePlugin pm txpConfig nr
128133
else identity
129-
auxxModeAction = modifier (auxxPlugin pm txpConfig opts command)
134+
auxxModeAction = modifier (auxxPlugin coreConfig txpConfig opts command)
130135
in runRealMode pm txpConfig nr $ \diffusion ->
131136
toRealMode (auxxModeAction (hoistDiffusion realModeToAuxx toRealMode diffusion))
132137

auxx/src/Command/Proc.hs

+49-36
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ 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, mkMultiKeyDistr,
26+
unsafeGetCoin)
2627
import Pos.Core.Common (AddrAttributes (..), AddrSpendingData (..),
2728
makeAddress)
28-
import Pos.Core.Configuration (genesisSecretKeys)
2929
import Pos.Core.Delegation (HeavyDlgIndex (..))
30+
import Pos.Core.Genesis (gsSecretKeys)
3031
import Pos.Core.Txp (TxOut (..))
3132
import Pos.Core.Update (SoftwareVersion (..))
32-
import Pos.Crypto (ProtocolMagic, PublicKey, emptyPassphrase,
33-
encToPublic, fullPublicKeyF, hashHexF, noPassEncrypt,
34-
safeCreatePsk, unsafeCheatingHashCoerce, withSafeSigner)
33+
import Pos.Crypto (PublicKey, SecretKey, emptyPassphrase, encToPublic,
34+
fullPublicKeyF, hashHexF, noPassEncrypt, safeCreatePsk,
35+
unsafeCheatingHashCoerce, withSafeSigner)
3536
import Pos.DB.Class (MonadGState (..))
3637
import Pos.Infra.Diffusion.Types (Diffusion (..))
3738
import Pos.Util.UserSecret (WalletUserSecret (..), readUserSecret,
@@ -64,13 +65,13 @@ import Repl (PrintAction)
6465

6566
createCommandProcs ::
6667
forall m. (MonadIO m, CanLog m, HasLoggerName m)
67-
=> Maybe ProtocolMagic
68+
=> Maybe Core.Config
6869
-> Maybe TxpConfiguration
6970
-> Maybe (Dict (MonadAuxxMode m))
7071
-> PrintAction m
7172
-> Maybe (Diffusion m)
7273
-> [CommandProc m]
73-
createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights . fix $ \commands -> [
74+
createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = rights . fix $ \commands -> [
7475

7576
return CommandProc
7677
{ cpName = "L"
@@ -212,7 +213,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
212213
},
213214

214215
let name = "send-to-all-genesis" in
215-
needsProtocolMagic name >>= \pm ->
216+
needsCoreConfig name >>= \coreConfig ->
216217
needsDiffusion name >>= \diffusion ->
217218
needsAuxxMode name >>= \Dict ->
218219
return CommandProc
@@ -226,7 +227,11 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
226227
stagpTpsSentFile <- getArg tyFilePath "file"
227228
return Tx.SendToAllGenesisParams{..}
228229
, cpExec = \stagp -> do
229-
Tx.sendToAllGenesis pm diffusion stagp
230+
let secretKeys = getSecretKeys coreConfig
231+
Tx.sendToAllGenesis (configProtocolMagic coreConfig)
232+
secretKeys
233+
diffusion
234+
stagp
230235
return ValueUnit
231236
, cpHelp = "create and send transactions from all genesis addresses \
232237
\ for <duration> seconds, <delay> in ms. <conc> is the \
@@ -247,7 +252,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
247252
},
248253

249254
let name = "send" in
250-
needsProtocolMagic name >>= \pm ->
255+
needsCoreConfig name >>= \coreConfig ->
251256
needsDiffusion name >>= \diffusion ->
252257
needsAuxxMode name >>= \Dict ->
253258
return CommandProc
@@ -257,14 +262,14 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
257262
(,) <$> getArg tyInt "i"
258263
<*> getArgSome tyTxOut "out"
259264
, cpExec = \(i, outputs) -> do
260-
Tx.send pm diffusion i outputs
265+
Tx.send (configProtocolMagic coreConfig) diffusion i outputs
261266
return ValueUnit
262267
, cpHelp = "send from #i to specified transaction outputs \
263268
\ (use 'tx-out' to build them)"
264269
},
265270

266271
let name = "vote" in
267-
needsProtocolMagic name >>= \pm ->
272+
needsCoreConfig name >>= \coreConfig ->
268273
needsDiffusion name >>= \diffusion ->
269274
needsAuxxMode name >>= \Dict ->
270275
return CommandProc
@@ -275,7 +280,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
275280
<*> getArg tyBool "agree"
276281
<*> getArg tyHash "up-id"
277282
, cpExec = \(i, decision, upId) -> do
278-
Update.vote pm diffusion i decision upId
283+
Update.vote (configProtocolMagic coreConfig) diffusion i decision upId
279284
return ValueUnit
280285
, cpHelp = "send vote for update proposal <up-id> and \
281286
\ decision <agree> ('true' or 'false'), \
@@ -331,7 +336,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
331336
},
332337

333338
let name = "propose-update" in
334-
needsProtocolMagic name >>= \pm ->
339+
needsCoreConfig name >>= \coreConfig ->
335340
needsDiffusion name >>= \diffusion ->
336341
needsAuxxMode name >>= \Dict ->
337342
return CommandProc
@@ -353,7 +358,8 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
353358
-- FIXME: confuses existential/universal. A better solution
354359
-- is to have two ValueHash constructors, one with universal and
355360
-- one with existential (relevant via singleton-style GADT) quantification.
356-
ValueHash . unsafeCheatingHashCoerce <$> Update.propose pm diffusion params
361+
ValueHash . unsafeCheatingHashCoerce
362+
<$> Update.propose (configProtocolMagic coreConfig) diffusion params
357363
, cpHelp = "propose an update with one positive vote for it \
358364
\ using secret key #i"
359365
},
@@ -369,7 +375,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
369375
},
370376

371377
let name = "delegate-heavy" in
372-
needsProtocolMagic name >>= \pm ->
378+
needsCoreConfig name >>= \coreConfig ->
373379
needsDiffusion name >>= \diffusion ->
374380
needsAuxxMode name >>= \Dict ->
375381
return CommandProc
@@ -385,7 +391,10 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
385391
withSafeSigner issuerSk (pure emptyPassphrase) $ \case
386392
Nothing -> logError "Invalid passphrase"
387393
Just ss -> do
388-
let psk = safeCreatePsk pm ss delegatePk (HeavyDlgIndex curEpoch)
394+
let psk = safeCreatePsk (configProtocolMagic coreConfig)
395+
ss
396+
delegatePk
397+
(HeavyDlgIndex curEpoch)
389398
if dry
390399
then do
391400
printAction $
@@ -403,7 +412,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
403412
},
404413

405414
let name = "generate-blocks" in
406-
needsProtocolMagic name >>= \pm ->
415+
needsCoreConfig name >>= \coreConfig ->
407416
needsAuxxMode name >>= \Dict ->
408417
needsTxpConfig name >>= \txpConfig ->
409418
return CommandProc
@@ -414,22 +423,23 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
414423
bgoSeed <- getArgOpt tyInt "seed"
415424
return GenBlocksParams{..}
416425
, cpExec = \params -> do
417-
generateBlocks pm txpConfig params
426+
generateBlocks (configProtocolMagic coreConfig) txpConfig params
418427
return ValueUnit
419428
, cpHelp = "generate <n> blocks"
420429
},
421430

422431
let name = "add-key-pool" in
432+
needsCoreConfig name >>= \config ->
423433
needsAuxxMode name >>= \Dict ->
424434
return CommandProc
425435
{ cpName = name
426436
, cpArgumentPrepare = identity
427437
, cpArgumentConsumer = getArgMany tyInt "i"
428438
, cpExec = \is -> do
429439
when (null is) $ logWarning "Not adding keys from pool (list is empty)"
430-
let secrets = fromMaybe (error "Secret keys are unknown") genesisSecretKeys
440+
let secretKeys = getSecretKeys config
431441
forM_ is $ \i -> do
432-
key <- evaluateNF $ secrets !! i
442+
key <- evaluateNF $ secretKeys !! i
433443
addSecretKey $ noPassEncrypt key
434444
return ValueUnit
435445
, cpHelp = ""
@@ -458,7 +468,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
458468
},
459469

460470
let name = "rollback" in
461-
needsProtocolMagic name >>= \pm ->
471+
needsCoreConfig name >>= \coreConfig ->
462472
needsAuxxMode name >>= \Dict ->
463473
return CommandProc
464474
{ cpName = name
@@ -468,7 +478,9 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
468478
rpDumpPath <- getArg tyFilePath "dump-file"
469479
pure RollbackParams{..}
470480
, cpExec = \RollbackParams{..} -> do
471-
Rollback.rollbackAndDump pm rpNum rpDumpPath
481+
Rollback.rollbackAndDump (configProtocolMagic coreConfig)
482+
rpNum
483+
rpDumpPath
472484
return ValueUnit
473485
, cpHelp = ""
474486
},
@@ -513,18 +525,19 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
513525
, cpHelp = "display this message"
514526
}]
515527
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
528+
needsData :: Maybe a -> Text -> Name -> Either UnavailableCommand a
529+
needsData mData msg name = maybe
530+
(Left $ UnavailableCommand name (msg <> " is not available"))
531+
Right
532+
mData
533+
needsAuxxMode = needsData hasAuxxMode "AuxxMode"
534+
needsDiffusion = needsData mDiffusion "Diffusion layer"
535+
needsCoreConfig = needsData mCoreConfig "Core.Config"
536+
needsTxpConfig = needsData mTxpConfig "TxpConfiguration"
537+
getSecretKeys :: Core.Config -> [SecretKey]
538+
getSecretKeys coreConfig = gsSecretKeys $ fromMaybe
539+
(error "Proc.createCommandProcs: GeneratedSecrets missing from config")
540+
(configGeneratedSecrets coreConfig)
528541

529542
procConst :: Applicative m => Name -> Value -> CommandProc m
530543
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)