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

[CDEC-418] Reunite orphan Bi instances in txp #3179

Merged
merged 1 commit into from
Jul 5, 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
1 change: 0 additions & 1 deletion block/src/Pos/Block/Network/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Serokell.Util.Text (listJson)
import qualified System.Metrics.Gauge as Metrics
import System.Wlog (logDebug, logInfo, logWarning)

import Pos.Binary.Txp ()
import Pos.Block.BlockWorkMode (BlockWorkMode)
import Pos.Block.Error (ApplyBlocksException)
import Pos.Block.Logic (ClassifyHeaderRes (..), classifyNewHeader,
Expand Down
2 changes: 1 addition & 1 deletion block/test/Test/Pos/Block/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import Pos.Crypto (ProtocolMagic, PublicKey, SecretKey, createPsk,
import Pos.Data.Attributes (areAttributesKnown)

import Test.Pos.Core.Arbitrary (genSlotId)
import Test.Pos.Core.Arbitrary.Txp (genTxPayload)
import Test.Pos.Crypto.Dummy (dummyProtocolMagic)
import Test.Pos.Delegation.Arbitrary (genDlgPayload)
import Test.Pos.Txp.Arbitrary (genTxPayload)
import Test.Pos.Update.Arbitrary (genUpdatePayload)

newtype BodyDependsOnSlot b = BodyDependsOnSlot
Expand Down
5 changes: 2 additions & 3 deletions client/src/Pos/Client/Txp/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ import Pos.Communication.Message ()
import Pos.Communication.Types (InvOrDataTK)
import Pos.Core (Address, Coin, makeRedeemAddress, mkCoin,
unsafeAddCoin)
import Pos.Core.Txp (TxAux (..), TxId, TxOut (..), TxOutAux (..),
txaF)
import Pos.Core.Txp (TxAux (..), TxId, TxMsgContents (..), TxOut (..),
TxOutAux (..), txaF)
import Pos.Crypto (ProtocolMagic, RedeemSecretKey, SafeSigner, hash,
redeemToPublic)
import Pos.Infra.Communication.Protocol (OutSpecs)
import Pos.Infra.Communication.Specs (createOutSpecs)
import Pos.Infra.Diffusion.Types (Diffusion (sendTx))
import Pos.Txp.Network.Types (TxMsgContents (..))
import Pos.Util.Util (eitherToThrow)
import Pos.WorkMode.Class (MinWorkMode)

Expand Down
1 change: 1 addition & 0 deletions core/cardano-sl-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ library
-- Txp
Pos.Core.Txp.Tx
Pos.Core.Txp.TxAux
Pos.Core.Txp.TxMsg
Pos.Core.Txp.TxOutAux
Pos.Core.Txp.TxPayload
Pos.Core.Txp.TxProof
Expand Down
2 changes: 2 additions & 0 deletions core/src/Pos/Core/Txp.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Pos.Core.Txp
( module Pos.Core.Txp.Tx
, module Pos.Core.Txp.TxAux
, module Pos.Core.Txp.TxMsg
, module Pos.Core.Txp.TxOutAux
, module Pos.Core.Txp.TxPayload
, module Pos.Core.Txp.TxProof
Expand All @@ -10,6 +11,7 @@ module Pos.Core.Txp

import Pos.Core.Txp.Tx
import Pos.Core.Txp.TxAux
import Pos.Core.Txp.TxMsg
import Pos.Core.Txp.TxOutAux
import Pos.Core.Txp.TxPayload
import Pos.Core.Txp.TxProof
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
-- | Types used for communication about transactions.

module Pos.Txp.Network.Types
module Pos.Core.Txp.TxMsg
( TxMsgContents (..)
) where

import qualified Data.Text.Buildable as Buildable
import Formatting (bprint, (%))
import Universum

import Pos.Core.Txp (TxAux (..), txaF)
import Data.Text.Buildable (Buildable (..))
import Formatting (bprint, (%))

import Pos.Core.Txp.TxAux (TxAux (..), txaF)

-- | Data message. Can be used to send one transaction per message.
-- Transaction is sent with auxilary data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-- | `Arbitrary` instances for Txp types

module Test.Pos.Txp.Arbitrary
module Test.Pos.Core.Arbitrary.Txp
( BadSigsTx (..)
, DoubleInputTx (..)
, GoodTx (..)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

-- | 'Arbitrary' unsafe instances for some types from Txp types

module Test.Pos.Txp.Arbitrary.Unsafe () where
module Test.Pos.Core.Arbitrary.Txp.Unsafe () where

import Universum

Expand Down
2 changes: 2 additions & 0 deletions core/test/cardano-sl-core-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ library
Test.Pos.Core.Gen
Test.Pos.Core.Arbitrary
Test.Pos.Core.Arbitrary.Unsafe
Test.Pos.Core.Arbitrary.Txp
Test.Pos.Core.Arbitrary.Txp.Unsafe

build-depends: QuickCheck
, base
Expand Down
2 changes: 1 addition & 1 deletion explorer/bench/Bench/Pos/Explorer/ServerBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Pos.Explorer.Web.ClientTypes (CBlockEntry)
import Pos.Explorer.Web.Server (getBlocksPage, getBlocksTotal)

import Test.Pos.Configuration (withDefConfigurations)
import Test.Pos.Txp.Arbitrary.Unsafe ()
import Test.Pos.Core.Arbitrary.Txp.Unsafe ()

----------------------------------------------------------------
-- Mocked functions
Expand Down
1 change: 1 addition & 0 deletions explorer/cardano-sl-explorer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ benchmark cardano-explorer-bench
build-depends: QuickCheck
, base
, cardano-sl
, cardano-sl-core-test
, cardano-sl-explorer
, cardano-sl-txp
, cardano-sl-txp-test
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/Pos/Arbitrary/Explorer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Test.QuickCheck.Arbitrary.Generic (genericArbitrary,
import Pos.Explorer.Core.Types (TxExtra (..))

import Test.Pos.Core.Arbitrary ()
import Test.Pos.Txp.Arbitrary ()
import Test.Pos.Core.Arbitrary.Txp ()

instance Arbitrary TxExtra where
arbitrary = genericArbitrary
Expand Down
1 change: 1 addition & 0 deletions generator/cardano-sl-generator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ test-suite cardano-generator-test
, cardano-sl-block
, cardano-sl-block-test
, cardano-sl-core
, cardano-sl-core-test
, cardano-sl-crypto
, cardano-sl-crypto-test
, cardano-sl-db
Expand Down
2 changes: 1 addition & 1 deletion generator/test/Test/Pos/Block/Logic/CreationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import Pos.Update.Configuration (HasUpdateConfiguration)
import Test.Pos.Block.Arbitrary ()
import Test.Pos.Configuration (withDefConfiguration,
withDefUpdateConfiguration)
import Test.Pos.Core.Arbitrary.Txp (GoodTx, goodTxToTxAux)
import Test.Pos.Crypto.Dummy (dummyProtocolMagic)
import Test.Pos.Delegation.Arbitrary (genDlgPayload)
import Test.Pos.Txp.Arbitrary (GoodTx, goodTxToTxAux)
import Test.Pos.Util.QuickCheck (SmallGenerator (..), makeSmall)

spec :: Spec
Expand Down
5 changes: 5 additions & 0 deletions infra/src/Pos/Infra/Communication/Types/Relay.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Formatting (bprint, build, (%))
import Pos.Binary.Class (Bi (..))
import qualified Pos.Core.Update as U
import Pos.Crypto (hash)
import Pos.Core.Txp (TxMsgContents (..))
import Pos.Util.Util (cborError)

-- | Inventory message. Can be used to announce the fact that you have
Expand Down Expand Up @@ -67,6 +68,10 @@ data DataMsg contents = DataMsg
{ dmContents :: !contents
} deriving (Generic, Show, Eq)

instance Bi (DataMsg TxMsgContents) where
Copy link
Contributor

@Jimbo4350 Jimbo4350 Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in txp/src/Pos/Txp/Network/Types.hs with TxMsgContents as per: https://iohk.myjetbrains.com/youtrack/issue/CDEC-401 @erikd

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally probably yes, and in the end, maybe yes, but right now, definitely no :).

What we are aiming for at the moment is to fix txp so it no longer depends in infra and in the end, make infra depend on txp. We also want to avoid doing this in one huge PR that takes a week or more to get ready and then days to review etc.

So, we are temporarily going to contravene our normal good practices and do what ever it takes to fix the way txp and infra depend on each other.

encode (DataMsg (TxMsgContents txAux)) = encode txAux
decode = DataMsg <$> (TxMsgContents <$> decode)

instance Bi (DataMsg U.UpdateVote) where
encode = encode . dmContents
decode = DataMsg <$> decode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS_GHC -fno-warn-orphans #-}

-- | 'Arbitrary' instances for 'Pos.Txp.Network' types defined in 'src'
-- | 'Arbitrary' instances for 'Pos.Infra.Communication' types defined in 'src'

module Test.Pos.Txp.Arbitrary.Network () where
module Test.Pos.Infra.Arbitrary.Communication () where

import Universum

import Test.QuickCheck (Arbitrary (..))
import Test.QuickCheck.Arbitrary.Generic (genericArbitrary,
genericShrink)

import Pos.Core.Txp (TxMsgContents (..))
import Pos.Infra.Communication.Types.Relay (DataMsg (..))
import Pos.Txp.Network.Types (TxMsgContents (..))

import Test.Pos.Txp.Arbitrary ()

instance Arbitrary TxMsgContents where
arbitrary = genericArbitrary
shrink = genericShrink
import Test.Pos.Infra.Arbitrary.Txp ()

instance Arbitrary (DataMsg TxMsgContents) where
arbitrary = DataMsg <$> arbitrary
Expand Down
21 changes: 21 additions & 0 deletions infra/test/Test/Pos/Infra/Arbitrary/Txp.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS_GHC -fno-warn-orphans #-}

-- | 'Arbitrary' instances for 'Pos.Infra.Communication' types defined in 'src'

module Test.Pos.Infra.Arbitrary.Txp () where

import Universum

import Test.QuickCheck (Arbitrary (..))
import Test.QuickCheck.Arbitrary.Generic (genericArbitrary,
genericShrink)

import Pos.Core.Txp (TxMsgContents (..))

import Test.Pos.Core.Arbitrary.Txp ()

instance Arbitrary TxMsgContents where
arbitrary = genericArbitrary
shrink = genericShrink
2 changes: 2 additions & 0 deletions infra/test/cardano-sl-infra-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ cabal-version: >=1.10
library
exposed-modules:
Test.Pos.Infra.Arbitrary
Test.Pos.Infra.Arbitrary.Communication
Test.Pos.Infra.Arbitrary.Slotting
Test.Pos.Infra.Arbitrary.Txp
Test.Pos.Infra.Gen

build-depends: QuickCheck
Expand Down
2 changes: 1 addition & 1 deletion lib/bench/Bench/Pos/Criterion/TxSigningBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Pos.Crypto (SecretKey, SignTag (SignTx), sign)
import Pos.Ssc ()
import Pos.Txp (TxId, TxSig, TxSigData (..))

import Test.Pos.Txp.Arbitrary.Unsafe ()
import Test.Pos.Core.Arbitrary.Txp.Unsafe ()
import Test.Pos.Util.QuickCheck.Arbitrary (arbitraryUnsafe)

import Bench.Configuration (benchProtocolMagic)
Expand Down
1 change: 0 additions & 1 deletion lib/src/Pos/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ module Pos.Binary
import Pos.Binary.Class
import Pos.Binary.Communication ()
import Pos.Binary.Delegation ()
import Pos.Binary.Txp ()
3 changes: 1 addition & 2 deletions lib/src/Pos/Communication/Limits.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ import Pos.Core.Block (Block, BlockHeader (..), GenesisBlock,
import Pos.Core.Delegation (HeavyDlgIndex (..), LightDlgIndices (..))
import Pos.Core.Ssc (Commitment (..), InnerSharesMap, Opening (..),
SignedCommitment)
import Pos.Core.Txp (TxAux)
import Pos.Core.Txp (TxAux, TxMsgContents (..))
import Pos.Core.Update (UpdateProposal (..), UpdateVote (..))
import Pos.Crypto (ProxyCert (..), ProxySecretKey (..),
SecretProof (..))
import Pos.Ssc.Message (MCCommitment (..), MCOpening (..),
MCShares (..), MCVssCertificate (..))
import Pos.Txp.Network.Types (TxMsgContents (..))

import Pos.Core.Chrono (NewestFirst (..))
import Pos.Crypto.Limits (mlAbstractHash, mlDecShare, mlEncShare,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Pos/Communication/Message.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import Node.Message.Class (Message (..))
import Pos.Block.Network (MsgBlock, MsgGetBlocks, MsgGetHeaders,
MsgHeaders, MsgStream, MsgStreamBlock)
import Pos.Core (ProxySKHeavy)
import Pos.Core.Txp (TxMsgContents)
import Pos.Core.Update (UpdateProposal, UpdateVote)
import Pos.Infra.Communication.Types.Protocol (MsgSubscribe,
MsgSubscribe1)
import Pos.Infra.Communication.Types.Relay (DataMsg, InvMsg,
InvOrData, MempoolMsg, ReqMsg, ReqOrRes)
import Pos.Ssc.Message (MCCommitment, MCOpening, MCShares,
MCVssCertificate)
import Pos.Txp.Network.Types (TxMsgContents)

-- Why?
instance Message Void where
Expand Down
2 changes: 0 additions & 2 deletions lib/src/Pos/Communication/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ module Pos.Communication.Types
( -- * Messages and socket state
module Pos.Infra.Communication.Types.Protocol
, module Pos.Infra.Communication.Types.Relay
, module Pos.Txp.Network.Types
) where

import Pos.Infra.Communication.Types.Protocol
import Pos.Infra.Communication.Types.Relay
import Pos.Txp.Network.Types
4 changes: 1 addition & 3 deletions lib/src/Pos/Diffusion/Full/Txp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import qualified Network.Broadcast.OutboundQueue as OQ
import Universum

import Pos.Binary.Communication ()
import Pos.Binary.Txp ()
import Pos.Communication.Limits (mlTxMsgContents)
import Pos.Communication.Message ()
import Pos.Core.Txp (TxAux (..), TxId)
import Pos.Core.Txp (TxAux (..), TxId, TxMsgContents (..))
import Pos.Crypto (hash)
import Pos.Infra.Communication.Protocol (EnqueueMsg, MkListeners,
MsgType (..), NodeId, Origin (..), OutSpecs)
Expand All @@ -25,7 +24,6 @@ import Pos.Infra.Communication.Relay (InvReqDataParams (..),
import Pos.Infra.Network.Types (Bucket)
import Pos.Logic.Types (Logic (..))
import qualified Pos.Logic.Types as KV (KeyVal (..))
import Pos.Txp.Network.Types (TxMsgContents (..))
import Pos.Util.Trace (Severity, Trace)

-- | Send Tx to given addresses.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Pos/Logic/Full.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Pos.Core (Block, BlockHeader, BlockVersionData,
TxAux (..), addressHash, getCertId, lookupVss)
import Pos.Core.Chrono (NE, NewestFirst, OldestFirst)
import Pos.Core.Ssc (getCommitmentsMap)
import Pos.Core.Txp (TxMsgContents (..))
import Pos.Core.Update (UpdateProposal (..), UpdateVote (..))
import Pos.Crypto (ProtocolMagic, hash)
import qualified Pos.DB.Block as DB (getTipBlock)
Expand Down Expand Up @@ -55,7 +56,6 @@ import Pos.Txp (MemPool (..))
import Pos.Txp.MemState (getMemPool, withTxpLocalData)
import Pos.Txp.Network.Listeners (TxpMode)
import qualified Pos.Txp.Network.Listeners as Txp (handleTxDo)
import Pos.Txp.Network.Types (TxMsgContents (..))
import qualified Pos.Update.Logic.Local as Update (getLocalProposalNVotes,
getLocalVote, isProposalNeeded, isVoteNeeded)
import Pos.Update.Mode (UpdateMode)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/Pos/Logic/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import Pipes.Internal (unsafeHoist)

import Pos.Block.Logic (GetHashesRangeError,
GetHeadersFromManyToError)
import Pos.Communication (NodeId, TxMsgContents)
import Pos.Communication (NodeId)
import Pos.Core (HeaderHash, ProxySKHeavy, StakeholderId)
import Pos.Core.Block (Block, BlockHeader)
import Pos.Core.Chrono (NE, NewestFirst, OldestFirst (..))
import Pos.Core.Txp (TxId)
import Pos.Core.Txp (TxId, TxMsgContents)
import Pos.Core.Update (BlockVersionData, UpId, UpdateProposal,
UpdateVote, VoteId)
import Pos.DB.Class (SerializedBlock)
Expand Down
19 changes: 10 additions & 9 deletions lib/test/Test/Pos/Cbor/CborSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Pos.Communication.Limits (mlOpening, mlUpdateVote,
mlVssCertificate)
import Pos.Core (ProxySKHeavy, StakeholderId, VssCertificate)
import qualified Pos.Core.Ssc as Ssc
import Pos.Core.Txp (TxMsgContents (..))
import Pos.Crypto.Signing (EncryptedSecretKey)
import Pos.Delegation (DlgPayload, DlgUndo)
import Pos.Infra.Binary ()
Expand All @@ -49,8 +50,8 @@ import Test.Pos.Core.Arbitrary ()
import Test.Pos.Crypto.Arbitrary ()
import Test.Pos.Delegation.Arbitrary ()
import Test.Pos.Infra.Arbitrary ()
import Test.Pos.Infra.Arbitrary.Communication ()
import Test.Pos.Infra.Arbitrary.Slotting ()
import Test.Pos.Txp.Arbitrary.Network ()
import Test.Pos.Update.Arbitrary ()
import Test.Pos.Util.QuickCheck (SmallGenerator)

Expand Down Expand Up @@ -148,17 +149,17 @@ spec = withDefConfiguration $ \_ -> do
binaryTest @(SmallGenerator T.TxPayload)
binaryTest @T.TxpUndo
describe "Network" $ do
binaryTest @(R.InvMsg (Tagged T.TxMsgContents T.TxId))
binaryTest @(R.ReqMsg (Tagged T.TxMsgContents T.TxId))
binaryTest @(R.MempoolMsg T.TxMsgContents)
binaryTest @(R.DataMsg T.TxMsgContents)
binaryTest @(R.InvMsg (Tagged TxMsgContents T.TxId))
binaryTest @(R.ReqMsg (Tagged TxMsgContents T.TxId))
binaryTest @(R.MempoolMsg TxMsgContents)
binaryTest @(R.DataMsg TxMsgContents)
describe "Bi extension" $ do
prop "TxInWitness" (extensionProperty @T.TxInWitness)
describe "Message length limit" $ do
msgLenLimitedTest @(R.InvMsg (Tagged T.TxMsgContents T.TxId)) mlInvMsg
msgLenLimitedTest @(R.ReqMsg (Tagged T.TxMsgContents T.TxId)) mlReqMsg
msgLenLimitedTest @(R.MempoolMsg T.TxMsgContents) mlMempoolMsg
-- No check for (DataMsg T.TxMsgContents) since overal message size
msgLenLimitedTest @(R.InvMsg (Tagged TxMsgContents T.TxId)) mlInvMsg
msgLenLimitedTest @(R.ReqMsg (Tagged TxMsgContents T.TxId)) mlReqMsg
msgLenLimitedTest @(R.MempoolMsg TxMsgContents) mlMempoolMsg
-- No check for (DataMsg TxMsgContents) since overal message size
-- is forcely limited
describe "Update system" $ do
describe "Bi instances" $ do
Expand Down
4 changes: 2 additions & 2 deletions lib/test/Test/Pos/Types/Identity/SafeCopySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import qualified Pos.Core.Txp as Txp

import Test.Pos.Binary.Helpers (safeCopyTest)
import Test.Pos.Configuration (withDefConfiguration)
import Test.Pos.Txp.Arbitrary ()
import Test.Pos.Txp.Arbitrary.Network ()
import Test.Pos.Core.Arbitrary.Txp ()
import Test.Pos.Infra.Arbitrary.Txp ()

spec :: Spec
spec = withDefConfiguration $ \_ -> describe "Types" $ do
Expand Down
Loading