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

Fix ci #44

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
GitGab19 marked this conversation as resolved.
Show resolved Hide resolved
os: [ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -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
GitGab19 marked this conversation as resolved.
Show resolved Hide resolved
- 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 .
GitGab19 marked this conversation as resolved.
Show resolved Hide resolved
- name: Build Docker Compose Files (config-c)
run: docker compose -f docker-compose-config-c.yaml build
11 changes: 8 additions & 3 deletions log-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,12 +22,14 @@ struct Data {
result: Vec<ResultItem>,
}

#[allow(dead_code)]
Shourya742 marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Deserialize, Debug)]
struct ResultItem {
stream: Stream,
values: Vec<(String, String)>,
}

#[allow(dead_code)]
Shourya742 marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Deserialize, Debug)]
struct Stream {
container: String,
Expand Down Expand Up @@ -151,7 +154,7 @@ async fn get_containers(log_label: &str) -> Result<Vec<String>, Box<dyn std::err
.filter_map(|container| {
container.names.and_then(|names| {
names
.get(0)
.first()
.map(|name| name.trim_start_matches('/').to_string())
})
})
Expand Down Expand Up @@ -182,8 +185,10 @@ async fn fetch_logs(

let formatted_logs: String = logs
.into_iter()
.map(|(_, message)| format!("{}\n", message))
.collect();
.fold(String::new(), |mut acc, (_, message)| {
writeln!(&mut acc, "{}", message).unwrap();
acc
});
GitGab19 marked this conversation as resolved.
Show resolved Hide resolved

info!("Fetched logs for container: {}", container);
Ok(formatted_logs)
Expand Down
2 changes: 1 addition & 1 deletion pools-latency-calculator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn subscribe_to_pool(mut stream: TcpStream) -> Result<Duration, std::io::E
let start = Instant::now();
stream.write_all(subscribe_msg.as_bytes()).await?;
let mut buffer = vec![0; 2028];
stream.read(&mut buffer).await?;
stream.read_exact(&mut buffer).await?;
Ok(start.elapsed())
}

Expand Down
51 changes: 25 additions & 26 deletions sv1-custom-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use tokio::net::{TcpListener, TcpStream};
use tokio::time::{sleep, Duration};
use warp::Filter;

#[allow(clippy::too_many_arguments)]
async fn transfer(
mut inbound: TcpStream,
mut outbound: TcpStream,
Expand Down Expand Up @@ -112,7 +113,7 @@ async fn transfer(
if let Some(value) = line.chars().nth(start) {
if value != 's' {
if let Some((_, timestamp)) =
line.rsplit_once(" ")
line.rsplit_once(' ')
{
println!(
"The extracted timestamp is: {}",
Expand All @@ -129,24 +130,22 @@ async fn transfer(
} else {
println!("No timestamp value found.");
}
} else if let Some((_, timestamp)) =
line.rsplit_once(' ')
{
println!(
"The extracted timestamp is: {}",
timestamp.trim()
);
let new_job_timestamp = timestamp
.trim()
.parse::<f64>()
.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::<f64>()
.unwrap();
let delta = current_timestamp
- new_job_timestamp;
new_job_gauge.set(delta);
} else {
println!("No timestamp value found.");
}
println!("No timestamp value found.");
}
}
}
Expand Down Expand Up @@ -182,6 +181,7 @@ async fn transfer(
Ok(())
}

#[allow(unused_assignments)]
Shourya742 marked this conversation as resolved.
Show resolved Hide resolved
async fn handle_rpc_request(
req: Request<Body>,
forward_uri: Uri,
Expand Down Expand Up @@ -228,7 +228,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) => {
Expand Down Expand Up @@ -339,12 +339,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") {
Expand Down Expand Up @@ -628,17 +628,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::<f64>().unwrap();
Expand All @@ -658,8 +657,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: {:?}",
Expand Down
9 changes: 7 additions & 2 deletions sv2-custom-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
GitGab19 marked this conversation as resolved.
Show resolved Hide resolved
}

fn reverse_hash(hash: &str) -> String {
Expand Down Expand Up @@ -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
Expand Down
Loading