Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change serialization of OneEraGenTxId to treat it as though it's simply a ShortByteString #1311

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

fraser-iohk
Copy link
Contributor

@fraser-iohk fraser-iohk commented Nov 19, 2024

Description

This PR changes the serialization of OneEraGenTxId so that it's serialized and deserialized as an era-independent ShortByteString rather than as an era-tag-prefixed ShortByteString. As part of this, I've had to make a breaking change to the representation of TxId (GenTx ByronBlock), since there is now no way to identify which kind of Byron-era transaction ID we're deserializing – TxId, CertificateId, UpId, or VoteId – and these are all now represented simply in ByronGenTxId as a Hash.

As this is a breaking change to the wire format, there's a new protocol version and a corresponding branch on ouroboros-network here: fraser-iohk/one-era-gen-tx-id-protocol-version-bump

@fraser-iohk fraser-iohk force-pushed the fraser-iohk/one-era-gen-tx-id-bytestring branch 2 times, most recently from 46a029e to e0cd631 Compare November 21, 2024 01:25
@fraser-iohk
Copy link
Contributor Author

what should happen in the case that the blessed GenTxId era is disabled in the config? should we pick another era arbitrarily? should there be a way to order fallbacks?

          *** Failed! Falsified (after 15 tests):
          WithVersion (HardForkNodeToClientEnabled HardForkSpecificNodeToClientVersion4 (EraNodeToClientEnabled ByronNodeToClientVersion1 :* EraNodeToClientEnabled ShelleyNodeToClientVersion6 :* EraNodeToClientEnabled ShelleyNodeToClientVersion9 :* EraNodeToClientEnabled ShelleyNodeToClientVersion1 :* EraNodeToClientEnabled ShelleyNodeToClientVersion5 :* EraNodeToClientDisabled :* EraNodeToClientEnabled ShelleyNodeToClientVersion5 :* Nil)) (HardForkGenTxId {getHardForkGenTxId = S (S (S (Z (WrapGenTxId {unwrapGenTxId = txid: TxId {unTxId = SafeHash "fb4ea1312616d1a61645991aa8012a3aca2178e121759fb833177201080c5673"}}))))})
          DeserialiseFailure 0 "HardForkEncoderDisabledEra (SingleEraInfo {singleEraName = \"Babbage\"})"
          When deserialising 5820fb4ea1312616d1a61645991aa8012a3aca2178e121759fb833177201080c5673
          Use --quickcheck-replay="(SMGen 1921722396195416107 8896093690400693515,14)" to reproduce.
          Use -p '/Roundtrip.SerialiseNodeToClient.roundtrip GenTxId/' to rerun this test only.

@fraser-iohk fraser-iohk force-pushed the fraser-iohk/one-era-gen-tx-id-bytestring branch from e0cd631 to 78c7730 Compare November 21, 2024 01:30
@amesgen
Copy link
Member

amesgen commented Nov 21, 2024

what should happen in the case that the blessed GenTxId era is disabled in the config? should we pick another era arbitrarily? should there be a way to order fallbacks?

What about picking an era that is supported by all CardanoNodeToXVersions, eg Shelley should work I think?

Related: The next Network release (#1314) will have IntersectMBO/ouroboros-network#5002, such that we can remove all old CardanoNodeToClientVersions that do not support all currently known eras.

@fraser-iohk fraser-iohk force-pushed the fraser-iohk/one-era-gen-tx-id-bytestring branch from 78c7730 to 21b5d07 Compare November 21, 2024 10:43
@fraser-iohk
Copy link
Contributor Author

yeah, I saw the changes in network and kinda feel like this is irrelevant since we're dropping support for older NodeToClientVersions. does picking Shelley have any other risks that would be relevant? I did think about messing with the Arbitrary instances to always pick a sensible era instead

@amesgen
Copy link
Member

amesgen commented Nov 21, 2024

does picking Shelley have any other risks that would be relevant?

I can't think of anything; everything that uses our code shouldn't care about this at all due to #1017; and I don't think that external services (like custom tx submission clients) do either.

@fraser-iohk fraser-iohk force-pushed the fraser-iohk/one-era-gen-tx-id-bytestring branch 5 times, most recently from 2e7dbb8 to b340e48 Compare December 2, 2024 14:30
@fraser-iohk fraser-iohk marked this pull request as ready for review December 3, 2024 12:37
@fraser-iohk
Copy link
Contributor Author

added the no changelog label for -diffusion, whose only change is a new instance for HasBlessedGenTxIdEra

@fraser-iohk fraser-iohk force-pushed the fraser-iohk/one-era-gen-tx-id-bytestring branch from b340e48 to d144054 Compare December 3, 2024 13:26
Copy link
Member

@amesgen amesgen left a comment

Choose a reason for hiding this comment

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

Looks good! (Sorry for not sending this review earlier, just noticed it while closing tabs)

I think it makes sense to also give a self-contained overview of what changes here for external implementations of mini-protocols involving tx ids, such that they can easily adapt to this change without having to read the code (ideally, we would have CDDL specs as tracked by #7, but we aren't there yet).

-- need to handle the cases where 'ShortByteString's are serialised with
-- an era tag ('encodeNS').

encodeNodeToClient _cc v (HardForkGenTxId (OneEraGenTxId txid)) =
Copy link
Member

Choose a reason for hiding this comment

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

Can we share the NodeToClient and NodeToNode logic?

Comment on lines 222 to 226
-- absolutely horrible. should be HasLatestStableGenTxIdEra probably.
-- especially nasty because it's a K () rather than an equivalent (but
-- non-existent) 'Void :: (Type -> Type) -> Type'
class HasBlessedGenTxIdEra (xs :: [Type]) where
blessedGenTxIdEra :: NS (K ()) xs
Copy link
Member

Choose a reason for hiding this comment

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

Just brainstorming an alternative: Instead of having a typeclass for this, we could also "hardcode" this choice in the serialization logic (e.g. sth like: "use the first index when xs has length 1, otherwise, use the second index). The downside is that one can't customize this for a hypothetical different HardForkBlock that would need to customize this, but that seems unlikely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants