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

Commit

Permalink
[CDEC-505] Move Pos.Core.Delegation to Pos.Chain.Delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
ruhatch committed Sep 14, 2018
1 parent 295647b commit 8d5a138
Show file tree
Hide file tree
Showing 65 changed files with 279 additions and 240 deletions.
2 changes: 1 addition & 1 deletion auxx/src/Command/Proc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import qualified Data.Map as Map
import Formatting (build, int, sformat, stext, (%))
import qualified Text.JSON.Canonical as CanonicalJSON

import Pos.Chain.Delegation (HeavyDlgIndex (..))
import Pos.Chain.Genesis as Genesis (Config (..), configEpochSlots,
configGeneratedSecretsThrow)
import Pos.Chain.Genesis (gsSecretKeys)
Expand All @@ -26,7 +27,6 @@ import Pos.Core (AddrStakeDistribution (..), StakeholderId,
addressHash, mkMultiKeyDistr, unsafeGetCoin)
import Pos.Core.Common (AddrAttributes (..), AddrSpendingData (..),
makeAddress)
import Pos.Core.Delegation (HeavyDlgIndex (..))
import Pos.Core.Update (SoftwareVersion (..))
import Pos.Crypto (PublicKey, emptyPassphrase, encToPublic,
fullPublicKeyF, hashHexF, noPassEncrypt, safeCreatePsk,
Expand Down
2 changes: 1 addition & 1 deletion chain/bench/block-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Pos.Chain.Block (Body, BodyProof, ConsensusData, ExtraBodyData,
MainBlockchain, _gbBody, _gbExtra, _gbHeader,
_gbhBodyProof, _gbhConsensus, _gbhExtra, _mbDlgPayload,
_mbSscPayload, _mbTxPayload, _mbUpdatePayload)
import Pos.Chain.Delegation (DlgPayload)
import Pos.Chain.Txp (TxPayload (..))
import Pos.Core.Delegation (DlgPayload)
import Pos.Core.Ssc (SscPayload)
import Pos.Core.Update (UpdatePayload)
import Pos.Crypto (ProtocolMagic (..))
Expand Down
7 changes: 7 additions & 0 deletions chain/cardano-sl-chain.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ library
Pos.Chain.Delegation.Cede.Types
Pos.Chain.Delegation.Class
Pos.Chain.Delegation.Configuration
Pos.Chain.Delegation.HeavyDlgIndex
Pos.Chain.Delegation.LightDlgIndices
Pos.Chain.Delegation.Payload
Pos.Chain.Delegation.Proof
Pos.Chain.Delegation.Types

-- Genesis
Expand Down Expand Up @@ -225,6 +229,9 @@ test-suite test
Test.Pos.Chain.Block.Gen
Test.Pos.Chain.Block.SafeCopySpec
Test.Pos.Chain.Delegation.Arbitrary
Test.Pos.Chain.Delegation.Bi
Test.Pos.Chain.Delegation.Example
Test.Pos.Chain.Delegation.Gen
Test.Pos.Chain.Genesis.Dummy
Test.Pos.Chain.Genesis.Example
Test.Pos.Chain.Genesis.Gen
Expand Down
2 changes: 1 addition & 1 deletion chain/src/Pos/Chain/Block/BHelpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import Pos.Chain.Block.Union (Block, BlockHeader (..),
BlockSignature (..), GenesisBlockchain, MainBlockchain,
MainConsensusData (..), MainToSign (..),
mainBlockEBDataProof)
import Pos.Chain.Delegation (LightDlgIndices (..), checkDlgPayload)
import Pos.Chain.Genesis as Genesis (Config (..))
import Pos.Chain.Ssc (verifySscPayload)
import Pos.Chain.Txp (checkTxPayload)
import Pos.Core.Delegation (LightDlgIndices (..), checkDlgPayload)
import Pos.Core.Slotting (SlotId (..))
import Pos.Core.Ssc (checkSscPayload)
import Pos.Core.Update (checkSoftwareVersion, checkUpdatePayload)
Expand Down
2 changes: 1 addition & 1 deletion chain/src/Pos/Chain/Block/Constructors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import Pos.Chain.Block.Union (BlockHeader, BlockSignature (..),
GenesisBlock, GenesisBlockHeader, HeaderHash, MainBlock,
MainBlockHeader, MainConsensusData (..), MainToSign (..),
headerHash)
import Pos.Chain.Delegation (ProxySKBlockInfo)
import Pos.Chain.Genesis (GenesisHash (..))
import Pos.Core.Attributes (mkAttributes)
import Pos.Core.Common (ChainDifficulty, HasDifficulty (..),
SlotLeaders)
import Pos.Core.Delegation (ProxySKBlockInfo)
import Pos.Core.Slotting (EpochIndex, SlotId)
import Pos.Core.Update (BlockVersion, SoftwareVersion)
import Pos.Crypto (ProtocolMagic, SecretKey, SignTag (..), hash,
Expand Down
2 changes: 1 addition & 1 deletion chain/src/Pos/Chain/Block/Main/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import qualified Formatting.Buildable as Buildable

import Pos.Binary.Class (Bi (..), Cons (..), Field (..),
deriveSimpleBi, encodeListLen, enforceSize)
import Pos.Chain.Delegation.Payload (DlgPayload)
import Pos.Chain.Txp.TxPayload (TxPayload)
import Pos.Chain.Txp.TxProof (TxProof)
import Pos.Core.Attributes (Attributes, areAttributesKnown)
import Pos.Core.Delegation (DlgPayload)
import Pos.Core.Ssc (SscPayload, SscProof)
import Pos.Core.Update (BlockVersion, SoftwareVersion, UpdatePayload,
UpdateProof)
Expand Down
4 changes: 3 additions & 1 deletion chain/src/Pos/Chain/Block/Union/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ import Pos.Chain.Block.Genesis.Types (GenesisBody (..),
import Pos.Chain.Block.Main.Types (BlockBodyAttributes,
BlockHeaderAttributes, MainBody (..), MainExtraBodyData,
MainExtraHeaderData, MainProof (..))
import Pos.Chain.Delegation.HeavyDlgIndex (ProxySigHeavy)
import Pos.Chain.Delegation.LightDlgIndices (ProxySigLight)
import Pos.Chain.Delegation.Payload (DlgPayload)
import Pos.Chain.Txp.Tx (Tx)
import Pos.Chain.Txp.TxPayload (TxPayload, txpTxs, txpWitnesses)
import Pos.Chain.Txp.TxProof (mkTxProof)
import Pos.Chain.Txp.TxWitness (TxWitness)
import Pos.Core.Common (ChainDifficulty, HasDifficulty (..))
import Pos.Core.Delegation (DlgPayload, ProxySigHeavy, ProxySigLight)
import Pos.Core.Slotting (EpochOrSlot (..), HasEpochIndex (..),
HasEpochOrSlot (..), SlotId (..), slotIdF)
import Pos.Core.Ssc (SscPayload, mkSscProof)
Expand Down
17 changes: 9 additions & 8 deletions chain/src/Pos/Chain/Delegation.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
-- | Reexport module

module Pos.Chain.Delegation
( module Pos.Chain.Delegation.Types
, module Pos.Chain.Delegation.Configuration
, module Pos.Chain.Delegation.Class
, module Pos.Chain.Delegation.Cede
( module X
) where

import Pos.Chain.Delegation.Cede
import Pos.Chain.Delegation.Class
import Pos.Chain.Delegation.Configuration
import Pos.Chain.Delegation.Types
import Pos.Chain.Delegation.Cede as X
import Pos.Chain.Delegation.Class as X
import Pos.Chain.Delegation.Configuration as X
import Pos.Chain.Delegation.HeavyDlgIndex as X
import Pos.Chain.Delegation.LightDlgIndices as X
import Pos.Chain.Delegation.Payload as X
import Pos.Chain.Delegation.Proof as X
import Pos.Chain.Delegation.Types as X
2 changes: 1 addition & 1 deletion chain/src/Pos/Chain/Delegation/Cede/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Universum
import Control.Monad.Trans (MonadTrans)

import Pos.Chain.Delegation.Cede.Types (DlgEdgeAction (..))
import Pos.Chain.Delegation.HeavyDlgIndex (ProxySKHeavy)
import Pos.Core (StakeholderId, addressHash)
import Pos.Core.Delegation (ProxySKHeavy)
import Pos.Crypto (PublicKey)


Expand Down
2 changes: 1 addition & 1 deletion chain/src/Pos/Chain/Delegation/Cede/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import Formatting (bprint, build, (%))
import qualified Formatting.Buildable
import Universum

import Pos.Chain.Delegation.HeavyDlgIndex (ProxySKHeavy)
import Pos.Chain.Delegation.Types (isRevokePsk)
import Pos.Core (StakeholderId, addressHash)
import Pos.Core.Delegation (ProxySKHeavy)
import Pos.Crypto (pskIssuerPk)

-- | Action on delegation database, used commonly. Generalizes
Expand Down
3 changes: 2 additions & 1 deletion chain/src/Pos/Chain/Delegation/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import Data.Time.Clock (UTCTime)
import Serokell.Data.Memory.Units (Byte)

import Pos.Chain.Block.Union (HeaderHash)
import Pos.Chain.Delegation.Types (DlgMemPool, ProxySKHeavy)
import Pos.Chain.Delegation.HeavyDlgIndex (ProxySKHeavy)
import Pos.Chain.Delegation.Types (DlgMemPool)
import Pos.Util.Util (HasLens (..))

---------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE RecordWildCards #-}

module Pos.Core.Delegation.HeavyDlgIndex
module Pos.Chain.Delegation.HeavyDlgIndex
( HeavyDlgIndex (..)
, ProxySigHeavy
, ProxySKHeavy
Expand All @@ -9,16 +9,18 @@ module Pos.Core.Delegation.HeavyDlgIndex

import Universum

import Control.Monad.Except (MonadError)
import qualified Data.Aeson as Aeson (FromJSON (..), ToJSON (..))
import Data.SafeCopy (SafeCopy (..), contain, safeGet, safePut)
import Formatting (bprint, build)
import qualified Formatting.Buildable
import Text.JSON.Canonical (FromJSON (..), Int54, JSValue (..),
ReportSchemaErrors, ToJSON (..), fromJSField, mkObject)
ToJSON (..), fromJSField, mkObject)

import Pos.Binary.Class (Bi (..))
import Pos.Core.Slotting (EpochIndex)
import Pos.Crypto (ProxySecretKey (..), ProxySignature, PublicKey)
import Pos.Util.Json.Canonical (SchemaError)

-- | Witness for heavy delegation signature -- epoch in which
-- certificate starts being active. It is needed for replay attack
Expand Down Expand Up @@ -65,7 +67,7 @@ instance Monad m => ToJSON m ProxySKHeavy where
, ("cert", toJSON $ pskCert psk)
]

instance ReportSchemaErrors m => FromJSON m ProxySKHeavy where
instance MonadError SchemaError m => FromJSON m ProxySKHeavy where
fromJSON obj = do
pskOmega <- HeavyDlgIndex . fromIntegral @Int54 <$> fromJSField obj "omega"
pskIssuerPk <- fromJSField obj "issuerPk"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pos.Core.Delegation.LightDlgIndices
module Pos.Chain.Delegation.LightDlgIndices
( LightDlgIndices (..)
, ProxySigLight
, ProxySKLight
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pos.Core.Delegation.Payload
module Pos.Chain.Delegation.Payload
( DlgPayload (..)
, checkDlgPayload
) where
Expand All @@ -16,7 +16,7 @@ import Pos.Binary.Class (Bi (..))
import Pos.Crypto (ProtocolMagic, ProxySecretKey (..),
validateProxySecretKey)

import Pos.Core.Delegation.HeavyDlgIndex
import Pos.Chain.Delegation.HeavyDlgIndex

-- | 'DlgPayload' is put into 'MainBlock' and is a set of heavyweight
-- proxy signing keys. List of psk issuers should be unique also.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Pos.Core.Delegation.Proof
module Pos.Chain.Delegation.Proof
( DlgProof
, mkDlgProof
) where

import Pos.Crypto (Hash, hash)

import Pos.Core.Delegation.Payload
import Pos.Chain.Delegation.Payload

-- | Proof of delegation payload.
type DlgProof = Hash DlgPayload
Expand Down
5 changes: 2 additions & 3 deletions chain/src/Pos/Chain/Delegation/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Pos.Chain.Delegation.Types
( DlgPayload (..)
, DlgUndo (..)
, DlgMemPool
, module Pos.Core.Delegation
, isRevokePsk

, DlgBlock
Expand All @@ -21,9 +20,9 @@ import Serokell.Util.Text (listJson)

import Pos.Binary.Class (Cons (..), Field (..), deriveSimpleBi)
import Pos.Chain.Block.Union (ComponentBlock (..))
import Pos.Chain.Delegation.HeavyDlgIndex (ProxySKHeavy)
import Pos.Chain.Delegation.Payload (DlgPayload (..))
import Pos.Core (StakeholderId)
import Pos.Core.Delegation (DlgPayload (..), ProxySKBlockInfo,
ProxySKHeavy, checkDlgPayload)
import Pos.Crypto (ProxySecretKey, PublicKey, isSelfSignedPsk)

-- | Undo for the delegation component.
Expand Down
2 changes: 1 addition & 1 deletion chain/src/Pos/Chain/Genesis/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ instance Monad m => ToJSON m GenesisData where
, ("ftsSeed", toJSON gdFtsSeed)
]

instance (Monad m, MonadError SchemaError m) => FromJSON m GenesisData where
instance MonadError SchemaError m => FromJSON m GenesisData where
fromJSON obj = do
gdBootStakeholders <- fromJSField obj "bootStakeholders"
gdHeavyDelegation <- fromJSField obj "heavyDelegation"
Expand Down
8 changes: 4 additions & 4 deletions chain/src/Pos/Chain/Genesis/Delegation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import qualified Data.Aeson as Aeson (FromJSON (..), ToJSON (..))
import qualified Data.HashMap.Strict as HM
import Formatting (build, sformat, (%))
import Serokell.Util (allDistinct)
import Text.JSON.Canonical (FromJSON (..), ReportSchemaErrors,
ToJSON (..))
import Text.JSON.Canonical (FromJSON (..), ToJSON (..))

import Pos.Chain.Delegation (ProxySKHeavy)
import Pos.Core.Common (StakeholderId, addressHash)
import Pos.Core.Delegation (ProxySKHeavy)
import Pos.Crypto.Signing (ProxySecretKey (..), isSelfSignedPsk)
import Pos.Util.Json.Canonical (SchemaError)
import Pos.Util.Json.Parse (wrapConstructor)
import Pos.Util.Util (toAesonError)

Expand All @@ -39,7 +39,7 @@ newtype GenesisDelegation = UnsafeGenesisDelegation
instance Monad m => ToJSON m GenesisDelegation where
toJSON = toJSON . unGenesisDelegation

instance ReportSchemaErrors m => FromJSON m GenesisDelegation where
instance MonadError SchemaError m => FromJSON m GenesisDelegation where
fromJSON val = do
psks <- fromJSON val
wrapConstructor $ recreateGenesisDelegation psks
Expand Down
2 changes: 1 addition & 1 deletion chain/src/Pos/Chain/Genesis/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import Serokell.Util.Verify (VerificationRes (..), formatAllErrors,
verifyGeneric)

import Pos.Binary.Class (asBinary, serialize')
import Pos.Chain.Delegation (HeavyDlgIndex (..), ProxySKHeavy)
import Pos.Core.Common (Address, Coin, IsBootstrapEraAddr (..),
StakeholderId, addressHash, applyCoinPortionDown,
coinToInteger, deriveFirstHDAddress,
makePubKeyAddressBoot, mkCoin, sumCoins,
unsafeIntegerToCoin)
import Pos.Core.Delegation (HeavyDlgIndex (..), ProxySKHeavy)
import Pos.Core.ProtocolConstants (ProtocolConstants, vssMaxTTL,
vssMinTTL)
import Pos.Core.Ssc (VssCertificate, VssCertificatesMap,
Expand Down
2 changes: 1 addition & 1 deletion chain/test/Test/Pos/Chain/Block/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import Test.QuickCheck.Arbitrary.Generic (genericArbitrary,
import Pos.Binary.Class (biSize)
import Pos.Chain.Block (HeaderHash)
import qualified Pos.Chain.Block as Block
import qualified Pos.Chain.Delegation as Core
import Pos.Chain.Genesis (GenesisHash (..))
import Pos.Core (localSlotIndexMaxBound, localSlotIndexMinBound)
import qualified Pos.Core as Core
import Pos.Core.Attributes (areAttributesKnown)
import qualified Pos.Core.Delegation as Core
import Pos.Crypto (ProtocolMagic, PublicKey, SecretKey, createPsk,
hash, toPublic)

Expand Down
12 changes: 6 additions & 6 deletions chain/test/Test/Pos/Chain/Block/Bi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ import Pos.Chain.Block (BlockHeader (..), BlockHeaderAttributes,
MainExtraBodyData (..), MainExtraHeaderData (..),
MainProof (..), MainToSign (..), mkGenesisHeader,
mkMainHeaderExplicit)
import Pos.Chain.Delegation (DlgPayload (..))
import Pos.Chain.Genesis (GenesisHash (..))
import Pos.Core (EpochIndex (..))
import Pos.Core.Attributes (mkAttributes)
import Pos.Core.Delegation (DlgPayload (..))
import Pos.Crypto (Hash, ProtocolMagic (..), SignTag (..),
abstractHash, createPsk, hash, proxySign, sign, toPublic)

import Test.Pos.Binary.Helpers.GoldenRoundTrip (goldenTestBi,
roundTripsBiBuildable, roundTripsBiShow)
import Test.Pos.Chain.Block.Gen
import Test.Pos.Chain.Delegation.Example (exampleLightDlgIndices,
staticHeavyDlgIndexes, staticProxySKHeavys)
import Test.Pos.Chain.Txp.Example (exampleTxPayload, exampleTxProof)
import Test.Pos.Core.ExampleHelpers (exampleBlockVersion,
exampleChainDifficulty, exampleEpochIndex,
exampleLightDlgIndices, examplePublicKey,
exampleSecretKey, exampleSecretKeys, exampleSlotId,
exampleSlotLeaders, exampleSoftwareVersion,
examplePublicKey, exampleSecretKey, exampleSecretKeys,
exampleSlotId, exampleSlotLeaders, exampleSoftwareVersion,
exampleSscPayload, exampleSscProof, exampleUpdatePayload,
exampleUpdateProof, feedPM, feedPMEpochSlots,
staticHeavyDlgIndexes, staticProxySKHeavys)
exampleUpdateProof, feedPM, feedPMEpochSlots)
import Test.Pos.Util.Golden (discoverGolden, eachOf)
import Test.Pos.Util.Tripping (discoverRoundTrip)

Expand Down
2 changes: 1 addition & 1 deletion chain/test/Test/Pos/Chain/Block/BlockSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import Pos.Chain.Block (BlockHeader (..), BlockSignature (..),
MainExtraHeaderData (..), MainToSign (..), headerHash,
mkBodyProof, mkGenericHeader, mkGenesisHeader)
import qualified Pos.Chain.Block as Block
import Pos.Chain.Delegation (HeavyDlgIndex (..), LightDlgIndices (..))
import Pos.Chain.Genesis (GenesisHash (..))
import Pos.Core (EpochIndex (..), SlotId (..), difficultyL)
import Pos.Core.Attributes (mkAttributes)
import Pos.Core.Chrono (NewestFirst (..))
import Pos.Core.Delegation (HeavyDlgIndex (..), LightDlgIndices (..))
import Pos.Crypto (ProtocolMagic (..), ProxySecretKey (pskIssuerPk),
SecretKey, SignTag (..), createPsk, proxySign, sign,
toPublic)
Expand Down
5 changes: 3 additions & 2 deletions chain/test/Test/Pos/Chain/Block/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ import Pos.Core (SlotCount)
import Pos.Core.Attributes (mkAttributes)
import Pos.Crypto (ProtocolMagic)

import Test.Pos.Chain.Delegation.Gen (genDlgPayload, genHeavyDlgIndex,
genLightDlgIndices)
import Test.Pos.Chain.Txp.Gen (genTxPayload, genTxProof)
import Test.Pos.Core.Gen (genBlockVersion, genChainDifficulty,
genDlgPayload, genEpochIndex, genHeavyDlgIndex,
genLightDlgIndices, genSlotId, genSlotLeaders,
genEpochIndex, genSlotId, genSlotLeaders,
genSoftwareVersion, genSscPayload, genSscProof,
genTextHash, genUpdatePayload, genUpdateProof)
import Test.Pos.Crypto.Gen (genAbstractHash, genProxySignature,
Expand Down
15 changes: 13 additions & 2 deletions chain/test/Test/Pos/Chain/Delegation/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import Test.QuickCheck (Arbitrary (..), Gen, listOf)
import Test.QuickCheck.Arbitrary.Generic (genericArbitrary,
genericShrink)

import Pos.Chain.Delegation (DlgPayload (..), DlgUndo (..))
import Pos.Chain.Delegation (DlgPayload (..), DlgUndo (..),
HeavyDlgIndex (..), LightDlgIndices (..))
import Pos.Core (EpochIndex)
import Pos.Core.Delegation (HeavyDlgIndex (..))
import Pos.Crypto (ProtocolMagic, ProxySecretKey (..), createPsk)

import Test.Pos.Core.Arbitrary ()
Expand All @@ -37,3 +37,14 @@ instance Arbitrary DlgPayload where
instance Arbitrary DlgUndo where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary HeavyDlgIndex where
arbitrary = HeavyDlgIndex <$> arbitrary
shrink = genericShrink

instance Arbitrary LightDlgIndices where
arbitrary = do
l <- arbitrary
r <- arbitrary
pure $ LightDlgIndices $ if r >= l then (l,r) else (r,l)
shrink = genericShrink
Loading

0 comments on commit 8d5a138

Please sign in to comment.