Skip to content

Commit

Permalink
Update to latest ouroboros-network
Browse files Browse the repository at this point in the history
  • Loading branch information
redxaxder authored and Jimbo4350 committed Mar 2, 2021
1 parent 9de088d commit 5a7a3bb
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 127 deletions.
8 changes: 4 additions & 4 deletions cabal.project
Expand Up @@ -111,8 +111,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 99e2f2e32ebfca3291fa523ddcae14c8cbb48fa0
--sha256: 0fy8y7cp10ls8p3zs2fqzqpd41vri6z0imhyif5wa9bi2rp57i3z
tag: a4eaf8819515003e287c8960817d2599cfdda1c6
--sha256: 0ayq5xaxdf6c5y524c3gz3052dcclqf93kiwf1zhpmq6q960l45y
subdir:
byron/chain/executable-spec
byron/crypto
Expand Down Expand Up @@ -160,8 +160,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: 96cf17bcc6ea4ef455a19430313ce17d476d62b5
--sha256: 00xp605lb8qp1jhp43mg7818x8yzn2rnsd18qcy5721yj4q675nz
tag: a8e3ad077e7a84727381a0a4d930450116209f95
--sha256: 04dp49hnk473fz1pa0n6chs1x69x01l7fjsxhrajqcijmksdi9f9
subdir:
io-sim
io-sim-classes
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/cardano-api.cabal
Expand Up @@ -87,7 +87,7 @@ library
, cardano-crypto
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-ledger
, cardano-ledger-byron
, cardano-ledger-shelley-ma
, cardano-prelude
, cardano-slotting
Expand Down Expand Up @@ -157,7 +157,7 @@ test-suite cardano-api-test
, cardano-crypto-test
, cardano-crypto-tests
, cardano-crypto-wrapper
, cardano-ledger-test
, cardano-ledger-byron-test
, cardano-prelude
, cardano-prelude-test
, cardano-slotting
Expand Down
78 changes: 54 additions & 24 deletions cardano-api/src/Cardano/Api/Orphans.hs
Expand Up @@ -17,6 +17,7 @@ import qualified Data.Aeson as Aeson
import Data.Aeson.Types (ToJSONKey (..), toJSONKeyText)
import qualified Data.ByteString.Base16 as B16
import qualified Data.Map.Strict as Map
import Data.Scientific
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
Expand All @@ -25,14 +26,17 @@ import qualified Cardano.Crypto.Hash.Class as Crypto
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Crypto as Crypto
import qualified Cardano.Ledger.Mary.Value as Mary
import qualified Cardano.Ledger.SafeHash as SafeHash
import qualified Cardano.Ledger.Shelley.Constraints as Shelley
import Cardano.Slotting.Slot (SlotNo (..))
import qualified Ouroboros.Consensus.Shelley.Eras as Consensus
import qualified Shelley.Spec.Ledger.API as Shelley
import Shelley.Spec.Ledger.BaseTypes (StrictMaybe)
import Shelley.Spec.Ledger.BaseTypes (StrictMaybe (..))
import qualified Shelley.Spec.Ledger.Coin as Shelley
import qualified Shelley.Spec.Ledger.Delegation.Certificates as Shelley
import qualified Shelley.Spec.Ledger.EpochBoundary as ShelleyEpoch
import qualified Shelley.Spec.Ledger.LedgerState as ShelleyLedger
import Shelley.Spec.Ledger.PParams (PParamsUpdate)
import qualified Shelley.Spec.Ledger.Rewards as Shelley

-- Orphan instances involved in the JSON output of the API queries.
Expand Down Expand Up @@ -68,6 +72,8 @@ instance ToJSON Shelley.AccountState where

instance ( Consensus.ShelleyBasedEra era
, ToJSON (Core.TxOut era)
, ToJSON (Core.PParams era)
, ToJSON (Shelley.PParamsDelta era)
) => ToJSON (Shelley.EpochState era) where
toJSON eState = object [ "esAccountState" .= Shelley.esAccountState eState
, "esSnapshots" .= Shelley.esSnapshots eState
Expand All @@ -79,48 +85,58 @@ instance ( Consensus.ShelleyBasedEra era

instance ( Consensus.ShelleyBasedEra era
, ToJSON (Core.TxOut era)
, ToJSON (Shelley.PParamsDelta era)
) => ToJSON (Shelley.LedgerState era) where
toJSON lState = object [ "utxoState" .= Shelley._utxoState lState
, "delegationState" .= Shelley._delegationState lState
]

instance ( Consensus.ShelleyBasedEra era
, ToJSON (Core.TxOut era)
, ToJSON (Shelley.PParamsDelta era)
) => ToJSON (Shelley.UTxOState era) where
toJSON utxoState = object [ "utxo" .= Shelley._utxo utxoState
, "deposited" .= Shelley._deposited utxoState
, "fees" .= Shelley._fees utxoState
, "ppups" .= Shelley._ppups utxoState
]

instance ToJSON (Shelley.PPUPState era) where
instance ( ToJSON (Shelley.PParamsDelta era)
, Shelley.UsesPParams era
) => ToJSON (Shelley.PPUPState era) where
toJSON ppUpState = object [ "proposals" .= Shelley.proposals ppUpState
, "futureProposals" .= Shelley.futureProposals ppUpState
]

instance ToJSON (Shelley.ProposedPPUpdates era) where
instance ( ToJSON (Shelley.PParamsDelta era)
, Shelley.UsesPParams era
) => ToJSON (Shelley.ProposedPPUpdates era) where
toJSON (Shelley.ProposedPPUpdates ppUpdates) = toJSON $ Map.toList ppUpdates

instance ToJSON (Shelley.PParams' StrictMaybe era) where
toJSON pparams =
object [ "minfeeA" .= Shelley._minfeeA pparams
, "minfeeB" .= Shelley._minfeeB pparams
, "maxBBSize" .= Shelley._maxBBSize pparams
, "maxTxSize" .= Shelley._maxTxSize pparams
, "maxBHSize" .= Shelley._maxBHSize pparams
, "keyDeposit" .= Shelley._keyDeposit pparams
, "poolDeposit" .= Shelley._poolDeposit pparams
, "eMax" .= Shelley._eMax pparams
, "nOpt" .= Shelley._nOpt pparams
, "a0" .= Shelley._a0 pparams
, "rho" .= Shelley._rho pparams
, "tau" .= Shelley._tau pparams
, "d" .= Shelley._d pparams
, "extraEntropy" .= Shelley._extraEntropy pparams
, "protocolVersion" .= Shelley._protocolVersion pparams
, "minUTxOValue" .= Shelley._minUTxOValue pparams
, "minPoolCost" .= Shelley._minPoolCost pparams
]
instance ToJSON (PParamsUpdate era) where
toJSON pp =
Aeson.object $
[ "minFeeA" .= x | x <- mbfield (Shelley._minfeeA pp) ]
++ [ "minFeeB" .= x | x <- mbfield (Shelley._minfeeB pp) ]
++ [ "maxBlockBodySize" .= x | x <- mbfield (Shelley._maxBBSize pp) ]
++ [ "maxTxSize" .= x | x <- mbfield (Shelley._maxTxSize pp) ]
++ [ "maxBlockHeaderSize" .= x | x <- mbfield (Shelley._maxBHSize pp) ]
++ [ "keyDeposit" .= x | x <- mbfield (Shelley._keyDeposit pp) ]
++ [ "poolDeposit" .= x | x <- mbfield (Shelley._poolDeposit pp) ]
++ [ "eMax" .= x | x <- mbfield (Shelley._eMax pp) ]
++ [ "nOpt" .= x | x <- mbfield (Shelley._nOpt pp) ]
++ [ "a0" .= (fromRational x :: Scientific)
| x <- mbfield (Shelley._a0 pp) ]
++ [ "rho" .= x | x <- mbfield (Shelley._rho pp) ]
++ [ "tau" .= x | x <- mbfield (Shelley._tau pp) ]
++ [ "decentralisationParam" .= x | x <- mbfield (Shelley._d pp) ]
++ [ "extraEntropy" .= x | x <- mbfield (Shelley._extraEntropy pp) ]
++ [ "protocolVersion" .= x | x <- mbfield (Shelley._protocolVersion pp) ]
++ [ "minUTxOValue" .= x | x <- mbfield (Shelley._minUTxOValue pp) ]
++ [ "minPoolCost" .= x | x <- mbfield (Shelley._minPoolCost pp) ]
where
mbfield SNothing = []
mbfield (SJust x) = [x]

instance Crypto.Crypto crypto => ToJSON (Shelley.DPState crypto) where
toJSON dpState = object [ "dstate" .= Shelley._dstate dpState
Expand Down Expand Up @@ -191,7 +207,7 @@ instance Crypto.Crypto crypto => ToJSONKey (Shelley.TxIn crypto) where

txInToText :: Crypto.Crypto crypto => Shelley.TxIn crypto -> Text
txInToText (Shelley.TxIn (Shelley.TxId txidHash) ix) =
hashToText txidHash
hashToText (SafeHash.extractHash txidHash)
<> Text.pack "#"
<> Text.pack (show ix)

Expand Down Expand Up @@ -243,3 +259,17 @@ instance ToJSON (Shelley.IndividualPoolStake crypto) where
, "individualPoolStakeVrf" .= Shelley.individualPoolStakeVrf indivPoolStake
]

instance ToJSON (Shelley.Reward crypto) where
toJSON reward =
object [ "rewardType" .= Shelley.rewardType reward
, "rewardPool" .= Shelley.rewardPool reward
, "rewardAmount" .= Shelley.rewardAmount reward
]

instance ToJSON Shelley.RewardType where
toJSON Shelley.MemberReward = "MemberReward"
toJSON Shelley.LeaderReward = "LeaderReward"

instance ToJSON (SafeHash.SafeHash c a) where
toJSON = toJSON . SafeHash.extractHash

28 changes: 21 additions & 7 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs
Expand Up @@ -66,6 +66,7 @@ import qualified Cardano.Crypto.Hash.Class as Crypto
import Cardano.Slotting.Slot (EpochNo, EpochSize (..))

import qualified Cardano.Ledger.Era as Ledger
import qualified Cardano.Ledger.Shelley.Constraints as Shelley
import Ouroboros.Consensus.Shelley.Eras (StandardShelley)
import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)

Expand Down Expand Up @@ -563,19 +564,26 @@ data GenesisParameters =
-- Conversion functions
--

toShelleyUpdate :: Ledger.Crypto ledgerera ~ StandardCrypto
toShelleyUpdate :: ( Ledger.Crypto ledgerera ~ StandardCrypto
, Shelley.PParamsDelta ledgerera
~ Shelley.PParamsUpdate ledgerera
)
=> UpdateProposal -> Shelley.Update ledgerera
toShelleyUpdate (UpdateProposal ppup epochno) =
Shelley.Update (toShelleyProposedPPUpdates ppup) epochno


toShelleyProposedPPUpdates :: Ledger.Crypto ledgerera ~ StandardCrypto
=> Map (Hash GenesisKey) ProtocolParametersUpdate
-> Shelley.ProposedPPUpdates ledgerera
toShelleyProposedPPUpdates :: forall ledgerera.
( Ledger.Crypto ledgerera ~ StandardCrypto
, Shelley.PParamsDelta ledgerera
~ Shelley.PParamsUpdate ledgerera
)
=> Map (Hash GenesisKey) ProtocolParametersUpdate
-> Shelley.ProposedPPUpdates ledgerera
toShelleyProposedPPUpdates =
Shelley.ProposedPPUpdates
. Map.mapKeysMonotonic (\(GenesisKeyHash kh) -> kh)
. Map.map toShelleyPParamsUpdate
. Map.map (toShelleyPParamsUpdate @ledgerera)


toShelleyPParamsUpdate :: ProtocolParametersUpdate
Expand Down Expand Up @@ -629,13 +637,19 @@ toShelleyPParamsUpdate
maybeToStrictMaybe protocolUpdateMinPoolCost
}

fromShelleyUpdate :: Ledger.Crypto ledgerera ~ StandardCrypto
fromShelleyUpdate :: ( Ledger.Crypto ledgerera ~ StandardCrypto
, Shelley.PParamsDelta ledgerera
~ Shelley.PParamsUpdate ledgerera
)
=> Shelley.Update ledgerera -> UpdateProposal
fromShelleyUpdate (Shelley.Update ppup epochno) =
UpdateProposal (fromShelleyProposedPPUpdates ppup) epochno


fromShelleyProposedPPUpdates :: Ledger.Crypto ledgerera ~ StandardCrypto
fromShelleyProposedPPUpdates :: ( Ledger.Crypto ledgerera ~ StandardCrypto
, Shelley.PParamsDelta ledgerera
~ Shelley.PParamsUpdate ledgerera
)
=> Shelley.ProposedPPUpdates ledgerera
-> Map (Hash GenesisKey) ProtocolParametersUpdate
fromShelleyProposedPPUpdates =
Expand Down
6 changes: 6 additions & 0 deletions cardano-api/src/Cardano/Api/Query.hs
Expand Up @@ -66,6 +66,8 @@ import qualified Cardano.Ledger.Era as Ledger

import qualified Shelley.Spec.Ledger.API as Shelley
import qualified Shelley.Spec.Ledger.LedgerState as Shelley
import qualified Shelley.Spec.Ledger.PParams as Shelley
import qualified Cardano.Ledger.Shelley.Constraints as Shelley

import Cardano.Api.Address
import Cardano.Api.Block
Expand Down Expand Up @@ -181,6 +183,8 @@ instance (Typeable era, Shelley.TransLedgerState FromCBOR (ShelleyLedgerEra era)
instance ( IsShelleyBasedEra era
, ShelleyLedgerEra era ~ ledgerera
, Consensus.ShelleyBasedEra ledgerera
, ToJSON (Core.PParams ledgerera)
, ToJSON (Shelley.PParamsDelta ledgerera)
, ToJSON (Core.TxOut ledgerera)) => ToJSON (LedgerState era) where
toJSON (LedgerState newEpochS) = object [ "lastEpoch" .= Shelley.nesEL newEpochS
, "blocksBefore" .= Shelley.nesBprev newEpochS
Expand Down Expand Up @@ -423,6 +427,8 @@ fromConsensusQueryResult (QueryInEra MaryEraInCardanoMode
fromConsensusQueryResultShelleyBased
:: forall era ledgerera result result'.
ShelleyLedgerEra era ~ ledgerera
=> Shelley.PParams ledgerera ~ Core.PParams ledgerera
=> Shelley.PParamsDelta ledgerera ~ Shelley.PParamsUpdate ledgerera
=> Consensus.ShelleyBasedEra ledgerera
=> Ledger.Crypto ledgerera ~ Consensus.StandardCrypto
=> ShelleyBasedEra era
Expand Down
45 changes: 23 additions & 22 deletions cardano-api/src/Cardano/Api/Tx.hs
Expand Up @@ -87,11 +87,11 @@ import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)

import qualified Cardano.Ledger.Core as Ledger
import qualified Cardano.Ledger.Era as Ledger
import qualified Cardano.Ledger.SafeHash as Ledger
import qualified Cardano.Ledger.Shelley.Constraints as Shelley

import qualified Shelley.Spec.Ledger.Address.Bootstrap as Shelley
import Shelley.Spec.Ledger.BaseTypes (maybeToStrictMaybe, strictMaybeToMaybe)
import qualified Shelley.Spec.Ledger.Hashing as Shelley
import qualified Shelley.Spec.Ledger.Keys as Shelley
import qualified Shelley.Spec.Ledger.Tx as Shelley

Expand Down Expand Up @@ -586,19 +586,21 @@ makeShelleyBootstrapWitness _ ByronTxBody{} _ =

makeShelleyBootstrapWitness nwOrAddr (ShelleyTxBody era txbody _) sk =
case era of
ShelleyBasedEraShelley -> makeShelleyBasedBootstrapWitness era
nwOrAddr txbody sk
ShelleyBasedEraAllegra -> makeShelleyBasedBootstrapWitness era
nwOrAddr txbody sk
ShelleyBasedEraMary -> makeShelleyBasedBootstrapWitness era
nwOrAddr txbody sk

makeShelleyBasedBootstrapWitness :: forall era ledgerera.
Shelley.ShelleyBased ledgerera
=> Ledger.Crypto ledgerera ~ StandardCrypto
ShelleyBasedEraShelley ->
makeShelleyBasedBootstrapWitness era nwOrAddr txbody sk
ShelleyBasedEraAllegra ->
makeShelleyBasedBootstrapWitness era nwOrAddr txbody sk
ShelleyBasedEraMary ->
makeShelleyBasedBootstrapWitness era nwOrAddr txbody sk

makeShelleyBasedBootstrapWitness :: forall era.
(Ledger.HashAnnotated
(Ledger.TxBody (ShelleyLedgerEra era))
Ledger.EraIndependentTxBody
StandardCrypto)
=> ShelleyBasedEra era
-> WitnessNetworkIdOrByronAddress
-> Ledger.TxBody ledgerera
-> Ledger.TxBody (ShelleyLedgerEra era)
-> SigningKey ByronKey
-> Witness era
makeShelleyBasedBootstrapWitness era nwOrAddr txbody (ByronSigningKey sk) =
Expand All @@ -625,14 +627,14 @@ makeShelleyBasedBootstrapWitness era nwOrAddr txbody (ByronSigningKey sk) =
-- reuse that here.
--
signature :: Shelley.SignedDSIGN StandardCrypto
(Shelley.Hash StandardCrypto Shelley.EraIndependentTxBody)
(Shelley.Hash StandardCrypto Ledger.EraIndependentTxBody)
signature = makeShelleySignature
txhash
-- Make the signature with the extended key directly:
(ShelleyExtendedSigningKey (Byron.unSigningKey sk))

txhash :: Shelley.Hash StandardCrypto Shelley.EraIndependentTxBody
txhash = Shelley.hashAnnotated txbody
txhash :: Shelley.Hash StandardCrypto Ledger.EraIndependentTxBody
txhash = Ledger.extractHash (Ledger.hashAnnotated txbody)
--TODO: use Shelley.eraIndTxBodyHash txbody once that function has a
-- suitably general type.

Expand Down Expand Up @@ -688,8 +690,8 @@ data ShelleyWitnessSigningKey =
| WitnessGenesisUTxOKey (SigningKey GenesisUTxOKey)


makeShelleyKeyWitness :: forall era.
IsShelleyBasedEra era
makeShelleyKeyWitness :: forall era
. IsShelleyBasedEra era
=> TxBody era
-> ShelleyWitnessSigningKey
-> Witness era
Expand All @@ -699,16 +701,15 @@ makeShelleyKeyWitness (ShelleyTxBody era txbody _) =
ShelleyBasedEraAllegra -> makeShelleyBasedKeyWitness txbody
ShelleyBasedEraMary -> makeShelleyBasedKeyWitness txbody
where
makeShelleyBasedKeyWitness :: forall ledgerera.
Shelley.ShelleyBased ledgerera
=> Ledger.Crypto ledgerera ~ StandardCrypto
makeShelleyBasedKeyWitness :: Shelley.ShelleyBased ledgerera
=> ShelleyLedgerEra era ~ ledgerera
=> Ledger.TxBody ledgerera
-> ShelleyWitnessSigningKey
-> Witness era
makeShelleyBasedKeyWitness txbody' =

let txhash :: Shelley.Hash StandardCrypto Shelley.EraIndependentTxBody
txhash = Shelley.hashAnnotated txbody'
let txhash :: Shelley.Hash StandardCrypto Ledger.EraIndependentTxBody
txhash = Ledger.extractHash (Ledger.hashAnnotated txbody')

-- To allow sharing of the txhash computation across many signatures we
-- define and share the txhash outside the lambda for the signing key:
Expand Down

0 comments on commit 5a7a3bb

Please sign in to comment.