From 32aef259ed3fa3a1e6df1f3e61805856f314b6c1 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Thu, 12 Oct 2023 14:27:27 +0200 Subject: [PATCH 1/5] Init scriv for sop-extras and strict-sop-core --- sop-extras/CHANGELOG.md | 7 +++++-- sop-extras/changelog.d/scriv.ini | 13 +++++++++++++ strict-sop-core/CHANGELOG.md | 7 +++++-- strict-sop-core/changelog.d/scriv.ini | 13 +++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 sop-extras/changelog.d/scriv.ini create mode 100644 strict-sop-core/changelog.d/scriv.ini diff --git a/sop-extras/CHANGELOG.md b/sop-extras/CHANGELOG.md index ba0759d611..c26778a875 100644 --- a/sop-extras/CHANGELOG.md +++ b/sop-extras/CHANGELOG.md @@ -1,5 +1,8 @@ -# Revision history for sop-extras +# sop-extras Changelog -## 0.1.0.0 -- YYYY-mm-dd +# Changelog entries + + +## 0.1.0.0 — 2023-09-07 * First version. Released on an unsuspecting world. diff --git a/sop-extras/changelog.d/scriv.ini b/sop-extras/changelog.d/scriv.ini new file mode 100644 index 0000000000..aacceaa8da --- /dev/null +++ b/sop-extras/changelog.d/scriv.ini @@ -0,0 +1,13 @@ +[scriv] +format = md +insert_marker = Changelog entries +md_header_level = 2 +version = literal: sop-extras.cabal: version +categories = Patch, Non-Breaking, Breaking +end_marker = scriv-end-here +fragment_directory = changelog.d +ghrel_template = {{body}} +main_branches = master, main, develop +new_fragment_template = file: new_fragment.${config:format}.j2 +output_file = CHANGELOG.${config:format} +skip_fragments = README.* diff --git a/strict-sop-core/CHANGELOG.md b/strict-sop-core/CHANGELOG.md index 2f13b1e71a..d0098e81e2 100644 --- a/strict-sop-core/CHANGELOG.md +++ b/strict-sop-core/CHANGELOG.md @@ -1,5 +1,8 @@ -# Revision history for strict-sop-core +# strict-sop-core Changelog -## 0.1.0.0 -- YYYY-mm-dd +# Changelog entries + + +## 0.1.0.0 — 2023-09-07 * First version. Released on an unsuspecting world. diff --git a/strict-sop-core/changelog.d/scriv.ini b/strict-sop-core/changelog.d/scriv.ini new file mode 100644 index 0000000000..e318dbaa9c --- /dev/null +++ b/strict-sop-core/changelog.d/scriv.ini @@ -0,0 +1,13 @@ +[scriv] +format = md +insert_marker = Changelog entries +md_header_level = 2 +version = literal: strict-sop-core.cabal: version +categories = Patch, Non-Breaking, Breaking +end_marker = scriv-end-here +fragment_directory = changelog.d +ghrel_template = {{body}} +main_branches = master, main, develop +new_fragment_template = file: new_fragment.${config:format}.j2 +output_file = CHANGELOG.${config:format} +skip_fragments = README.* From f87326f759377eb0027acc6bb3fbf83086f1ff11 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Thu, 12 Oct 2023 14:19:36 +0200 Subject: [PATCH 2/5] Add `Ord (EraIndex xs)` --- .../HardFork/Combinator/Abstract/SingleEraBlock.hs | 8 +++++--- sop-extras/changelog.d/20231012_142650_alexander.esgen.md | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 sop-extras/changelog.d/20231012_142650_alexander.esgen.md diff --git a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Abstract/SingleEraBlock.hs b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Abstract/SingleEraBlock.hs index 4bcb69307f..d6cd17c1ab 100644 --- a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Abstract/SingleEraBlock.hs +++ b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Abstract/SingleEraBlock.hs @@ -22,12 +22,11 @@ module Ouroboros.Consensus.HardFork.Combinator.Abstract.SingleEraBlock ( ) where import Codec.Serialise -import Data.Either (isRight) +import Data.Function (on) import Data.Proxy import Data.SOP.BasicFunctors import Data.SOP.Constraint import Data.SOP.Index -import Data.SOP.Match import Data.SOP.Strict import qualified Data.Text as Text import Data.Void @@ -117,7 +116,10 @@ newtype EraIndex xs = EraIndex { } instance Eq (EraIndex xs) where - EraIndex era == EraIndex era' = isRight (matchNS era era') + (==) = (==) `on` eraIndexToInt + +instance Ord (EraIndex xs) where + compare = compare `on` eraIndexToInt instance All SingleEraBlock xs => Show (EraIndex xs) where show = hcollapse . hcmap proxySingle getEraName . getEraIndex diff --git a/sop-extras/changelog.d/20231012_142650_alexander.esgen.md b/sop-extras/changelog.d/20231012_142650_alexander.esgen.md new file mode 100644 index 0000000000..eeaa38a643 --- /dev/null +++ b/sop-extras/changelog.d/20231012_142650_alexander.esgen.md @@ -0,0 +1,3 @@ +### Non-Breaking + +- Add `Ord (EraIndex xs)` instance From 6d9ac256510694dadd3d6ab00837b3fd95940ae7 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Thu, 12 Oct 2023 14:28:01 +0200 Subject: [PATCH 3/5] HFC: document that ticking alone can't reveal era transitions --- .../Consensus/HardFork/Combinator/Ledger.hs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Ledger.hs b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Ledger.hs index 6f866524d2..b1614a526c 100644 --- a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Ledger.hs +++ b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Ledger.hs @@ -113,6 +113,42 @@ deriving anyclass instance CanHardFork xs => NoThunks (Ticked (LedgerState (HardForkBlock xs))) +-- | = HFC ticking +-- +-- This is the place where era transitions happen, ie when we have @st :: +-- 'LedgerState' ('HardForkBlock' xs)@ and, for a valid @slotNo@, +-- +-- @ +-- tickedSt :: 'Ticked' ('LedgerState' ('HardForkBlock' xs)) +-- tickedSt = 'applyChainTick' cfg slotNo st +-- @ +-- +-- we have the corresponding era indices +-- +-- @ +-- ixSt, ixTickedSt :: 'EraIndex' xs +-- ixSt = +-- 'eraIndexFromNS' . State.'State.tip' . 'hardForkLedgerStatePerEra' $ st +-- ixTickedState = +-- 'eraIndexFromNS' . State.'State.tip' . 'tickedHardForkLedgerStatePerEra' $ tickedSt +-- @ +-- +-- and we always have +-- +-- >>> ixSt <= ixTickedSt +-- True +-- +-- with inequality exactly if we ticked across an era boundary. +-- +-- == Ticking alone can't reveal era transitions +-- +-- Note however that if we performed an era transition (ie @ixSt < ixTickedSt@), +-- it must have already been known via 'singleEraTransition' for @st@; or more +-- concretely, @'mostRecentTransitionInfo' cfg st@ must have already returned +-- 'TransitionKnown'. This is a reflection of the fact that ticking alone +-- currently can't make a transition become known. Also see +-- for +-- future work to reconsider this fact. instance CanHardFork xs => IsLedger (LedgerState (HardForkBlock xs)) where type LedgerErr (LedgerState (HardForkBlock xs)) = HardForkLedgerError xs From b236a8ad6bad6d8a41040d517d6e96c49bd4e749 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Thu, 12 Oct 2023 15:26:20 +0200 Subject: [PATCH 4/5] Document requirements/usage of cross-era state translation --- .../HardFork/Combinator/Translation.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Translation.hs b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Translation.hs index 725fadf993..f61db35d4f 100644 --- a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Translation.hs +++ b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Translation.hs @@ -17,7 +17,25 @@ import Ouroboros.Consensus.TypeFamilyWrappers -------------------------------------------------------------------------------} data EraTranslation xs = EraTranslation { + -- | For each pair @(x, y)@ of subsequent eras, describe how to construct + -- the initial ledger state for @y@ from the last ledger state in @x@. + -- + -- When ticking across an era boundary, the HFC will first invoke this and + -- then tick the resulting ledger state (in @y@) to the requested slot. + -- + -- The resulting ledger state must summarize every relevant aspect of what + -- came before the new era. This is intentionally vague; for example, + -- ticking in @y@ might work rather differntly than in @x@, and so certain + -- aspects of the ticking logic of @x@ might need to happen as part of + -- 'translateLedgerState'. For a concrete example in Cardano, see + -- 'translateLedgerStateBabbageToConwayWrapper'. translateLedgerState :: InPairs (RequiringBoth WrapLedgerConfig (Translate LedgerState)) xs + -- | For each pair @(x, y)@ of subsequent eras, describe how to construct + -- the initial chain-dependent state for @y@ from the last chain-dep state + -- in @x@. + -- + -- When ticking across an era boundary, the HFC will first invoke this and + -- then tick the resulting chain-dep state (in @y@) to the requested slot. , translateChainDepState :: InPairs (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState)) xs , crossEraForecast :: InPairs (RequiringBoth WrapLedgerConfig (CrossEraForecaster LedgerState WrapLedgerView)) xs } From 6dd0b2b05af6e4e2298e925efe5a122ac447742c Mon Sep 17 00:00:00 2001 From: amesgen Date: Mon, 16 Oct 2023 12:16:22 +0200 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Nicolas Frisby --- .../Ouroboros/Consensus/HardFork/Combinator/Translation.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Translation.hs b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Translation.hs index f61db35d4f..5cf708a888 100644 --- a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Translation.hs +++ b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Translation.hs @@ -18,20 +18,20 @@ import Ouroboros.Consensus.TypeFamilyWrappers data EraTranslation xs = EraTranslation { -- | For each pair @(x, y)@ of subsequent eras, describe how to construct - -- the initial ledger state for @y@ from the last ledger state in @x@. + -- the initial ledger state for @y@ from the ledger state resulting from the last block in @x@. -- -- When ticking across an era boundary, the HFC will first invoke this and -- then tick the resulting ledger state (in @y@) to the requested slot. -- -- The resulting ledger state must summarize every relevant aspect of what -- came before the new era. This is intentionally vague; for example, - -- ticking in @y@ might work rather differntly than in @x@, and so certain + -- ticking in @y@ might work rather differently than in @x@, and so certain -- aspects of the ticking logic of @x@ might need to happen as part of -- 'translateLedgerState'. For a concrete example in Cardano, see -- 'translateLedgerStateBabbageToConwayWrapper'. translateLedgerState :: InPairs (RequiringBoth WrapLedgerConfig (Translate LedgerState)) xs -- | For each pair @(x, y)@ of subsequent eras, describe how to construct - -- the initial chain-dependent state for @y@ from the last chain-dep state + -- the initial chain-dependent state for @y@ from the chain-dep state after the last header -- in @x@. -- -- When ticking across an era boundary, the HFC will first invoke this and