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

Commit 94cde4b

Browse files
committed
[CDEC-505] Move Pos.Core.Genesis to Pos.Chain.Genesis
1 parent a8b3fee commit 94cde4b

File tree

213 files changed

+2426
-2243
lines changed

Some content is hidden

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

213 files changed

+2426
-2243
lines changed

Diff for: auxx/Main.hs

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import qualified System.IO.Temp as Temp
1414

1515
import Ntp.Client (NtpConfiguration)
1616

17+
import Pos.Chain.Genesis as Genesis (Config (..), ConfigurationError)
1718
import Pos.Chain.Txp (TxpConfiguration)
1819
import qualified Pos.Client.CLI as CLI
1920
import Pos.Context (NodeContext (..))
20-
import Pos.Core as Core (Config (..), ConfigurationError)
2121
import Pos.DB.DB (initNodeDBs)
2222
import Pos.DB.Txp (txpGlobalSettings)
2323
import Pos.Infra.Diffusion.Types (Diffusion, hoistDiffusion)
@@ -76,13 +76,13 @@ correctNodeParams AuxxOptions {..} np = do
7676

7777
runNodeWithSinglePlugin ::
7878
(HasConfigurations, HasCompileInfo)
79-
=> Core.Config
79+
=> Genesis.Config
8080
-> TxpConfiguration
8181
-> NodeResources EmptyMempoolExt
8282
-> (Diffusion AuxxMode -> AuxxMode ())
8383
-> Diffusion AuxxMode -> AuxxMode ()
84-
runNodeWithSinglePlugin coreConfig txpConfig nr plugin =
85-
runNode coreConfig txpConfig nr [plugin]
84+
runNodeWithSinglePlugin genesisConfig txpConfig nr plugin =
85+
runNode genesisConfig txpConfig nr [plugin]
8686

8787
action :: HasCompileInfo => AuxxOptions -> Either WithCommandAction Text -> IO ()
8888
action opts@AuxxOptions {..} command = do
@@ -108,14 +108,14 @@ action opts@AuxxOptions {..} command = do
108108
runWithoutNode :: PrintAction IO -> IO ()
109109
runWithoutNode printAction = printAction "Mode: light" >> rawExec Nothing Nothing Nothing opts Nothing command
110110

111-
runWithConfig :: HasConfigurations => PrintAction IO -> Core.Config -> TxpConfiguration -> NtpConfiguration -> IO ()
112-
runWithConfig printAction coreConfig txpConfig _ntpConfig = do
111+
runWithConfig :: HasConfigurations => PrintAction IO -> Genesis.Config -> TxpConfiguration -> NtpConfiguration -> IO ()
112+
runWithConfig printAction genesisConfig txpConfig _ntpConfig = do
113113
printAction "Mode: with-config"
114114
(nodeParams, tempDbUsed) <- (correctNodeParams opts . fst) =<< CLI.getNodeParams
115115
loggerName
116116
cArgs
117117
nArgs
118-
(configGeneratedSecrets coreConfig)
118+
(configGeneratedSecrets genesisConfig)
119119

120120
let toRealMode :: AuxxMode a -> RealMode EmptyMempoolExt a
121121
toRealMode auxxAction = do
@@ -129,17 +129,17 @@ action opts@AuxxOptions {..} command = do
129129
(npUserSecret nodeParams ^. usVss)
130130
sscParams = CLI.gtSscParams cArgs vssSK (npBehaviorConfig nodeParams)
131131

132-
bracketNodeResources coreConfig
132+
bracketNodeResources genesisConfig
133133
nodeParams
134134
sscParams
135-
(txpGlobalSettings coreConfig txpConfig)
136-
(initNodeDBs coreConfig) $ \nr ->
135+
(txpGlobalSettings genesisConfig txpConfig)
136+
(initNodeDBs genesisConfig) $ \nr ->
137137
let NodeContext {..} = nrContext nr
138138
modifier = if aoStartMode == WithNode
139-
then runNodeWithSinglePlugin coreConfig txpConfig nr
139+
then runNodeWithSinglePlugin genesisConfig txpConfig nr
140140
else identity
141-
auxxModeAction = modifier (auxxPlugin coreConfig txpConfig opts command)
142-
in runRealMode coreConfig txpConfig nr $ \diffusion ->
141+
auxxModeAction = modifier (auxxPlugin genesisConfig txpConfig opts command)
142+
in runRealMode genesisConfig txpConfig nr $ \diffusion ->
143143
toRealMode (auxxModeAction (hoistDiffusion realModeToAuxx toRealMode diffusion))
144144

145145
cArgs@CLI.CommonNodeArgs {..} = aoCommonNodeArgs

Diff for: auxx/src/Command/BlockGen.hs

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import Data.Default (def)
1313
import System.Random (mkStdGen, randomIO)
1414

1515
import Pos.AllSecrets (mkAllSecretsSimple)
16+
import Pos.Chain.Genesis as Genesis (Config (..),
17+
configBootStakeholders)
1618
import Pos.Chain.Txp (TxpConfiguration)
1719
import Pos.Client.KeyStorage (getSecretKeysPlain)
18-
import Pos.Core as Core (Config (..), configBootStakeholders)
1920
import Pos.Crypto (encToSecret)
2021
import Pos.DB.Txp (txpGlobalSettings)
2122
import Pos.Generator.Block (BlockGenParams (..), genBlocks,
@@ -29,11 +30,11 @@ import Lang.Value (GenBlocksParams (..))
2930
import Mode (MonadAuxxMode)
3031

3132
generateBlocks :: MonadAuxxMode m
32-
=> Core.Config
33+
=> Genesis.Config
3334
-> TxpConfiguration
3435
-> GenBlocksParams
3536
-> m ()
36-
generateBlocks coreConfig txpConfig GenBlocksParams{..} = withStateLock HighPriority ApplyBlock $ \_ -> do
37+
generateBlocks genesisConfig txpConfig GenBlocksParams{..} = withStateLock HighPriority ApplyBlock $ \_ -> do
3738
seed <- liftIO $ maybe randomIO pure bgoSeed
3839
logInfo $ "Generating with seed " <> show seed
3940

@@ -42,16 +43,16 @@ generateBlocks coreConfig txpConfig GenBlocksParams{..} = withStateLock HighPrio
4243
let bgenParams =
4344
BlockGenParams
4445
{ _bgpSecrets = allSecrets
45-
, _bgpGenStakeholders = configBootStakeholders coreConfig
46+
, _bgpGenStakeholders = configBootStakeholders genesisConfig
4647
, _bgpBlockCount = fromIntegral bgoBlockN
4748
-- tx generation is disabled for now
4849
, _bgpTxGenParams = def & tgpTxCountRange .~ (0,0)
4950
, _bgpInplaceDB = True
5051
, _bgpSkipNoKey = True
51-
, _bgpTxpGlobalSettings = txpGlobalSettings coreConfig txpConfig
52+
, _bgpTxpGlobalSettings = txpGlobalSettings genesisConfig txpConfig
5253
}
5354
withCompileInfo $ evalRandT
54-
(genBlocks coreConfig txpConfig bgenParams (const ()))
55+
(genBlocks genesisConfig txpConfig bgenParams (const ()))
5556
(mkStdGen seed)
5657
-- We print it twice because there can be a ton of logs and
5758
-- you don't notice the first message.

Diff for: auxx/src/Command/Proc.hs

+33-33
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ import qualified Data.Map as Map
1515
import Formatting (build, int, sformat, stext, (%))
1616
import qualified Text.JSON.Canonical as CanonicalJSON
1717

18+
import Pos.Chain.Genesis as Genesis (Config (..), configEpochSlots,
19+
configGeneratedSecretsThrow)
20+
import Pos.Chain.Genesis (gsSecretKeys)
1821
import Pos.Chain.Txp (TxOut (..), TxpConfiguration)
1922
import Pos.Chain.Update (BlockVersionModifier (..))
2023
import Pos.Client.KeyStorage (addSecretKey, getSecretKeysPlain)
2124
import Pos.Client.Txp.Balances (getBalance)
22-
import Pos.Core as Core (AddrStakeDistribution (..), Config (..),
23-
StakeholderId, addressHash, configEpochSlots,
24-
configGeneratedSecretsThrow, mkMultiKeyDistr,
25-
unsafeGetCoin)
25+
import Pos.Core (AddrStakeDistribution (..), StakeholderId,
26+
addressHash, mkMultiKeyDistr, unsafeGetCoin)
2627
import Pos.Core.Common (AddrAttributes (..), AddrSpendingData (..),
2728
makeAddress)
2829
import Pos.Core.Delegation (HeavyDlgIndex (..))
29-
import Pos.Core.Genesis (gsSecretKeys)
3030
import Pos.Core.Update (SoftwareVersion (..))
3131
import Pos.Crypto (PublicKey, emptyPassphrase, encToPublic,
3232
fullPublicKeyF, hashHexF, noPassEncrypt, safeCreatePsk,
@@ -65,7 +65,7 @@ import Repl (PrintAction)
6565

6666
createCommandProcs ::
6767
forall m. (MonadIO m, CanLog m, HasLoggerName m)
68-
=> Maybe Core.Config
68+
=> Maybe Genesis.Config
6969
-> Maybe TxpConfiguration
7070
-> Maybe (Dict (MonadAuxxMode m))
7171
-> PrintAction m
@@ -102,7 +102,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
102102
},
103103

104104
let name = "addr" in
105-
needsCoreConfig name >>= \coreConfig ->
105+
needsCoreConfig name >>= \genesisConfig ->
106106
needsAuxxMode name >>= \Dict ->
107107
return CommandProc
108108
{ cpName = name
@@ -114,7 +114,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
114114
, cpExec = \(pk', mDistr) -> do
115115
pk <- toLeft pk'
116116
addr <- case mDistr of
117-
Nothing -> makePubKeyAddressAuxx (configEpochSlots coreConfig) pk
117+
Nothing -> makePubKeyAddressAuxx (configEpochSlots genesisConfig) pk
118118
Just distr -> return $
119119
makeAddress (PubKeyASD pk) (AddrAttributes Nothing distr)
120120
return $ ValueAddress addr
@@ -124,7 +124,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
124124
},
125125

126126
let name = "addr-hd" in
127-
needsCoreConfig name >>= \coreConfig ->
127+
needsCoreConfig name >>= \genesisConfig ->
128128
needsAuxxMode name >>= \Dict ->
129129
return CommandProc
130130
{ cpName = name
@@ -135,7 +135,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
135135
sk <- evaluateWHNF (sks !! i) -- WHNF is sufficient to force possible errors
136136
-- from using (!!). I'd use NF but there's no
137137
-- NFData instance for secret keys.
138-
addrHD <- deriveHDAddressAuxx (configEpochSlots coreConfig) sk
138+
addrHD <- deriveHDAddressAuxx (configEpochSlots genesisConfig) sk
139139
return $ ValueAddress addrHD
140140
, cpHelp = "address of the HD wallet for the specified public key"
141141
},
@@ -192,17 +192,17 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
192192
return . procConst "false" $ ValueBool False,
193193

194194
let name = "balance" in
195-
needsCoreConfig name >>= \coreConfig ->
195+
needsCoreConfig name >>= \genesisConfig ->
196196
needsAuxxMode name >>= \Dict ->
197197
return CommandProc
198198
{ cpName = name
199199
, cpArgumentPrepare = identity
200200
, cpArgumentConsumer = getArg (tyAddress `tyEither` tyPublicKey `tyEither` tyInt) "addr"
201201
, cpExec = \addr' -> do
202202
addr <-
203-
either return (makePubKeyAddressAuxx $ configEpochSlots coreConfig) <=<
203+
either return (makePubKeyAddressAuxx $ configEpochSlots genesisConfig) <=<
204204
traverse (either return getPublicKeyFromIndex) $ addr'
205-
balance <- getBalance (configGenesisData coreConfig) addr
205+
balance <- getBalance (configGenesisData genesisConfig) addr
206206
return $ ValueNumber (fromIntegral . unsafeGetCoin $ balance)
207207
, cpHelp = "check the amount of coins on the specified address"
208208
},
@@ -218,7 +218,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
218218
},
219219

220220
let name = "send-to-all-genesis" in
221-
needsCoreConfig name >>= \coreConfig ->
221+
needsCoreConfig name >>= \genesisConfig ->
222222
needsDiffusion name >>= \diffusion ->
223223
needsAuxxMode name >>= \Dict ->
224224
return CommandProc
@@ -232,8 +232,8 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
232232
stagpTpsSentFile <- getArg tyFilePath "file"
233233
return Tx.SendToAllGenesisParams{..}
234234
, cpExec = \stagp -> do
235-
secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow coreConfig
236-
Tx.sendToAllGenesis coreConfig secretKeys diffusion stagp
235+
secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow genesisConfig
236+
Tx.sendToAllGenesis genesisConfig secretKeys diffusion stagp
237237
return ValueUnit
238238
, cpHelp = "create and send transactions from all genesis addresses \
239239
\ for <duration> seconds, <delay> in ms. <conc> is the \
@@ -254,7 +254,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
254254
},
255255

256256
let name = "send" in
257-
needsCoreConfig name >>= \coreConfig ->
257+
needsCoreConfig name >>= \genesisConfig ->
258258
needsDiffusion name >>= \diffusion ->
259259
needsAuxxMode name >>= \Dict ->
260260
return CommandProc
@@ -264,14 +264,14 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
264264
(,) <$> getArg tyInt "i"
265265
<*> getArgSome tyTxOut "out"
266266
, cpExec = \(i, outputs) -> do
267-
Tx.send coreConfig diffusion i outputs
267+
Tx.send genesisConfig diffusion i outputs
268268
return ValueUnit
269269
, cpHelp = "send from #i to specified transaction outputs \
270270
\ (use 'tx-out' to build them)"
271271
},
272272

273273
let name = "vote" in
274-
needsCoreConfig name >>= \coreConfig ->
274+
needsCoreConfig name >>= \genesisConfig ->
275275
needsDiffusion name >>= \diffusion ->
276276
needsAuxxMode name >>= \Dict ->
277277
return CommandProc
@@ -282,7 +282,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
282282
<*> getArg tyBool "agree"
283283
<*> getArg tyHash "up-id"
284284
, cpExec = \(i, decision, upId) -> do
285-
Update.vote (configProtocolMagic coreConfig) diffusion i decision upId
285+
Update.vote (configProtocolMagic genesisConfig) diffusion i decision upId
286286
return ValueUnit
287287
, cpHelp = "send vote for update proposal <up-id> and \
288288
\ decision <agree> ('true' or 'false'), \
@@ -338,7 +338,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
338338
},
339339

340340
let name = "propose-update" in
341-
needsCoreConfig name >>= \coreConfig ->
341+
needsCoreConfig name >>= \genesisConfig ->
342342
needsDiffusion name >>= \diffusion ->
343343
needsAuxxMode name >>= \Dict ->
344344
return CommandProc
@@ -361,7 +361,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
361361
-- is to have two ValueHash constructors, one with universal and
362362
-- one with existential (relevant via singleton-style GADT) quantification.
363363
ValueHash . unsafeCheatingHashCoerce
364-
<$> Update.propose (configProtocolMagic coreConfig) diffusion params
364+
<$> Update.propose (configProtocolMagic genesisConfig) diffusion params
365365
, cpHelp = "propose an update with one positive vote for it \
366366
\ using secret key #i"
367367
},
@@ -377,7 +377,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
377377
},
378378

379379
let name = "delegate-heavy" in
380-
needsCoreConfig name >>= \coreConfig ->
380+
needsCoreConfig name >>= \genesisConfig ->
381381
needsDiffusion name >>= \diffusion ->
382382
needsAuxxMode name >>= \Dict ->
383383
return CommandProc
@@ -393,7 +393,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
393393
withSafeSigner issuerSk (pure emptyPassphrase) $ \case
394394
Nothing -> logError "Invalid passphrase"
395395
Just ss -> do
396-
let psk = safeCreatePsk (configProtocolMagic coreConfig)
396+
let psk = safeCreatePsk (configProtocolMagic genesisConfig)
397397
ss
398398
delegatePk
399399
(HeavyDlgIndex curEpoch)
@@ -414,7 +414,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
414414
},
415415

416416
let name = "generate-blocks" in
417-
needsCoreConfig name >>= \coreConfig ->
417+
needsCoreConfig name >>= \genesisConfig ->
418418
needsAuxxMode name >>= \Dict ->
419419
needsTxpConfig name >>= \txpConfig ->
420420
return CommandProc
@@ -425,21 +425,21 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
425425
bgoSeed <- getArgOpt tyInt "seed"
426426
return GenBlocksParams{..}
427427
, cpExec = \params -> do
428-
generateBlocks coreConfig txpConfig params
428+
generateBlocks genesisConfig txpConfig params
429429
return ValueUnit
430430
, cpHelp = "generate <n> blocks"
431431
},
432432

433433
let name = "add-key-pool" in
434-
needsCoreConfig name >>= \coreConfig ->
434+
needsCoreConfig name >>= \genesisConfig ->
435435
needsAuxxMode name >>= \Dict ->
436436
return CommandProc
437437
{ cpName = name
438438
, cpArgumentPrepare = identity
439439
, cpArgumentConsumer = getArgMany tyInt "i"
440440
, cpExec = \is -> do
441441
when (null is) $ logWarning "Not adding keys from pool (list is empty)"
442-
secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow coreConfig
442+
secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow genesisConfig
443443
forM_ is $ \i -> do
444444
key <- evaluateNF $ secretKeys !! i
445445
addSecretKey $ noPassEncrypt key
@@ -470,7 +470,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
470470
},
471471

472472
let name = "rollback" in
473-
needsCoreConfig name >>= \coreConfig ->
473+
needsCoreConfig name >>= \genesisConfig ->
474474
needsAuxxMode name >>= \Dict ->
475475
return CommandProc
476476
{ cpName = name
@@ -480,20 +480,20 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
480480
rpDumpPath <- getArg tyFilePath "dump-file"
481481
pure RollbackParams{..}
482482
, cpExec = \RollbackParams{..} -> do
483-
Rollback.rollbackAndDump coreConfig rpNum rpDumpPath
483+
Rollback.rollbackAndDump genesisConfig rpNum rpDumpPath
484484
return ValueUnit
485485
, cpHelp = ""
486486
},
487487

488488
let name = "listaddr" in
489-
needsCoreConfig name >>= \coreConfig ->
489+
needsCoreConfig name >>= \genesisConfig ->
490490
needsAuxxMode name >>= \Dict ->
491491
return CommandProc
492492
{ cpName = name
493493
, cpArgumentPrepare = identity
494494
, cpArgumentConsumer = do pure ()
495495
, cpExec = \() -> do
496-
let epochSlots = configEpochSlots coreConfig
496+
let epochSlots = configEpochSlots genesisConfig
497497
sks <- getSecretKeysPlain
498498
printAction "Available addresses:"
499499
for_ (zip [0 :: Int ..] sks) $ \(i, sk) -> do
@@ -534,7 +534,7 @@ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = r
534534
mData
535535
needsAuxxMode = needsData hasAuxxMode "AuxxMode"
536536
needsDiffusion = needsData mDiffusion "Diffusion layer"
537-
needsCoreConfig = needsData mCoreConfig "Core.Config"
537+
needsCoreConfig = needsData mCoreConfig "Genesis.Config"
538538
needsTxpConfig = needsData mTxpConfig "TxpConfiguration"
539539

540540
procConst :: Applicative m => Name -> Value -> CommandProc m

0 commit comments

Comments
 (0)