diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 112c207..d7a36b5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -50,11 +50,11 @@ jobs: run: cargo fmt -- --check docker_build: - name: Docker Build + name: Docker Compose Build runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] steps: - name: Checkout code uses: actions/checkout@v3 @@ -63,24 +63,24 @@ jobs: if: runner.os == 'Linux' run: | sudo apt-get update - sudo apt-get install -y docker.io - sudo systemctl start docker - sudo systemctl enable docker + sudo apt-get install -y \ + ca-certificates \ + curl \ + gnupg \ + lsb-release + sudo mkdir -p /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --batch --yes --dearmor -o /etc/apt/keyrings/docker.gpg + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update + sudo apt-get install -y docker-ce docker-ce-cli containerd.io + sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose - - name: Set up Docker (macOS) - if: runner.os == 'macOS' - run: | - brew install --cask docker - open /Applications/Docker.app - while ! docker system info > /dev/null 2>&1; do sleep 1; done + - name: Build Docker Compose Files (config-a) + run: docker compose -f docker-compose-config-a.yaml build - - name: Build Docker Images - run: | - docker build -t log-server ./log-server - docker build -t pools-latency-calculator ./pools-latency-calculator - docker build -t sv1-custom-proxy ./sv1-custom-proxy - docker build -t sv2-custom-proxy ./sv2-custom-proxy - docker build -f sv1-public-pool.dockerfile -t sv1-public-pool . - docker build -f template-provider.dockerfile -t template-provider . - docker build -f sv2-roles.dockerfile -t sv2-roles . - docker build -f pools-latency-calculator.dockerfile -t pools-latency-calculator . + - name: Build Docker Compose Files (config-c) + run: docker compose -f docker-compose-config-c.yaml build \ No newline at end of file diff --git a/log-server/src/main.rs b/log-server/src/main.rs index 50f07f1..978b069 100644 --- a/log-server/src/main.rs +++ b/log-server/src/main.rs @@ -6,6 +6,7 @@ use reqwest::Client; use serde::Deserialize; use std::collections::HashMap; use std::env; +use std::fmt::Write; use tar::Builder; use warp::http::Response; use warp::hyper::Body; @@ -23,15 +24,9 @@ struct Data { #[derive(Deserialize, Debug)] struct ResultItem { - stream: Stream, values: Vec<(String, String)>, } -#[derive(Deserialize, Debug)] -struct Stream { - container: String, -} - #[tokio::main] async fn main() { dotenv().ok(); @@ -151,7 +146,7 @@ async fn get_containers(log_label: &str) -> Result, Box Result() + .unwrap(); + let delta = + current_timestamp - new_job_timestamp; + new_job_gauge.set(delta); } else { - if let Some((_, timestamp)) = - line.rsplit_once(" ") - { - println!( - "The extracted timestamp is: {}", - timestamp.trim() - ); - let new_job_timestamp = timestamp - .trim() - .parse::() - .unwrap(); - let delta = current_timestamp - - new_job_timestamp; - new_job_gauge.set(delta); - } else { - println!("No timestamp value found."); - } + println!("No timestamp value found."); } } } @@ -228,7 +227,7 @@ async fn handle_rpc_request( }; let nonce_value = &line[start..end]; // Decode the nonce hex string into bytes - let nonce_bytes_result = hex::decode(&nonce_value); + let nonce_bytes_result = hex::decode(nonce_value); let nonce_bytes = match nonce_bytes_result { Ok(bytes) => bytes, Err(e) => { @@ -319,8 +318,6 @@ async fn handle_rpc_request( if let Ok(json) = serde_json::from_slice::(&body_bytes) { if is_get_block_template { - is_get_block_template = false; - if let Some(result) = json.get("result") { if let Some(previousblockhash) = result.get("previousblockhash") { if let Some(prevhash) = previousblockhash.as_str() { @@ -339,12 +336,12 @@ async fn handle_rpc_request( .expect("Time went backwards") .as_millis() as f64; sv1_new_job_vec - .with_label_values(&[&prev_hash, &flag]) + .with_label_values(&[&prev_hash, flag]) .set(current_timestamp); tokio::spawn(async move { sleep(Duration::from_secs(1)).await; // Remove the metric from Prometheus - let _ = sv1_new_job_vec.remove_label_values(&[&prev_hash, &flag]); + let _ = sv1_new_job_vec.remove_label_values(&[&prev_hash, flag]); }); // Take the coinbase value and set the block template value metric if let Some(coinbasevalue) = result.get("coinbasevalue") { @@ -628,17 +625,16 @@ async fn transfer_new_job( 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("prevhash=") { let start = start_index + "prevhash=\"".len(); - let _end = match line[start..].find("\"") { + let _end = match line[start..].find('"') { Some(index) => start + index, None => { println!("Failed to find end quote for prevhash in line: {}", line); continue; } }; - if let Some((_, timestamp)) = line.rsplit_once(" ") + if let Some((_, timestamp)) = line.rsplit_once(' ') { let new_job_timestamp = timestamp.trim().parse::().unwrap(); @@ -658,8 +654,8 @@ async fn transfer_new_job( println!("No timestamp value found."); } } - if let Some(_) = line.find("id=") { - if let Some((_, timestamp)) = line.rsplit_once(" ") + if line.contains("id=") { + if let Some((_, timestamp)) = line.rsplit_once(' ') { println!( "Current timestamp: {:?}", diff --git a/sv2-custom-proxy/src/main.rs b/sv2-custom-proxy/src/main.rs index 5064a76..ae6d63c 100644 --- a/sv2-custom-proxy/src/main.rs +++ b/sv2-custom-proxy/src/main.rs @@ -12,6 +12,7 @@ use prometheus::{ use reqwest::Client; use serde_json::Value; use std::env; +use std::fmt::Write; use std::net::ToSocketAddrs; use std::time::SystemTime; use tokio::net::TcpStream; @@ -296,7 +297,11 @@ async fn connect_to_server(server_address: &str) -> TcpStream { } pub fn encode_hex(bytes: &[u8]) -> String { - bytes.iter().map(|b| format!("{:02x}", b)).collect() + let hex_string = bytes.iter().fold(String::new(), |mut acc, b| { + write!(&mut acc, "{:02x}", b).unwrap(); + acc + }); + hex_string } fn reverse_hash(hash: &str) -> String { @@ -593,7 +598,7 @@ async fn intercept_submit_solution( .expect("Time went backwards") .as_millis() as f64; let id = m.header_nonce; - let url = format!("http://10.5.0.17:3456/metrics"); + let url = "http://10.5.0.17:3456/metrics".to_string(); if let Ok(response) = client.get(&url).send().await { if let Ok(body) = response.text().await { // Simple parsing to find the metric for the specific nonce