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

Added a channel version to Commitments object #1059

Merged
merged 4 commits into from
Jul 12, 2019
Merged

Conversation

pm47
Copy link
Member

@pm47 pm47 commented Jul 2, 2019

In a backward-compatible way, by using the fact that the first object of
a legacy Commitments was a public key, starting from 0x02 or 0x03.

In a backward-compatible way, by using the fact that the first object of
a legacy `Commitments` was a public key, starting from 0x02 or 0x03.
@pm47 pm47 requested a review from sstone July 2, 2019 15:31
@@ -50,6 +50,14 @@ object ChannelCodecs extends Logging {
("path" | keyPathCodec) ::
("parent" | int64)).as[ExtendedPrivateKey]

val channelVersionCodec: Codec[ChannelVersion] = discriminatorWithDefault[ChannelVersion](
discriminator = discriminated[ChannelVersion].by(byte)
.typecase(0x01, provide(ChannelVersion.STANDARD))
Copy link
Contributor

Choose a reason for hiding this comment

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

How about encoding the type byte inside the ChannelVersion object?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why would we do that? The object and its encoding are two different things.

Copy link
Contributor

Choose a reason for hiding this comment

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

Each subtype of ChannelVersion will be associated with a particular byte that is used in the codec, since all versions will have a version byte it seemed reasonable to have it embedded in ChannelVersion itself. The code would become something like:

.typecase(ChannelVersion.STANDARD.typeByte, provide(ChannelVersion.STANDARD))

Copy link
Member Author

Choose a reason for hiding this comment

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

You are thinking in terms of code factorization but I'm more concerned about proper separation of layers. With your proposal the codec would be partly defined in the ChannelCodecs file and partly in the ChannelTypes file. Meaning that modifying ChannelTypes could create backward incompatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes i agree that layer separation is quite important here and we definitely don't want to define the codec in two different places, however it felt reasonable to declare the codec byte close to the definition of the scala type for a certain commitment version (after all they are always and uniquely associated), i did something similar here although i did not include it in the object.

for consistency with `ChannelFlags`
@codecov-io
Copy link

codecov-io commented Jul 4, 2019

Codecov Report

Merging #1059 into master will decrease coverage by 8.63%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1059      +/-   ##
==========================================
- Coverage    82.5%   73.87%   -8.64%     
==========================================
  Files          99      126      +27     
  Lines        7587     8489     +902     
  Branches      298      325      +27     
==========================================
+ Hits         6260     6271      +11     
- Misses       1327     2218     +891
Impacted Files Coverage Δ
...n/scala/fr/acinq/eclair/channel/ChannelTypes.scala 100% <ø> (ø) ⬆️
...ain/scala/fr/acinq/eclair/wire/ChannelCodecs.scala 100% <100%> (ø) ⬆️
...in/scala/fr/acinq/eclair/api/JsonSerializers.scala 96.96% <100%> (+0.09%) ⬆️
...c/main/scala/fr/acinq/eclair/channel/Channel.scala 84.16% <100%> (-0.1%) ⬇️
...in/scala/fr/acinq/eclair/channel/Commitments.scala 86.92% <100%> (ø) ⬆️
.../fr/acinq/eclair/gui/stages/OpenChannelStage.scala 0% <0%> (ø)
...r/gui/controllers/NotificationPaneController.scala 0% <0%> (ø)
...gui/src/main/scala/fr/acinq/eclair/gui/FxApp.scala 0% <0%> (ø)
...cala/fr/acinq/eclair/gui/utils/GUIValidators.scala 0% <0%> (ø)
... and 25 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1621e39...ec7e95d. Read the comment docs.

sstone
sstone previously approved these changes Jul 11, 2019
@pm47 pm47 merged commit c1a7b4f into master Jul 12, 2019
@pm47 pm47 deleted the commitment-version branch July 12, 2019 11:36
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.

4 participants