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

[CDEC-509] Remove HasGeneratedSecrets #3437

Merged
merged 1 commit into from
Aug 24, 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
14 changes: 9 additions & 5 deletions auxx/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import Ntp.Client (NtpConfiguration)
import Pos.Chain.Txp (TxpConfiguration)
import qualified Pos.Client.CLI as CLI
import Pos.Context (NodeContext (..))
import Pos.Core (ConfigurationError, epochSlots)
import Pos.Core as Core (Config (..), ConfigurationError,
configGeneratedSecretsThrow, epochSlots)
import Pos.Crypto (ProtocolMagic)
import Pos.DB.DB (initNodeDBs)
import Pos.DB.Txp (txpGlobalSettings)
Expand Down Expand Up @@ -102,12 +103,14 @@ action opts@AuxxOptions {..} command = do
runWithoutNode :: PrintAction IO -> IO ()
runWithoutNode printAction = printAction "Mode: light" >> rawExec Nothing Nothing Nothing opts Nothing command

runWithConfig :: HasConfigurations => PrintAction IO -> ProtocolMagic -> TxpConfiguration -> NtpConfiguration -> IO ()
runWithConfig printAction pm txpConfig ntpConfig = do
runWithConfig :: HasConfigurations => PrintAction IO -> Core.Config -> TxpConfiguration -> NtpConfiguration -> IO ()
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
correctNodeParams opts =<<
CLI.getNodeParams loggerName cArgs nArgs generatedSecrets

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

let pm = configProtocolMagic coreConfig
bracketNodeResources nodeParams sscParams (txpGlobalSettings pm txpConfig) (initNodeDBs pm epochSlots) $ \nr ->
let NodeContext {..} = nrContext nr
modifier = if aoStartMode == WithNode
then runNodeWithSinglePlugin pm txpConfig nr
else identity
auxxModeAction = modifier (auxxPlugin pm txpConfig opts command)
auxxModeAction = modifier (auxxPlugin coreConfig txpConfig opts command)
in runRealMode pm txpConfig nr $ \diffusion ->
toRealMode (auxxModeAction (hoistDiffusion realModeToAuxx toRealMode diffusion))

Expand Down
82 changes: 46 additions & 36 deletions auxx/src/Command/Proc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ import Pos.Chain.Txp (TxpConfiguration)
import Pos.Chain.Update (BlockVersionModifier (..))
import Pos.Client.KeyStorage (addSecretKey, getSecretKeysPlain)
import Pos.Client.Txp.Balances (getBalance)
import Pos.Core (AddrStakeDistribution (..), Address, StakeholderId,
addressHash, mkMultiKeyDistr, unsafeGetCoin)
import Pos.Core as Core (AddrStakeDistribution (..), Address,
Config (..), StakeholderId, addressHash,
configGeneratedSecretsThrow, mkMultiKeyDistr,
unsafeGetCoin)
import Pos.Core.Common (AddrAttributes (..), AddrSpendingData (..),
makeAddress)
import Pos.Core.Configuration (genesisSecretKeys)
import Pos.Core.Delegation (HeavyDlgIndex (..))
import Pos.Core.Genesis (gsSecretKeys)
import Pos.Core.Txp (TxOut (..))
import Pos.Core.Update (SoftwareVersion (..))
import Pos.Crypto (ProtocolMagic, PublicKey, emptyPassphrase,
encToPublic, fullPublicKeyF, hashHexF, noPassEncrypt,
safeCreatePsk, unsafeCheatingHashCoerce, withSafeSigner)
import Pos.Crypto (PublicKey, emptyPassphrase, encToPublic,
fullPublicKeyF, hashHexF, noPassEncrypt, safeCreatePsk,
unsafeCheatingHashCoerce, withSafeSigner)
import Pos.DB.Class (MonadGState (..))
import Pos.Infra.Diffusion.Types (Diffusion (..))
import Pos.Util.UserSecret (WalletUserSecret (..), readUserSecret,
Expand Down Expand Up @@ -64,13 +66,13 @@ import Repl (PrintAction)

createCommandProcs ::
forall m. (MonadIO m, CanLog m, HasLoggerName m)
=> Maybe ProtocolMagic
=> Maybe Core.Config
-> Maybe TxpConfiguration
-> Maybe (Dict (MonadAuxxMode m))
-> PrintAction m
-> Maybe (Diffusion m)
-> [CommandProc m]
createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights . fix $ \commands -> [
createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = rights . fix $ \commands -> [

return CommandProc
{ cpName = "L"
Expand Down Expand Up @@ -212,7 +214,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
},

let name = "send-to-all-genesis" in
needsProtocolMagic name >>= \pm ->
needsCoreConfig name >>= \coreConfig ->
needsDiffusion name >>= \diffusion ->
needsAuxxMode name >>= \Dict ->
return CommandProc
Expand All @@ -226,7 +228,11 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
stagpTpsSentFile <- getArg tyFilePath "file"
return Tx.SendToAllGenesisParams{..}
, cpExec = \stagp -> do
Tx.sendToAllGenesis pm diffusion stagp
secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow coreConfig
Tx.sendToAllGenesis (configProtocolMagic coreConfig)
secretKeys
diffusion
stagp
return ValueUnit
, cpHelp = "create and send transactions from all genesis addresses \
\ for <duration> seconds, <delay> in ms. <conc> is the \
Expand All @@ -247,7 +253,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
},

let name = "send" in
needsProtocolMagic name >>= \pm ->
needsCoreConfig name >>= \coreConfig ->
needsDiffusion name >>= \diffusion ->
needsAuxxMode name >>= \Dict ->
return CommandProc
Expand All @@ -257,14 +263,14 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
(,) <$> getArg tyInt "i"
<*> getArgSome tyTxOut "out"
, cpExec = \(i, outputs) -> do
Tx.send pm diffusion i outputs
Tx.send (configProtocolMagic coreConfig) diffusion i outputs
return ValueUnit
, cpHelp = "send from #i to specified transaction outputs \
\ (use 'tx-out' to build them)"
},

let name = "vote" in
needsProtocolMagic name >>= \pm ->
needsCoreConfig name >>= \coreConfig ->
needsDiffusion name >>= \diffusion ->
needsAuxxMode name >>= \Dict ->
return CommandProc
Expand All @@ -275,7 +281,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
<*> getArg tyBool "agree"
<*> getArg tyHash "up-id"
, cpExec = \(i, decision, upId) -> do
Update.vote pm diffusion i decision upId
Update.vote (configProtocolMagic coreConfig) diffusion i decision upId
return ValueUnit
, cpHelp = "send vote for update proposal <up-id> and \
\ decision <agree> ('true' or 'false'), \
Expand Down Expand Up @@ -331,7 +337,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
},

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

let name = "delegate-heavy" in
needsProtocolMagic name >>= \pm ->
needsCoreConfig name >>= \coreConfig ->
needsDiffusion name >>= \diffusion ->
needsAuxxMode name >>= \Dict ->
return CommandProc
Expand All @@ -385,7 +392,10 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
withSafeSigner issuerSk (pure emptyPassphrase) $ \case
Nothing -> logError "Invalid passphrase"
Just ss -> do
let psk = safeCreatePsk pm ss delegatePk (HeavyDlgIndex curEpoch)
let psk = safeCreatePsk (configProtocolMagic coreConfig)
ss
delegatePk
(HeavyDlgIndex curEpoch)
if dry
then do
printAction $
Expand All @@ -403,7 +413,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
},

let name = "generate-blocks" in
needsProtocolMagic name >>= \pm ->
needsCoreConfig name >>= \coreConfig ->
needsAuxxMode name >>= \Dict ->
needsTxpConfig name >>= \txpConfig ->
return CommandProc
Expand All @@ -414,22 +424,23 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
bgoSeed <- getArgOpt tyInt "seed"
return GenBlocksParams{..}
, cpExec = \params -> do
generateBlocks pm txpConfig params
generateBlocks (configProtocolMagic coreConfig) txpConfig params
return ValueUnit
, cpHelp = "generate <n> blocks"
},

let name = "add-key-pool" in
needsCoreConfig name >>= \coreConfig ->
needsAuxxMode name >>= \Dict ->
return CommandProc
{ cpName = name
, cpArgumentPrepare = identity
, cpArgumentConsumer = getArgMany tyInt "i"
, cpExec = \is -> do
when (null is) $ logWarning "Not adding keys from pool (list is empty)"
let secrets = fromMaybe (error "Secret keys are unknown") genesisSecretKeys
secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow coreConfig
forM_ is $ \i -> do
key <- evaluateNF $ secrets !! i
key <- evaluateNF $ secretKeys !! i
addSecretKey $ noPassEncrypt key
return ValueUnit
, cpHelp = ""
Expand Down Expand Up @@ -458,7 +469,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
},

let name = "rollback" in
needsProtocolMagic name >>= \pm ->
needsCoreConfig name >>= \coreConfig ->
needsAuxxMode name >>= \Dict ->
return CommandProc
{ cpName = name
Expand All @@ -468,7 +479,9 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
rpDumpPath <- getArg tyFilePath "dump-file"
pure RollbackParams{..}
, cpExec = \RollbackParams{..} -> do
Rollback.rollbackAndDump pm rpNum rpDumpPath
Rollback.rollbackAndDump (configProtocolMagic coreConfig)
rpNum
rpDumpPath
return ValueUnit
, cpHelp = ""
},
Expand Down Expand Up @@ -513,18 +526,15 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
, cpHelp = "display this message"
}]
where
needsAuxxMode :: Name -> Either UnavailableCommand (Dict (MonadAuxxMode m))
needsAuxxMode name =
maybe (Left $ UnavailableCommand name "AuxxMode is not available") Right hasAuxxMode
needsDiffusion :: Name -> Either UnavailableCommand (Diffusion m)
needsDiffusion name =
maybe (Left $ UnavailableCommand name "Diffusion layer is not available") Right mDiffusion
needsProtocolMagic :: Name -> Either UnavailableCommand ProtocolMagic
needsProtocolMagic name =
maybe (Left $ UnavailableCommand name "ProtocolMagic is not available") Right mpm
needsTxpConfig :: Name -> Either UnavailableCommand TxpConfiguration
needsTxpConfig name =
maybe (Left $ UnavailableCommand name "TxpConfiguration is not available") Right mTxpConfig
needsData :: Maybe a -> Text -> Name -> Either UnavailableCommand a
needsData mData msg name = maybe
(Left $ UnavailableCommand name (msg <> " is not available"))
Right
mData
needsAuxxMode = needsData hasAuxxMode "AuxxMode"
needsDiffusion = needsData mDiffusion "Diffusion layer"
needsCoreConfig = needsData mCoreConfig "Core.Config"
needsTxpConfig = needsData mTxpConfig "TxpConfiguration"

procConst :: Applicative m => Name -> Value -> CommandProc m
procConst name value =
Expand Down
13 changes: 6 additions & 7 deletions auxx/src/Command/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ import Pos.Core (IsBootstrapEraAddr (..), Timestamp (..),
deriveFirstHDAddress, makePubKeyAddress, mkCoin)
import Pos.Core.Conc (concurrently, currentTime, delay,
forConcurrently, modifySharedAtomic, newSharedAtomic)
import Pos.Core.Configuration (genesisBlockVersionData,
genesisSecretKeys)
import Pos.Core.Configuration (genesisBlockVersionData)
import Pos.Core.Txp (TxAux (..), TxIn (TxInUtxo), TxOut (..),
TxOutAux (..), txaF)
import Pos.Core.Update (BlockVersionData (..))
import Pos.Crypto (EncryptedSecretKey, ProtocolMagic, emptyPassphrase,
encToPublic, fakeSigner, hash, safeToPublic, toPublic,
withSafeSigners)
import Pos.Crypto (EncryptedSecretKey, ProtocolMagic, SecretKey,
emptyPassphrase, encToPublic, fakeSigner, hash,
safeToPublic, toPublic, withSafeSigners)
import Pos.Infra.Diffusion.Types (Diffusion (..))
import Pos.Util.UserSecret (usWallet, userSecret, wusRootKey)
import Pos.Util.Util (maybeThrow)
Expand Down Expand Up @@ -87,12 +86,12 @@ addTxSubmit =
sendToAllGenesis
:: forall m. MonadAuxxMode m
=> ProtocolMagic
-> [SecretKey]
-> Diffusion m
-> SendToAllGenesisParams
-> m ()
sendToAllGenesis pm diffusion (SendToAllGenesisParams genesisTxsPerThread txsPerThread conc delay_ tpsSentFile) = do
sendToAllGenesis pm keysToSend diffusion (SendToAllGenesisParams genesisTxsPerThread txsPerThread conc delay_ tpsSentFile) = do
let genesisSlotDuration = fromIntegral (toMicroseconds $ bvdSlotDuration genesisBlockVersionData) `div` 1000000 :: Int
keysToSend = fromMaybe (error "Genesis secret keys are unknown") genesisSecretKeys
tpsMVar <- newSharedAtomic $ TxCount 0 conc
startTime <- show . toInteger . getTimestamp . Timestamp <$> currentTime
bracket (openFile tpsSentFile WriteMode) (liftIO . hClose) $ \h -> do
Expand Down
34 changes: 19 additions & 15 deletions auxx/src/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import System.IO (hFlush, stdout)
import System.Wlog (CanLog, HasLoggerName, logInfo)

import Pos.Chain.Txp (TxpConfiguration, genesisUtxo, unGenesisUtxo)
import Pos.Core as Core (Config)
import Pos.Core.Conc (delay)
import Pos.Crypto (AHash (..), ProtocolMagic, fullPublicKeyF,
hashHexF)
import Pos.Crypto (AHash (..), fullPublicKeyF, hashHexF)
import Pos.Infra.Diffusion.Types (Diffusion)

import AuxxOptions (AuxxOptions (..))
Expand All @@ -42,49 +42,49 @@ import Repl (PrintAction, WithCommandAction (..))

auxxPlugin ::
MonadAuxxMode m
=> ProtocolMagic
=> Core.Config
-> TxpConfiguration
-> AuxxOptions
-> Either WithCommandAction Text
-> Diffusion m
-> m ()
auxxPlugin pm txpConfig auxxOptions repl = \diffusion -> do
auxxPlugin coreConfig txpConfig auxxOptions repl = \diffusion -> do
logInfo $ sformat ("Length of genesis utxo: " %int)
(length $ unGenesisUtxo genesisUtxo)
rawExec (Just pm) (Just txpConfig) (Just Dict) auxxOptions (Just diffusion) repl
rawExec (Just coreConfig) (Just txpConfig) (Just Dict) auxxOptions (Just diffusion) repl

rawExec ::
( MonadIO m
, MonadCatch m
, CanLog m
, HasLoggerName m
)
=> Maybe ProtocolMagic
=> Maybe Core.Config
-> Maybe TxpConfiguration
-> Maybe (Dict (MonadAuxxMode m))
-> AuxxOptions
-> Maybe (Diffusion m)
-> Either WithCommandAction Text
-> m ()
rawExec pm txpConfig mHasAuxxMode AuxxOptions{..} mDiffusion = \case
rawExec mCoreConfig txpConfig mHasAuxxMode AuxxOptions{..} mDiffusion = \case
Left WithCommandAction{..} -> do
printAction "... the auxx plugin is ready"
forever $ withCommand $ runCmd pm txpConfig mHasAuxxMode mDiffusion printAction
Right cmd -> runWalletCmd pm txpConfig mHasAuxxMode mDiffusion cmd
forever $ withCommand $ runCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion printAction
Right cmd -> runWalletCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion cmd

runWalletCmd ::
( MonadIO m
, CanLog m
, HasLoggerName m
)
=> Maybe ProtocolMagic
=> Maybe Core.Config
-> Maybe TxpConfiguration
-> Maybe (Dict (MonadAuxxMode m))
-> Maybe (Diffusion m)
-> Text
-> m ()
runWalletCmd pm txpConfig mHasAuxxMode mDiffusion line = do
runCmd pm txpConfig mHasAuxxMode mDiffusion printAction line
runWalletCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion line = do
runCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion printAction line
printAction "Command execution finished"
printAction " " -- for exit by SIGPIPE
liftIO $ hFlush stdout
Expand All @@ -100,15 +100,19 @@ runCmd ::
, CanLog m
, HasLoggerName m
)
=> Maybe ProtocolMagic
=> Maybe Core.Config
-> Maybe TxpConfiguration
-> Maybe (Dict (MonadAuxxMode m))
-> Maybe (Diffusion m)
-> PrintAction m
-> Text
-> m ()
runCmd pm txpConfig mHasAuxxMode mDiffusion printAction line = do
let commandProcs = createCommandProcs pm txpConfig mHasAuxxMode printAction mDiffusion
runCmd mCoreConfig txpConfig mHasAuxxMode mDiffusion printAction line = do
let commandProcs = createCommandProcs mCoreConfig
txpConfig
mHasAuxxMode
printAction
mDiffusion
parse = withExceptT Lang.ppParseError . ExceptT . return . Lang.parse
resolveCommandProcs =
withExceptT Lang.ppResolveErrors . ExceptT . return .
Expand Down
Loading