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

Move TranslatorSv2 lib code out of main.rs #1092

Merged
merged 2 commits into from
Aug 30, 2024

Conversation

jbesraa
Copy link
Contributor

@jbesraa jbesraa commented Aug 13, 2024

Related to #1093

Copy link
Contributor

github-actions bot commented Aug 13, 2024

🐰Bencher

ReportFri, August 30, 2024 at 16:47:57 UTC
ProjectStratum v2 (SRI)
Branch2024-08-09-refactor-tproxy
Testbedsv1
Click to view all benchmark results
BenchmarkEstimated CyclesEstimated Cycles Results
estimated cycles | (Δ%)
Estimated Cycles Upper Boundary
estimated cycles | (%)
InstructionsInstructions Results
instructions | (Δ%)
Instructions Upper Boundary
instructions | (%)
L1 AccessesL1 Accesses Results
accesses | (Δ%)
L1 Accesses Upper Boundary
accesses | (%)
L2 AccessesL2 Accesses Results
accesses | (Δ%)
L2 Accesses Upper Boundary
accesses | (%)
RAM AccessesRAM Accesses Results
accesses | (Δ%)
RAM Accesses Upper Boundary
accesses | (%)
get_authorize✅ (view plot)8,402.00 (-0.40%)8,692.44 (96.66%)✅ (view plot)3,746.00 (+0.02%)3,847.26 (97.37%)✅ (view plot)5,252.00 (-0.02%)5,392.16 (97.40%)✅ (view plot)7.00 (-5.99%)10.23 (68.40%)✅ (view plot)89.00 (-0.97%)93.49 (95.19%)
get_submit✅ (view plot)95,345.00 (-0.18%)96,052.56 (99.26%)✅ (view plot)59,439.00 (-0.05%)59,718.77 (99.53%)✅ (view plot)85,370.00 (-0.05%)85,759.69 (99.55%)✅ (view plot)42.00 (-16.89%)64.84 (64.77%)✅ (view plot)279.00 (-0.90%)287.78 (96.95%)
get_subscribe✅ (view plot)8,025.00 (+0.35%)8,263.37 (97.12%)✅ (view plot)2,841.00 (+0.26%)2,931.83 (96.90%)✅ (view plot)3,970.00 (+0.24%)4,091.45 (97.03%)✅ (view plot)13.00 (-7.79%)20.50 (63.42%)✅ (view plot)114.00 (+0.61%)117.57 (96.96%)
serialize_authorize✅ (view plot)12,249.00 (+0.10%)12,520.46 (97.83%)✅ (view plot)5,317.00 (+0.01%)5,418.26 (98.13%)✅ (view plot)7,414.00 (-0.01%)7,554.46 (98.14%)✅ (view plot)8.00 (-18.04%)13.37 (59.81%)✅ (view plot)137.00 (+0.45%)141.22 (97.01%)
serialize_deserialize_authorize✅ (view plot)24,687.00 (+0.59%)24,835.07 (99.40%)✅ (view plot)9,868.00 (-0.32%)10,016.87 (98.51%)✅ (view plot)13,927.00 (-0.30%)14,141.04 (98.49%)✅ (view plot)38.00 (+5.78%)41.82 (90.87%)✅ (view plot)302.00 (+1.69%)303.92 (99.37%)
serialize_deserialize_handle_authorize✅ (view plot)30,354.00 (+0.49%)30,482.93 (99.58%)✅ (view plot)12,071.00 (-0.18%)12,197.97 (98.96%)✅ (view plot)17,089.00 (-0.17%)17,264.29 (98.98%)✅ (view plot)63.00 (+8.91%)64.08 (98.31%)✅ (view plot)370.00 (+1.18%)372.71 (99.27%)
serialize_deserialize_handle_submit✅ (view plot)126,518.00 (+0.06%)126,996.55 (99.62%)✅ (view plot)73,280.00 (+0.02%)73,563.30 (99.61%)✅ (view plot)105,053.00 (+0.03%)105,446.38 (99.63%)✅ (view plot)107.00 (-5.90%)133.70 (80.03%)✅ (view plot)598.00 (+0.34%)601.87 (99.36%)
serialize_deserialize_handle_subscribe✅ (view plot)28,002.00 (+1.48%)28,089.85 (99.69%)✅ (view plot)9,659.00 (+0.20%)9,740.10 (99.17%)✅ (view plot)13,657.00 (+0.17%)13,772.85 (99.16%)✅ (view plot)69.00 (+6.14%)72.47 (95.21%)✅ (view plot)400.00 (+2.68%)402.33 (99.42%)
serialize_deserialize_submit✅ (view plot)115,181.00 (+0.03%)115,651.25 (99.59%)✅ (view plot)68,057.00 (-0.02%)68,355.56 (99.56%)✅ (view plot)97,656.00 (-0.03%)98,096.24 (99.55%)✅ (view plot)61.00 (-7.10%)77.03 (79.19%)✅ (view plot)492.00 (+0.52%)495.41 (99.31%)
serialize_deserialize_subscribe✅ (view plot)23,379.00 (+1.57%)23,506.94 (99.46%)✅ (view plot)8,211.00 (+0.21%)8,295.25 (98.98%)✅ (view plot)11,564.00 (+0.19%)11,680.43 (99.00%)✅ (view plot)39.00 (+1.56%)43.34 (89.99%)✅ (view plot)332.00 (+2.97%)334.59 (99.23%)
serialize_submit✅ (view plot)99,814.00 (-0.08%)100,406.97 (99.41%)✅ (view plot)61,483.00 (-0.05%)61,766.64 (99.54%)✅ (view plot)88,209.00 (-0.05%)88,610.71 (99.55%)✅ (view plot)46.00 (-10.64%)64.18 (71.68%)✅ (view plot)325.00 (-0.10%)331.03 (98.18%)
serialize_subscribe✅ (view plot)11,426.00 (+0.47%)11,657.07 (98.02%)✅ (view plot)4,188.00 (+0.17%)4,278.83 (97.88%)✅ (view plot)5,826.00 (+0.14%)5,948.62 (97.94%)✅ (view plot)14.00 (-4.94%)19.70 (71.06%)✅ (view plot)158.00 (+0.88%)162.11 (97.46%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

Copy link
Contributor

github-actions bot commented Aug 13, 2024

🐰Bencher

ReportFri, August 30, 2024 at 16:48:11 UTC
ProjectStratum v2 (SRI)
Branch2024-08-09-refactor-tproxy
Testbedsv2

🚨 1 ALERT: Threshold Boundary Limit exceeded!
BenchmarkMeasure (units)ViewValueLower BoundaryUpper Boundary
client_sv2_mining_message_submit_standardL2 Accesses (accesses)🚨 (view plot | view alert)24.00 (+38.22%)22.94 (104.64%)

Click to view all benchmark results
BenchmarkEstimated CyclesEstimated Cycles Results
estimated cycles | (Δ%)
Estimated Cycles Upper Boundary
estimated cycles | (%)
InstructionsInstructions Results
instructions | (Δ%)
Instructions Upper Boundary
instructions | (%)
L1 AccessesL1 Accesses Results
accesses | (Δ%)
L1 Accesses Upper Boundary
accesses | (%)
L2 AccessesL2 Accesses Results
accesses | (Δ%)
L2 Accesses Upper Boundary
accesses | (%)
RAM AccessesRAM Accesses Results
accesses | (Δ%)
RAM Accesses Upper Boundary
accesses | (%)
client_sv2_handle_message_common✅ (view plot)2,137.00 (+3.46%)2,149.55 (99.42%)✅ (view plot)473.00 (+0.39%)484.17 (97.69%)✅ (view plot)732.00 (-0.10%)752.21 (97.31%)✅ (view plot)8.00 (+23.94%)12.28 (65.13%)✅ (view plot)39.00 (+4.95%)39.47 (98.82%)
client_sv2_handle_message_mining✅ (view plot)8,204.00 (-0.00%)8,318.34 (98.63%)✅ (view plot)2,137.00 (+0.24%)2,168.30 (98.56%)✅ (view plot)3,159.00 (+0.23%)3,210.50 (98.40%)✅ (view plot)36.00 (-3.00%)43.06 (83.60%)✅ (view plot)139.00 (-0.04%)141.62 (98.15%)
client_sv2_mining_message_submit_standard✅ (view plot)6,339.00 (+0.92%)6,382.19 (99.32%)✅ (view plot)1,750.00 (-0.01%)1,762.52 (99.29%)✅ (view plot)2,544.00 (-0.37%)2,573.12 (98.87%)🚨 (view plot | view alert)24.00 (+38.22%)22.94 (104.64%)✅ (view plot)105.00 (+0.94%)106.78 (98.33%)
client_sv2_mining_message_submit_standard_serialize✅ (view plot)14,792.00 (+0.14%)14,987.52 (98.70%)✅ (view plot)4,694.00 (-0.00%)4,706.52 (99.73%)✅ (view plot)6,752.00 (-0.06%)6,774.23 (99.67%)✅ (view plot)47.00 (+3.27%)52.47 (89.58%)✅ (view plot)223.00 (+0.22%)228.65 (97.53%)
client_sv2_mining_message_submit_standard_serialize_deserialize✅ (view plot)27,578.00 (+0.27%)27,805.12 (99.18%)✅ (view plot)10,585.00 (+0.25%)10,605.85 (99.80%)✅ (view plot)15,398.00 (+0.23%)15,432.00 (99.78%)✅ (view plot)84.00 (+2.07%)88.43 (94.99%)✅ (view plot)336.00 (+0.26%)343.54 (97.81%)
client_sv2_open_channel✅ (view plot)4,413.00 (-0.75%)4,612.87 (95.67%)✅ (view plot)1,461.00 (+0.06%)1,471.98 (99.25%)✅ (view plot)2,158.00 (+0.15%)2,172.80 (99.32%)✅ (view plot)10.00 (-8.90%)15.90 (62.90%)✅ (view plot)63.00 (-1.42%)68.41 (92.10%)
client_sv2_open_channel_serialize✅ (view plot)14,084.00 (-0.53%)14,420.90 (97.66%)✅ (view plot)5,064.00 (+0.02%)5,074.98 (99.78%)✅ (view plot)7,324.00 (+0.05%)7,340.34 (99.78%)✅ (view plot)36.00 (+0.83%)41.33 (87.11%)✅ (view plot)188.00 (-1.20%)197.62 (95.13%)
client_sv2_open_channel_serialize_deserialize✅ (view plot)22,711.00 (+0.29%)22,950.41 (98.96%)✅ (view plot)8,027.00 (+0.35%)8,045.05 (99.78%)✅ (view plot)11,671.00 (+0.29%)11,703.50 (99.72%)✅ (view plot)80.00 (+8.51%)82.21 (97.31%)✅ (view plot)304.00 (0.00%)312.53 (97.27%)
client_sv2_setup_connection✅ (view plot)4,715.00 (+0.53%)4,756.67 (99.12%)✅ (view plot)1,502.00 (+0.06%)1,512.98 (99.27%)✅ (view plot)2,275.00 (-0.07%)2,295.45 (99.11%)✅ (view plot)12.00 (+26.92%)14.35 (83.60%)✅ (view plot)68.00 (+0.57%)69.51 (97.83%)
client_sv2_setup_connection_serialize✅ (view plot)16,182.00 (-0.27%)16,445.56 (98.40%)✅ (view plot)5,963.00 (+0.02%)5,973.98 (99.82%)✅ (view plot)8,662.00 (+0.05%)8,678.47 (99.81%)✅ (view plot)41.00 (-4.40%)51.55 (79.53%)✅ (view plot)209.00 (-0.53%)216.06 (96.73%)
client_sv2_setup_connection_serialize_deserialize✅ (view plot)35,624.00 (+0.23%)35,716.48 (99.74%)✅ (view plot)14,855.00 (+0.19%)14,873.38 (99.88%)✅ (view plot)21,819.00 (+0.19%)21,854.54 (99.84%)✅ (view plot)94.00 (-1.96%)111.38 (84.40%)✅ (view plot)381.00 (+0.37%)383.65 (99.31%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

Copy link
Contributor

github-actions bot commented Aug 13, 2024

🐰Bencher

ReportFri, August 30, 2024 at 16:47:58 UTC
ProjectStratum v2 (SRI)
Branch2024-08-09-refactor-tproxy
Testbedsv2

🚨 2 ALERTS: Threshold Boundary Limits exceeded!
BenchmarkMeasure (units)ViewValueLower BoundaryUpper Boundary
client_sv2_mining_message_submit_standard_serialize_deserializeLatency (nanoseconds (ns))🚨 (view plot | view alert)668.70 (+12.46%)632.52 (105.72%)
client_sv2_open_channelLatency (nanoseconds (ns))🚨 (view plot | view alert)177.66 (+7.12%)172.37 (103.07%)

Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns) | (Δ%)
Latency Upper Boundary
nanoseconds (ns) | (%)
client_sv2_handle_message_common✅ (view plot)44.01 (-1.37%)45.57 (96.59%)
client_sv2_handle_message_mining✅ (view plot)74.59 (+0.93%)83.03 (89.83%)
client_sv2_mining_message_submit_standard✅ (view plot)14.66 (+0.01%)14.71 (99.66%)
client_sv2_mining_message_submit_standard_serialize✅ (view plot)273.22 (+2.50%)284.84 (95.92%)
client_sv2_mining_message_submit_standard_serialize_deserialize🚨 (view plot | view alert)668.70 (+12.46%)632.52 (105.72%)
client_sv2_open_channel🚨 (view plot | view alert)177.66 (+7.12%)172.37 (103.07%)
client_sv2_open_channel_serialize✅ (view plot)294.64 (+4.54%)294.70 (99.98%)
client_sv2_open_channel_serialize_deserialize✅ (view plot)376.48 (-0.41%)427.76 (88.01%)
client_sv2_setup_connection✅ (view plot)160.54 (-1.76%)174.94 (91.77%)
client_sv2_setup_connection_serialize✅ (view plot)429.79 (-8.69%)511.71 (83.99%)
client_sv2_setup_connection_serialize_deserialize✅ (view plot)1,052.00 (+7.08%)1,074.35 (97.92%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

Copy link
Contributor

github-actions bot commented Aug 13, 2024

🐰Bencher

ReportFri, August 30, 2024 at 16:48:11 UTC
ProjectStratum v2 (SRI)
Branch1092/merge
Testbedsv1
Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns) | (Δ%)
Latency Upper Boundary
nanoseconds (ns) | (%)
client-submit-serialize✅ (view plot)6,867.90 (+0.46%)7,297.83 (94.11%)
client-submit-serialize-deserialize✅ (view plot)7,858.40 (+0.99%)8,279.94 (94.91%)
client-submit-serialize-deserialize-handle/client-submit-serialize-deserialize-handle✅ (view plot)8,369.00 (+0.15%)8,782.27 (95.29%)
client-sv1-authorize-serialize-deserialize-handle/client-sv1-authorize-serialize-deserialize-handle✅ (view plot)904.09 (-0.07%)941.83 (95.99%)
client-sv1-authorize-serialize-deserialize/client-sv1-authorize-serialize-deserialize✅ (view plot)726.37 (+3.19%)733.75 (98.99%)
client-sv1-authorize-serialize/client-sv1-authorize-serialize✅ (view plot)252.96 (+1.47%)256.22 (98.73%)
client-sv1-get-authorize/client-sv1-get-authorize✅ (view plot)157.71 (+0.31%)162.27 (97.19%)
client-sv1-get-submit✅ (view plot)6,571.10 (-0.63%)7,056.49 (93.12%)
client-sv1-get-subscribe/client-sv1-get-subscribe✅ (view plot)270.81 (-2.27%)292.58 (92.56%)
client-sv1-subscribe-serialize-deserialize-handle/client-sv1-subscribe-serialize-deserialize-handle✅ (view plot)772.76 (+2.39%)791.01 (97.69%)
client-sv1-subscribe-serialize-deserialize/client-sv1-subscribe-serialize-deserialize✅ (view plot)624.25 (+1.17%)642.97 (97.09%)
client-sv1-subscribe-serialize/client-sv1-subscribe-serialize✅ (view plot)207.57 (+0.08%)218.55 (94.98%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

@jbesraa jbesraa marked this pull request as ready for review August 13, 2024 11:00
@jbesraa jbesraa force-pushed the 2024-08-09-refactor-tproxy branch from 825b8c9 to 8461b4b Compare August 13, 2024 14:07
@jbesraa jbesraa changed the title Refactor TranslatorSv2 MoveTranslatorSv2 lib code out of main.rs Aug 13, 2024
Copy link
Contributor

@Shourya742 Shourya742 left a comment

Choose a reason for hiding this comment

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

Concept ACK

debug!("Starting up status listener");
// Check all tasks if is_finished() is true, if so exit
loop {
let task_status = tokio::select! {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let task_status = tokio::select! {
let task_status = select! {

Select macro can be added to above tokio import

Comment on lines 18 to 79
pub struct TranslatorProxyUpstream {
address: String,
port: u16,
authority_pubkey: Secp256k1PublicKey,
difficulty_config: UpstreamDifficultyConfig,
}

pub struct TranslatorProxyDownstream {
address: String,
port: u16,
difficulty_config: DownstreamDifficultyConfig,
}

impl ProxyConfig {
pub fn new(
upstream: TranslatorProxyUpstream,
downstream: TranslatorProxyDownstream,
max_supported_version: u16,
min_supported_version: u16,
min_extranonce2_size: u16,
) -> Self {
Self {
upstream_address: upstream.address,
upstream_port: upstream.port,
upstream_authority_pubkey: upstream.authority_pubkey,
downstream_address: downstream.address,
downstream_port: downstream.port,
max_supported_version,
min_supported_version,
min_extranonce2_size,
downstream_difficulty_config: downstream.difficulty_config,
upstream_difficulty_config: upstream.difficulty_config,
}
}
}

Copy link
Contributor

@Shourya742 Shourya742 Aug 14, 2024

Choose a reason for hiding this comment

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

Since these structs are open to anyone starting a translator and are used for the initial proxy setup, it’s important to make sure they're easy to use and less error-prone. These structs have a lot of fields and can get pretty lengthy, so I suggest using the Builder design pattern to simplify things. This approach will make initialization less prone to mistakes and more straightforward. Here’s a quick example:

#[derive(Debug, Deserialize, Clone)]
struct ProxyConfig {
    pub upstream_address: String,
    pub upstream_port: u16,
    pub upstream_authority_pubkey: Secp256k1PublicKey,
    pub downstream_address: String,
    pub downstream_port: u16,
    pub max_supported_version: u16,
    pub min_supported_version: u16,
    pub min_extranonce2_size: u16,
    pub downstream_difficulty_config: DownstreamDifficultyConfig,
    pub upstream_difficulty_config: UpstreamDifficultyConfig,
}

pub struct ProxyConfigBuilder {
    upstream: Option<TranslatorProxyUpstream>,
    downstream: Option<TranslatorProxyDownstream>,
    max_supported_version: Option<u16>,
    min_supported_version: Option<u16>,
    min_extranonce2_size: Option<u16>,
}

impl ProxyConfigBuilder {
    pub fn builder() -> Self {
        Self {
            upstream: None,
            downstream: None,
            max_supported_version: None,
            min_supported_version: None,
            min_extranonce2_size: None,
        }
    }

    pub fn upstream(mut self, upstream: TranslatorProxyUpstream) -> Self {
        self.upstream = Some(upstream);
        self
    }

    pub fn downstream(mut self, downstream: TranslatorProxyDownstream) -> Self {
        self.downstream = Some(downstream);
        self
    }

    pub fn max_supported_version(mut self, version: u16) -> Self {
        self.max_supported_version = Some(version);
        self
    }

    pub fn min_supported_version(mut self, version: u16) -> Self {
        self.min_supported_version = Some(version);
        self
    }

    pub fn min_extranonce2_size(mut self, size: u16) -> Self {
        self.min_extranonce2_size = Some(size);
        self
    }

    pub fn build(self) -> Result<ProxyConfig, &'static str> {
        Ok(ProxyConfig {
            upstream_address: self.upstream.ok_or("Upstream not set")?.address,
            upstream_port: self.upstream.ok_or("Upstream not set")?.port,
            upstream_authority_pubkey: self.upstream.ok_or("Upstream not set")?.authority_pubkey,
            downstream_address: self.downstream.ok_or("Downstream not set")?.address,
            downstream_port: self.downstream.ok_or("Downstream not set")?.port,
            max_supported_version: self.max_supported_version.ok_or("Max version not set")?,
            min_supported_version: self.min_supported_version.ok_or("Min version not set")?,
            min_extranonce2_size: self.min_extranonce2_size.ok_or("Min extranonce size not set")?,
            downstream_difficulty_config: self.downstream.ok_or("Downstream not set")?.difficulty_config,
            upstream_difficulty_config: self.upstream.ok_or("Upstream not set")?.difficulty_config,
        })
    }
}

So, the public API would look something like this:

let proxy_config = ProxyConfigBuilder::builder().upstream(upstream).downstream(downstream).max_supported_version(2).min_supported_version(1).min_extranonce2_size(8).build()

This makes it easier to set up and less likely to cause errors.

cc: @plebhash @GitGab19 @jbesraa

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see any cons in doing that. I just think that if we are going to use a specific pattern, it should be the same everywhere

Copy link
Contributor

Choose a reason for hiding this comment

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

If this change is desired (I like builder patterns, personally), it should be a separate PR and issue, imho. Would make for a good first issue

Copy link
Collaborator

Choose a reason for hiding this comment

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

If this change is desired (I like builder patterns, personally), it should be a separate PR and issue, imho. Would make for a good first issue

Completely agree 💯
Maybe we could push this one which could be used as an example for the good first issue(s)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I relayed #1116 to #1069 (comment)

this is a good idea but probably not too urgent for now

Copy link
Collaborator

Choose a reason for hiding this comment

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

also related: #1069 (comment)

Copy link
Contributor

@average-gary average-gary left a comment

Choose a reason for hiding this comment

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

lgtm pending updating with base branch

let proxy_config = self.config.clone();
// Sender/Receiver to send a SV2 `SubmitSharesExtended` from the `Bridge` to the `Upstream`
// (Sender<SubmitSharesExtended<'static>>, Receiver<SubmitSharesExtended<'static>>)
let (tx_sv2_submit_shares_ext, rx_sv2_submit_shares_ext) = bounded(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 18 to 79
pub struct TranslatorProxyUpstream {
address: String,
port: u16,
authority_pubkey: Secp256k1PublicKey,
difficulty_config: UpstreamDifficultyConfig,
}

pub struct TranslatorProxyDownstream {
address: String,
port: u16,
difficulty_config: DownstreamDifficultyConfig,
}

impl ProxyConfig {
pub fn new(
upstream: TranslatorProxyUpstream,
downstream: TranslatorProxyDownstream,
max_supported_version: u16,
min_supported_version: u16,
min_extranonce2_size: u16,
) -> Self {
Self {
upstream_address: upstream.address,
upstream_port: upstream.port,
upstream_authority_pubkey: upstream.authority_pubkey,
downstream_address: downstream.address,
downstream_port: downstream.port,
max_supported_version,
min_supported_version,
min_extranonce2_size,
downstream_difficulty_config: downstream.difficulty_config,
upstream_difficulty_config: upstream.difficulty_config,
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If this change is desired (I like builder patterns, personally), it should be a separate PR and issue, imho. Would make for a good first issue

}

impl ProxyConfig {
pub fn new(
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like there could be additional limitation to the extranonce and version fields here. Definitely outside the scope of this PR but worth mentioning for discussion.

@Shourya742
Copy link
Contributor

I tested the branch locally, and the logs for the translator look fine. However, I noticed quite a few warnings. I believe some of the error cases are no longer being triggered. If possible, could you remove those and resolve the other warnings as well? Everything else looks good.

Warning Logs Translator

fields extranonce and extranonce2_len are never read
--> translator/src/lib/downstream_sv1/mod.rs:27:9
|
24 | pub struct SubmitShareWithChannelId {
| ------------------------ fields in this struct
...
27 | pub extranonce: Vec,
| ^^^^^^^^^^
28 | pub extranonce2_len: usize,
| ^^^^^^^^^^^^^^^
|
= note: SubmitShareWithChannelId has a derived impl for the trait Debug, but this is intentionally ignored during dead code analysis
= note: #[warn(dead_code)] on by default

warning: field 0 is never read
--> translator/src/lib/error.rs:16:9
|
15 | SubmitSharesExtended(
| -------------------- field in this variant
16 | async_channel::SendError<roles_logic_sv2::mining_sv2::SubmitSharesExtended<'a...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
16 | (),
| ~~

warning: field 0 is never read
--> translator/src/lib/error.rs:18:20
|
18 | SetNewPrevHash(async_channel::SendError<roles_logic_sv2::mining_sv2::SetNewPrevHash<'a>...
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| field in this variant
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
18 | SetNewPrevHash(()),
| ~~

warning: field 0 is never read
--> translator/src/lib/error.rs:19:26
|
19 | NewExtendedMiningJob(async_channel::SendError<NewExtendedMiningJob<'a>...
| -------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| field in this variant
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
19 | NewExtendedMiningJob(()),
| ~~

warning: field 0 is never read
--> translator/src/lib/error.rs:20:12
|
20 | Notify(tokio::sync::broadcast::error::SendError<Notify<'a>>),
| ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| field in this variant
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
20 | Notify(()),
| ~~

warning: field 0 is never read
--> translator/src/lib/error.rs:21:15
|
21 | V1Message(async_channel::SendErrorv1::Message),
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| field in this variant
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
21 | V1Message(()),
| ~~

warning: field 0 is never read
--> translator/src/lib/error.rs:22:13
|
22 | General(String),
| ------- ^^^^^^
| |
| field in this variant
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
22 | General(()),
| ~~

warning: field 0 is never read
--> translator/src/lib/error.rs:23:16
|
23 | Extranonce(async_channel::SendError<(ExtendedExtranonce, u32)>),
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| field in this variant
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
23 | Extranonce(()),
| ~~

warning: field 0 is never read
--> translator/src/lib/error.rs:25:9
|
24 | SetCustomMiningJob(
| ------------------ field in this variant
25 | async_channel::SendError<roles_logic_sv2::mining_sv2::SetCustomMiningJob<'a...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
25 | (),
| ~~

warning: field 0 is never read
--> translator/src/lib/error.rs:28:9
|
27 | NewTemplate(
| ----------- field in this variant
28 | / async_channel::SendError<(
29 | | roles_logic_sv2::template_distribution_sv2::SetNewPrevHash...
30 | | Vec,
31 | | )>,
| |__________^
|
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
28 | (),
| ~~

warning: field target is never read
--> translator/src/lib/proxy/bridge.rs:529:9
|
525 | pub struct OpenSv1Downstream {
| ----------------- field in this struct
...
529 | pub target: Arc<Mutex<Vec>>,
| ^^^^^^

warning: struct TranslatorProxyUpstream is never constructed
--> translator/src/lib/proxy_config.rs:18:12
|
18 | pub struct TranslatorProxyUpstream {
| ^^^^^^^^^^^^^^^^^^^^^^^

warning: struct TranslatorProxyDownstream is never constructed
--> translator/src/lib/proxy_config.rs:25:12
|
25 | pub struct TranslatorProxyDownstream {
| ^^^^^^^^^^^^^^^^^^^^^^^^^

warning: associated function new is never used
--> translator/src/lib/proxy_config.rs:32:12
|
31 | impl ProxyConfig {
| ---------------- associated function in this implementation
32 | pub fn new(
| ^^^

warning: associated function new is never used
--> translator/src/lib/proxy_config.rs:65:12
|
64 | impl DownstreamDifficultyConfig {
| ------------------------------- associated function in this implementation
65 | pub fn new(
| ^^^

warning: fields timestamp_of_last_update and should_aggregate are never read
--> translator/src/lib/proxy_config.rs:91:9
|
87 | pub struct UpstreamDifficultyConfig {
| ------------------------ fields in this struct
...
91 | pub timestamp_of_last_update: u64,
| ^^^^^^^^^^^^^^^^^^^^^^^^
92 | #[serde(default = "bool::default")]
93 | pub should_aggregate: bool,
| ^^^^^^^^^^^^^^^^
|
= note: UpstreamDifficultyConfig has derived impls for the traits Clone and Debug, but these are intentionally ignored during dead code analysis

warning: associated function new is never used
--> translator/src/lib/proxy_config.rs:97:12
|
96 | impl UpstreamDifficultyConfig {
| ----------------------------- associated function in this implementation
97 | pub fn new(
| ^^^

warning: struct Sv2MiningConnection is never constructed
--> translator/src/lib/upstream_sv2/mod.rs:15:12
|
15 | pub struct Sv2MiningConnection {
| ^^^^^^^^^^^^^^^^^^^
|
= note: Sv2MiningConnection has derived impls for the traits Debug and Clone, but these are intentionally ignored during dead code analysis

@jbesraa jbesraa mentioned this pull request Aug 19, 2024
@jbesraa jbesraa force-pushed the 2024-08-09-refactor-tproxy branch from 8461b4b to cb0ef3d Compare August 19, 2024 16:53
@jbesraa jbesraa changed the title MoveTranslatorSv2 lib code out of main.rs Move TranslatorSv2 lib code out of main.rs Aug 19, 2024
@plebhash plebhash linked an issue Aug 20, 2024 that may be closed by this pull request
6 tasks
@jbesraa jbesraa force-pushed the 2024-08-09-refactor-tproxy branch from cb0ef3d to 8d90263 Compare August 21, 2024 10:34
@jbesraa
Copy link
Contributor Author

jbesraa commented Aug 21, 2024

I tested the branch locally, and the logs for the translator look fine. However, I noticed quite a few warnings. I believe some of the error cases are no longer being triggered. If possible, could you remove those and resolve the other warnings as well? Everything else looks good.
Warning Logs Translator
fields `extranonce` and `extranonce2_len` are never read --> translator/src/lib/downstream_sv1/mod.rs:27:9 | 24 | pub struct SubmitShareWithChannelId { | ------------------------ fields in this struct ... 27 | pub extranonce: Vec, | ^^^^^^^^^^ 28 | pub extranonce2_len: usize, | ^^^^^^^^^^^^^^^ | = note: `SubmitShareWithChannelId` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default warning: field `0` is never read --> translator/src/lib/error.rs:16:9 | 15 | SubmitSharesExtended( | -------------------- field in this variant 16 | async_channel::SendError<roles_logic_sv2::mining_sv2::SubmitSharesExtended<'a... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 16 | (), | ~~ warning: field `0` is never read --> translator/src/lib/error.rs:18:20 | 18 | SetNewPrevHash(async_channel::SendError<roles_logic_sv2::mining_sv2::SetNewPrevHash<'a>... | -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | field in this variant | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 18 | SetNewPrevHash(()), | ~~ warning: field `0` is never read --> translator/src/lib/error.rs:19:26 | 19 | NewExtendedMiningJob(async_channel::SendError<NewExtendedMiningJob<'a>... | -------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | field in this variant | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 19 | NewExtendedMiningJob(()), | ~~ warning: field `0` is never read --> translator/src/lib/error.rs:20:12 | 20 | Notify(tokio::sync::broadcast::error::SendError<Notify<'a>>), | ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | field in this variant | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 20 | Notify(()), | ~~ warning: field `0` is never read --> translator/src/lib/error.rs:21:15 | 21 | V1Message(async_channel::SendErrorv1::Message), | --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | field in this variant | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 21 | V1Message(()), | ~~ warning: field `0` is never read --> translator/src/lib/error.rs:22:13 | 22 | General(String), | ------- ^^^^^^ | | | field in this variant | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 22 | General(()), | ~~ warning: field `0` is never read --> translator/src/lib/error.rs:23:16 | 23 | Extranonce(async_channel::SendError<(ExtendedExtranonce, u32)>), | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | field in this variant | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 23 | Extranonce(()), | ~~ warning: field `0` is never read --> translator/src/lib/error.rs:25:9 | 24 | SetCustomMiningJob( | ------------------ field in this variant 25 | async_channel::SendError<roles_logic_sv2::mining_sv2::SetCustomMiningJob<'a... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 25 | (), | ~~ warning: field `0` is never read --> translator/src/lib/error.rs:28:9 | 27 | NewTemplate( | ----------- field in this variant 28 | / async_channel::SendError<( 29 | | roles_logic_sv2::template_distribution_sv2::SetNewPrevHash... 30 | | Vec, 31 | | )>, | |__________^ | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 28 | (), | ~~ warning: field `target` is never read --> translator/src/lib/proxy/bridge.rs:529:9 | 525 | pub struct OpenSv1Downstream { | ----------------- field in this struct ... 529 | pub target: Arc<Mutex<Vec>>, | ^^^^^^ warning: struct `TranslatorProxyUpstream` is never constructed --> translator/src/lib/proxy_config.rs:18:12 | 18 | pub struct TranslatorProxyUpstream { | ^^^^^^^^^^^^^^^^^^^^^^^ warning: struct `TranslatorProxyDownstream` is never constructed --> translator/src/lib/proxy_config.rs:25:12 | 25 | pub struct TranslatorProxyDownstream { | ^^^^^^^^^^^^^^^^^^^^^^^^^ warning: associated function `new` is never used --> translator/src/lib/proxy_config.rs:32:12 | 31 | impl ProxyConfig { | ---------------- associated function in this implementation 32 | pub fn new( | ^^^ warning: associated function `new` is never used --> translator/src/lib/proxy_config.rs:65:12 | 64 | impl DownstreamDifficultyConfig { | ------------------------------- associated function in this implementation 65 | pub fn new( | ^^^ warning: fields `timestamp_of_last_update` and `should_aggregate` are never read --> translator/src/lib/proxy_config.rs:91:9 | 87 | pub struct UpstreamDifficultyConfig { | ------------------------ fields in this struct ... 91 | pub timestamp_of_last_update: u64, | ^^^^^^^^^^^^^^^^^^^^^^^^ 92 | #[serde(default = "bool::default")] 93 | pub should_aggregate: bool, | ^^^^^^^^^^^^^^^^ | = note: `UpstreamDifficultyConfig` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis warning: associated function `new` is never used --> translator/src/lib/proxy_config.rs:97:12 | 96 | impl UpstreamDifficultyConfig { | ----------------------------- associated function in this implementation 97 | pub fn new( | ^^^ warning: struct `Sv2MiningConnection` is never constructed --> translator/src/lib/upstream_sv2/mod.rs:15:12 | 15 | pub struct Sv2MiningConnection { | ^^^^^^^^^^^^^^^^^^^ | = note: `Sv2MiningConnection` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis

Ill leave this to a different PR if thats ok?

@jbesraa jbesraa force-pushed the 2024-08-09-refactor-tproxy branch 2 times, most recently from 2447dac to 43b9d01 Compare August 21, 2024 12:30
@jbesraa jbesraa force-pushed the 2024-08-09-refactor-tproxy branch from 43b9d01 to 6ac6768 Compare August 23, 2024 10:38
Copy link
Collaborator

@GitGab19 GitGab19 left a comment

Choose a reason for hiding this comment

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

tACK.
But I left some comments, mostly due to warnings received while compiling it.

roles/translator/src/lib/mod.rs Show resolved Hide resolved
roles/translator/src/lib/mod.rs Show resolved Hide resolved
roles/translator/src/lib/proxy_config.rs Show resolved Hide resolved
roles/translator/src/lib/proxy_config.rs Show resolved Hide resolved
roles/translator/src/lib/proxy_config.rs Show resolved Hide resolved
@jbesraa jbesraa force-pushed the 2024-08-09-refactor-tproxy branch from 6ac6768 to 7664c9e Compare August 26, 2024 08:04
.. to allow using the `translator` in other environements.
@jbesraa jbesraa force-pushed the 2024-08-09-refactor-tproxy branch from 7664c9e to 1c5c317 Compare August 26, 2024 08:59
@plebhash plebhash changed the base branch from dev to main August 28, 2024 19:19
@plebhash plebhash merged commit 4173c4d into stratum-mining:main Aug 30, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done ✅
Development

Successfully merging this pull request may close these issues.

Restructure Roles as a prepration for integration tests
5 participants