Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ci skip][skip ci][skip netlify] -bors-staging-tmp-1827
  • Loading branch information
iohk-bors[bot] committed Jul 2, 2020
2 parents a082564 + 499d4eb commit 262bd84
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 85 deletions.
2 changes: 2 additions & 0 deletions lib/byron/src/Cardano/Wallet/Byron/Compatibility.hs
Expand Up @@ -189,6 +189,7 @@ mainnetNetworkParameters = W.NetworkParameters
, getTxMaxSize =
Quantity 4096
}
, desiredNumberOfStakePools = 0
}
}

Expand Down Expand Up @@ -429,6 +430,7 @@ protocolParametersFromPP pp = W.ProtocolParameters
{ getFeePolicy = fromTxFeePolicy $ Update.ppTxFeePolicy pp
, getTxMaxSize = fromMaxTxSize $ Update.ppMaxTxSize pp
}
, desiredNumberOfStakePools = 0
}

-- | Extract the protocol parameters relevant to the wallet out of the
Expand Down
Expand Up @@ -36,5 +36,7 @@ spec = do
r <- request @ApiNetworkParameters ctx Link.getNetworkParams Default Empty
expectResponseCode @IO HTTP.status200 r
let Right d = Quantity <$> mkPercentage (3 % 4)
let nOpt = 3
verify r
[ expectField (#decentralizationLevel) (`shouldBe` d) ]
[ expectField (#decentralizationLevel) (`shouldBe` d)
, expectField (#desiredPoolNumber) (`shouldBe` nOpt)]
4 changes: 3 additions & 1 deletion lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -232,7 +232,7 @@ import Data.Time.Clock
import Data.Time.Text
( iso8601, iso8601ExtendedUtc, utcTimeFromText, utcTimeToText )
import Data.Word
( Word32, Word64 )
( Word16, Word32, Word64 )
import Data.Word.Odd
( Word31 )
import Fmt
Expand Down Expand Up @@ -502,6 +502,7 @@ data ApiNetworkParameters = ApiNetworkParameters
, epochStability :: !(Quantity "block" Word32)
, activeSlotCoefficient :: !(Quantity "percent" Double)
, decentralizationLevel :: !(Quantity "percent" Percentage)
, desiredPoolNumber :: !Word16
} deriving (Eq, Generic, Show)

toApiNetworkParameters :: NetworkParameters -> ApiNetworkParameters
Expand All @@ -516,6 +517,7 @@ toApiNetworkParameters (NetworkParameters gp pp) = ApiNetworkParameters
$ unActiveSlotCoefficient
$ getActiveSlotCoefficient gp)
(Quantity $ unDecentralizationLevel $ view #decentralizationLevel pp)
(view #desiredNumberOfStakePools pp)

newtype ApiTxId = ApiTxId
{ id :: ApiT (Hash "Tx")
Expand Down
12 changes: 8 additions & 4 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Expand Up @@ -1003,18 +1003,22 @@ mkProtocolParametersEntity
-> W.ProtocolParameters
-> ProtocolParameters
mkProtocolParametersEntity wid pp =
ProtocolParameters wid fp (getQuantity mx) dl
ProtocolParameters wid fp (getQuantity mx) dl desiredPoolNum
where
(W.ProtocolParameters (W.DecentralizationLevel dl) (W.TxParameters fp mx)) =
pp
(W.ProtocolParameters
(W.DecentralizationLevel dl)
(W.TxParameters fp mx)
desiredPoolNum
) = pp

protocolParametersFromEntity
:: ProtocolParameters
-> W.ProtocolParameters
protocolParametersFromEntity (ProtocolParameters _ fp mx dl) =
protocolParametersFromEntity (ProtocolParameters _ fp mx dl poolNum) =
W.ProtocolParameters
(W.DecentralizationLevel dl)
(W.TxParameters fp (Quantity mx))
poolNum

{-------------------------------------------------------------------------------
DB Queries
Expand Down
9 changes: 5 additions & 4 deletions lib/core/src/Cardano/Wallet/DB/Sqlite/TH.hs
Expand Up @@ -147,10 +147,11 @@ Checkpoint
deriving Show Generic

ProtocolParameters
protocolParametersWalletId W.WalletId sql=wallet_id
protocolParametersFeePolicy W.FeePolicy sql=fee_policy
protocolParametersTxMaxSize Word16 sql=tx_max_size
protocolParametersDecentralizationLevel Percentage sql=decentralization_level
protocolParametersWalletId W.WalletId sql=wallet_id
protocolParametersFeePolicy W.FeePolicy sql=fee_policy
protocolParametersTxMaxSize Word16 sql=tx_max_size
protocolParametersDecentralizationLevel Percentage sql=decentralization_level
protocolParametersDesiredNumberOfPools Word16 sql=desired_pool_number
Primary protocolParametersWalletId
Foreign Wallet fk_wallet_protocol_parameters protocolParametersWalletId ! ON DELETE CASCADE
deriving Show Generic
Expand Down
5 changes: 5 additions & 0 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Expand Up @@ -1401,6 +1401,10 @@ data ProtocolParameters = ProtocolParameters
, txParameters
:: TxParameters
-- ^ Parameters that affect transaction construction.
, desiredNumberOfStakePools
:: Word16
-- ^ The current desired number of stakepools in the network.
-- Also known as k parameter.
} deriving (Eq, Generic, Show)

instance NFData ProtocolParameters
Expand All @@ -1409,6 +1413,7 @@ instance Buildable ProtocolParameters where
build pp = blockListF' "" id
[ "Decentralization level: " <> build (pp ^. #decentralizationLevel)
, "Transaction parameters: " <> build (pp ^. #txParameters)
, "Desired number of pools: " <> build (pp ^. #desiredNumberOfStakePools)
]

-- | Indicates the current level of decentralization in the network.
Expand Down

0 comments on commit 262bd84

Please sign in to comment.