From 0d7744ca51b2fa31d93fc6c54306a025a338a803 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Thu, 5 Sep 2024 15:22:28 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Revert=20"Minimal=20workaround=20for=20upda?= =?UTF-8?q?ting=20protocol=20params=20on=20Babbage=E2=86=92Conway"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 173f1ad372984aaec0847487413a8d2d719e985e. --- .../Consensus/Cardano/CanHardFork.hs | 68 ++----------------- 1 file changed, 4 insertions(+), 64 deletions(-) diff --git a/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs b/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs index ab2de63f5b..f3262c38cf 100644 --- a/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs +++ b/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs @@ -33,27 +33,20 @@ import qualified Cardano.Chain.Genesis as CC.Genesis import qualified Cardano.Chain.Update as CC.Update import Cardano.Crypto.DSIGN (Ed25519DSIGN) import Cardano.Crypto.Hash.Blake2b (Blake2b_224, Blake2b_256) -import qualified Cardano.Ledger.BaseTypes as SL -import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Crypto (ADDRHASH, Crypto, DSIGN, HASH) import qualified Cardano.Ledger.Era as SL import qualified Cardano.Ledger.Genesis as SL import Cardano.Ledger.Hashes (EraIndependentTxBody) import Cardano.Ledger.Keys (DSignable, Hash) import qualified Cardano.Ledger.Shelley.API as SL -import qualified Cardano.Ledger.Shelley.LedgerState as SL import Cardano.Ledger.Shelley.Translation (toFromByronTranslationContext) import qualified Cardano.Protocol.TPraos.API as SL import qualified Cardano.Protocol.TPraos.Rules.Prtcl as SL import qualified Cardano.Protocol.TPraos.Rules.Tickn as SL -import Cardano.Slotting.EpochInfo (epochInfoFirst) import Control.Monad import Control.Monad.Except (runExcept, throwError) -import qualified Control.State.Transition as STS import Data.Coerce (coerce) -import Data.Function ((&)) -import Data.Functor.Identity import qualified Data.Map.Strict as Map import Data.Maybe (listToMaybe, mapMaybe) import Data.Proxy @@ -62,11 +55,8 @@ import Data.SOP.InPairs (RequiringBoth (..), ignoringBoth) import qualified Data.SOP.Strict as SOP import Data.SOP.Tails (Tails (..)) import qualified Data.SOP.Tails as Tails -import Data.Void import Data.Word import GHC.Generics (Generic) -import Lens.Micro ((.~)) -import Lens.Micro.Extras (view) import NoThunks.Class (NoThunks) import Ouroboros.Consensus.Block import Ouroboros.Consensus.Byron.Ledger @@ -719,66 +709,16 @@ translateValidatedTxAlonzoToBabbageWrapper ctxt = InjectValidatedTx $ -------------------------------------------------------------------------------} translateLedgerStateBabbageToConwayWrapper :: - forall c. (Praos.PraosCrypto c) + (Praos.PraosCrypto c) => RequiringBoth WrapLedgerConfig (Translate LedgerState) (ShelleyBlock (Praos c) (BabbageEra c)) (ShelleyBlock (Praos c) (ConwayEra c)) translateLedgerStateBabbageToConwayWrapper = - RequireBoth $ \cfgBabbage cfgConway -> - Translate $ \epochNo -> - let -- It would be cleaner to just pass in the entire 'Bound' instead of - -- just the 'EpochNo'. - firstSlotNewEra = runIdentity $ epochInfoFirst ei epochNo - where - ei = - SL.epochInfoPure - $ shelleyLedgerGlobals - $ unwrapLedgerConfig cfgConway - - -- HACK to make sure protocol parameters get properly updated on the - -- era transition from Babbage to Conway. This will be replaced by a - -- more principled refactoring in the future. - -- - -- Pre-Conway, protocol parameters (like the ledger protocol - -- version) were updated by the UPEC rule, which is executed while - -- ticking across an epoch boundary. If sufficiently many Genesis - -- keys submitted the same update proposal, it will update the - -- governance state accordingly. - -- - -- Conway has a completely different governance scheme (CIP-1694), - -- and thus has no representation for pre-Conway update proposals, - -- which are hence discarded by 'SL.translateEra'' below. Therefore, - -- we monkey-patch the governance state by ticking across the - -- era/epoch boundary using Babbage logic, and set the governance - -- state to the updated one /before/ translating. - patchGovState :: - LedgerState (ShelleyBlock proto (BabbageEra c)) - -> LedgerState (ShelleyBlock proto (BabbageEra c)) - patchGovState st = - st { shelleyLedgerState = shelleyLedgerState st - & SL.newEpochStateGovStateL .~ newGovState - } - where - newGovState = - view SL.newEpochStateGovStateL - . tickedShelleyLedgerState - . applyChainTick - (unwrapLedgerConfig cfgBabbage) - firstSlotNewEra - $ st - - -- The UPEC rule emits no ledger events, hence this hack is not - -- swallowing anything. - _upecNoLedgerEvents :: - STS.Event (Core.EraRule "UPEC" (BabbageEra c)) :~: Void - _upecNoLedgerEvents = Refl - - in unComp - . SL.translateEra' (getConwayTranslationContext cfgConway) - . Comp - . patchGovState + RequireBoth $ \_cfgBabbage cfgConway -> + Translate $ \_epochNo -> + unComp . SL.translateEra' (getConwayTranslationContext cfgConway) . Comp getConwayTranslationContext :: WrapLedgerConfig (ShelleyBlock (Praos c) (ConwayEra c)) From 6a8d239114492797dc5940f6d7581977af8a5ef8 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Thu, 5 Sep 2024 15:22:35 +0200 Subject: [PATCH 2/2] Minimally re-add additional logic on Babbage->Conway translation for backwards-compatibility with a past hack --- ...n_minimize_babbage_conway_hfc_tick_hack.md | 3 ++ .../Consensus/Cardano/CanHardFork.hs | 35 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 ouroboros-consensus-cardano/changelog.d/20240905_151832_alexander.esgen_minimize_babbage_conway_hfc_tick_hack.md diff --git a/ouroboros-consensus-cardano/changelog.d/20240905_151832_alexander.esgen_minimize_babbage_conway_hfc_tick_hack.md b/ouroboros-consensus-cardano/changelog.d/20240905_151832_alexander.esgen_minimize_babbage_conway_hfc_tick_hack.md new file mode 100644 index 0000000000..c942584efe --- /dev/null +++ b/ouroboros-consensus-cardano/changelog.d/20240905_151832_alexander.esgen_minimize_babbage_conway_hfc_tick_hack.md @@ -0,0 +1,3 @@ +### Patch + +- Minimize additional logic on ledger state translation from Babbage to Conway. diff --git a/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs b/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs index f3262c38cf..d34004ffb1 100644 --- a/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs +++ b/ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs @@ -33,12 +33,13 @@ import qualified Cardano.Chain.Genesis as CC.Genesis import qualified Cardano.Chain.Update as CC.Update import Cardano.Crypto.DSIGN (Ed25519DSIGN) import Cardano.Crypto.Hash.Blake2b (Blake2b_224, Blake2b_256) +import qualified Cardano.Ledger.Babbage.Core as SL import Cardano.Ledger.Crypto (ADDRHASH, Crypto, DSIGN, HASH) -import qualified Cardano.Ledger.Era as SL import qualified Cardano.Ledger.Genesis as SL import Cardano.Ledger.Hashes (EraIndependentTxBody) import Cardano.Ledger.Keys (DSignable, Hash) import qualified Cardano.Ledger.Shelley.API as SL +import qualified Cardano.Ledger.Shelley.LedgerState as SL import Cardano.Ledger.Shelley.Translation (toFromByronTranslationContext) import qualified Cardano.Protocol.TPraos.API as SL @@ -47,6 +48,7 @@ import qualified Cardano.Protocol.TPraos.Rules.Tickn as SL import Control.Monad import Control.Monad.Except (runExcept, throwError) import Data.Coerce (coerce) +import Data.Function ((&)) import qualified Data.Map.Strict as Map import Data.Maybe (listToMaybe, mapMaybe) import Data.Proxy @@ -57,6 +59,7 @@ import Data.SOP.Tails (Tails (..)) import qualified Data.SOP.Tails as Tails import Data.Word import GHC.Generics (Generic) +import Lens.Micro ((%~)) import NoThunks.Class (NoThunks) import Ouroboros.Consensus.Block import Ouroboros.Consensus.Byron.Ledger @@ -709,7 +712,7 @@ translateValidatedTxAlonzoToBabbageWrapper ctxt = InjectValidatedTx $ -------------------------------------------------------------------------------} translateLedgerStateBabbageToConwayWrapper :: - (Praos.PraosCrypto c) + forall c. (Praos.PraosCrypto c) => RequiringBoth WrapLedgerConfig (Translate LedgerState) @@ -718,7 +721,33 @@ translateLedgerStateBabbageToConwayWrapper :: translateLedgerStateBabbageToConwayWrapper = RequireBoth $ \_cfgBabbage cfgConway -> Translate $ \_epochNo -> - unComp . SL.translateEra' (getConwayTranslationContext cfgConway) . Comp + unComp + . SL.translateEra' (getConwayTranslationContext cfgConway) + . Comp + . patchGovState + where + patchGovState :: + LedgerState (ShelleyBlock proto (BabbageEra c)) + -> LedgerState (ShelleyBlock proto (BabbageEra c)) + patchGovState st = + st { shelleyLedgerState = shelleyLedgerState st + & SL.newEpochStateGovStateL %~ rotateGovState + } + where + -- This is only needed to keep backwards-compatibility with a past hack. + -- Concretely, this means that the tick across the epoch/era boundary + -- (using Conway logic) will consider the protocol parameters of the + -- first Conway epoch (instead of the last Babbage epoch) to be the + -- /current/ protocol parameters. The only effect is that delegations + -- from pointer addresses are ignored already at this epoch boundary. + rotateGovState :: + SL.ShelleyGovState (BabbageEra c) + -> SL.ShelleyGovState (BabbageEra c) + rotateGovState gs = gs { + SL.sgsPrevPParams = SL.sgsCurPParams gs + , SL.sgsCurPParams = SL.nextEpochPParams gs + , SL.sgsFuturePParams = SL.PotentialPParamsUpdate Nothing + } getConwayTranslationContext :: WrapLedgerConfig (ShelleyBlock (Praos c) (ConwayEra c))