Skip to content

Commit

Permalink
Merge branch 'main-tarilabs'
Browse files Browse the repository at this point in the history
  • Loading branch information
leet4tari committed Oct 16, 2024
2 parents e54504a + c9f815a commit 2e025bf
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 107 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/target
config.json
data

# Ignore OS files
.DS_Store
.idea/
.vscode/*
!.vscode/extensions.json
!.vscode/extensions.json
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
[package]
name = "glytex"
version = "0.1.13"
version = "0.1.16"
edition = "2021"

[dependencies]
tari_core = { git = "https://github.com/tari-project/tari", default-features = false, features = [
"transactions",
] }
minotari_app_grpc = { git = "http://github.com/tari-project/tari" }
tari_common_types = { git = "http://github.com/tari-project/tari" }
tari_common = { git = "http://github.com/tari-project/tari" }
tari_script = { git = "http://github.com/tari-project/tari" }
tari_key_manager = { git = "http://github.com/tari-project/tari" }
tari_shutdown = { git = "https://github.com/tari-project/tari.git" }
tari_crypto = { version = "0.20.3", features = ["borsh"] }
tari_utilities = "0.7"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.68"
anyhow = "*"
clap = { version = "4.5.0", features = ["derive"] }
sha3 = "0.10"
clap = {version = "4.5.0", features = ["derive"]}
minotari_app_grpc = {git = "http://github.com/tari-project/tari"}
num-format = "0.4.4"
serde = {version = "1.0.130", features = ["derive"]}
serde_json = "1.0.68"
sha3 = "0.10"
tari_common = {git = "http://github.com/tari-project/tari"}
tari_common_types = {git = "http://github.com/tari-project/tari"}
tari_core = {git = "https://github.com/tari-project/tari", default-features = false, features = [
"transactions",
]}
tari_crypto = {version = "0.20.3", features = ["borsh"]}
tari_key_manager = {git = "http://github.com/tari-project/tari"}
tari_script = {git = "http://github.com/tari-project/tari"}
tari_shutdown = {git = "https://github.com/tari-project/tari.git"}
tari_utilities = "0.7"

tokio = { version = "1.36", features = ["full"] }
tonic = { version = "0.12.3" }
libsqlite3-sys = {version = "0.25.1", features = ["bundled"]}
prost = "0.13.3"
prost-types = "0.13.3"
rand = "0.8"
libsqlite3-sys = { version = "0.25.1", features = ["bundled"] }
tokio = {version = "1.36", features = ["full"]}
tonic = {version = "0.12.3"}

cust = { version = "0.3.2", optional = true }
opencl3 = { version = "0.9.5", optional = true }
opencl-sys = "*"
axum = "0.7.5"
thiserror = "1.0.63"
cust = {version = "0.3.2", optional = true}
log = "0.4.22"
log4rs = "1.3.0"
opencl-sys = "*"
opencl3 = {version = "0.9.5", optional = true}
thiserror = "1.0.63"

[features]
default = []
Expand Down
9 changes: 8 additions & 1 deletion log4rs_sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ appenders:

# Set the default logging level to "info"
root:
level: info
level: warn
appenders:
- stdout
- xtrgpuminer

loggers:
tari:
level: info
appenders:
- stdout
- xtrgpuminer
2 changes: 1 addition & 1 deletion src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Default for ConfigFile {
// In range 1-1000
gpu_percentage: 1000,
grid_size: 1000,
template_timeout_secs: 5,
template_timeout_secs: 1,
}
}
}
Expand Down
28 changes: 18 additions & 10 deletions src/http/handlers/stats.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
use std::collections::HashMap;

use axum::{extract::State, http::StatusCode, Json};
use serde::{Deserialize, Serialize};

use crate::http::server::AppState;
use crate::http::{
server::AppState,
stats_collector::{AverageHashrate, GetHashrateResponse},
};

#[derive(Serialize, Deserialize)]
#[derive(Serialize)]
pub struct Stats {
pub hashes_per_second: u64,
pub accepted_blocks: u64,
pub rejected_blocks: u64,
hashrate_per_device: HashMap<u32, AverageHashrate>,
total_hashrate: AverageHashrate,
}

pub async fn handle_get_stats(State(state): State<AppState>) -> Result<Json<Stats>, StatusCode> {
Ok(Json(Stats {
hashes_per_second: state.stats_store.hashes_per_second(),
accepted_blocks: state.stats_store.accepted_blocks(),
rejected_blocks: state.stats_store.rejected_blocks(),
}))
let hashrate = state.stats_client.get_hashrate().await.map_err(|e| {
log::error!("Failed to get hashrate: {:?}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;
let stats = Stats {
hashrate_per_device: hashrate.devices,
total_hashrate: hashrate.total,
};
Ok(Json(stats))
}
1 change: 1 addition & 0 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod config;
mod handlers;
pub mod server;
pub mod stats_collector;
11 changes: 6 additions & 5 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tari_shutdown::ShutdownSignal;
use thiserror::Error;
use tokio::io;

use super::stats_collector::StatsClient;
use crate::{
http::{
config,
Expand All @@ -20,7 +21,7 @@ const LOG_TARGET: &str = "tari::gpuminer::server";
pub struct HttpServer {
shutdown_signal: ShutdownSignal,
config: config::Config,
stats_store: Arc<StatsStore>,
stats_client: StatsClient,
}

#[derive(Error, Debug)]
Expand All @@ -31,15 +32,15 @@ pub enum Error {

#[derive(Clone)]
pub struct AppState {
pub stats_store: Arc<StatsStore>,
pub stats_client: StatsClient,
}

impl HttpServer {
pub fn new(shutdown_signal: ShutdownSignal, config: config::Config, stats_store: Arc<StatsStore>) -> Self {
pub fn new(shutdown_signal: ShutdownSignal, config: config::Config, stats_client: StatsClient) -> Self {
Self {
shutdown_signal,
config,
stats_store,
stats_client,
}
}

Expand All @@ -49,7 +50,7 @@ impl HttpServer {
.route("/version", get(version::handle_version))
.route("/stats", get(stats::handle_get_stats))
.with_state(AppState {
stats_store: self.stats_store.clone(),
stats_client: self.stats_client.clone(),
})
}

Expand Down
Loading

0 comments on commit 2e025bf

Please sign in to comment.