Conversation
b0e0138 to
27feb2f
Compare
lehins
left a comment
There was a problem hiding this comment.
Sorry, but this is not a viable approach for protocol parameters. We can talk more about it later on today in the meeting(s).
.../cardano-ledger-canonical-state/src/Cardano/Ledger/CanonicalState/Namespace/GovPParams/V0.hs
Outdated
Show resolved
Hide resolved
libs/cardano-ledger-canonical-state/conway/Cardano/Ledger/CanonicalState/Conway.hs
Outdated
Show resolved
Hide resolved
|
Fixed all of the comments! |
754a631 to
59374fb
Compare
lehins
left a comment
There was a problem hiding this comment.
Few things needs some adjustments, but overall looks good.
| & ppDRepDepositCompactL .~ unCoin dRepDepositCompact | ||
| & ppDRepActivityL .~ dRepActivity | ||
| & ppMinFeeRefScriptCostPerByteL .~ minFeeRefScriptCostPerByte | ||
| & ppProtocolVersionL .~ ProtVer (eraProtVerLow @ConwayEra) 0 |
There was a problem hiding this comment.
We do actually need to save the actual protocol version in the canonical ledger state
| & 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 |
There was a problem hiding this comment.
| tau <- decodeField @"gov/pparams/v0" 11 | |
| tau <- decodeField @"gov/pparams/v0" 11 | |
| protVer <- decodeField @"gov/pparams/v0" 14 |
| Versioned value <- fromCanonicalCBOR @v | ||
| return value |
There was a problem hiding this comment.
Is there no accessor for Versioned?
| Versioned value <- fromCanonicalCBOR @v | |
| return value | |
| unVersioned <$> fromCanonicalCBOR @v |
| 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" |
There was a problem hiding this comment.
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 keyThis will let us solve this kind of pattern in a much more robust way:
| 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 |
libs/cardano-ledger-canonical-state/conway/Cardano/Ledger/CanonicalState/Conway.hs
Show resolved
Hide resolved
|
|
||
| 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 |
There was a problem hiding this comment.
This shouldn't exist. PParams without protocol version do not make sense
| 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 |
| 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" |
There was a problem hiding this comment.
| 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" |
libs/cardano-ledger-canonical-state/conway/Cardano/Ledger/CanonicalState/Conway.hs
Show resolved
Hide resolved
59374fb to
1a8f29a
Compare
|
I've addressed (applied suggestions actually) all the comments |
84d85c5 to
0c6608f
Compare
|
UPD, now rebased atop of MapExtras and passed the tests. I've returned SRP because we still adjusting specs |
3ff100e to
2eb8d84
Compare
2eb8d84 to
97fd769
Compare
Description
Checklist
CHANGELOG.mdfiles updated for packages with externally visible changes.NOTE: New section is never added with the code changes. (See RELEASING.md).
.cabalandCHANGELOG.mdfiles when necessary, according to theversioning process.
.cabalfiles updated when necessary.NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
scripts/fourmolize.sh).scripts/cabal-format.sh).scripts/gen-cddl.sh)hie.yamlupdated (usescripts/gen-hie.sh).