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

Add SnifferSV1 to ITF #1580

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

Conversation

jbesraa
Copy link
Contributor

@jbesraa jbesraa commented Mar 18, 2025

resolves #1564

Copy link

codecov bot commented Mar 18, 2025

Codecov Report

Attention: Patch coverage is 86.20690% with 4 lines in your changes missing coverage. Please review.

Project coverage is 19.53%. Comparing base (d12f081) to head (e4ee253).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../roles-utils/network-helpers/src/sv1_connection.rs 86.20% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1580      +/-   ##
==========================================
+ Coverage   19.31%   19.53%   +0.21%     
==========================================
  Files         131      132       +1     
  Lines        9298     9328      +30     
==========================================
+ Hits         1796     1822      +26     
- Misses       7502     7506       +4     
Flag Coverage Δ
binary_codec_sv2-coverage 0.00% <ø> (ø)
binary_sv2-coverage 8.59% <ø> (ø)
bip32_derivation-coverage 0.00% <ø> (ø)
buffer_sv2-coverage 37.68% <ø> (ø)
codec_sv2-coverage 0.03% <ø> (ø)
common_messages_sv2-coverage 0.21% <ø> (ø)
const_sv2-coverage 0.00% <ø> (ø)
error_handling-coverage 0.00% <ø> (ø)
framing_sv2-coverage 0.45% <ø> (ø)
jd_client-coverage 0.44% <ø> (ø)
jd_server-coverage 14.50% <ø> (ø)
job_declaration_sv2-coverage 0.00% <ø> (ø)
key-utils-coverage 3.61% <ø> (ø)
mining-coverage 3.89% <ø> (+0.02%) ⬆️
mining_device-coverage 0.00% <ø> (ø)
mining_proxy_sv2-coverage 0.98% <ø> (ø)
noise_sv2-coverage 7.30% <ø> (ø)
pool_sv2-coverage 2.68% <ø> (ø)
protocols 27.17% <ø> (+0.02%) ⬆️
roles 7.69% <86.20%> (+0.56%) ⬆️
roles_logic_sv2-coverage 13.57% <ø> (ø)
sv2_ffi-coverage 0.00% <ø> (ø)
template_distribution_sv2-coverage 0.00% <ø> (ø)
translator_sv2-coverage 10.18% <ø> (ø)
utils 36.39% <ø> (ø)
v1-coverage 3.74% <ø> (ø)

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.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jbesraa jbesraa force-pushed the 2025-03-13/sv1-sniffer branch 3 times, most recently from bd91e82 to 86049b4 Compare March 19, 2025 12:34
@jbesraa jbesraa marked this pull request as ready for review March 19, 2025 12:35
jbesraa added 2 commits March 20, 2025 12:50
..Currently if we exit a test while it is running the miner wont stop
due to its background(async) jobs not getting the signal.
@jbesraa jbesraa force-pushed the 2025-03-13/sv1-sniffer branch from 86049b4 to b5b0b08 Compare March 20, 2025 10:53
jbesraa added 3 commits March 20, 2025 13:03
This module can be utilized in order to setup a connection either on the
upstream or downstream side in a Stratum V1 enviornment.
`SnifferSV1` acts as a middleman between two SV1 roles. It forwards
messages from one role to the other and vice versa. It also provides
methods to wait for specific messages to be received from the downstream
or upstream role.
@jbesraa jbesraa force-pushed the 2025-03-13/sv1-sniffer branch from b5b0b08 to e4ee253 Compare March 20, 2025 11:04
@plebhash
Copy link
Collaborator

oops, looks like adding c8a721b to #1551 introduced a conflict here

perhaps it would have been better to have merged this first, sorry about that

Comment on lines +12 to +14
/// This struct can be used read and write messages to the other side of the connection. The
/// channel is unidirectional, so you will need two instances of this struct to communicate in both
/// directions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

this comment feels a bit confusing

with sender I can send, with receiver I can receive... therefore this is bidirectional?

features = ["with_buffer_pool"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should add sv1 feature here so it is added to docs

error!("Failed to send message to receiver_incoming: {:?}", e);
break; // Exit the loop if sending fails
tokio::select!(
_ = tokio::signal::ctrl_c() => { },
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this intentionally empty?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry dumb question.. just refreshed my understanding of tokio::select and now I understand that as soon as ctrl+c happens, all the other branches are cancelled

resolving the similar questions I asked in other parts of the PR

}

/// Wait for a specific message to be received from the downstream role.
pub async fn wait_for_message_from_downstream(&self, message: &str) {
Copy link
Collaborator

@plebhash plebhash Mar 20, 2025

Choose a reason for hiding this comment

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

I see this is diverging from the Sv2 Sniffer wait_for_message_type pattern

here we have two distinct functions, while on Sv2 Sniffer we just have one and take MessageDirection as input

is there some fundamental limitation on Sv1 Sniffer that forces this specific design?

if not, I think maybe it's better to have both following the same patterns, just to make the APIs a bit more intutive

.await
.map_err(|_| SnifferError::DownstreamClosed)?;
upstream_messages.add_message(msg.clone()).await;
sleep(Duration::from_millis(100)).await;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why sleep here?


[lib]
path = "lib/mod.rs"

[features]
default = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
default = []
default = ["sv1"]

having to add --features sv1 to cargo test feels a bit counter-intuitive... and forgetting to do it basically disables the tests that use Sv1 Sniffer

}

/// Wait for a specific message to be received from the upstream role.
pub async fn wait_for_message_from_upstream(&self, message: &[&str]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

also this takes an array, while wait_for_message_from_downstream doesn't

which is yet another reason I believe these should be just one function instead of two (to avoid fragmented patterns)

@plebhash
Copy link
Collaborator

I added some tracing logs, please cherry-pick in case you agree

ea02800

58feb8a

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.

Integration Tests Framework needs a Sv1 Sniffer
2 participants