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

Reorganize internal codecs (rework-closing-commit-published) #1731

Closed
wants to merge 9 commits into from

Conversation

pm47
Copy link
Member

@pm47 pm47 commented Mar 18, 2021

Builds on #1728.

The goal is to separate internal codecs from protocol codecs, and to reduce risk during migrations.

Commits should be read one by one.

Re-work the `CommitPublished` types to work better with anchor outputs.
We previously stored the txs spending utxos that we could claim: this
doesn't make sense anymore if these txs may be RBF-ed, because the final
tx will be different from the initial one.

We instead track what `OutPoint`s we can claim, and the information
necessary to claim them. This way we can in the future let a different
actor finalize the txs that spend these outpoints (set the fees and sign).

We also add information on mutual close txs to immediately identify our
output and its amount: this makes auditing how much sats we'll get back
very easy from the API when we have many channels to watch.

This commit contains a DB migration of the channel data types, but in a
backwards-compatible way: we can still read from old data. The only
scenario impacted is channels that started force-closing before the migration.
They need special care to handle the fact that they had less data than
migrated channels, which is why we keep some legacy code around.
Add tests for the changes in the business logic.
Add a few tests in places that were previously lacking a bit.
@pm47 pm47 requested a review from t-bast March 18, 2021 16:41
This allows us to strictly segregate each codec version (to make sure
that we don't accidentally mix codec versions), while still letting
tests access each unitary codecs (which using inner `private classes`
would have prevented). Relevant tests only need to be moved to the
appropriate package.

```
wire
 |
 `-- ChannelCodecs
 |
 `-- legacy
 |      |
 |      `-- legacy0
 |      |      |
 |      |      `-- LegacyChannelCodecs0
 |      |
 |      `-- legacy1
 |      |      |
 |      |      `-- LegacyChannelCodecs1
 |      |
 |      `-- ChannelTypes
 |
 `-- others
```
This saves us from repeating `private[package]` for each individual
codec and is more foolproof (we only need to make sur that the codec is
inside the inner class).
This more rigorous organization showed that we were using some
codecs in an unrelated wallet database used with electrum. We should
probably introduce a `InternalCommonCodecs` class that is more or less
immutable (elementary codecs not impacted by versions changes, such
as `txCodec` or `bool8`).

```
wire
 |
 `-- internal
 |       |
 |       `-- channel
 |       |      |
 |       |      `-- legacy
 |       |      |      |
 |       |      |      `-- legacy0
 |       |      |      |      |
 |       |      |      |      `-- LegacyChannelCodecs0
 |       |      |      |
 |       |      |      `-- legacy1
 |       |      |      |      |
 |       |      |      |      `-- LegacyChannelCodecs1
 |       |      |      |
 |       |      |      `-- ChannelTypes
 |       |      |
 |       |      `-- ChannelCodecs
 |       |
 |       `-- CommandCodecs
 |
 `-- others
```
This means that when adding a new version of codecs, we will add a new
file instead of overwriting previous files. It's easier to keep track
of modifications.

Also, the `stateDataCodec` is now more clearly separated.

```
wire
 |
 `-- internal
 |       |
 |       `-- channel
 |       |      |
 |       |      `-- legacy
 |       |      |      |
 |       |      |      `-- version0
 |       |      |      |      |
 |       |      |      |      `-- ChannelCodecs0
 |       |      |      |
 |       |      |      `-- version1
 |       |      |      |      |
 |       |      |      |      `-- ChannelCodecs1
 |       |      |      |
 |       |      |      `-- ChannelTypes
 |       |      |
 |       |      `-- version2
 |       |      |      |
 |       |      |      `-- ChannelCodecs2
 |       |      |
 |       |      `-- ChannelCodecs
 |       |
 |       `-- CommandCodecs
 |
 `-- others
```
All versions are now at the same level, which means adding a new version
is really just adding a new package. This may remove a lot of headaches
for further migration.

The downside is that we can't restrict the visibility of `MigrationUtils`
(formerly `ChannelTypes`) to versions 0 and 1, but we would have had the
same issue as soon as we introduce version 3 anyway (because the current
version 2 codecs would have been moved to the legacy package).

```
wire
 |
 `-- internal
 |       |
 |       `-- channel
 |       |      |
 |       |      `-- MigrationTools
 |       |      |
 |       |      `-- version0
 |       |      |      |
 |       |      |      `-- ChannelCodecs0
 |       |      |
 |       |      `-- version1
 |       |      |      |
 |       |      |      `-- ChannelCodecs1
 |       |      |
 |       |      `-- version2
 |       |      |      |
 |       |      |      `-- ChannelCodecs2
 |       |      |
 |       |      `-- ChannelCodecs
 |       |
 |       `-- CommandCodecs
 |
 `-- others
```
@pm47 pm47 force-pushed the rework-closing-commit-published-pm branch from d5991fa to 41bf1fa Compare March 18, 2021 17:11
@pm47 pm47 changed the title Reorganize internal codecs Reorganize internal codecs (rework-closing-commit-published) Mar 19, 2021
@pm47
Copy link
Member Author

pm47 commented Mar 19, 2021

Superseded by #1732.

@pm47 pm47 closed this Mar 19, 2021
@t-bast t-bast deleted the rework-closing-commit-published-pm branch August 16, 2022 09:47
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.

2 participants