Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validators module #253

Merged
merged 6 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ endBlock _ = do
pure $ EndBlockResult (map convertToValUp (Map.assocs updatesMap)) Nothing
where
convertToValUp (PubKey_ key, power) =
ABCI.ValidatorUpdate key (ABCI.WrappedVal (fromIntegral power))
ABCI.ValidatorUpdate (Just key) (ABCI.WrappedVal (fromIntegral power))
7 changes: 4 additions & 3 deletions hs-abci-sdk/src/Tendermint/SDK/Modules/Validators/Keeper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Tendermint.SDK.Modules.Validators.Keeper where

import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import Data.Maybe (fromJust, fromMaybe)
import qualified Data.Set as Set
import Data.Word (Word64)
import Network.ABCI.Types.Messages.FieldTypes
Expand Down Expand Up @@ -57,17 +57,18 @@ getQueuedUpdatesF
:: Members [ReadStore, Error AppError] r
=> Sem r (Map.Map PubKey_ Word64)
getQueuedUpdatesF = L.foldl (\m (ValidatorUpdate_ ValidatorUpdate{..}) ->
Map.alter (Just . fromMaybe (toWord validatorUpdatePower)) (PubKey_ validatorUpdatePubKey) m) Map.empty updatesList
Map.alter (Just . fromMaybe (toWord validatorUpdatePower)) (toPK_ validatorUpdatePubKey) m) Map.empty updatesList
where
toWord (WrappedVal x) = fromIntegral x
toPK_ = PubKey_ . fromJust
martyall marked this conversation as resolved.
Show resolved Hide resolved

queueUpdateF
:: Members [ReadStore, WriteStore, Error AppError] r
=> PubKey_
-> Word64
-> Sem r ()
queueUpdateF (PubKey_ key) power =
L.append (ValidatorUpdate_(ValidatorUpdate key (wrapInt power))) updatesList
L.append (ValidatorUpdate_(ValidatorUpdate (Just key) (wrapInt power))) updatesList
where
wrapInt p = WrappedVal (fromIntegral p)

6 changes: 3 additions & 3 deletions hs-abci-types/src/Network/ABCI/Types/Messages/FieldTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ instance Wrapped PubKey where
}

data ValidatorUpdate = ValidatorUpdate
{ validatorUpdatePubKey :: PubKey
{ validatorUpdatePubKey :: Maybe PubKey
-- ^ Public key of the validator
, validatorUpdatePower :: WrappedVal Int64
-- ^ Voting power of the validator
Expand All @@ -286,11 +286,11 @@ instance Wrapped ValidatorUpdate where
where
t ValidatorUpdate{..} =
defMessage
& PT.pubKey .~ validatorUpdatePubKey ^. _Wrapped'
& PT.maybe'pubKey .~ validatorUpdatePubKey ^? _Just . _Wrapped'
& PT.power .~ unWrappedVal validatorUpdatePower
f a =
ValidatorUpdate
{ validatorUpdatePubKey = a ^. PT.pubKey . _Unwrapped'
{ validatorUpdatePubKey = a ^? PT.maybe'pubKey . _Just . _Unwrapped'
, validatorUpdatePower = WrappedVal $ a ^. PT.power
}

Expand Down