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

Followup: custom HTLC TLVs #2504

Merged

Conversation

alecchendev
Copy link
Contributor

Couple follow ups on #2308, let me know if I missed anything.

No idea why the compiler wanted me to add the import on the doc tests

Remove print statement, remove some unnecessary checks copied over from
test utils, make minor simplifications, wrap especially long lines.
@codecov-commenter
Copy link

codecov-commenter commented Aug 16, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (9b13862) 90.39% compared to head (83f0dbc) 90.39%.

❗ 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    #2504   +/-   ##
=======================================
  Coverage   90.39%   90.39%           
=======================================
  Files         106      106           
  Lines       56295    56267   -28     
  Branches    56295    56267   -28     
=======================================
- Hits        50887    50863   -24     
+ Misses       5408     5404    -4     
Files Changed Coverage Δ
lightning/src/util/ser_macros.rs 74.83% <ø> (ø)
lightning/src/ln/msgs.rs 85.35% <100.00%> (-0.02%) ⬇️
lightning/src/ln/outbound_payment.rs 90.25% <100.00%> (ø)
lightning/src/ln/payment_tests.rs 97.50% <100.00%> (+0.09%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

wpaulino
wpaulino previously approved these changes Aug 16, 2023
} else { None };
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(preimage.iter()).collect();
let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't buy that we need to collect here. We construct an iterator and then turn it into a vec, and then pass it to the macro as an iterator. The macro uses the iterator twice, iirc, so we can't just generate the iterator here and then give it to the macro, but we can paste this line in the macro call and it should just work (or have the macro clone the iterator before use).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We sort after we collect into a vec?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh oops, right, hmmm, I mean its definitely possible to avoid the collect but probably not entirely worth writing a custom iterator for it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess its not that crazy to build the iterator by hand using https://doc.rust-lang.org/std/iter/fn.from_fn.html but no need to bother.

} else { None };
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(preimage.iter()).collect();
let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess its not that crazy to build the iterator by hand using https://doc.rust-lang.org/std/iter/fn.from_fn.html but no need to bother.

@@ -143,6 +144,9 @@ macro_rules! encode_tlv_stream {
#[macro_export]
macro_rules! _encode_tlv_stream {
($stream: expr, {$(($type: expr, $field: expr, $fieldty: tt)),* $(,)*}) => { {
_encode_tlv_stream!($stream, { $(($type, $field, $fieldty)),* }, &[])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be $crate::_encode_tlv_stream

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah!

@@ -580,6 +577,7 @@ macro_rules! _decode_tlv_stream_range {
///
/// For example,
/// ```
/// # use lightning::_encode_tlv_stream;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Then we can drop the doc changes.

Don't collect iterators to compare, minorly simplify encoding the
keysend TLV, combine the _encode_tlv_stream variants to check that the
ordering of TLVs is correct including custom TLVs.
@TheBlueMatt TheBlueMatt merged commit 9de2a91 into lightningdevkit:main Aug 17, 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.

4 participants