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

Protocols v2 no_std support #1394

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Georges760
Copy link
Contributor

@Georges760 Georges760 commented Jan 24, 2025

Here are a couple of change to avoid getrandom which is not compatible with no_std.

Copy link

codecov bot commented Jan 24, 2025

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 19.08%. Comparing base (757b9ef) to head (1694832).
Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
protocols/v2/codec-sv2/src/encoder.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1394      +/-   ##
==========================================
- Coverage   19.08%   19.08%   -0.01%     
==========================================
  Files         166      166              
  Lines       11066    11068       +2     
==========================================
  Hits         2112     2112              
- Misses       8954     8956       +2     
Flag Coverage Δ
binary_codec_sv2-coverage 0.00% <0.00%> (ø)
binary_serde_sv2-coverage 3.55% <0.00%> (-0.01%) ⬇️
binary_sv2-coverage 5.34% <0.00%> (-0.01%) ⬇️
bip32_derivation-coverage 0.00% <ø> (ø)
buffer_sv2-coverage 25.02% <ø> (ø)
codec_sv2-coverage 0.01% <0.00%> (ø)
common_messages_sv2-coverage 0.13% <0.00%> (-0.01%) ⬇️
const_sv2-coverage 0.00% <0.00%> (ø)
error_handling-coverage 0.00% <ø> (ø)
framing_sv2-coverage 0.28% <0.00%> (-0.01%) ⬇️
jd_client-coverage 0.00% <ø> (ø)
jd_server-coverage 7.79% <ø> (ø)
job_declaration_sv2-coverage 0.00% <0.00%> (ø)
key-utils-coverage 2.39% <ø> (ø)
mining-coverage 2.44% <0.00%> (-0.01%) ⬇️
mining_device-coverage 0.00% <ø> (ø)
mining_proxy_sv2-coverage 0.70% <ø> (ø)
noise_sv2-coverage 4.44% <0.00%> (-0.01%) ⬇️
pool_sv2-coverage 2.04% <ø> (ø)
protocols 24.57% <0.00%> (-0.01%) ⬇️
roles 6.54% <ø> (ø)
roles_logic_sv2-coverage 7.93% <0.00%> (-0.01%) ⬇️
sv2_ffi-coverage 0.00% <0.00%> (ø)
template_distribution_sv2-coverage 0.00% <0.00%> (ø)
translator_sv2-coverage 9.60% <ø> (ø)
utils 25.13% <ø> (ø)
v1-coverage 2.41% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@plebhash
Copy link
Collaborator

thanks for this @Georges760

on the PR description you mention:

getrandom which is not compatible with no_std

I was looking at the Rust Docs for the getrandom crate, and I noticed a few things:

while I don't really oppose this PR (as the changes are mostly harmless) I wonder if the initial assumptions are correct?

@Georges760
Copy link
Contributor Author

thanks for this @Georges760

on the PR description you mention:

getrandom which is not compatible with no_std

I was looking at the Rust Docs for the getrandom crate, and I noticed a few things:

while I don't really oppose this PR (as the changes are mostly harmless) I wonder if the initial assumptions are correct?

To be accurate getrandom crate can be no_std for WASM for example, but is not compatible with embedded system (often amalgamed to no_std).

In embedded system the HW RNG can be (and should be) used to get random number. That's why in noise_sv and codec_sv2 (and key-utils too) I had to add an intermediary API for embedded system to provide their specific HW RNG by argument of xxx_with_rng() function.
getrandom is a (convenient) crate that get random number from any std or some no_std system but not all. It can't know about the specific HW RNG that some MCU have.

Trying to build the stm32_sv2 demo (in the context of embedded stm32 embassy project), the build fail on getrandom because we are not in a supported target.
But the getrandom dependancy is itself unused and result in a lazy dep feature selection, so just adding some features to some deps, remove the getrandom crate from the depenancy graph (without the need to provide any other RNG so it proves it was not used at all).

TLDR: you are right the inital assumption was incorrect, was just a shortcut of all above explanations.

@Georges760 Georges760 requested a review from Shourya742 January 28, 2025 16:26
@Sjors
Copy link
Collaborator

Sjors commented Jan 29, 2025

Code review ACK 1694832

Caveat: I'm not a Rust dev :-)

Copy link
Contributor

@jbesraa jbesraa left a comment

Choose a reason for hiding this comment

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

LGTM

@plebhash plebhash added ready-to-be-merged triggers auto rebase bot and removed ready-to-be-merged triggers auto rebase bot labels Jan 30, 2025
@plebhash
Copy link
Collaborator

hey @Georges760 we're ready to merge this

unfortunately our magic ready-to-be-merged label doesn't work to keep this up-to-date, so we have to coordinate so you rebase it and we merge this before some other PR

@Shourya742
Copy link
Contributor

I want to re-review this, can we defer merging till tomorrow?

@plebhash
Copy link
Collaborator

ping @Georges760 again, I guess now we're good to go

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.

5 participants