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

Update the code to edition 2018, and update dependencies #331

Merged
merged 8 commits into from Jun 8, 2022

Conversation

elichai
Copy link
Member

@elichai elichai commented Sep 15, 2021

As proposed in rust-bitcoin/rust-bitcoin#510 (comment) this PR raises the MSRV to 1.41.1 it also changes the code to be Edition 2018.

The PR contains a few things:

  • Moving to edition 2018 and fixing the imports
  • Sorting and combining imports to make them more concise
  • Replacing our c_void with core::ffi::c_void
  • Bumping the rand version to latest and modifying our RngCore implementations accordingly
  • Doing some small refactoring and using the new TryInto trait where it makes the code nicer

If people prefer I can split this PR into multiple and/or drop some commits

@elichai elichai mentioned this pull request Sep 15, 2021
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Thank you for doing this, looking forward to dropping old rand dependencies in our project :)

src/ecdh.rs Outdated
Comment on lines 177 to 209
use crate::Secp256k1;

use super::SharedSecret;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend we move to starting every test module with use super::*. In most cases, that will bring in all the types required for the tests.

examples/generate_keys.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
secp256k1-sys/src/lib.rs Show resolved Hide resolved
.github/workflows/rust.yml Outdated Show resolved Hide resolved
@elichai elichai force-pushed the edition-2018 branch 2 times, most recently from 0a096c7 to e6dc0b2 Compare September 16, 2021 14:00
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

utACK e6dc0b2

@Kixunil
Copy link
Collaborator

Kixunil commented Sep 17, 2021

Didn't review but I randomly noticed that we could change CONTEXT from Option to MaybeUninit (probably as a separate PR).

@apoelstra
Copy link
Member

Cool! concept ACK. Will review in detail later.

I think there is nothing stopping us merging this now? For rust-bitcoin I want a taproot release before the 2018 release, but I believe we don't need any further supporting changes from rust-secp for Taproot?

match data.len() {
constants::SECRET_KEY_SIZE => {
let mut ret = [0; constants::SECRET_KEY_SIZE];
match <[u8; constants::SECRET_KEY_SIZE]>::try_from(data) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general TryFrom should be used to implement fallible conversion, try_into() to call fallible conversion. (because TryFrom implies TryInto) I think it's OK when the types are not generic but maybe keeping the good habit is worth changing?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO try_into hides information into which specific type the conversion happens and makes code less readable / verifiable by human

Copy link
Contributor

Choose a reason for hiding this comment

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

@Kixunil I don't think that is generally true. AFAIK it is idiomatic to prefer TryInto over TryFrom but if you are not doing trait-bounds at all, TryFrom might be better because it doesn't need type annotations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is possible:

let x: Type = y.try_into()?;

But I think TryFrom is OK in this case.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

The commit message of the final commit (bde5f3a Use new trait TryInto and do small refactoring is now out of date (should be 'TryFrom'). Also there is one lint warning still on this PR

warning: unused import: `fmt`
--> secp256k1-sys/src/types.rs:2:12
|
2 | use core::{fmt, mem};
|            ^^^
|
= note: `#[warn(unused_imports)]` on by default

Apart from that, LGTM :)

@@ -60,7 +60,7 @@ jobs:
strategy:
matrix:
rust:
- 1.29.0
- 1.36.0
Copy link
Member

Choose a reason for hiding this comment

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

Does it make any difference if this is 1.36 as opposed to 1.36.0? Said another way, will anything be added to a later patch version of 1.36 that we should be enforcing the usage of? I don't know the answer I'm just wondering.

Copy link
Collaborator

Choose a reason for hiding this comment

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

One thing I noticed in the past, running cargo +1.36 build didn't work while cargo +1.36.0 did, so maybe this has the same interface.

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean didn't work as in the build failed? If so then that would validate my question and we should decide whether we are enforcing 1.36.0 or latest 1.36.*, right?

FTR I have been testing using cargo +1.36 check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It said unknown toolchain or something like that. But TBH it was a long ago, maybe it changed to support it.

@apoelstra
Copy link
Member

We do actually need to do a rust-secp release for Taproot, so delaying this until the next major rev.

Also, needs rebase.

@tcharding
Copy link
Member

In case you want to save yourself some work @elichai I was playing around with this branch and it took me quite a while to rebase it. Feel free to grab what I have done to save yourself having to do it. Same branch name on my tree (github.com/tcharding/rust-secp256k1).

@elichai elichai force-pushed the edition-2018 branch 2 times, most recently from 6eb22e5 to a2d43df Compare January 14, 2022 14:06
@tcharding
Copy link
Member

tcharding commented Jan 15, 2022

Have I had a git fail @elichai and pushed to your branch? Super sorry if I did, I did not realize pushRemote = git@github.com:elichai/rust-secp256k1.git was set in my config. FTR I checked out your branch using gh pr (github's command line tool). I assumed the branch would be configured to push to origin, I was wrong. I feel pretty rude having done that, please accept my apologies. Although I'm pretty confused right now looking at the times of the commits above, you might have pulled the changes from my tree.

@tcharding
Copy link
Member

Anyways, there is a branch on my tree now that has been updated to do two things

  • Use Rust 1.41.1
  • Try to make the diff as small and easy to review as possible (mainly this means not moving the import statements around anymore than is necessary).

@elichai
Copy link
Member Author

elichai commented Jan 15, 2022

No you didn't push here, Thanks for your rebase it helped to make sure I'm rebasing correctly (still rebased myself as to know what actually changed)

* Use Rust 1.41.1

Does that change anything here?

@tcharding
Copy link
Member

Does that change anything here?

Does not change the patch set AFAICT except for the actual version number itself and the commit messages.

@tcharding
Copy link
Member

Hey @elichai, no clue what order the MSRV patches are going to merge across the rust-bitcoin stack but we are in the vicinity of ready to merge this one, have you time to update the PR?

@tcharding
Copy link
Member

I was messing around with rust-bitcoin/rust-bitcoin#967 and chased build errors into secp, then into rand and ended up rebasing my local copy of this PR to see if it was a rand 6 problem. Anyways, in case its of any use I pushed it up to my tree on a branch of the same name again. FTR I'm hitting a build error still when enabling use-serde (on rust-bitcoin), but anyways there it is :)

@elichai
Copy link
Member Author

elichai commented Apr 26, 2022

Hey @elichai, no clue what order the MSRV patches are going to merge across the rust-bitcoin stack but we are in the vicinity of ready to merge this one, have you time to update the PR?

I'll rebase today-tomorrow

@elichai
Copy link
Member Author

elichai commented May 6, 2022

First push is a rebase, and the second one is fixing the nits

src/schnorr.rs Outdated
@@ -139,8 +135,7 @@ impl<C: Signing> Secp256k1<C> {
#[cfg(any(test, feature = "rand-std"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))]
pub fn sign_schnorr(&self, msg: &Message, keypair: &KeyPair) -> Signature {
let mut rng = thread_rng();
self.sign_schnorr_with_rng(msg, keypair, &mut rng)
self.schnorrsig_sign_with_rng(msg, keypair, &mut rand::thread_rng())
Copy link
Member

Choose a reason for hiding this comment

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

In f792674:

schnorrsig_sign_with_rng is deprecated; we should use the other method

Copy link
Member

Choose a reason for hiding this comment

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

IMO this is blocking merge.

Copy link
Member

Choose a reason for hiding this comment

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

@elichai I am happy to merge this once you address this

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, missed the notification on this

@@ -162,9 +163,8 @@ impl SecretKey {
/// ```
#[inline]
pub fn from_slice(data: &[u8])-> Result<SecretKey, Error> {
match data.len() {
Copy link
Member

Choose a reason for hiding this comment

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

In ac8e966:

Maybe worth thinking about turning these from_slice methods into TryFrom impls entirely ... doesn't need to be in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW I rekon we should keep this PR as lean as possible to help expedite review/merge.

apoelstra
apoelstra previously approved these changes May 6, 2022
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 2f18866 aside from nits

tcharding
tcharding previously approved these changes May 8, 2022
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 2f18866

@tcharding
Copy link
Member

Oh, @elichai, I just noticed the PR description mentions 1.36 still.

@tcharding
Copy link
Member

This is the last on to go and we have done it, friendly bump please reviewers :)

@koushiro
Copy link

Hi, can I ask when this PR is planned to be merged and a new version containing the PR will be released?

@Kixunil
Copy link
Collaborator

Kixunil commented May 30, 2022

@koushiro we hope for it to be faster than usual but it'll probably still take some time.

@tcharding
Copy link
Member

As far as I understand it, soon as this PR merges we can start releasing each of the crates in the rust-bitcoin stack starting at the bottom. rust-bech32 has been done already so next its rust-bitcoinconsensus, then bitcoin_hashes then this one. Hope that helps explain the process and potential timing.

@tcharding
Copy link
Member

Friendly bump, can we get an ack on this from another maintainer please. (I don't actually know who are the maintainers of this crate? @real-or-random, @jonasnick). Is that what you are waiting for to merge this @apoelstra?

@apoelstra
Copy link
Member

I am waiting for the use of self.schnorrsig_sign_with_rng to be removed.

@elichai
Copy link
Member Author

elichai commented Jun 7, 2022

Fixed, sorry that it took me so long

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 5d2f1ce

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 5d2f1ce

@apoelstra apoelstra merged commit 4f7f138 into rust-bitcoin:master Jun 8, 2022
@elichai elichai deleted the edition-2018 branch June 8, 2022 21:45
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.

None yet

8 participants