From b3aba75139d28e372893161e3b7385c805b3390e Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Tue, 13 Oct 2020 16:57:12 +1000 Subject: [PATCH] Revert genesis block changes from #2227 This reverts commits: - e7626ab943fcc486a336ca66e89086f020fc2bad - 6fd2291936be4db93b8216685592d063dd56dff0 - 7d201a19dbff625912f0e74f40abaaf0ceb09567 - cd8cf558e3fe2d880ada3713c5907104ea0743d6 --- .../src/Cardano/Wallet/Byron/Compatibility.hs | 68 ++++++++++++++++++- .../Cardano/Wallet/Shelley/Compatibility.hs | 49 +++---------- .../src/Cardano/Wallet/Shelley/Launch.hs | 4 +- 3 files changed, 77 insertions(+), 44 deletions(-) diff --git a/lib/shelley/src/Cardano/Wallet/Byron/Compatibility.hs b/lib/shelley/src/Cardano/Wallet/Byron/Compatibility.hs index 109a583bc30..631c645b74b 100644 --- a/lib/shelley/src/Cardano/Wallet/Byron/Compatibility.hs +++ b/lib/shelley/src/Cardano/Wallet/Byron/Compatibility.hs @@ -27,7 +27,10 @@ module Cardano.Wallet.Byron.Compatibility , mainnetVersionData , testnetVersionData + , mainnetNetworkParameters + -- * Genesis + , emptyGenesis , genesisTip , genesisBlockFromTxOuts @@ -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 @@ -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 @@ -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 diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs index 958f081b385..102a9924a5e 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs @@ -34,8 +34,6 @@ module Cardano.Wallet.Shelley.Compatibility , mainnetVersionData , testnetVersionData - , mainnetNetworkParameters - -- * Genesis , emptyGenesis , genesisTip @@ -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 @@ -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 @@ -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. @@ -315,6 +276,11 @@ emptyGenesis gp = W.Block } } +-------------------------------------------------------------------------------- +-- +-- Genesis + + genesisTip :: Tip (CardanoBlock sc) genesisTip = legacyTip genesisPoint genesisBlockNo where @@ -325,6 +291,7 @@ genesisTip = legacyTip genesisPoint genesisBlockNo -- Usage of this function should be phased out. genesisBlockNo = BlockNo 0 + -------------------------------------------------------------------------------- -- -- Network Parameters diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs index acf1bc34e2e..c0c16c23c5c 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Launch.hs @@ -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