Skip to content

Commit 81e4600

Browse files
committed
Minimally re-add additional logic on Babbage->Conway translation
for backwards-compatibility with a past hack
1 parent 8a15a0c commit 81e4600

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Patch
2+
3+
- Minimize additional logic on ledger state translation from Babbage to Conway.

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ import qualified Cardano.Chain.Genesis as CC.Genesis
3333
import qualified Cardano.Chain.Update as CC.Update
3434
import Cardano.Crypto.DSIGN (Ed25519DSIGN)
3535
import Cardano.Crypto.Hash.Blake2b (Blake2b_224, Blake2b_256)
36+
import qualified Cardano.Ledger.Babbage.Core as SL
3637
import Cardano.Ledger.Crypto (ADDRHASH, Crypto, DSIGN, HASH)
37-
import qualified Cardano.Ledger.Era as SL
3838
import qualified Cardano.Ledger.Genesis as SL
3939
import Cardano.Ledger.Hashes (EraIndependentTxBody)
4040
import Cardano.Ledger.Keys (DSignable, Hash)
4141
import qualified Cardano.Ledger.Shelley.API as SL
42+
import qualified Cardano.Ledger.Shelley.LedgerState as SL
4243
import Cardano.Ledger.Shelley.Translation
4344
(toFromByronTranslationContext)
4445
import qualified Cardano.Protocol.TPraos.API as SL
@@ -47,6 +48,7 @@ import qualified Cardano.Protocol.TPraos.Rules.Tickn as SL
4748
import Control.Monad
4849
import Control.Monad.Except (runExcept, throwError)
4950
import Data.Coerce (coerce)
51+
import Data.Function ((&))
5052
import qualified Data.Map.Strict as Map
5153
import Data.Maybe (listToMaybe, mapMaybe)
5254
import Data.Proxy
@@ -57,6 +59,7 @@ import Data.SOP.Tails (Tails (..))
5759
import qualified Data.SOP.Tails as Tails
5860
import Data.Word
5961
import GHC.Generics (Generic)
62+
import Lens.Micro ((%~))
6063
import NoThunks.Class (NoThunks)
6164
import Ouroboros.Consensus.Block
6265
import Ouroboros.Consensus.Byron.Ledger
@@ -709,7 +712,7 @@ translateValidatedTxAlonzoToBabbageWrapper ctxt = InjectValidatedTx $
709712
-------------------------------------------------------------------------------}
710713

711714
translateLedgerStateBabbageToConwayWrapper ::
712-
(Praos.PraosCrypto c)
715+
forall c. (Praos.PraosCrypto c)
713716
=> RequiringBoth
714717
WrapLedgerConfig
715718
(Translate LedgerState)
@@ -718,7 +721,34 @@ translateLedgerStateBabbageToConwayWrapper ::
718721
translateLedgerStateBabbageToConwayWrapper =
719722
RequireBoth $ \_cfgBabbage cfgConway ->
720723
Translate $ \_epochNo ->
721-
unComp . SL.translateEra' (getConwayTranslationContext cfgConway) . Comp
724+
unComp
725+
. SL.translateEra' (getConwayTranslationContext cfgConway)
726+
. Comp
727+
. patchGovState
728+
where
729+
patchGovState ::
730+
LedgerState (ShelleyBlock proto (BabbageEra c))
731+
-> LedgerState (ShelleyBlock proto (BabbageEra c))
732+
patchGovState st =
733+
st { shelleyLedgerState = shelleyLedgerState st
734+
& SL.newEpochStateGovStateL %~ rotateGovState
735+
}
736+
where
737+
-- This is only needed to keep backwards-compatibility with a past hack.
738+
-- Concretely, this means that the tick across the epoch/era boundary
739+
-- (using Conway logic) will consider the protocol parameters of the
740+
-- first Conway epoch (instead of the last Babbage epoch) to be the
741+
-- /current/ protocol parameters. The only effect is that delegations
742+
-- from pointer addresses are ignored one already at this epoch
743+
-- boundary.
744+
rotateGovState ::
745+
SL.ShelleyGovState (BabbageEra c)
746+
-> SL.ShelleyGovState (BabbageEra c)
747+
rotateGovState gs = gs {
748+
SL.sgsPrevPParams = SL.sgsCurPParams gs
749+
, SL.sgsCurPParams = SL.nextEpochPParams gs
750+
, SL.sgsFuturePParams = SL.PotentialPParamsUpdate Nothing
751+
}
722752

723753
getConwayTranslationContext ::
724754
WrapLedgerConfig (ShelleyBlock (Praos c) (ConwayEra c))

0 commit comments

Comments
 (0)