From 366564656c63bab7f9572d5711cf165bd387cc49 Mon Sep 17 00:00:00 2001 From: Rupert Horlick Date: Sat, 25 Aug 2018 17:41:01 -0400 Subject: [PATCH] [CBR-400] Fix wallet failing to start --- auxx/Main.hs | 12 ++++++------ explorer/src/explorer/Main.hs | 9 ++++++--- lib/src/Pos/Client/CLI/Params.hs | 6 +++--- lib/src/Pos/Client/CLI/Secrets.hs | 14 ++++++++++---- node/Main.hs | 8 +++++--- tools/src/dbgen/Main.hs | 9 +++++---- wallet-new/server/Main.hs | 16 ++++++++-------- 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/auxx/Main.hs b/auxx/Main.hs index fa1888d434c..40b0c6fbecf 100644 --- a/auxx/Main.hs +++ b/auxx/Main.hs @@ -17,8 +17,7 @@ import Ntp.Client (NtpConfiguration) import Pos.Chain.Txp (TxpConfiguration) import qualified Pos.Client.CLI as CLI import Pos.Context (NodeContext (..)) -import Pos.Core as Core (Config (..), ConfigurationError, - configGeneratedSecretsThrow, epochSlots) +import Pos.Core as Core (Config (..), ConfigurationError, epochSlots) import Pos.Crypto (ProtocolMagic) import Pos.DB.DB (initNodeDBs) import Pos.DB.Txp (txpGlobalSettings) @@ -107,10 +106,11 @@ action opts@AuxxOptions {..} command = do runWithConfig printAction coreConfig txpConfig ntpConfig = do printAction "Mode: with-config" CLI.printInfoOnStart aoCommonNodeArgs ntpConfig txpConfig - generatedSecrets <- configGeneratedSecretsThrow coreConfig - (nodeParams, tempDbUsed) <- - correctNodeParams opts =<< - CLI.getNodeParams loggerName cArgs nArgs generatedSecrets + (nodeParams, tempDbUsed) <- correctNodeParams opts =<< CLI.getNodeParams + loggerName + cArgs + nArgs + (configGeneratedSecrets coreConfig) let toRealMode :: AuxxMode a -> RealMode EmptyMempoolExt a toRealMode auxxAction = do diff --git a/explorer/src/explorer/Main.hs b/explorer/src/explorer/Main.hs index 7ad24b7d18f..4f57b82501a 100644 --- a/explorer/src/explorer/Main.hs +++ b/explorer/src/explorer/Main.hs @@ -22,7 +22,7 @@ import Pos.Client.CLI (CommonNodeArgs (..), NodeArgs (..), getNodeParams) import qualified Pos.Client.CLI as CLI import Pos.Context (NodeContext (..)) -import Pos.Core (Config (..), configGeneratedSecretsThrow, epochSlots) +import Pos.Core (Config (..), epochSlots) import Pos.Crypto (ProtocolMagic) import Pos.Explorer.DB (explorerInitDB) import Pos.Explorer.ExtraContext (makeExtraCtx) @@ -63,8 +63,11 @@ action (ExplorerNodeArgs (cArgs@CommonNodeArgs{..}) ExplorerArgs{..}) = withCompileInfo $ do CLI.printInfoOnStart cArgs ntpConfig txpConfig logInfo $ "Explorer is enabled!" - generatedSecrets <- configGeneratedSecretsThrow coreConfig - currentParams <- getNodeParams loggerName cArgs nodeArgs generatedSecrets + currentParams <- getNodeParams + loggerName + cArgs + nodeArgs + (configGeneratedSecrets coreConfig) let vssSK = fromJust $ npUserSecret currentParams ^. usVss let sscParams = CLI.gtSscParams cArgs vssSK (npBehaviorConfig currentParams) diff --git a/lib/src/Pos/Client/CLI/Params.hs b/lib/src/Pos/Client/CLI/Params.hs index cbf606f323d..fca6aba6995 100644 --- a/lib/src/Pos/Client/CLI/Params.hs +++ b/lib/src/Pos/Client/CLI/Params.hs @@ -66,10 +66,10 @@ getNodeParams :: => LoggerName -> CommonNodeArgs -> NodeArgs - -> GeneratedSecrets + -> Maybe GeneratedSecrets -> m NodeParams -getNodeParams defaultLoggerName cArgs@CommonNodeArgs{..} NodeArgs{..} generatedSecrets = do - (primarySK, userSecret) <- prepareUserSecret cArgs generatedSecrets +getNodeParams defaultLoggerName cArgs@CommonNodeArgs{..} NodeArgs{..} mGeneratedSecrets = do + (primarySK, userSecret) <- prepareUserSecret cArgs mGeneratedSecrets =<< peekUserSecret (getKeyfilePath cArgs) userPublic <- peekUserPublic publicKeyfilePath npNetworkConfig <- intNetworkConfigOpts networkConfigOpts diff --git a/lib/src/Pos/Client/CLI/Secrets.hs b/lib/src/Pos/Client/CLI/Secrets.hs index c4b3a10fa56..dc50d1b2f92 100644 --- a/lib/src/Pos/Client/CLI/Secrets.hs +++ b/lib/src/Pos/Client/CLI/Secrets.hs @@ -28,17 +28,23 @@ import Pos.Client.CLI.NodeOptions (CommonNodeArgs (..)) prepareUserSecret :: (MonadIO m, WithLogger m) => CommonNodeArgs - -> GeneratedSecrets + -> Maybe GeneratedSecrets -> UserSecret -> m (SecretKey, UserSecret) -prepareUserSecret CommonNodeArgs {devGenesisSecretI} generatedSecrets userSecret = do +prepareUserSecret CommonNodeArgs {devGenesisSecretI} mGeneratedSecrets userSecret = do (_, userSecretWithVss) <- fillUserSecretVSS (rsVssKeyPair <$> predefinedRichKeys) userSecret fillPrimaryKey (rsPrimaryKey <$> predefinedRichKeys) userSecretWithVss where predefinedRichKeys :: Maybe RichSecrets - predefinedRichKeys = - devGenesisSecretI >>= \i -> gsRichSecrets generatedSecrets ^? ix i + predefinedRichKeys = do + i <- devGenesisSecretI + case mGeneratedSecrets of + Nothing -> error + $ "devGenesisSecretI is specified, but GeneratedSecrets are " + <> "missing from Core.Config. GenesisInitializer might be " + <> "incorrectly specified." + Just generatedSecrets -> gsRichSecrets generatedSecrets ^? ix i -- Make sure UserSecret contains a primary key. fillPrimaryKey :: diff --git a/node/Main.hs b/node/Main.hs index fbe2542dd52..39d1855d1ac 100644 --- a/node/Main.hs +++ b/node/Main.hs @@ -21,7 +21,7 @@ import Pos.Chain.Txp (TxpConfiguration) import Pos.Client.CLI (CommonNodeArgs (..), NodeArgs (..), SimpleNodeArgs (..)) import qualified Pos.Client.CLI as CLI -import Pos.Core as Core (Config (..), configGeneratedSecretsThrow) +import Pos.Core as Core (Config (..)) import Pos.Crypto (ProtocolMagic) import Pos.Launcher (HasConfigurations, NodeParams (..), loggerBracket, runNodeReal, withConfigurations) @@ -59,8 +59,10 @@ action action (SimpleNodeArgs (cArgs@CommonNodeArgs {..}) (nArgs@NodeArgs {..})) coreConfig txpConfig ntpConfig = do CLI.printInfoOnStart cArgs ntpConfig txpConfig logInfo "Wallet is disabled, because software is built w/o it" - generatedSecrets <- configGeneratedSecretsThrow coreConfig - currentParams <- CLI.getNodeParams loggerName cArgs nArgs generatedSecrets + currentParams <- CLI.getNodeParams loggerName + cArgs + nArgs + (configGeneratedSecrets coreConfig) let vssSK = fromJust $ npUserSecret currentParams ^. usVss let sscParams = CLI.gtSscParams cArgs vssSK (npBehaviorConfig currentParams) diff --git a/tools/src/dbgen/Main.hs b/tools/src/dbgen/Main.hs index 1e26338bd1b..faf08343492 100644 --- a/tools/src/dbgen/Main.hs +++ b/tools/src/dbgen/Main.hs @@ -22,8 +22,7 @@ import Options.Generic (getRecord) import Pos.Chain.Txp (TxpConfiguration) import Pos.Client.CLI (CommonArgs (..), CommonNodeArgs (..), NodeArgs (..), getNodeParams, gtSscParams) -import Pos.Core as Core (Config (..), Timestamp (..), - configGeneratedSecretsThrow, epochSlots) +import Pos.Core as Core (Config (..), Timestamp (..), epochSlots) import Pos.DB.DB (initNodeDBs) import Pos.DB.Rocks.Functions (openNodeDBs) import Pos.DB.Rocks.Types (NodeDBs) @@ -110,8 +109,10 @@ newRealModeContext coreConfig txpConfig dbs confOpts publicKeyPath secretKeyPath , cnaDumpConfiguration = False } loggerName <- askLoggerName - generatedSecrets <- configGeneratedSecretsThrow coreConfig - nodeParams <- getNodeParams loggerName cArgs nodeArgs generatedSecrets + nodeParams <- getNodeParams loggerName + cArgs + nodeArgs + (configGeneratedSecrets coreConfig) let vssSK = fromJust $ npUserSecret nodeParams ^. usVss let gtParams = gtSscParams cArgs vssSK (npBehaviorConfig nodeParams) bracketNodeResources @() nodeParams gtParams (txpGlobalSettings pm txpConfig) (initNodeDBs pm epochSlots) $ \NodeResources{..} -> diff --git a/wallet-new/server/Main.hs b/wallet-new/server/Main.hs index 236921800e7..2a311aa7fcf 100644 --- a/wallet-new/server/Main.hs +++ b/wallet-new/server/Main.hs @@ -16,7 +16,7 @@ import Pos.Chain.Ssc (SscParams) import Pos.Chain.Txp (TxpConfiguration) import qualified Pos.Client.CLI as CLI import Pos.Context (ncUserSecret) -import Pos.Core (Config (..), configGeneratedSecretsThrow, epochSlots) +import Pos.Core (Config (..), epochSlots) import Pos.Core.Genesis (GeneratedSecrets) import Pos.Crypto (ProtocolMagic) import Pos.DB.DB (initNodeDBs) @@ -174,10 +174,10 @@ actionWithNewWallet pm txpConfig sscParams nodeParams ntpConfig params = startEdgeNode :: HasCompileInfo => WalletStartupOptions -> IO () startEdgeNode wso = withConfigurations blPath conf $ \coreConfig txpConfig ntpConfig -> do - generatedSecrets <- configGeneratedSecretsThrow coreConfig - (sscParams, nodeParams) <- getParameters generatedSecrets - txpConfig - ntpConfig + (sscParams, nodeParams) <- getParameters + (configGeneratedSecrets coreConfig) + txpConfig + ntpConfig case wsoWalletBackendParams wso of WalletLegacy legacyParams -> actionWithWallet (configProtocolMagic coreConfig) @@ -195,13 +195,13 @@ startEdgeNode wso = newParams where getParameters :: HasConfigurations - => GeneratedSecrets + => Maybe GeneratedSecrets -> TxpConfiguration -> NtpConfiguration -> IO (SscParams, NodeParams) - getParameters generatedSecrets txpConfig ntpConfig = do + getParameters mGeneratedSecrets txpConfig ntpConfig = do - currentParams <- CLI.getNodeParams defaultLoggerName (wsoNodeArgs wso) nodeArgs generatedSecrets + currentParams <- CLI.getNodeParams defaultLoggerName (wsoNodeArgs wso) nodeArgs mGeneratedSecrets let vssSK = fromJust $ npUserSecret currentParams ^. usVss let gtParams = CLI.gtSscParams (wsoNodeArgs wso) vssSK (npBehaviorConfig currentParams)