-
Notifications
You must be signed in to change notification settings - Fork 39
Integrate cardano-ledger for node-8.11.0
#1069
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
Changes from all commits
1fc53f3
2353df1
18f186d
5958f1c
0fc34d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ### Patch | ||
|
|
||
| - Update `SupportsTwoPhaseValidation` instance for `Conway`: | ||
| `ConwayUtxowFailure` was changed upstream | ||
|
|
||
| ### Non-Breaking | ||
|
|
||
| - Update ledger packages: | ||
| - `cardano-ledger-alonzo`: `^>=1.8` | ||
| - `cardano-ledger-babbage`: `^>=1.8` | ||
| - `cardano-ledger-conway`: `^>=1.14` | ||
| - `cardano-ledger-core`: `^>=1.12` | ||
| - `cardano-ledger-mary`: `^>=1.6` | ||
| - `cardano-ledger-shelley`: `^>=1.11` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <!-- | ||
| A new scriv changelog fragment. | ||
|
|
||
| Uncomment the section that is right (remove the HTML comment wrapper). | ||
| --> | ||
|
|
||
| <!-- | ||
| ### Patch | ||
|
|
||
| - A bullet item for the Patch category. | ||
|
|
||
| --> | ||
| <!-- | ||
| ### Non-Breaking | ||
|
|
||
| - A bullet item for the Non-Breaking category. | ||
|
|
||
| --> | ||
|
|
||
| ### Breaking | ||
|
|
||
| - Remove `getProposedProtocolVersion` and `defaultGetProposedProtocolVersion` | ||
| - Remove `ProtocolUpdate`, `UpdateProposal`, `UpdateState` and `protocolUpdates` | ||
| - Add `pparamsUpdate` | ||
| - Change `ShelleyLedgerUpdate` by replacing `ShelleyUpdatedProtocolUpdates` with `ShelleyUpdatedPParams` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,166 +8,55 @@ | |
|
|
||
| {-# OPTIONS_GHC -Wno-orphans #-} | ||
| module Ouroboros.Consensus.Shelley.Ledger.Inspect ( | ||
| ProtocolUpdate (..) | ||
| , ShelleyLedgerUpdate (..) | ||
| , UpdateProposal (..) | ||
| , UpdateState (..) | ||
| , protocolUpdates | ||
| ShelleyLedgerUpdate (..) | ||
| , pparamsUpdate | ||
| ) where | ||
|
|
||
| import Cardano.Ledger.BaseTypes (StrictMaybe (..)) | ||
| import qualified Cardano.Ledger.Shelley.API as SL | ||
| import qualified Cardano.Ledger.Shelley.Core as Core | ||
| import qualified Cardano.Ledger.Shelley.Governance as SL | ||
| import qualified Cardano.Ledger.Shelley.LedgerState as SL | ||
| import qualified Cardano.Ledger.Shelley.PParams as SL | ||
| import Control.Monad | ||
| import Data.Map.Strict (Map) | ||
| import qualified Data.Map.Strict as Map | ||
| import Data.Maybe (fromMaybe) | ||
| import Data.Void | ||
| import Data.Word (Word64) | ||
| import Lens.Micro.Extras (view) | ||
| import Lens.Micro ((^.)) | ||
| import Ouroboros.Consensus.Block | ||
| import Ouroboros.Consensus.Config | ||
| import Ouroboros.Consensus.Ledger.Abstract | ||
| import Ouroboros.Consensus.Ledger.Inspect | ||
| import Ouroboros.Consensus.Shelley.Eras (EraCrypto, | ||
| ShelleyBasedEra (..)) | ||
| import Ouroboros.Consensus.Shelley.Ledger.Block | ||
| import Ouroboros.Consensus.Shelley.Ledger.Ledger | ||
| import Ouroboros.Consensus.Util.Condense | ||
|
|
||
| data ProtocolUpdate era = ProtocolUpdate { | ||
| protocolUpdateProposal :: UpdateProposal era | ||
| , protocolUpdateState :: UpdateState (EraCrypto era) | ||
| } | ||
| deriving instance Eq (Core.PParamsUpdate era) => Eq (ProtocolUpdate era) | ||
| deriving instance Show (Core.PParamsUpdate era) => Show (ProtocolUpdate era) | ||
|
|
||
| -- | Update proposal | ||
| -- | ||
| -- As in Byron, a proposal is a partial map from parameters to their values. | ||
| data UpdateProposal era = UpdateProposal { | ||
| -- | The protocol parameters changed by this update proposal | ||
| -- | ||
| -- An update is /identified/ by how it updates the protocol parameters. | ||
| proposalParams :: Core.PParamsUpdate era | ||
|
|
||
| -- | New version (if changed by this proposal) | ||
| -- | ||
| -- The protocol version itself is also considered to be just another | ||
| -- parameter, and parameters can change /without/ changing the protocol | ||
| -- version, although a convention /could/ be established that the protocol | ||
| -- version must change if any of the parameters do; but the specification | ||
| -- itself does not mandate this. | ||
| -- | ||
| -- We record the version separately for the convenience of the HFC. | ||
| , proposalVersion :: Maybe SL.ProtVer | ||
|
|
||
| -- | The 'EpochNo' the proposal becomes active in, if it is adopted | ||
| , proposalEpoch :: EpochNo | ||
| } | ||
|
|
||
| deriving instance Eq (Core.PParamsUpdate era) => Eq (UpdateProposal era) | ||
| deriving instance Show (Core.PParamsUpdate era) => Show (UpdateProposal era) | ||
|
|
||
| -- | Proposal state | ||
| -- | ||
| -- The update mechanism in Shelley is simpler than it is in Byron. There is no | ||
| -- distinction between votes and proposals: to \"vote\" for a proposal one | ||
| -- merely submits the exact same proposal. There is also no separate | ||
| -- endorsement step. The procedure is as follows: | ||
| -- | ||
| -- 1. During each epoch, a genesis key can submit (via its delegates) zero, | ||
| -- one, or many proposals; each submission overrides the previous one. | ||
| -- 2. \"Voting\" (submitting of proposals) ends @2 * stabilityWindow@ slots | ||
| -- (i.e. @6k/f@) before the end of the epoch. In other words, proposals | ||
| -- for the upcoming epoch must be submitted within the first @4k/f@ slots | ||
| -- of this one. | ||
| -- 3. At the end of an epoch, if the majority of nodes (as determined by the | ||
| -- @Quorum@ specification constant, which must be greater than half the | ||
| -- nodes) have most recently submitted the same exact proposal, then it is | ||
| -- adopted. | ||
| -- 4. The next epoch is always started with a clean slate, proposals from the | ||
| -- previous epoch that didn't make it are discarded (except for "future | ||
| -- proposals" that are explicitly marked for future epochs). | ||
| data UpdateState c = UpdateState { | ||
| -- | The genesis delegates that voted for this proposal | ||
| proposalVotes :: [SL.KeyHash 'SL.Genesis c] | ||
|
|
||
| -- | Has this proposal reached sufficient votes to be adopted? | ||
| , proposalReachedQuorum :: Bool | ||
| } | ||
| deriving (Show, Eq) | ||
|
|
||
| protocolUpdates :: | ||
| forall era proto. ShelleyBasedEra era | ||
| => SL.ShelleyGenesis (EraCrypto era) | ||
| -> LedgerState (ShelleyBlock proto era) | ||
| -> [ProtocolUpdate era] | ||
| protocolUpdates genesis st = [ | ||
| ProtocolUpdate { | ||
| protocolUpdateProposal = UpdateProposal { | ||
| proposalParams = proposal | ||
| , proposalEpoch = succ currentEpoch | ||
| , proposalVersion = getProposedProtocolVersion proposal | ||
| } | ||
| , protocolUpdateState = UpdateState { | ||
| proposalVotes = votes | ||
| , proposalReachedQuorum = length votes >= fromIntegral quorum | ||
| } | ||
| } | ||
| | (proposal, votes) <- Map.toList $ invertMap proposals | ||
| ] | ||
| where | ||
| invertMap :: Ord b => Map a b -> Map b [a] | ||
| invertMap = Map.fromListWith (<>) . fmap swizzle . Map.toList | ||
| where | ||
| swizzle (a, b) = (b, [a]) | ||
|
|
||
| -- Updated proposed within the proposal window | ||
| proposals :: Map (SL.KeyHash 'SL.Genesis (EraCrypto era)) (Core.PParamsUpdate era) | ||
| SL.ProposedPPUpdates proposals = | ||
| fromMaybe SL.emptyPPPUpdates | ||
| . Core.getProposedPPUpdates | ||
| . view SL.newEpochStateGovStateL | ||
| . shelleyLedgerState | ||
| $ st | ||
|
|
||
| -- A proposal is accepted if the number of votes is equal to or greater | ||
| -- than the quorum. The quorum itself must be strictly greater than half | ||
| -- the number of genesis keys, but we do not rely on that property here. | ||
| quorum :: Word64 | ||
| quorum = SL.sgUpdateQuorum genesis | ||
|
|
||
| -- The proposals in 'SL.proposals' are for the upcoming epoch | ||
| -- (we ignore 'futureProposals') | ||
| currentEpoch :: EpochNo | ||
| currentEpoch = SL.nesEL . shelleyLedgerState $ st | ||
|
|
||
| {------------------------------------------------------------------------------- | ||
| Inspection | ||
| -------------------------------------------------------------------------------} | ||
|
|
||
| data ShelleyLedgerUpdate era = | ||
| ShelleyUpdatedProtocolUpdates [ProtocolUpdate era] | ||
| ShelleyUpdatedPParams | ||
| !(StrictMaybe (Core.PParams era)) | ||
| !EpochNo | ||
|
|
||
| deriving instance Eq (Core.PParamsUpdate era) => Eq (ShelleyLedgerUpdate era) | ||
| deriving instance Show (Core.PParamsUpdate era) => Show (ShelleyLedgerUpdate era) | ||
| deriving instance Eq (Core.PParams era) => Eq (ShelleyLedgerUpdate era) | ||
| deriving instance Show (Core.PParams era) => Show (ShelleyLedgerUpdate era) | ||
|
|
||
| instance Show (Core.PParamsUpdate era) => Condense (ShelleyLedgerUpdate era) where | ||
| instance Show (Core.PParams era) => Condense (ShelleyLedgerUpdate era) where | ||
| condense = show | ||
|
|
||
| instance ShelleyBasedEra era => InspectLedger (ShelleyBlock proto era) where | ||
| type LedgerWarning (ShelleyBlock proto era) = Void | ||
| type LedgerUpdate (ShelleyBlock proto era) = ShelleyLedgerUpdate era | ||
|
|
||
| inspectLedger tlc before after = do | ||
| inspectLedger _tlc before after = do | ||
| guard $ updatesBefore /= updatesAfter | ||
| return $ LedgerUpdate $ ShelleyUpdatedProtocolUpdates updatesAfter | ||
| return $ LedgerUpdate updatesAfter | ||
| where | ||
| genesis :: SL.ShelleyGenesis (EraCrypto era) | ||
| genesis = shelleyLedgerGenesis (configLedger tlc) | ||
|
|
||
| updatesBefore, updatesAfter :: [ProtocolUpdate era] | ||
| updatesBefore = protocolUpdates genesis before | ||
| updatesAfter = protocolUpdates genesis after | ||
| updatesBefore, updatesAfter :: ShelleyLedgerUpdate era | ||
| updatesBefore = pparamsUpdate before | ||
| updatesAfter = pparamsUpdate after | ||
|
Comment on lines
-164
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FTR: With the new code, we will log one |
||
|
|
||
| pparamsUpdate :: | ||
| forall era proto. ShelleyBasedEra era | ||
| => LedgerState (ShelleyBlock proto era) | ||
| -> ShelleyLedgerUpdate era | ||
| pparamsUpdate st = | ||
| let nes = shelleyLedgerState st | ||
| in ShelleyUpdatedPParams | ||
| (SL.nextEpochUpdatedPParams (nes ^. SL.newEpochStateGovStateL)) | ||
| (succ (SL.nesEL nes)) | ||
Uh oh!
There was an error while loading. Please reload this page.