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

feat: add squad to p2pool #1371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src-tauri/binaries_versions_esmeralda.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"binaries": {
"xmrig": "=6.22.0",
"mmproxy": "=1.9.1-pre.2",
"minotari_node": "=1.9.1-pre.2",
"wallet": "=1.9.1-pre.2",
"sha-p2pool": "=0.19.0",
"mmproxy": "=1.9.2-pre.0",
"minotari_node": "=1.9.2-pre.0",
"wallet": "=1.9.2-pre.0",
"sha-p2pool": "=0.20.0",
"xtrgpuminer": "=0.2.10",
"tor": "=13.5.7"
}
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/binaries_versions_nextnet.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"binaries": {
"xmrig": "=6.22.0",
"mmproxy": "=1.9.1-rc.3",
"minotari_node": "=1.9.1-rc.3",
"wallet": "=1.9.1-rc.3",
"sha-p2pool": "=0.19.0",
"mmproxy": "=1.9.2-rc.0",
"minotari_node": "=1.9.2-rc.0",
"wallet": "=1.9.2-rc.0",
"sha-p2pool": "=0.20.0",
"xtrgpuminer": "=0.2.10",
"tor": "=13.5.7"
}
Expand Down
22 changes: 3 additions & 19 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::external_dependencies::{
use crate::gpu_miner_adapter::{GpuMinerStatus, GpuNodeSource};
use crate::hardware::hardware_status_monitor::{HardwareStatusMonitor, PublicDeviceProperties};
use crate::internal_wallet::{InternalWallet, PaperWalletConfig};
use crate::p2pool::models::{Connections, Stats};
use crate::p2pool::models::{Connections, P2poolStats};
use crate::progress_tracker::ProgressTracker;
use crate::tor_adapter::TorConfig;
use crate::utils::shutdown_utils::stop_all_processes;
Expand Down Expand Up @@ -523,29 +523,13 @@ pub async fn get_monero_seed_words(
#[tauri::command]
pub async fn get_p2pool_stats(
state: tauri::State<'_, UniverseAppState>,
) -> Result<Option<Stats>, String> {
) -> Result<Option<P2poolStats>, String> {
let timer = Instant::now();
if state.is_getting_p2pool_stats.load(Ordering::SeqCst) {
let read = state.cached_p2pool_stats.read().await;
if let Some(stats) = &*read {
warn!(target: LOG_TARGET, "Already getting p2pool stats, returning cached value");
return Ok(stats.clone());
}
warn!(target: LOG_TARGET, "Already getting p2pool stats");
return Err("Already getting p2pool stats".to_string());
}
state.is_getting_p2pool_stats.store(true, Ordering::SeqCst);
let p2pool_stats = state.p2pool_manager.get_stats().await.unwrap_or_else(|e| {
warn!(target: LOG_TARGET, "Error getting p2pool stats: {}", e);
None
});
let p2pool_stats = state.p2pool_latest_status.borrow().clone();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've seen some issues with the latest status caching. When you stop mining the last mining status will be cached, and continue to offer whatever stats were last given. Even if no longer connected. (This was fixed for the GPU miner before).

Just mentioning it here in case it's something that should be looked at in regards to p2p stats. Such as p2p is no longer connected but the cached stats have connected_since and makes everyone think it's still connected.

https://github.com/tari-project/universe/pull/1304/files#diff-31c51000768ebc0fedcd78a7c5282936ecee9a65108f5deff570b4d98af9a12cR123-R129


if timer.elapsed() > MAX_ACCEPTABLE_COMMAND_TIME {
warn!(target: LOG_TARGET, "get_p2pool_stats took too long: {:?}", timer.elapsed());
}
let mut lock = state.cached_p2pool_stats.write().await;
*lock = Some(p2pool_stats.clone());
state.is_getting_p2pool_stats.store(false, Ordering::SeqCst);
Ok(p2pool_stats)
}

Expand Down
13 changes: 6 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use crate::gpu_miner::GpuMiner;
use crate::internal_wallet::InternalWallet;
use crate::mm_proxy_manager::{MmProxyManager, StartConfig};
use crate::node_manager::NodeManager;
use crate::p2pool::models::Stats;
use crate::p2pool::models::P2poolStats;
use crate::p2pool_manager::{P2poolConfig, P2poolManager};
use crate::tor_manager::TorManager;
use crate::utils::auto_rollback::AutoRollback;
Expand Down Expand Up @@ -578,7 +578,7 @@ struct UniverseAppState {
base_node_latest_status: Arc<watch::Receiver<BaseNodeStatus>>,
wallet_latest_balance: Arc<watch::Receiver<Option<WalletBalance>>>,
gpu_latest_status: Arc<watch::Receiver<GpuMinerStatus>>,
is_getting_p2pool_stats: Arc<AtomicBool>,
p2pool_latest_status: Arc<watch::Receiver<Option<P2poolStats>>>,
is_getting_p2pool_connections: Arc<AtomicBool>,
is_getting_miner_metrics: Arc<AtomicBool>,
is_getting_transaction_history: Arc<AtomicBool>,
Expand All @@ -599,7 +599,6 @@ struct UniverseAppState {
p2pool_manager: P2poolManager,
tor_manager: TorManager,
updates_manager: UpdatesManager,
cached_p2pool_stats: Arc<RwLock<Option<Option<Stats>>>>,
cached_p2pool_connections: Arc<RwLock<Option<Option<Connections>>>>,
cached_miner_metrics: Arc<RwLock<Option<MinerMetrics>>>,
setup_counter: Arc<RwLock<AutoRollback<bool>>>,
Expand Down Expand Up @@ -637,7 +636,8 @@ fn main() {
let (wallet_watch_tx, wallet_watch_rx) = watch::channel::<Option<WalletBalance>>(None);
let wallet_manager = WalletManager::new(node_manager.clone(), wallet_watch_tx);
let wallet_manager2 = wallet_manager.clone();
let p2pool_manager = P2poolManager::new();
let (p2pool_stats_tx, p2pool_stats_rx) = watch::channel(None);
let p2pool_manager = P2poolManager::new(p2pool_stats_tx);

let cpu_config = Arc::new(RwLock::new(CpuMinerConfig {
node_connection: CpuMinerConnection::BuiltInProxy,
Expand All @@ -664,9 +664,9 @@ fn main() {
app_config.clone(),
app_in_memory_config.clone(),
Some(Network::default()),
p2pool_manager.clone(),
gpu_status_rx.clone(),
base_node_watch_rx.clone(),
p2pool_stats_rx.clone(),
);

let updates_manager = UpdatesManager::new(app_config.clone(), shutdown.to_signal());
Expand All @@ -677,11 +677,11 @@ fn main() {
let app_state = UniverseAppState {
stop_start_mutex: Arc::new(Mutex::new(())),
is_getting_miner_metrics: Arc::new(AtomicBool::new(false)),
is_getting_p2pool_stats: Arc::new(AtomicBool::new(false)),
is_getting_p2pool_connections: Arc::new(AtomicBool::new(false)),
base_node_latest_status: Arc::new(base_node_watch_rx),
wallet_latest_balance: Arc::new(wallet_watch_rx),
gpu_latest_status: Arc::new(gpu_status_rx),
p2pool_latest_status: Arc::new(p2pool_stats_rx),
is_setup_finished: Arc::new(RwLock::new(false)),
is_getting_transaction_history: Arc::new(AtomicBool::new(false)),
config: app_config.clone(),
Expand All @@ -700,7 +700,6 @@ fn main() {
airdrop_access_token: Arc::new(RwLock::new(None)),
tor_manager: TorManager::new(),
updates_manager,
cached_p2pool_stats: Arc::new(RwLock::new(None)),
cached_p2pool_connections: Arc::new(RwLock::new(None)),
cached_miner_metrics: Arc::new(RwLock::new(None)),
setup_counter: Arc::new(RwLock::new(AutoRollback::new(false))),
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/src/p2pool/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ pub(crate) struct ConnectionCounters {
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Stats {
pub struct P2poolStats {
pub connection_info: ConnectionInfo,
pub connected_since: Option<EpochTime>,
pub randomx_stats: ChainStats,
pub sha3x_stats: ChainStats,
pub last_gossip_message: EpochTime,
pub peer_id: String,
pub squad: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/p2pool/stats_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::p2pool::models::{Connections, Stats};
use crate::p2pool::models::{Connections, P2poolStats};
use anyhow::Error;
use log::warn;

Expand All @@ -37,10 +37,10 @@ impl Client {
}
}

pub async fn stats(&self) -> Result<Stats, Error> {
pub async fn stats(&self) -> Result<P2poolStats, Error> {
let stats = reqwest::get(format!("{}/stats", self.stats_server_address))
.await?
.json::<Stats>()
.json::<P2poolStats>()
.await
.inspect_err(|e| warn!(target: LOG_TARGET, "P2pool stats error: {:?}", e))?;
Ok(stats)
Expand Down
28 changes: 21 additions & 7 deletions src-tauri/src/p2pool_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ use std::collections::HashMap;
use std::path::PathBuf;
use tari_common::configuration::Network;
use tari_shutdown::Shutdown;
use tokio::sync::watch;

use crate::p2pool;
use crate::p2pool::models::{Connections, Stats};
use crate::p2pool::models::{Connections, P2poolStats};
use crate::p2pool_manager::P2poolConfig;
use crate::process_adapter::HealthStatus;
use crate::process_adapter::ProcessStartupSpec;
Expand All @@ -45,11 +46,15 @@ const LOG_TARGET: &str = "tari::universe::p2pool_adapter";

pub struct P2poolAdapter {
pub(crate) config: Option<P2poolConfig>,
stats_broadcast: watch::Sender<Option<P2poolStats>>,
}

impl P2poolAdapter {
pub fn new() -> Self {
Self { config: None }
pub fn new(stats_broadcast: watch::Sender<Option<P2poolStats>>) -> Self {
Self {
config: None,
stats_broadcast,
}
}

#[allow(dead_code)]
Expand Down Expand Up @@ -136,7 +141,10 @@ impl ProcessAdapter for P2poolAdapter {
name: "P2pool".to_string(),
},
},
P2poolStatusMonitor::new(format!("http://127.0.0.1:{}", config.stats_server_port)),
P2poolStatusMonitor::new(
format!("http://127.0.0.1:{}", config.stats_server_port),
self.stats_broadcast.clone(),
),
))
}

Expand All @@ -152,12 +160,17 @@ impl ProcessAdapter for P2poolAdapter {
#[derive(Clone)]
pub struct P2poolStatusMonitor {
stats_client: p2pool::stats_client::Client,
latest_status_broadcast: watch::Sender<Option<P2poolStats>>,
}

impl P2poolStatusMonitor {
pub fn new(stats_server_addr: String) -> Self {
pub fn new(
stats_server_addr: String,
stats_broadcast: watch::Sender<Option<P2poolStats>>,
) -> Self {
Self {
stats_client: p2pool::stats_client::Client::new(stats_server_addr),
latest_status_broadcast: stats_broadcast,
}
}
}
Expand All @@ -166,7 +179,7 @@ impl P2poolStatusMonitor {
impl StatusMonitor for P2poolStatusMonitor {
async fn check_health(&self) -> HealthStatus {
match self.stats_client.stats().await {
Ok(_stats) => {
Ok(stats) => {
// if stats
// .connection_info
// .network_info
Expand All @@ -187,6 +200,7 @@ impl StatusMonitor for P2poolStatusMonitor {
// warn!(target: LOG_TARGET, "P2pool last gossip message was more than 60 seconds ago, health check warning");
// return HealthStatus::Warning;
// }
let _unused = self.latest_status_broadcast.send(Some(stats));

HealthStatus::Healthy
}
Expand All @@ -199,7 +213,7 @@ impl StatusMonitor for P2poolStatusMonitor {
}

impl P2poolStatusMonitor {
pub async fn status(&self) -> Result<Stats, Error> {
pub async fn status(&self) -> Result<P2poolStats, Error> {
self.stats_client.stats().await
}

Expand Down
17 changes: 4 additions & 13 deletions src-tauri/src/p2pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use std::time::Duration;
use futures_util::future::FusedFuture;
use log::warn;
use tari_shutdown::ShutdownSignal;
use tokio::sync::RwLock;
use tokio::sync::{watch, RwLock};
use tokio::time::sleep;

use crate::p2pool::models::{Connections, Stats};
use crate::p2pool::models::{Connections, P2poolStats};
use crate::p2pool_adapter::P2poolAdapter;
use crate::port_allocator::PortAllocator;
use crate::process_watcher::ProcessWatcher;
Expand Down Expand Up @@ -109,8 +109,8 @@ pub struct P2poolManager {
}

impl P2poolManager {
pub fn new() -> Self {
let adapter = P2poolAdapter::new();
pub fn new(stats_broadcast: watch::Sender<Option<P2poolStats>>) -> Self {
let adapter = P2poolAdapter::new(stats_broadcast);
let mut process_watcher = ProcessWatcher::new(adapter);
process_watcher.expected_startup_time = Duration::from_secs(30);

Expand All @@ -119,15 +119,6 @@ impl P2poolManager {
}
}

pub async fn get_stats(&self) -> Result<Option<Stats>, anyhow::Error> {
let process_watcher = self.watcher.read().await;
if let Some(status_monitor) = &process_watcher.status_monitor {
Ok(Some(status_monitor.status().await?))
} else {
Ok(None)
}
}

pub async fn get_connections(&self) -> Result<Option<Connections>, anyhow::Error> {
let process_watcher = self.watcher.read().await;
if let Some(status_monitor) = &process_watcher.status_monitor {
Expand Down
Loading
Loading