Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

[release/1.3.1] [CO-354] Add RequiresNetworkMagic and modify ProtocolMagic #3556

Merged
merged 2 commits into from
Sep 7, 2018

Conversation

intricate
Copy link
Contributor

@intricate intricate commented Sep 7, 2018

Description

This PR modifies the ProtocolMagic data structure and introduces new data types: RequiresNetworkMagic and ProtocolMagicId (a new type wrapper around an Int32).

ProtocolMagic has been modified such that it consists of two fields: getProtocolMagicId :: ProtocolMagicId and getRequiresNetworkMagic :: RequiresNetworkMagic.

The goldenTestJSONDec and goldenTestCanonicalJSONDec tests which were introduced in #3540 have assisted us in ensuring that we've maintained backwards compatibility in our implementation of ProtocolMagic.

Linked issue

https://iohk.myjetbrains.com/youtrack/issue/CO-354

Type of change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🛠 New feature (non-breaking change which adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🏭 Refactoring that does not change existing functionality but does improve things like code readability, structure etc
  • 🔨 New or improved tests for existing code
  • ⛑ git-flow chore (backport, hotfix, etc)

Developer checklist

  • I have read the style guide document, and my code follows the code style of this project.
  • If my code deals with exceptions, it follows the guidelines.
  • I have updated any documentation accordingly, if needed. Documentation changes can be reflected in opening a PR on cardanodocs.com, amending the inline Haddock comments, any relevant README file or one of the document listed in the docs directory.

Testing checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.

QA Steps

Screenshots (if available)

mhuesch and others added 2 commits September 6, 2018 10:57
Add `RequiresNetworkMagic` datatype and `requiresNetworkMagic` field
to `ProtocolMagic`. Pull `Int32` of ProtocolMagic into a newtype wrapper
`ProtocolMagicId`.

Push modified `ProtocolMagic` through the codebase.

Modify `GenericBlockHeader` to use `ProtocolMagicId` instead of
`ProtocolMagic`, to avoid issues of undefined `requiresNetworkMagic`
when reading a block.

import Test.Pos.Block.Arbitrary.Generate (generateMainBlock)

-- We need 'ProtocolMagic' and 'ProtocolConstants' in order to generate a
-- 'MainBlock'.

pm :: ProtocolMagic
pm = ProtocolMagic 0
pm = ProtocolMagic (ProtocolMagicId 0) NMMustBeNothing
Copy link
Member

Choose a reason for hiding this comment

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

\o/

Copy link
Member

@erikd erikd left a comment

Choose a reason for hiding this comment

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

Looks really good!

toJSON NMMustBeNothing = pure (JSString "NMMustBeNothing")
toJSON NMMustBeJust = pure (JSString "NMMustBeJust")

instance ReportSchemaErrors m => FromJSON m RequiresNetworkMagic where
Copy link
Contributor

Choose a reason for hiding this comment

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

If you replace ReportSchemaErrors m with (Monad m, MonadError SchemaError m) then you can drop -fno-simplifiable-class-constraints

Copy link
Contributor

@mhuesch mhuesch Sep 7, 2018

Choose a reason for hiding this comment

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

Thanks! Will apply this on develop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ruhatch Interesting. Will look to make this change.

Copy link
Contributor

@ruhatch ruhatch 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, but this is going to be horrible to merge back to develop!

@rvl rvl merged commit a07196f into release/1.3.1 Sep 7, 2018
@intricate
Copy link
Contributor Author

@ruhatch Oh, for sure!!

@mhuesch
Copy link
Contributor

mhuesch commented Sep 7, 2018

@ruhatch @intricate For better or worse, we began most of this work on develop and then cherry-picked it over to release/1.3.1. So we've already experienced >=1/2 of the pain of merging 😅 and it shouldn't be too bad to get this over to develop. The harder part is convincing ourselves that the code does the same thing 🤔

@mhuesch mhuesch deleted the intricate+mhuesch/CO-354/modify-protocolmagic branch September 14, 2018 17:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants