Skip to content

Update roles rust edition to 2021#1818

Merged
plebhash merged 5 commits into
stratum-mining:mainfrom
lucasbalieiro:update-rust-edition-2021
Aug 6, 2025
Merged

Update roles rust edition to 2021#1818
plebhash merged 5 commits into
stratum-mining:mainfrom
lucasbalieiro:update-rust-edition-2021

Conversation

@lucasbalieiro

@lucasbalieiro lucasbalieiro commented Jul 29, 2025

Copy link
Copy Markdown
Collaborator

closes #1666 ;

Updates all roles crates to edition 2021 where needed;

@lucasbalieiro

Copy link
Copy Markdown
Collaborator Author

Side note:

My initial attempt was to update to edition 2024, which I successfully did. However, when running the CI locally, I was blocked by the MSRV, which doesn’t support edition2024 yet. it was only stabilized in Rust 1.85.

https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2024

@lucasbalieiro lucasbalieiro marked this pull request as ready for review July 29, 2025 03:50
@lucasbalieiro lucasbalieiro force-pushed the update-rust-edition-2021 branch 3 times, most recently from c07d6da to ecd0c72 Compare July 30, 2025 01:23

@Shourya742 Shourya742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this! Could you run cargo fix --edition once and check if the lock file changes? Also, it'd be great if you can take a quick look to see if any new features in the edition might actually help us. For the role crates, MSRV doesn’t really matter since they’re just applications built on top of our protocol layer. But for the protocol crates, we do need to stick to an MSRV mainly to guarantee that downstream users can compile them with any stable compiler starting from 1.75. That also means we shouldn't use any syntax or features that aren’t supported in 1.75.

@plebhash

Copy link
Copy Markdown
Member

For the role crates, MSRV doesn’t really matter since they’re just applications built on top of our protocol layer.

if a dependency is attached to some MSRV, doesn't that mean the crate that depends on it is also bound to that MSRV?

in other words: what happens if I try to build pool_sv2 with rustc 1.74.0?

@lucasbalieiro

Copy link
Copy Markdown
Collaborator Author

Thanks for this! Could you run cargo fix --edition once and check if the lock file changes? Also, it'd be great if you can take a quick look to see if any new features in the edition might actually help us. For the role crates, MSRV doesn’t really matter since they’re just applications built on top of our protocol layer. But for the protocol crates, we do need to stick to an MSRV mainly to guarantee that downstream users can compile them with any stable compiler starting from 1.75. That also means we shouldn't use any syntax or features that aren’t supported in 1.75.

@Shourya742, thanks for the review!

I’ve completed the migration using cargo fix --edition, and it didn’t require any changes to the lock file.

I also took a quick look at the changes in the 2021 edition and didn’t notice anything particularly useful for our case.
Edition Guide - Rust 2021

The primary reason for opening this PR is that I noticed some mismatched editions between roles, with some on 2018 and others on 2021.

This is more of a housekeeping thing.

@lucasbalieiro

Copy link
Copy Markdown
Collaborator Author

For the role crates, MSRV doesn’t really matter since they’re just applications built on top of our protocol layer.

if a dependency is attached to some MSRV, doesn't that mean the crate that depends on it is also bound to that MSRV?

in other words: what happens if I try to build pool_sv2 with rustc 1.74.0?

@plebhash, just a practical response:

$ pwd && cargo +1.74.0 build
/home/lucasbalieiro/Projects/stratum/roles/pool
error: package `config v0.14.1` cannot be built because it requires rustc 1.75.0 or newer, while the currently active rustc version is 1.74.0
Either upgrade to rustc 1.75.0 or newer, or use
cargo update config@0.14.1 --precise ver
where `ver` is the latest version of `config` supporting rustc 1.74.0

As you can see, it throws an error about the config package, which is used by config_helpers. So, I guess the answer to your question is: yes, if a dependency has an MSRV requirement, it does impact the crates that depend on it.

@lucasbalieiro lucasbalieiro force-pushed the update-rust-edition-2021 branch from ecd0c72 to 88d7a3c Compare July 30, 2025 17:42
@lucasbalieiro lucasbalieiro changed the title Update rust edition 2021 Update roles rust edition to 2021 Jul 30, 2025
@Shourya742

Copy link
Copy Markdown
Member

For the role crates, MSRV doesn’t really matter since they’re just applications built on top of our protocol layer.

if a dependency is attached to some MSRV, doesn't that mean the crate that depends on it is also bound to that MSRV?

in other words: what happens if I try to build pool_sv2 with rustc 1.74.0?

Yes, the Rust version used to build these top-level crates should be greater than or equal to the highest MSRV among their dependencies. So, the role crates should be built with rustc >= 1.75.0. Any version above 1.75 will work, and you're free to use features introduced in those versions even if they wouldn't compile on 1.75. What I meant is: code that compiles with 1.75 will also compile with 1.80, but the reverse isn't necessarily true features from 1.80 may not be compatible with the 1.75 compiler.

@Shourya742 Shourya742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK

@lucasbalieiro lucasbalieiro force-pushed the update-rust-edition-2021 branch from 88d7a3c to b0357f6 Compare July 31, 2025 19:41
@GitGab19

GitGab19 commented Aug 1, 2025

Copy link
Copy Markdown
Member

LGTM, but I'm curious to know: have you tried to bump also protocol crates' editions during your testing?

@lucasbalieiro

Copy link
Copy Markdown
Collaborator Author

LGTM, but I'm curious to know: have you tried to bump also protocol crates' editions during your testing?

Yes, I ran cargo fix --edition and tested the changes locally. Everything works as expected. No additional modifications were needed aside from updating the edition in Cargo.toml.

Would you like me to include this in the current PR?

@GitGab19

GitGab19 commented Aug 3, 2025

Copy link
Copy Markdown
Member

Why not?
For coherence among our entire codebase I think it would make sense to have 2021 edition also there.

@lucasbalieiro

Copy link
Copy Markdown
Collaborator Author

Why not? For coherence among our entire codebase I think it would make sense to have 2021 edition also there.

protocols edition bumped in: upgrade protocols to rust edition 2021

@GitGab19

GitGab19 commented Aug 4, 2025

Copy link
Copy Markdown
Member

We still have stratum-common, integration_tests_sv2, buffer_sv2, and buffer-fuzz with 2018 edition.

@lucasbalieiro

Copy link
Copy Markdown
Collaborator Author

We still have stratum-common, integration_tests_sv2, buffer_sv2, and buffer-fuzz with 2018 edition.

@GitGab19, the buffer ones are a bit tricky.

buffer-fuzz relies on a specific toolchain that doesn't support the 2021 edition, which in turn prevents buffer_sv2 from being upgraded as well.

I added the commits for stratum-common and integration-tests: a7db02b feaf4c6

@GitGab19

GitGab19 commented Aug 4, 2025

Copy link
Copy Markdown
Member

Can you elaborate more on the toolchain? Which toolchain is used there?

@lucasbalieiro

Copy link
Copy Markdown
Collaborator Author

Can you elaborate more on the toolchain? Which toolchain is used there?

Apologies 😅, while writing up the explanation, I realized that the buffer-fuzz toolchain is actually using nightly, whereas I had been running cargo fix --edition with the stable toolchain.

$ cat utils/buffer/fuzz/rust-toolchain.toml 
[toolchain]
channel = "nightly-2020-04-06" #here is the toolchain for the buffer-fuzz

I've just updated the buffer crate accordingly.

@plebhash plebhash merged commit 3e5a325 into stratum-mining:main Aug 6, 2025
11 checks passed
@lucasbalieiro lucasbalieiro deleted the update-rust-edition-2021 branch August 6, 2025 14:30
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.

Upgrade rust edition in Roles from 2018

4 participants