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

Linter fixes #27

Merged
merged 6 commits into from
Mar 14, 2022
Merged

Linter fixes #27

merged 6 commits into from
Mar 14, 2022

Conversation

cryptoquick
Copy link
Member

One notable lint:
https://rust-lang.github.io/rust-clippy/master/index.html#init_numbered_fields
Which was why I made the AccountStep enum more consistent. I did that work as a separate commit because it's a bit more involved change.

There were a couple of other cases where I could've tried fixing the lint by adding named fields instead of a positional tuple struct to the enum member, which would fix the issue, but I became concerned it was indicative of an oversight in the strict encoding portion of the client side validation library. I've made an issue for that here:
LNP-BP/client_side_validation#54

@dr-orlovsky dr-orlovsky added the refactoring Refactoring of the existing code label Feb 19, 2022
@dr-orlovsky dr-orlovsky added this to the v0.7.0 milestone Feb 19, 2022
Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Can you pls give me more information: usually the repo passes clippy lints. Did something change in the latest clippy stable? We use stable clippy for CI (since in nightly there are sometimes random changes which break builds/CI unexpectedly)

@@ -102,6 +102,7 @@ impl string_result_t {
pub fn success(data: impl ToString) -> string_result_t {
let (code, details) = match CString::new(data.to_string()) {
Ok(s) => (error_t::success, result_details_t { data: s.into_raw() }),
#[allow(clippy::needless_borrow)]
Copy link
Member

Choose a reason for hiding this comment

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

Why just not remove the borrow here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because the CString NulError is of a different type, and there was some case where Clippy couldn't make sense of things.

Works:

#[allow(clippy::needless_borrow)]
Err(err) => (error_t::invalid_result_data, (&err).into()),

Does not work:

Err(err) => (error_t::invalid_result_data, err.into()),

Why:

the trait bound `signer::result_details_t: std::convert::From<std::ffi::NulError>` is not satisfied
the following implementations were found:
  <signer::result_details_t as std::convert::From<&E>>
required because of the requirements on the impl of `std::convert::Into<signer::result_details_t>` for `std::ffi::NulError`

However, doing the CString conversion manually works:

            Err(err) => (error_t::invalid_result_data, result_details_t {
                data: CString::new(err.to_string())
                    .expect("Null byte in string_result_t success code doc comments")
                    .into_raw(),
            }),

This was referencing the code in the from impl here:
https://github.com/LNP-BP/descriptor-wallet/pull/27/files#diff-d3399c793447433124719f22f76f514e89f4bff0280e4675af35ae071b376ee2L179

But that's less-than-ideal, since it's essentially identical code to the From implementation, duplicated over. It's not so simple to implement the error type for CStrings. Anyway, I've pushed that code, let me know if you have a better approach.

@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
Copy link
Member

Choose a reason for hiding this comment

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

hm, not sure we want to default to the nightly channel

Copy link
Member Author

Choose a reason for hiding this comment

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

I just noticed, as I tried setting this back to stable, it caused the issue I mentioned I had fixed by reverting to the old code mentioend in the comment here:
#27 (comment)

I'm not sure we can get this to pass clippy lints on stable at this time without also making breaking changes to dependents.

Copy link
Member

Choose a reason for hiding this comment

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

It seems that we can again move to stable with the latest 0.59 release

Copy link
Member Author

Choose a reason for hiding this comment

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

It's true, how convenient :)

@@ -15,6 +15,7 @@
// Coding conventions
#![recursion_limit = "256"]
#![deny(dead_code, /* missing_docs, */ warnings)]
#![allow(clippy::init_numbered_fields)]
Copy link
Member

Choose a reason for hiding this comment

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

Probably this will go away after resolving LNP-BP/client_side_validation#54

Copy link
Member

Choose a reason for hiding this comment

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

Can you pls check that we still need this with the latest 0.59 stable release?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing this allow statement presents this warning/error on 1.59:

Screenshot from 2022-03-07 05-09-12

Comment on lines 412 to 415
Normal {
/// Unhardened derivation 0-based index value
index: UnhardenedIndex,
},
Copy link
Member

Choose a reason for hiding this comment

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

I do not entirely get why do we need this. Is it something suggested by the linter?

This is a breaking change which will stop downstream projects from compiling, and will require a major release. Are we really that much needing it?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was originally suggested by the linter, but if that was a breaking put it back. It's basically caused by the error I mentioned and documented here:
LNP-BP/client_side_validation#54

But also, it's weird, once I put it back, the error is gone, which may also invalidate that issue. Good catch, either way, thank you. I wouldn't want to introduce bad code, nor would I want to waste your time.

@codecov
Copy link

codecov bot commented Feb 19, 2022

Codecov Report

Merging #27 (e156005) into master (91012a9) will decrease coverage by 0.2%.
The diff coverage is 54.5%.

❗ Current head e156005 differs from pull request most recent head ddb6f06. Consider uploading reports for the commit ddb6f06 to get more accurate results

Impacted file tree graph

@@           Coverage Diff            @@
##           master     #27     +/-   ##
========================================
- Coverage    19.2%   19.0%   -0.2%     
========================================
  Files          34      34             
  Lines        2748    2746      -2     
========================================
- Hits          528     523      -5     
- Misses       2220    2223      +3     
Impacted Files Coverage Δ
descriptors/src/lib.rs 100.0% <ø> (ø)
hd/src/lib.rs 100.0% <ø> (ø)
libbitcoin/src/signer.rs 0.0% <0.0%> (ø)
psbt/src/sign/signer.rs 0.0% <ø> (ø)
src/lib.rs 8.7% <ø> (ø)
hd/src/indexes.rs 16.5% <50.0%> (ø)
slip132/src/lib.rs 18.1% <50.0%> (ø)
scripts/src/parser.rs 93.3% <100.0%> (-0.6%) ⬇️

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 91012a9...ddb6f06. Read the comment docs.

Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Pls see my comments

@@ -15,6 +15,7 @@
// Coding conventions
#![recursion_limit = "256"]
#![deny(dead_code, /* missing_docs, */ warnings)]
#![allow(clippy::init_numbered_fields)]
Copy link
Member

Choose a reason for hiding this comment

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

Can you pls check that we still need this with the latest 0.59 stable release?

@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
Copy link
Member

Choose a reason for hiding this comment

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

It seems that we can again move to stable with the latest 0.59 release

@cryptoquick
Copy link
Member Author

I explicitly pegged the toolchain in the rust-toolchain.toml to 1.59 in case folks forget to rustup update. It passes linter on stable, but I had to leave in the clippy allow for init_numbered_fields.

@cryptoquick
Copy link
Member Author

@dr-orlovsky I just noticed that some additional commits were pushed to the master branch. What's going on there? And should we go back to using nightly due to the try trait v2 feature?

@dr-orlovsky
Copy link
Member

I merged previous work on taproot support since we've got rust-bitcoin release candidate out. Now it will be finalized.

We should not regress to nightly since nightly with try_trait_v2 feature is required only for libbitcoin and not the rest of the code. That is why in CI they are build separately

Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

ACK ddb6f06

@dr-orlovsky dr-orlovsky merged commit a10b227 into BP-WG:master Mar 14, 2022
@cryptoquick cryptoquick deleted the linter-fixes branch March 14, 2022 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring of the existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants