Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGab19 committed Oct 18, 2024
1 parent 9da0e73 commit 6f6d351
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 65 deletions.
6 changes: 3 additions & 3 deletions docker-compose-config-a.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ services:
labels:
logging: "config-a"
image: template-provider-builder-image
entrypoint: ["/bin/sh", "-c", "./scripts/update-mainnet-chainstate.sh ${NETWORK} && /bitcoin/bin/bitcoind -sv2 -sv2port=8442 -sv2interval=${SV2_INTERVAL} -sv2feedelta=0 -debug=sv2 -loglevel=sv2:trace -sv2bind=0.0.0.0 -${NETWORK}"]
entrypoint: ["/bin/sh", "-c", "./scripts/update-mainnet-chainstate.sh ${NETWORK} && /bitcoin/bin/bitcoind -sv2 -sv2port=8442 -sv2interval=${SV2_INTERVAL} -sv2feedelta=0 -debug=sv2 -loglevel=sv2:debug -sv2bind=0.0.0.0 -${NETWORK}"]
ports:
- "8442:8442"
- "18333:48333"
Expand Down Expand Up @@ -91,7 +91,7 @@ services:
labels:
logging: "config-a"
image: template-provider-builder-image
entrypoint: ["/bin/sh", "-c", "./scripts/update-mainnet-chainstate.sh ${NETWORK} && /bitcoin/bin/bitcoind -sv2 -sv2port=8443 -sv2interval=${SV2_INTERVAL} -sv2feedelta=0 -debug=sv2 -loglevel=sv2:trace -sv2bind=0.0.0.0 -${NETWORK}"]
entrypoint: ["/bin/sh", "-c", "./scripts/update-mainnet-chainstate.sh ${NETWORK} && /bitcoin/bin/bitcoind -sv2 -sv2port=8443 -sv2interval=${SV2_INTERVAL} -sv2feedelta=0 -debug=sv2 -loglevel=sv2:debug -sv2bind=0.0.0.0 -${NETWORK}"]
ports:
- "8443:8443"
- "28333:18333"
Expand Down Expand Up @@ -543,7 +543,7 @@ services:
ipv4_address: 10.5.0.18

loki:
image: grafana/loki
image: grafana/loki:2.9.8
container_name: loki
ports:
- "3100:3100"
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-config-c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ services:
labels:
logging: "config-c"
image: template-provider-builder-image
entrypoint: ["/bin/sh", "-c", "./scripts/update-mainnet-chainstate.sh ${NETWORK} && /bitcoin/bin/bitcoind -sv2 -sv2port=8442 -sv2interval=${SV2_INTERVAL} -sv2feedelta=0 -debug=sv2 -loglevel=sv2:trace -sv2bind=0.0.0.0 -${NETWORK}"]
entrypoint: ["/bin/sh", "-c", "./scripts/update-mainnet-chainstate.sh ${NETWORK} && /bitcoin/bin/bitcoind -sv2 -sv2port=8442 -sv2interval=${SV2_INTERVAL} -sv2feedelta=0 -debug=sv2 -loglevel=sv2:debug -sv2bind=0.0.0.0 -${NETWORK}"]
ports:
- "8442:8442"
- "18333:48333"
Expand Down Expand Up @@ -473,7 +473,7 @@ services:
ipv4_address: 10.5.0.18

loki:
image: grafana/loki
image: grafana/loki:2.9.8
container_name: loki
ports:
- "3100:3100"
Expand Down
51 changes: 7 additions & 44 deletions sv1-custom-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ async fn transfer(
while let Some(pos) = client_buf.iter().position(|&b| b == b'\n') {
let line = client_buf.drain(..=pos).collect::<Vec<_>>();
if let Ok(json) = serde_json::from_slice::<Value>(&line) {
println!("Client to Server: {}", json);
if json["method"] == "mining.submit" {
submitted_shares.inc();
if let Some(params) = json["params"].as_array() {
Expand All @@ -65,14 +64,14 @@ async fn transfer(
.remove_label_values(&[&nonce_string]);
});
} else {
println!("Client to Server: {:?}", line);
println!("Nonce not found in params");
}
} else {
println!("Client to Server: {:?}", line);
println!("Params is not an array");
}
}
} else {
println!("Client to Server: {:?}", line);
}
wo.write_all(&line).await?;
}
Expand All @@ -93,7 +92,6 @@ async fn transfer(
while let Some(pos) = server_buf.iter().position(|&b| b == b'\n') {
let line = server_buf.drain(..=pos).collect::<Vec<_>>();
if let Ok(json) = serde_json::from_slice::<Value>(&line) {
println!("Server to Client: {}", json);
if json["method"] == "mining.notify" {
if let Some(params) = json["params"].as_array() {
if let Some(_prevhash) = params.get(1) {
Expand All @@ -107,7 +105,6 @@ async fn transfer(
if let Ok(response) = client.get(prometheus_url).send().await {
if let Ok(body) = response.text().await {
for line in body.lines() {
println!("Line: {:?}", line);
if let Some(start_index) = line.find("flag=") {
let start = start_index + "flag=\"".len();
if let Some(value) = line.chars().nth(start) {
Expand All @@ -128,6 +125,7 @@ async fn transfer(
new_job_prev_hash_gauge.set(delta);
new_job_gauge.set(delta);
} else {
println!("Line: {:?}", line);
println!("No timestamp value found.");
}
} else if let Some((_, timestamp)) =
Expand All @@ -145,6 +143,7 @@ async fn transfer(
current_timestamp - new_job_timestamp;
new_job_gauge.set(delta);
} else {
println!("Line: {:?}", line);
println!("No timestamp value found.");
}
}
Expand All @@ -153,6 +152,7 @@ async fn transfer(
}
}
} else {
println!("Server to Client: {}", json);
println!("Prevhash not found in params");
}
}
Expand All @@ -168,9 +168,9 @@ async fn transfer(
stale_shares.inc();
}
} else {
// println!("Server to Client: {:?}", line);
println!("Server to Client: {:?}", line);
println!("Error in getting json from line")
}

wi.write_all(&line).await?;
}
}
Expand All @@ -190,14 +190,11 @@ async fn handle_rpc_request(
sv1_new_job_vec: GaugeVec,
prev_hash_mutex: Arc<Mutex<VecDeque<String>>>,
) -> Result<Response<Body>, hyper::Error> {
let uri = req.uri().clone();
let method = req.method().clone();
let headers = req.headers().clone();
let body_bytes = hyper::body::to_bytes(req.into_body()).await?;
let body_str = String::from_utf8_lossy(&body_bytes);
let mut is_get_block_template: bool = false;
println!("Incoming request: {} {} {:?}", method, uri, headers);
println!("Request body: {}", body_str);

if let Ok(json) = serde_json::from_slice::<Value>(&body_bytes) {
if let Some(method) = json.get("method") {
Expand Down Expand Up @@ -247,13 +244,7 @@ async fn handle_rpc_request(
if let Some(timestamp_str) = parts.get(1) {
if let Ok(previous_timestamp) = timestamp_str.parse::<f64>()
{
println!(
"Previous timestamp: {:?}",
previous_timestamp
);
println!("Current timestamp: {:?}", current_timestamp);
let latency = current_timestamp - previous_timestamp;
println!("Computed latency: {:?}", latency);
block_propagation_time.set(latency);
mined_blocks.inc();
}
Expand Down Expand Up @@ -291,16 +282,6 @@ async fn handle_rpc_request(
.insert("authorization", auth_value.parse().unwrap());
}

// Log the forwarded request
let forwarded_headers = new_req.headers().clone();
println!(
"Forwarded request: {} {} {:?}",
new_req.method(),
new_req.uri(),
forwarded_headers
);
println!("Forwarded request body: {}", body_str);

let res = match client.request(new_req).await {
Ok(res) => res,
Err(err) => {
Expand All @@ -310,11 +291,7 @@ async fn handle_rpc_request(
};

let status = res.status();
let headers = res.headers().clone();
let body_bytes = hyper::body::to_bytes(res.into_body()).await?;
let body_str = String::from_utf8_lossy(&body_bytes);
println!("Response: {} {:?}", status, headers);
println!("Response body: {}", body_str);

if let Ok(json) = serde_json::from_slice::<Value>(&body_bytes) {
if is_get_block_template {
Expand Down Expand Up @@ -346,7 +323,6 @@ async fn handle_rpc_request(
// Take the coinbase value and set the block template value metric
if let Some(coinbasevalue) = result.get("coinbasevalue") {
if let Some(block_value) = coinbasevalue.as_i64() {
println!("Block Template Value: {}", block_value);
sv1_block_template_value.set(block_value as f64);
}
}
Expand Down Expand Up @@ -638,14 +614,6 @@ async fn transfer_new_job(
{
let new_job_timestamp =
timestamp.trim().parse::<f64>().unwrap();
println!(
"Current timestamp: {:?}",
current_timestamp
);
println!(
"New job timestamp: {:?}",
new_job_timestamp
);
let delta =
current_timestamp - new_job_timestamp;
new_job_prev_hash_throught_sv2_jdc.set(delta);
Expand All @@ -657,11 +625,6 @@ async fn transfer_new_job(
if line.contains("id=") {
if let Some((_, timestamp)) = line.rsplit_once(' ')
{
println!(
"Current timestamp: {:?}",
current_timestamp
);
println!("Read Timestamp: {:?}", timestamp);
let new_job_timestamp =
timestamp.trim().parse::<f64>().unwrap();
let delta =
Expand Down
17 changes: 1 addition & 16 deletions sv2-custom-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ async fn fetch_block_reward(hash: &str) -> Result<u64, String> {
let height = json["height"]
.as_u64()
.ok_or("Failed to parse height from response")?;
println!("Height: {:?}", height);

let reward_stats_url = match network.as_str() {
"" => "https://mempool.space/api/v1/mining/reward-stats/1",
Expand All @@ -358,7 +357,6 @@ async fn fetch_block_reward(hash: &str) -> Result<u64, String> {
let start_block = reward_stats_json["startBlock"]
.as_u64()
.ok_or("Failed to parse startBlock from reward stats")?;
println!("start_block: {:?}", start_block);
let end_block = reward_stats_json["endBlock"]
.as_u64()
.ok_or("Failed to parse endBlock from reward stats")?;
Expand Down Expand Up @@ -402,11 +400,8 @@ async fn fetch_metric_from_prometheus(
"{}/api/v1/query?query={} &time={}",
prometheus_address, metric_name, timestamp
);
println!("Fetching from URL: {}", url); // Logging dell'URL
let response = client.get(&url).send().await.map_err(|e| e.to_string())?;
let body = response.text().await.map_err(|e| e.to_string())?;
println!("Received response body: {}", body); // Logging della risposta

let json: Value =
serde_json::from_str(&body).map_err(|e| format!("Error parsing JSON: {}", e))?;

Expand Down Expand Up @@ -438,7 +433,6 @@ async fn intercept_prev_hash(
m,
))) = r.recv().await
{
println!("Set prev hash received --> {:?}", m);
let mut id = m.prev_hash;
let d = id.inner_as_mut();
let prev_hash_hex = encode_hex(d);
Expand Down Expand Up @@ -483,7 +477,6 @@ async fn intercept_prev_hash(

// Set the fetched metric value for last_sv2_block_template_value
if let Ok(value) = fetch_metric_result {
println!("Fetched metric value: {}", value);
last_sv2_block_template_value_clone.set(value);
} else {
eprintln!("Error fetching metric");
Expand All @@ -504,7 +497,6 @@ async fn intercept_new_template(
while let Some(PoolMessages::TemplateDistribution(TemplateDistribution::NewTemplate(m))) =
r.recv().await
{
println!("Set new template received --> {:?}", m);
let id = m.template_id;
let current_time = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
Expand All @@ -522,7 +514,6 @@ async fn intercept_new_template(
// Take the coinbase value and set the block template value metric
let sv2_block_template_value_clone = sv2_block_template_value.clone();
let block_value = m.coinbase_tx_value_remaining;
println!("Block Template Value: {}", block_value);
sv2_block_template_value_clone.set(block_value as f64);
}
});
Expand All @@ -536,7 +527,6 @@ async fn intercept_submit_share_extended(
let mut r = builder.add_handler(Remote::Client, MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED);
tokio::spawn(async move {
while let Some(PoolMessages::Mining(Mining::SubmitSharesExtended(m))) = r.recv().await {
println!("SubmitSharesExtended received --> {:?}", m);
submitted_shares.inc();

let id = m.nonce;
Expand All @@ -562,8 +552,7 @@ async fn intercept_submit_share_extended(
async fn intercept_submit_share_success(builder: &mut ProxyBuilder, valid_shares: Counter) {
let mut r = builder.add_handler(Remote::Server, MESSAGE_TYPE_SUBMIT_SHARES_SUCCESS);
tokio::spawn(async move {
while let Some(PoolMessages::Mining(Mining::SubmitSharesSuccess(m))) = r.recv().await {
println!("SubmitSharesSuccess received --> {:?}", m);
while let Some(PoolMessages::Mining(Mining::SubmitSharesSuccess(_m))) = r.recv().await {
valid_shares.inc();
}
});
Expand Down Expand Up @@ -592,7 +581,6 @@ async fn intercept_submit_solution(
m,
))) = r.recv().await
{
println!("SubmitSolution received --> {:?}", m);
let current_timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Time went backwards")
Expand All @@ -609,10 +597,7 @@ async fn intercept_submit_solution(
let parts: Vec<&str> = line.split_whitespace().collect();
if let Some(timestamp_str) = parts.get(1) {
if let Ok(previous_timestamp) = timestamp_str.parse::<f64>() {
println!("Previous timestamp: {:?}", previous_timestamp);
println!("Current timestamp: {:?}", current_timestamp);
let latency = current_timestamp - previous_timestamp;
println!("Computed latency: {:?}", latency);
block_propagation_time.set(latency);
mined_blocks.inc();
}
Expand Down

0 comments on commit 6f6d351

Please sign in to comment.