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

[CO-410] Add RequiresNetworkMagic and modify ProtocolMagic #3715

Merged
merged 9 commits into from
Oct 15, 2018

Conversation

intricate
Copy link
Contributor

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 tests which were introduced in #3712 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-410

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)

@intricate intricate force-pushed the i+m/develop/CO-410/modify-protocolmagic branch 6 times, most recently from 0b8c020 to 7644bd3 Compare October 8, 2018 12:34
@intricate intricate changed the title [DO NOT MERGE] [WIP] [CO-410] Add RequiresNetworkMagic and modify ProtocolMagic [CO-410] Add RequiresNetworkMagic and modify ProtocolMagic Oct 8, 2018
@Jimbo4350 Jimbo4350 force-pushed the i+m/develop/CO-410/modify-protocolmagic branch 3 times, most recently from 4b9ee6a to e2f59a8 Compare October 10, 2018 12:56
@intricate intricate force-pushed the i+m/develop/CO-410/modify-protocolmagic branch from e2f59a8 to ad5438c Compare October 10, 2018 13:38
@intricate intricate mentioned this pull request Oct 10, 2018
5 tasks
Copy link
Contributor

@mhuesch mhuesch left a comment

Choose a reason for hiding this comment

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

FromJSON instances seem off to me... let me know if I'm misunderstanding though.

chain/bench/block-bench.hs Show resolved Hide resolved
chain/test/Test/Pos/Chain/Genesis/Dummy.hs Show resolved Hide resolved
<*> pure RequiresMagic
Just (A.String "NMMustBeNothing")
-> ProtocolMagic <$> (ProtocolMagicId <$> o .: "pm")
<*> pure RequiresNoMagic
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason that this legacy-migration logic is in the FromJSON ProtocolMagic instance, rather than directly in the FromJSON RequiresNetworkMagic instance?

Do we have an issue here and here with supporting the legacy names? It seems like those use the FromJSON RequiresNetworkMagic instance, which will not be equipped to handle the legacy names.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Oct 10, 2018

Choose a reason for hiding this comment

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

You're absolutely right, there will be issues in the FromJSON instance of Configuration . I'll make the necessary changes.

crypto/test/Test/Pos/Crypto/Json.hs Show resolved Hide resolved
startTime <- Timestamp . round . (* 1000000) <$> liftIO getPOSIXTime
let cfo = defaultConfigurationOptions
{ cfoFilePath = "./configuration.yaml"
{ cfoFilePath = configFilePath
Copy link
Contributor

Choose a reason for hiding this comment

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

The "./" prefix might be important in some contexts, I would keep it in there.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Jimbo4350 asked about this - I'm not sure that presence/absence of a "./ is an issue here, but given that the code has been working with the prefix, I'd hesitate to casually drop it. I'm not sure that all architectures treat said prefixes similarly.

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion is:

{ cfoFilePath = "./" <> configFilePath

@Jimbo4350 Jimbo4350 force-pushed the i+m/develop/CO-410/modify-protocolmagic branch 7 times, most recently from 2296464 to 66e820c Compare October 12, 2018 13:24
@Jimbo4350 Jimbo4350 force-pushed the i+m/develop/CO-410/modify-protocolmagic branch from 66e820c to dcb500b Compare October 12, 2018 13:36
@intricate intricate force-pushed the i+m/develop/CO-410/modify-protocolmagic branch from 2e1b589 to 61a7eeb Compare October 12, 2018 14:39
@Jimbo4350 Jimbo4350 force-pushed the i+m/develop/CO-410/modify-protocolmagic branch 9 times, most recently from 1eafd3f to 5d1317a Compare October 12, 2018 17:10
@Jimbo4350 Jimbo4350 force-pushed the i+m/develop/CO-410/modify-protocolmagic branch 2 times, most recently from c0972b1 to 7fb6ab3 Compare October 15, 2018 14:00
`systemTag` in `Configuration_Legacy` golden file
@Jimbo4350 Jimbo4350 force-pushed the i+m/develop/CO-410/modify-protocolmagic branch from 7fb6ab3 to a9309aa Compare October 15, 2018 14:22
Copy link
Contributor

@mhuesch mhuesch left a comment

Choose a reason for hiding this comment

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

LGTM - good work!

The path issue is likely not a big deal. We can change it or leave it.

, ccExplorerExtendedApi = False
}
, ccWallet = WalletConfiguration { ccThrottle = Nothing }
, ccReqNetMagic = RequiresNoMagic
Copy link
Contributor

Choose a reason for hiding this comment

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

Had to run this through in my head, but it seems that we're pulling the "requiresNetworkMagic":"RequiresNoMagic" field from JSON into ccReqNetMagic, and the ccGenesis.gsProtocolConstants.gpcProtocolMagic.getRequiresNetworkMagic value is defaulting because the JSON has "protocolMagic":55550001. This looks right 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this, @intricate.

@intricate intricate merged commit ccca8b3 into develop Oct 15, 2018
@intricate intricate deleted the i+m/develop/CO-410/modify-protocolmagic branch October 16, 2018 14:37
KtorZ pushed a commit that referenced this pull request Nov 9, 2018
* [CO-410] Port release/1.3.1 config to develop

* [CO-410] Modify ProtocolMagic

* [CO-410] Continue modifying ProtocolMagic

* [CO-410] Change naming

* [CO-410] Add golden files for legacy `RequiresNetworkMagic`

* [CO-410] Modify `RequiresNetworkMagic`'s `FromJSON` instance to support legacy encoding

* [CO-410] Add golden decoding tests for legacy `ProtocolMagic` encoding

* [CO-410] Add golden decode only test for `Configuration`

* [CO-410] Run `pkgs/generate.sh`, remove reference files, hardcode
`systemTag` in `Configuration_Legacy` golden file
KtorZ pushed a commit to input-output-hk/cardano-wallet-legacy that referenced this pull request Nov 9, 2018
…-output-hk/cardano-sl#3715)

* [CO-410] Port release/1.3.1 config to develop

* [CO-410] Modify ProtocolMagic

* [CO-410] Continue modifying ProtocolMagic

* [CO-410] Change naming

* [CO-410] Add golden files for legacy `RequiresNetworkMagic`

* [CO-410] Modify `RequiresNetworkMagic`'s `FromJSON` instance to support legacy encoding

* [CO-410] Add golden decoding tests for legacy `ProtocolMagic` encoding

* [CO-410] Add golden decode only test for `Configuration`

* [CO-410] Run `pkgs/generate.sh`, remove reference files, hardcode
`systemTag` in `Configuration_Legacy` golden file
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.

3 participants