Skip to content

Commit

Permalink
Merge #2236
Browse files Browse the repository at this point in the history
2236: Fix network parameters for both byron and shelley eras r=KtorZ a=rvl

### Issue Number

#2226 

### Overview

- [x] Revert genesis block changes from #2227
- [ ] Stop using genesis data for parameters which aren't covered by protocol parameter updates, but can change.
- [ ] Get epoch length (slots) and slot length (seconds) from HardFork History Interpreter.
- [ ] Get _ActiveSlotCoeff_ from TBD (perhaps a shelley genesis file)

### Comments

- WIP draft

Co-authored-by: Rodney Lorrimar <[email protected]>
  • Loading branch information
iohk-bors[bot] and rvl authored Oct 13, 2020
2 parents efd056b + b3aba75 commit f28289e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 44 deletions.
68 changes: 67 additions & 1 deletion lib/shelley/src/Cardano/Wallet/Byron/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ module Cardano.Wallet.Byron.Compatibility
, mainnetVersionData
, testnetVersionData

, mainnetNetworkParameters

-- * Genesis
, emptyGenesis
, genesisTip
, genesisBlockFromTxOuts

Expand Down Expand Up @@ -85,7 +88,7 @@ import Cardano.Crypto.ProtocolMagic
import Cardano.Wallet.Primitive.Slotting
( flatSlot, fromFlatSlot )
import Cardano.Wallet.Unsafe
( unsafeDeserialiseCbor )
( unsafeDeserialiseCbor, unsafeFromHex )
import Crypto.Hash.Utils
( blake2b256 )
import Data.Coerce
Expand All @@ -94,6 +97,8 @@ import Data.Quantity
( Quantity (..) )
import Data.Text
( Text )
import Data.Time.Clock.POSIX
( posixSecondsToUTCTime )
import Data.Word
( Word16, Word32 )
import GHC.Stack
Expand Down Expand Up @@ -143,10 +148,71 @@ import qualified Ouroboros.Network.Point as Point
type NodeVersionData =
(NodeToClientVersionData, CodecCBORTerm Text NodeToClientVersionData)

--------------------------------------------------------------------------------
--
-- Chain Parameters


mainnetNetworkParameters :: W.NetworkParameters
mainnetNetworkParameters = W.NetworkParameters
{ genesisParameters = W.GenesisParameters
{ getGenesisBlockHash = W.Hash $ unsafeFromHex
"5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb"
, getGenesisBlockDate =
W.StartTime $ posixSecondsToUTCTime 1506203091
, getSlotLength =
W.SlotLength 20
, getEpochLength =
W.EpochLength 21600
, getEpochStability =
Quantity 2160
, getActiveSlotCoefficient =
W.ActiveSlotCoefficient 1.0
}
, protocolParameters = W.ProtocolParameters
{ decentralizationLevel =
minBound
, txParameters = W.TxParameters
{ getFeePolicy =
W.LinearFee (Quantity 155381) (Quantity 43.946) (Quantity 0)
, getTxMaxSize =
Quantity 4096
}
, desiredNumberOfStakePools = 0
, minimumUTxOvalue = W.Coin 0
, hardforkEpochNo = Nothing
}
}

-- NOTE
-- For MainNet and TestNet, we can get away with empty genesis blocks with
-- the following assumption:
--
-- - Users won't ever restore a wallet that has genesis UTxO.
--
-- This assumption is _true_ for any user using HD wallets (sequential or
-- random) which means, any user of cardano-wallet.
emptyGenesis :: W.GenesisParameters -> W.Block
emptyGenesis gp = W.Block
{ transactions = []
, delegations = []
, header = W.BlockHeader
{ slotNo =
W.SlotNo 0
, blockHeight =
Quantity 0
, headerHash =
coerce $ W.getGenesisBlockHash gp
, parentHeaderHash =
W.Hash (BS.replicate 32 0)
}
}

--------------------------------------------------------------------------------
--
-- Genesis


genesisTip :: Tip ByronBlock
genesisTip = legacyTip genesisPoint genesisBlockNo
where
Expand Down
49 changes: 8 additions & 41 deletions lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ module Cardano.Wallet.Shelley.Compatibility
, mainnetVersionData
, testnetVersionData

, mainnetNetworkParameters

-- * Genesis
, emptyGenesis
, genesisTip
Expand Down Expand Up @@ -132,7 +130,7 @@ import Cardano.Wallet.Primitive.Types
, PoolRetirementCertificate (..)
)
import Cardano.Wallet.Unsafe
( unsafeDeserialiseCbor, unsafeFromHex, unsafeMkPercentage )
( unsafeDeserialiseCbor, unsafeMkPercentage )
import Codec.Binary.Bech32
( dataPartFromBytes, dataPartToBytes )
import Control.Applicative
Expand Down Expand Up @@ -177,8 +175,6 @@ import Data.Text
( Text )
import Data.Text.Class
( TextDecodingError (..) )
import Data.Time.Clock.POSIX
( posixSecondsToUTCTime )
import Data.Type.Equality
( testEquality )
import Data.Word
Expand Down Expand Up @@ -256,43 +252,8 @@ import qualified Shelley.Spec.Ledger.UTxO as SL
--
-- Chain Parameters

mainnetNetworkParameters :: W.NetworkParameters
mainnetNetworkParameters = W.NetworkParameters
{ genesisParameters = W.GenesisParameters
{ getGenesisBlockHash = W.Hash $ unsafeFromHex
"5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb"
, getGenesisBlockDate =
W.StartTime $ posixSecondsToUTCTime 1506203091
, getSlotLength =
W.SlotLength 1
, getEpochLength =
W.EpochLength 432000
, getEpochStability =
Quantity 2160
, getActiveSlotCoefficient =
W.ActiveSlotCoefficient 0.05
}
, protocolParameters = W.ProtocolParameters
{ decentralizationLevel =
minBound
, txParameters = W.TxParameters
{ getFeePolicy =
W.LinearFee (Quantity 155381) (Quantity 44) (Quantity 0)
, getTxMaxSize =
Quantity 4096
}
, desiredNumberOfStakePools = 0
, minimumUTxOvalue = W.Coin 0
, hardforkEpochNo = Nothing
}
}

--------------------------------------------------------------------------------
--
-- Genesis

-- NOTE
-- For Mainnet and Testnet, we can get away with empty genesis blocks with
-- For MainNet and TestNet, we can get away with empty genesis blocks with
-- the following assumption:
--
-- - Users won't ever restore a wallet that has genesis UTxO.
Expand All @@ -315,6 +276,11 @@ emptyGenesis gp = W.Block
}
}

--------------------------------------------------------------------------------
--
-- Genesis


genesisTip :: Tip (CardanoBlock sc)
genesisTip = legacyTip genesisPoint genesisBlockNo
where
Expand All @@ -325,6 +291,7 @@ genesisTip = legacyTip genesisPoint genesisBlockNo
-- Usage of this function should be phased out.
genesisBlockNo = BlockNo 0


--------------------------------------------------------------------------------
--
-- Network Parameters
Expand Down
4 changes: 2 additions & 2 deletions lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ parseGenesisData = \case
MainnetConfig -> do
pure
( SomeNetworkDiscriminant $ Proxy @'Mainnet
, Shelley.mainnetNetworkParameters
, Byron.mainnetNetworkParameters
, Byron.mainnetVersionData
, Shelley.emptyGenesis (genesisParameters Shelley.mainnetNetworkParameters)
, Byron.emptyGenesis (genesisParameters Byron.mainnetNetworkParameters)
)

TestnetConfig byronGenesisFile -> do
Expand Down

0 comments on commit f28289e

Please sign in to comment.