Skip to content

Support gov/canonical/pparams/v0 namespace#5579

Open
qnikst wants to merge 1 commit intomasterfrom
qnikst/canonical/gov/pparams/v0
Open

Support gov/canonical/pparams/v0 namespace#5579
qnikst wants to merge 1 commit intomasterfrom
qnikst/canonical/gov/pparams/v0

Conversation

@qnikst
Copy link
Collaborator

@qnikst qnikst commented Feb 16, 2026

Description

Checklist

  • Commits in meaningful sequence and with useful messages.
  • Tests added or updated when needed.
  • CHANGELOG.md files updated for packages with externally visible changes.
    NOTE: New section is never added with the code changes. (See RELEASING.md).
  • Versions updated in .cabal and CHANGELOG.md files when necessary, according to the
    versioning process.
  • Version bounds in .cabal files updated when necessary.
    NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
  • Code formatted (use scripts/fourmolize.sh).
  • Cabal files formatted (use scripts/cabal-format.sh).
  • CDDL files are up to date (use scripts/gen-cddl.sh)
  • hie.yaml updated (use scripts/gen-hie.sh).
  • Self-reviewed the diff.

@qnikst qnikst requested a review from a team as a code owner February 16, 2026 16:28
@qnikst qnikst force-pushed the qnikst/canonical/gov/pparams/v0 branch 4 times, most recently from b0e0138 to 27feb2f Compare February 19, 2026 12:53
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but this is not a viable approach for protocol parameters. We can talk more about it later on today in the meeting(s).

@qnikst
Copy link
Collaborator Author

qnikst commented Feb 23, 2026

Fixed all of the comments!

@qnikst qnikst requested a review from lehins February 23, 2026 16:19
@qnikst qnikst force-pushed the qnikst/canonical/gov/pparams/v0 branch from 754a631 to 59374fb Compare February 23, 2026 17:48
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things needs some adjustments, but overall looks good.

& ppDRepDepositCompactL .~ unCoin dRepDepositCompact
& ppDRepActivityL .~ dRepActivity
& ppMinFeeRefScriptCostPerByteL .~ minFeeRefScriptCostPerByte
& ppProtocolVersionL .~ ProtVer (eraProtVerLow @ConwayEra) 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do actually need to save the actual protocol version in the canonical ledger state

Suggested change
& ppProtocolVersionL .~ ProtVer (eraProtVerLow @ConwayEra) 0
& ppProtocolVersionL .~ protVer

nOpt <- decodeField @"gov/pparams/v0" 8
a0 <- decodeField @"gov/pparams/v0" 9
rho <- decodeField @"gov/pparams/v0" 10
tau <- decodeField @"gov/pparams/v0" 11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tau <- decodeField @"gov/pparams/v0" 11
tau <- decodeField @"gov/pparams/v0" 11
protVer <- decodeField @"gov/pparams/v0" 14

Comment on lines 175 to 176
Versioned value <- fromCanonicalCBOR @v
return value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no accessor for Versioned?

Suggested change
Versioned value <- fromCanonicalCBOR @v
return value
unVersioned <$> fromCanonicalCBOR @v

Comment on lines 61 to 78
deriving (Eq, Ord, Show)

instance IsKey GovPParamsIn where
keySize = namespaceKeySize @"gov/pparams/v0"
packKeyM GovPParamsInPrev =
packByteStringM "prev"
packKeyM GovPParamsInCurr = packByteStringM "curr"
packKeyM GovPParamsInPossibleFuture = packByteStringM "fut0"
packKeyM GovPParamsInDefiniteFuture = packByteStringM "fut1"
unpackKeyM = do
tag :: ByteString <- unpackByteStringM 4
case tag of
_
| tag == "prev" -> return GovPParamsInPrev
| tag == "curr" -> return GovPParamsInCurr
| tag == "fut0" -> return GovPParamsInPossibleFuture
| tag == "fut1" -> return GovPParamsInDefiniteFuture
| otherwise -> fail "Invalid GovPParamsIn tag"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I please ask you to add to Data.MapExtras in cardano-data this functionality:

boundedEnumMap :: (Ord k, Bounded a, Enum a) => (a -> k) -> Map k a
boundedEnumMap toTxt = Map.fromList [(toTxt t, t) | t <- [minBound .. maxBound]]

lookupMapFail
  :: (Ord k, Show k, MonadFail m) => String -> Map k v -> k -> m v
lookupMapFail name m key =
  case Map.lookup key m of
    Just t -> pure t
    Nothing -> fail $ "Unrecognized " <> name <> ": " ++ show key

This will let us solve this kind of pattern in a much more robust way:

Suggested change
deriving (Eq, Ord, Show)
instance IsKey GovPParamsIn where
keySize = namespaceKeySize @"gov/pparams/v0"
packKeyM GovPParamsInPrev =
packByteStringM "prev"
packKeyM GovPParamsInCurr = packByteStringM "curr"
packKeyM GovPParamsInPossibleFuture = packByteStringM "fut0"
packKeyM GovPParamsInDefiniteFuture = packByteStringM "fut1"
unpackKeyM = do
tag :: ByteString <- unpackByteStringM 4
case tag of
_
| tag == "prev" -> return GovPParamsInPrev
| tag == "curr" -> return GovPParamsInCurr
| tag == "fut0" -> return GovPParamsInPossibleFuture
| tag == "fut1" -> return GovPParamsInDefiniteFuture
| otherwise -> fail "Invalid GovPParamsIn tag"
deriving (Eq, Ord, Show, Enum, Bounded)
keyGovPParamsIn :: Exchange -> ByteString
keyGovPParamsIn = \case
GovPParamsInPrev -> "prev"
GovPParamsInCurr -> "curr"
GovPParamsInPossibleFuture -> "fut0"
GovPParamsInDefiniteFuture -> "fut1"
mapGovPParamsIn :: Map ByteString Exchange
mapGovPParamsIn = boundedEnumMap keyGovPParamsIn
instance IsKey GovPParamsIn where
keySize = namespaceKeySize @"gov/pparams/v0"
packKeyM = packByteStringM . keyGovPParamsIn
unpackKeyM = do
tag :: ByteString <- unpackByteStringM 4
lookupMapFail "GovPParamsIn tag" mapGovPParamsIn tag

Comment on lines 83 to 105

newtype PParamsWithProtVer era = PParamsWithProtVer {getPParams :: PParams era}

deriving instance Eq (PParams era) => Eq (PParamsWithProtVer era)

deriving instance Show (PParams era) => Show (PParamsWithProtVer era)

instance
ToCanonicalCBOR "gov/pparams/v0" (PParams era) =>
ToCanonicalCBOR "gov/pparams/v0" (PParamsWithProtVer era)
where
toCanonicalCBOR v (PParamsWithProtVer pparams) = toCanonicalCBOR v pparams

instance
FromCanonicalCBOR "gov/pparams/v0" (PParams era) =>
FromCanonicalCBOR "gov/pparams/v0" (PParamsWithProtVer era)
where
fromCanonicalCBOR = fmap PParamsWithProtVer <$> fromCanonicalCBOR

instance (Era era, EraPParams era, Arbitrary (PParams era)) => Arbitrary (PParamsWithProtVer era) where
arbitrary = do
pparams <- arbitrary @(PParams era)
return $ PParamsWithProtVer $ pparams & ppProtocolVersionL .~ ProtVer (eraProtVerLow @era) 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't exist. PParams without protocol version do not make sense

Suggested change
newtype PParamsWithProtVer era = PParamsWithProtVer {getPParams :: PParams era}
deriving instance Eq (PParams era) => Eq (PParamsWithProtVer era)
deriving instance Show (PParams era) => Show (PParamsWithProtVer era)
instance
ToCanonicalCBOR "gov/pparams/v0" (PParams era) =>
ToCanonicalCBOR "gov/pparams/v0" (PParamsWithProtVer era)
where
toCanonicalCBOR v (PParamsWithProtVer pparams) = toCanonicalCBOR v pparams
instance
FromCanonicalCBOR "gov/pparams/v0" (PParams era) =>
FromCanonicalCBOR "gov/pparams/v0" (PParamsWithProtVer era)
where
fromCanonicalCBOR = fmap PParamsWithProtVer <$> fromCanonicalCBOR
instance (Era era, EraPParams era, Arbitrary (PParams era)) => Arbitrary (PParamsWithProtVer era) where
arbitrary = do
pparams <- arbitrary @(PParams era)
return $ PParamsWithProtVer $ pparams & ppProtocolVersionL .~ ProtVer (eraProtVerLow @era) 0

Comment on lines 70 to 76
describe "gov/pparams/v0" $ do
prop "conforms to spec" $
propNamespaceEntryConformsToSpec @"gov/pparams/v0"

-- Is checked by the: isCanonical @"gov/pparams/v0" @(PParamsWithProtVer ConwayEra)
-- prop "canonical with regards to it's definition" $
-- propNamespaceEntryRoundTrip @"gov/pparams/v0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe "gov/pparams/v0" $ do
prop "conforms to spec" $
propNamespaceEntryConformsToSpec @"gov/pparams/v0"
-- Is checked by the: isCanonical @"gov/pparams/v0" @(PParamsWithProtVer ConwayEra)
-- prop "canonical with regards to it's definition" $
-- propNamespaceEntryRoundTrip @"gov/pparams/v0"
testNS "gov/pparams/v0"

@qnikst qnikst force-pushed the qnikst/canonical/gov/pparams/v0 branch from 59374fb to 1a8f29a Compare February 25, 2026 18:20
@qnikst qnikst requested a review from lehins February 25, 2026 18:22
@qnikst
Copy link
Collaborator Author

qnikst commented Feb 25, 2026

I've addressed (applied suggestions actually) all the comments

@qnikst qnikst force-pushed the qnikst/canonical/gov/pparams/v0 branch 2 times, most recently from 84d85c5 to 0c6608f Compare February 25, 2026 20:12
@qnikst
Copy link
Collaborator Author

qnikst commented Feb 25, 2026

UPD, now rebased atop of MapExtras and passed the tests.

I've returned SRP because we still adjusting specs

@qnikst qnikst force-pushed the qnikst/canonical/gov/pparams/v0 branch 2 times, most recently from 3ff100e to 2eb8d84 Compare February 26, 2026 11:11
@qnikst qnikst force-pushed the qnikst/canonical/gov/pparams/v0 branch from 2eb8d84 to 97fd769 Compare February 27, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants