Skip to content

Fix backwards compat for blocked_monitor_updates and finally kill vec_type #2400

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

Merged
merged 10 commits into from
Jul 11, 2023

Conversation

TheBlueMatt
Copy link
Collaborator

In 1ce2beb,
Channel::blocked_monitor_updates was moved to an even TLV to
ensure downgrades with vec entries are forbidden. However, the
serialized type remained vec_type, which is always written.

Instead, optional_vec must be used. This is fixed in the first commit.

Historically, we used vec_type for all TLV Vec reads/writes, but
it is asymmetric and thus somewhat confusing - on the write side it
always writes a TLV entry, even if there are zero elements. On the
read side, it happily accepts a missing TLV, providing a
zero-length vector.

In 85b573d a new optional_vec
TLV format was added which was symmetric, but only supports
optional vecs.

We then add a required_vec TLV format, and move all the old vec_type formats to either required_vec
or optional_vec, removing vec_type at the end to avoid these kinds of mistakes in the future.

In practice only the first commit needs to land for 0.0.116, but if we can go ahead and land the whole thing that'd be cool too.

In 1ce2beb,
`Channel::blocked_monitor_updates` was moved to an even TLV to
ensure downgrades with vec entries are forbidden. However, the
serialized type remained `vec_type`, which is always written.

Instead, `optional_vec` must be used.
Historically, we used `vec_type` for all TLV Vec reads/writes, but
it is asymmetric and thus somewhat confusing - on the write side it
always writes a TLV entry, even if there are zero elements. On the
read side, it happily accepts a missing TLV, providing a
zero-length vector.

In 85b573d a new `optional_vec`
TLV format was added which was symmetric, but only supports
optional vecs. This adds the corresponding required form, always
writing a TLV and ensuring it is present.
This converts some required TLVs to `required_vec` which are, in
fact, required (and have been written forever).

* `HTLCFailReason` hasn't changed since many structs were converted
  to TLVs in 66784e3.
* `NodeInfo::channels` has been written since `NetworkGraph`
  structs were converted to TLVs in 321b19c.
* Several test-only TLV writes were converted.
 * `PaymentPathFailed::path` was added without an optional compat
   wrapper in e5310dd.
 * `PaymentPathSuccessful::path` has always been written since the
   event was added in 2c4f16d.
 * `Probe{Failed,Successful}::path` have always been written since
   the events were added in eb8bce0.
* `CommitmentTransaction::htlcs` has always been written since the
  struct was converted to TLVs in 66784e3.
* `HolderCommitmentTransaction::counterparty_htlc_sigs` have always
  been written since the struct was converted to TLVs in
  c8bc1b6.
 * `BlindedTail::hops` has always been written since it was
   introduced in 64c26c8.
 * `PaymentParameters::clear_hints` has always been written since
   it was introduced as `Payee::route_hitns` in 46b68c5.
* `PhantomRouteHints::channels` has been written since the struct
  was added in 410eb05.
* `HTLCSource::path_hops` has been written since the struct was
  converted to TLVs in 66784e3.
@TheBlueMatt TheBlueMatt added this to the 0.0.116 milestone Jul 7, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 7, 2023

Codecov Report

Patch coverage: 79.16% and no project coverage change.

Comparison is base (e40b6ae) 90.31% compared to head (d83390c) 90.31%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #2400    +/-   ##
========================================
  Coverage   90.31%   90.31%            
========================================
  Files         106      106            
  Lines       54965    55166   +201     
  Branches    54965    55166   +201     
========================================
+ Hits        49639    49822   +183     
- Misses       5326     5344    +18     
Impacted Files Coverage Δ
lightning/src/events/mod.rs 41.76% <0.00%> (-0.10%) ⬇️
lightning/src/ln/msgs.rs 84.59% <ø> (ø)
lightning/src/ln/onion_utils.rs 90.68% <ø> (ø)
lightning/src/onion_message/packet.rs 76.92% <ø> (ø)
lightning/src/util/chacha20poly1305rfc.rs 95.33% <ø> (ø)
lightning/src/util/ser_macros.rs 69.69% <50.00%> (+0.21%) ⬆️
lightning/src/routing/gossip.rs 89.62% <75.00%> (+0.10%) ⬆️
lightning/src/chain/channelmonitor.rs 94.72% <100.00%> (+<0.01%) ⬆️
lightning/src/ln/chan_utils.rs 94.50% <100.00%> (-0.02%) ⬇️
lightning/src/ln/channel.rs 89.44% <100.00%> (+0.02%) ⬆️
... and 2 more

... and 12 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@alecchendev alecchendev left a comment

Choose a reason for hiding this comment

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

LGTM, checked all the commits referenced for fields being read as required and they seemed to look good

(4, path.hops, vec_type),
(4, path.hops, required_vec),
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, how did you find all the commits you referenced when checking if certain fields had been written as required for a while?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

git blame and some elbow grease :)

wpaulino
wpaulino previously approved these changes Jul 10, 2023
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

Nice catch!

@@ -6781,7 +6781,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
(5, self.context.config, required),
(6, serialized_holder_htlc_max_in_flight, option),
(7, self.context.shutdown_scriptpubkey, option),
(8, self.context.blocked_monitor_updates, vec_type),
(8, self.context.blocked_monitor_updates, optional_vec),
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops :( Good thing we're getting rid of vec_type.

@TheBlueMatt
Copy link
Collaborator Author

Added some further documentation on the TLV read/write types.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

LGTM after squash

 * `HolderSignedTx::htlc_outputs` has always been written since it
   was converted to TLVs in 86641ea.
 * `ChanelMonitorUpdateStep::*::htlc_outputs` have been written
   since the enum was converted to TLVs in 86641ea.
Historically, we used `vec_type` for all TLV Vec reads/writes, but
it is asymmetric and thus somewhat confusing - on the write side it
always writes a TLV entry, even if there are zero elements. On the
read side, it happily accepts a missing TLV, providing a
zero-length vector.

In 85b573d a new `optional_vec`
TLV format was added which was symmetric, but only supports
optional vecs.

Now that we've migrated entirely to the new `required_vec` TLV
type, we can entirely remove the awkward `vec_type`.
While we don't want to publicly document these and support them for
downstream crates, documenting them internally is useful.
@TheBlueMatt TheBlueMatt force-pushed the 2023-07-kill-vec_type branch from 28fa187 to d83390c Compare July 11, 2023 16:20
@TheBlueMatt
Copy link
Collaborator Author

Fixed a typo and squashed -

$ git diff-tree -U1 28fa1872 d83390c6
diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs
index 302cb6c31..710085e2b 100644
--- a/lightning/src/util/ser_macros.rs
+++ b/lightning/src/util/ser_macros.rs
@@ -20,3 +20,3 @@
 // Some of the other types include:
-//  * (default_value, $default) - reads optionally, writing $default if no TLV is present
+//  * (default_value, $default) - reads optionally, reading $default if no TLV is present
 //  * (static_value, $value) - ignores any TLVs, always using $value
$ 

@TheBlueMatt TheBlueMatt merged commit e404c12 into lightningdevkit:main Jul 11, 2023
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.

5 participants