Skip to content

Commit

Permalink
config param 16, docs and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking authored and KtorZ committed May 17, 2019
1 parent 904fe2f commit fec27f0
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions lib/jormungandr/src/Cardano/Wallet/Binary/Jormungandr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,39 @@ getTokenTransfer = do
-------------------------------------------------------------------------------}

data ConfigParam
-- Seconds elapsed since 1-Jan-1970 (unix time)
= Block0Date Word64
| ConfigDiscrimination Network
| ConsensusVersion Word16 -- ?
-- ^ The official start time of the blockchain, in seconds since the Unix
-- epoch.
| Discrimination Network
-- ^ Address discrimination. Testnet / Mainnet.
| Consensus ConsensusVersion
-- ^ Consensus version. BFT / Genesis Praos.
| SlotsPerEpoch Word32
-- ^ Number of slots in an epoch.
| SlotDuration Word8
-- ^ Slot duration in seconds.
| EpochStabilityDepth Word32
| ConsensusGenesisPraosActiveSlotsCoeff Milli
-- ^ The length of the suffix of the chain (in blocks) considered unstable.
| ConsensusGenesisPraosParamF Milli
-- ^ Determines maximum probability of a stakeholder being elected as leader
-- in a slot.
| MaxNumberOfTransactionsPerBlock Word32
-- ^ Maximum number of transactions in a block.
| BftSlotsRatio Milli
-- ^ Fraction of blocks to be created by BFT leaders.
| AddBftLeader LeaderId
-- ^ Add a BFT Leader
| RemoveBftLeader LeaderId
-- ^ Remove a BFT Leader
| AllowAccountCreation Bool
-- ^ Enable/disable account creation.
| ConfigLinearFee LinearFee
-- ^ Coefficients for fee calculations.
| ProposalExpiration Word32
-- ^ Number of epochs until an update proposal expires.
| KesUpdateSpeed Word32
-- ^ Maximum number of seconds per update for KES keys known by the system
-- after start time.
deriving (Eq, Show)

getConfigParam :: Get ConfigParam
Expand All @@ -257,21 +275,22 @@ getConfigParam = do
let len = fromIntegral $ taglen .&. (63) -- 0b111111

isolate len $ case tag of
1 -> ConfigDiscrimination <$> getNetwork
1 -> Discrimination <$> getNetwork
2 -> Block0Date <$> getWord64be
3 -> ConsensusVersion <$> getWord16be -- ?
3 -> Consensus <$> getConsensusVersion
4 -> SlotsPerEpoch <$> getWord32be
5 -> SlotDuration <$> getWord8
6 -> EpochStabilityDepth <$> getWord32be
8 -> ConsensusGenesisPraosActiveSlotsCoeff <$> getMilli
8 -> ConsensusGenesisPraosParamF <$> getMilli
9 -> MaxNumberOfTransactionsPerBlock <$> getWord32be
10 -> BftSlotsRatio <$> getMilli
11 -> AddBftLeader <$> getLeaderId
12 -> RemoveBftLeader <$> getLeaderId
13 -> AllowAccountCreation <$> getBool
14 -> ConfigLinearFee <$> getLinearFee
15 -> ProposalExpiration <$> getWord32be
a -> fail $ "Invalid config param with tag " ++ show a
16 -> KesUpdateSpeed <$> getWord32be
other -> fail $ "Invalid config param with tag " ++ show other

newtype Milli = Milli Word64
deriving (Eq, Show)
Expand All @@ -282,11 +301,20 @@ newtype LeaderId = LeaderId ByteString
data LinearFee = LinearFee Word64 Word64 Word64
deriving (Eq, Show)

data ConsensusVersion = BFT | GenesisPraos
deriving (Eq, Show)

getConsensusVersion :: Get ConsensusVersion
getConsensusVersion = getWord16be >>= \case
1 -> return BFT
2 -> return GenesisPraos
other -> fail $ "Unknown consensus version: " ++ show other

getNetwork :: Get Network
getNetwork = getWord8 >>= \case
1 -> return Mainnet
2 -> return Testnet
a -> fail $ "Invalid network/discrimination value: " ++ show a
other -> fail $ "Invalid network/discrimination value: " ++ show other

getMilli :: Get Milli
getMilli = Milli <$> getWord64be
Expand Down

0 comments on commit fec27f0

Please sign in to comment.