-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix ChannelType and Script decodings in TLVs #30
Conversation
f93b13e
to
2d7c0f6
Compare
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #30 +/- ##
========================================
- Coverage 35.1% 35.0% -0.1%
========================================
Files 17 17
Lines 1878 1881 +3
========================================
Hits 659 659
- Misses 1219 1222 +3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried run the tests, all tests failed.
I listed the reasons bellow:
- The TLV field
shutdown_scriptpubkey
causes a error when is empty. But this error is not related with this fix. I opened this issue. - The
ChannelType ::lightning_deserialize
does not handle the byte array correctly (see details bellow).
return Err(lightning_encoding::Error::DataIntegrityError(s!( | ||
"non-minimal channel type encoding" | ||
))); | ||
} else if flags.as_inner() == &[] as &[u8] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't seem right because if channel-type was not defined, FlagVec::lightning_deserialize (see here) returns FlagVec::default() (vec![0u8; 1]) instead of an empty vector.
} else if flags.as_inner() == &[] as &[u8] { | |
} else if flags == FlagVec::new() { |
lnp2p/src/bolt/bolt2.rs
Outdated
ChannelType::try_from(flags) | ||
} | ||
fn lightning_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error> { | ||
let flags = FlagVec::lightning_deserialize(data)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method still needs to be completed.
To clarify the problem, I wrote the test bellow:
#[test]
fn decode_static_remotekey_channel_type() {
// Byte array expected by ChannelType::lightning_deserialize method
let bytes = [0u8, 2u8, 0u8, 16u8];
// That's Working!
let msg = ChannelType::lightning_deserialize(&bytes);
assert_eq!(true, msg.is_ok());
// The byte array received by `ChannelType::lightning_deserialize` when
// we try decode open_channel message sent by clightning
let bytes = [16u8, 0u8];
// Fail!
let msg = ChannelType::lightning_deserialize(&bytes);
assert_eq!(true, msg.is_ok())
}
As we can see above, the ChannelType::lightning_deserialize
method receives an unexpected byte array. But I don't know if the problem is TLV decode or ChannelType itself.
419a7c4
to
7129e37
Compare
@crisdut I figured this thing out. If ends up with this story: So I had to update encoding of all types which appear only in TLV not to store the length value and rely on TLV I published v0.9.2 with all these changes |
Supersedes #27
@crisdut can you pls add your tests here and see would they pass? If yes, we will merge this one instead of #27