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

Remove schemars pin from manifest #1696

Merged
merged 2 commits into from Apr 19, 2023

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Mar 6, 2023

This has grown due to now including pinning work also done in #1736, I decided to do this because the PRs conflict and doing it all here saves accidentally getting out of sync. And #1764 requires this PR.

  • Patch 1 is unchanged
  • Patch 2 now fixes pinning in bitcoin and hashes CI scripts and in the docs of both as well as the manifest stuff relating to schemars - phew.

Fix: #1687

@tcharding tcharding changed the title hashes: Remove schemars pin WIP: hashes: Remove schemars pin Mar 6, 2023
Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

because it does not take into account the version of cargo in use.

That's not right, version of cargo is irrelevant. The reason it's wrong is if a different crate requires higher version those will be incompatible leading to at best duplication, at worst impossibility to compile.

hashes/Cargo.toml Outdated Show resolved Hide resolved
@Kixunil
Copy link
Collaborator

Kixunil commented Mar 6, 2023

You also need cargo update -p schemars --precise 0.8.3

@apoelstra
Copy link
Member

I didn't see this before opening #1697. But:

  • We don't actually need to pin schemars to compile with 1.41.1. We do need to pin url (2.2.2) and form_urlencoded (1.0.1).
  • However Jeremy's test fails, on all compilers, with schemars >0.8.3.

So I dunno, maybe the pin was correct.

@tcharding
Copy link
Member Author

That's not right, version of cargo is irrelevant. The reason it's wrong is if a different crate requires higher version those will be incompatible leading to at best duplication, at worst impossibility to compile.

Cool, thanks for the explanation.

@tcharding tcharding changed the title WIP: hashes: Remove schemars pin Remove schemars pin Mar 6, 2023
@tcharding tcharding changed the title Remove schemars pin Remove schemars pin from manifest Mar 6, 2023
@tcharding
Copy link
Member Author

tcharding commented Mar 6, 2023

We don't actually need to pin schemars to compile with 1.41.1.

I discovered this too but the versions of schemars used by hashes and extended_tests/schemars have to be the same when running extended_tests/schemars tests, and the tests fail without pinning so I'm guessing dowstream users will hit problems too if they do not pin. Did not verify that assumption.

@tcharding tcharding force-pushed the 03-36-schemars branch 4 times, most recently from 196fcc3 to a970c72 Compare March 6, 2023 23:35
@tcharding tcharding mentioned this pull request Mar 7, 2023
8 tasks
@apoelstra
Copy link
Member

The new README text is kinda misleading. You do need to pin schemars ... but this has nothing to do with the MSRV. For the MSRV you just need to pin url and formurll_encoded.

@tcharding
Copy link
Member Author

tcharding commented Mar 7, 2023

I'm a bit confused then,

rust-bitcoin

  • cargo test --features=schemars - works fine
  • cd hashes && cargo +1.41.1 test --features=schemars - works fine (can't use this command in workspace root with +1.41.1 for some reason)

extended_tests/schemars_test

  • cargo test fails unless schemars is pinned with --precise 0.8.3
  • cargo +1.41.1 test fails unless schemars, url, form_urlencdode are all pinned

@tcharding
Copy link
Member Author

tcharding commented Mar 7, 2023

The answer doesn't matter really, I could have easily made a mistake while checking every combination I could think of.

I changed hashes/README.md to be a hopefully loose enough to not be misleading and correct enough to help users out (based on your comment @apoelstra)

@apoelstra
Copy link
Member

apoelstra commented Mar 7, 2023

@tcharding to use 1.41.1 you need to pin url and form_urlencoded. There is no need to do this unless you are using 1.41.

To use schemars at all you need to pin schemars. Which begs the question of why we are unpinning it at all.

@Kixunil
Copy link
Collaborator

Kixunil commented Mar 7, 2023

To use schemars at all you need to pin schemars

Do you mean the test failure after doing the following?

  1. vim Cargo.toml - remove the pin
  2. cd extended_tests/schemars
  3. vim Cargo.toml - remove the pin
  4. cargo test

I printed the error:

ValidationError { msg: "Invalid type.", instance: Some(String("6cfb35868c4465b7c289d7d5641563aa973db6a929655282a7bf95c8257f53ef")), schema: Some(Object {"$schema": String("http://json-schema.org/draft-07/schema#"), "description": String("Output of the SHA256t hash function."), "items": Array [Object {"maxLength": Number(64), "minLength": Number(64), "pattern": String("[0-9a-fA-F]+"), "type": String("string")}], "maxItems": Number(1), "minItems": Number(1), "title": String("Hash_for_TestHashTag"), "type": String("array")}), instance_path: [], schema_path: ["type"] }

If I understand it correctly the type is OK, just jsonschema_valid thinks it's not? (In hurry so good chance I'm wrong.)

@apoelstra
Copy link
Member

Do you mean the test failure after doing the following?

Yes, I mean that test failure. I wasn't able to print the error because somehow nothing returned by the failing assert implements Debug. And I don't know what jsonschema_valid is or how it relates to schemars.

@jeandudey
Copy link
Contributor

jeandudey commented Mar 7, 2023

The schema generated is wrong because schemars is interpreting the struct tuple as a JSON array.

Can be easily solved by:

#[cfg(feature = "schemars")]
impl<T: Tag> actual_schemars::JsonSchema for Hash<T> {
    fn schema_name() -> String {
        "Hash".to_owned()
    }

    fn json_schema(gen: &mut actual_schemars::gen::SchemaGenerator) -> actual_schemars::schema::Schema {
        crate::util::json_hex_string::len_32(gen)
    }
}

To use schemars at all you need to pin schemars.

I think its better to unpin it and every other dependency and just pin using Cargo.lock with the commands to pin dependencies since it prevents rust-bitcoin for being packaged easily, for example, in GNU Guix as it provides schemars@0.8.8 which is not compatible with the current version spec, so one has to go and patch the Cargo.toml of the crate to be able to use it with newer versions. So that needs to be done for every pinned crate where a new version is available.

I think that's true for other distros that provide only a single version of a package instead of including all of the minor versions needed.

@jeandudey
Copy link
Contributor

jeandudey commented Mar 7, 2023

That would also effectively remove the need to pin other crates that we don't use directly in the Cargo.toml and allows to rename actual-schemars to schemars.

Comment on lines 35 to 36
# because 1.0.8 does not build with Rust 1.41.1 (because of useage of `Arc::as_ptr`).
dyn-clone = { version = "<=1.0.7", default_features = false, optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

If schemars if being unpinned this should be too IMO, by removing it completely, should allow for #1696 (comment)

@apoelstra
Copy link
Member

@jeandudey thanks for the fix!

We are all onboard with removing pins (all of them). The issue is that nobody besides you in this conversation has ever actually used schemars, the person who originally advocated for its inclusion is no longer working on it, and they evidently made some breaking change between 0.8.3 and 0.8.4 which is causing our only test case to break.

@tcharding tcharding marked this pull request as draft March 8, 2023 23:31
apoelstra added a commit that referenced this pull request Mar 22, 2023
ffee8ad Bump version to v0.30.0 (Tobin C. Harding)

Pull request description:

  Add changelog notes and bump the version number to v0.30.0.

  ## TODO - pre-merge

  - [x] Release `bitcoin_hashes` 0.12: #1694
  - [x] Release secp 0.27: rust-bitcoin/rust-secp256k1#588
    - rust-bitcoin/rust-secp256k1#590
  - [x] Update `secp256k1` dependency to use newly released v0.27: #1714
  - [x] Merge
    - ~#1696
    - #1695
    -  #1111
  - [x] If time permits merge these:
    - #1710
    - #1705
    - #1713
  - [x] Set the release date in changelog header
  - [x] And merge these:
    - #1721
    - #1720
    - #1719
    - #1717

  ## TODO  - post release
  - [ ] Release the blogpost: rust-bitcoin/www.rust-bitcoin.org#2
     - ~Set the date in the blog post to match the date 0.30 is released~

ACKs for top commit:
  sanket1729:
    reACK ffee8ad
  Kixunil:
    ACK ffee8ad
  apoelstra:
    ACK ffee8ad

Tree-SHA512: b0ea113ee1726fd9b263d0e01fe14bd544c007c05a9ac43b6c2d4edbeef3bb3ad456b061ef086626e1e1b27a0cda49cb6bc28aac3ad1691d72ffe00400ed5b45
tcharding added a commit to tcharding/rust-bitcoin that referenced this pull request Mar 23, 2023
The derived implementation of `JsonSchema` recently stopped working as
described here:

rust-bitcoin#1696 (comment)

Implement the suggestion.
@tcharding
Copy link
Member Author

Implemented all review suggestions, thanks crew.

Kixunil
Kixunil previously approved these changes Mar 28, 2023
Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK d02a984

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

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

This should be /usr/bin/env bash. Not all systems have bash in /bin.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing, can do.

(cd extended_tests/schemars && cargo test)
pushd "$REPO_DIR/hashes/extended_tests/schemars" > /dev/null
cargo test
popd
Copy link
Member

Choose a reason for hiding this comment

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

In d02a984:

May want to redirect popd to null as well if you're redirecting pushd.

Copy link
Member Author

@tcharding tcharding Mar 28, 2023

Choose a reason for hiding this comment

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

I added the redirect to null, FTR on my system popd does not output anything anyways. Are there different implementations of popd that do?

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. On my system popd also outputs the directory that it's changing to. I have bash 5.1. Maybe this is an obscure setting somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

derrrr me no Linux - I'm using zsh as my shell.

@apoelstra
Copy link
Member

Done reviewing d02a984. Looks good, but I would like the shebang to be fixed.

@tcharding
Copy link
Member Author

Fixed shebang and added redirect as requested. No other changes.

tcharding added a commit to tcharding/rust-bitcoin that referenced this pull request Mar 30, 2023
The derived implementation of `JsonSchema` recently stopped working as
described here:

rust-bitcoin#1696 (comment)

Implement the suggestion.
tcharding added a commit to tcharding/rust-bitcoin that referenced this pull request Mar 30, 2023
The derived implementation of `JsonSchema` recently stopped working as
described here:

rust-bitcoin#1696 (comment)

Implement the suggestion.
The derived implementation of `JsonSchema` recently stopped working as
described here:

rust-bitcoin#1696 (comment)

Implement the suggestion.
@tcharding
Copy link
Member Author

Please see PR description for what is in the last force push. Don't be surprised If I've confused you, I confused myself there for a bit.

@tcharding tcharding added the P-high High priority label Mar 31, 2023
@tcharding tcharding mentioned this pull request Mar 31, 2023
apoelstra
apoelstra previously approved these changes Mar 31, 2023
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 5d29cd6

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Not sure if I should ACK, am I developing OCD?

hashes/src/sha256t.rs Show resolved Hide resolved
@@ -17,6 +17,12 @@ if cargo --version | grep nightly >/dev/null; then
NIGHTLY=true
fi

# Pin dependencies as required if we are using MSRV toolchain.
if cargo --version | grep "1\.48"; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some sort of version comparison would be nice. sort can compare versions, so this hack should work:

if "$(echo -e "$(cargo | cut -d ' ' -f 2)"'\n1.48.0' | sort -V | tail -n 1)" = "1.48.0"; then

Copy link
Member

Choose a reason for hiding this comment

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

I agree, but I don't think it belongs in this PR -- in a future thing we should maybe try to rewrite this script entirely to clean it up (though I think it's mostly in good shape) and to make it easier/more intuitive to run locally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I didn't ACK because of the attribute.

@tcharding
Copy link
Member Author

tcharding commented Apr 3, 2023

Actually, it should be removed because of #1763 Sorry about the noise.

I don't follow - this is a feature guard, nothing to do with docs?

EDIT: Ignore this comment by me, I was confused.

Done as is single patch to make sure all the docs and CI are in sync and
correct.

We currently pin the `schemars` dependency using `<=0.8.3` as well as a
the `dyn-clone` transient dependency in the manifest (`hashes` and the
extended test crate). This is incorrect because it makes usage of the
crate klunky (or possibly impossible) if downstream users wish to use a
later version of `schemars`.

Observe also that we do not have to pin `schemars`, we do however have to pin
the `serde` crate if either `serde` or `schemars` features are enabled.
Do so in CI and document in the readme file within hashes.

Currently we have a pin remaining from the old MSRV (`syn` due to use
of `matches!`).

Fix pinning by:

- Remove pin in manifest for `schemars`
- Fix pinning for MSRV in CI and docs (this includes documenting pinning
  requirements for `schemars` feature because it is related to the other
  pin of `serde`) in both `hashes` readme and main repo readme.
@tcharding
Copy link
Member Author

tcharding commented Apr 19, 2023

Hey @Kixunil can you take a look at this one please, I think your suggestion ways misplaced unless I'm misunderstanding you. #1696 (comment)

Is there a reason for you not ack'ing this one @Kixunil?

Force push is to fix multiple types s/serder/serde in the commit log and also in one of the readmes. No other changes.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 6c61e10

hashes/src/sha256t.rs Show resolved Hide resolved
To run the tests with the MSRV you will need to pin some dependencies:

- `cargo update -p serde --precise 1.0.156`
- `cargo update -p syn --precise 1.0.107`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this isn't needed anymore?

Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure. The serde line definitely is, but syn you may be right that we can drop. In any case, can wait for a followup PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Verified, we no longer need the syn pin. Will do as follow up because this PR is blocking other work. Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, that's what I meant.

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 6c61e10

@apoelstra apoelstra merged commit 8440d80 into rust-bitcoin:master Apr 19, 2023
22 checks passed
@tcharding tcharding deleted the 03-36-schemars branch April 19, 2023 23:25
apoelstra added a commit that referenced this pull request Apr 20, 2023
53d75c7 extended_tests: Remove stale docs (Tobin C. Harding)

Pull request description:

  We no longer need to pin `syn`; remove stale docs.

  This is a follow up to #1696

ACKs for top commit:
  Kixunil:
    ACK 53d75c7
  apoelstra:
    ACK 53d75c7

Tree-SHA512: 9e939860cfb3731942e92a611632f0b24acc88e06a96e905ee2ae50e489d1610f7b9c79e20384196482aad4d5da182f6f919d18726e079a98a667532806d5aae
Subhra264 pushed a commit to Subhra264/rust-bitcoin that referenced this pull request Jun 24, 2023
The derived implementation of `JsonSchema` recently stopped working as
described here:

rust-bitcoin#1696 (comment)

Implement the suggestion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-high High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove schemars pin
4 participants