Skip to content

Commit

Permalink
feat: integrate algorithm of HR distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrix126 committed Mar 17, 2024
1 parent 87eb738 commit 74c6a92
Show file tree
Hide file tree
Showing 10 changed files with 495 additions and 122 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rand = "0.8.5"
regex = { version = "1.10.3", default-features = false, features = ["perf"] }
rfd = "0.14.0"
serde = { version = "1.0.197", features = ["rc", "derive"] }
serde_json = "1.0"
serde_json = "1.0.114"
sysinfo = { version = "0.30.5", default-features = false }
tls-api = "0.9.0"
tokio = { version = "1.36.0", features = ["rt", "time", "macros", "process"] }
Expand Down
21 changes: 21 additions & 0 deletions NOTES_ALGORITHM.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ The mHR is calculated depending on the sidechain the p2pool is mining on.
The XvB process will check every ten minutes the last 15 minutes average HR and decide when to switch (in seconds) for the ten next minutes. (first p2pool then XvB).
*Need to see the time for Xmrig takes to set the new settings by API.*
When the time to switch arrives, XvB process will send a request to Xmrig to change the node used.
### Modification of config of xmrig

The following 4 attributes must be applied to xmrig config when mining to XvB node.

```ignore
"url": "xvb node:4247"
"user": "user id",
"keepalive": true,
"tls": true,
```
Or to return back to p2pool

```ignore
"url": "127.0.0.1:3333"
"user": "Gupax_v1_3_5",
"keepalive": false,
"tls": false,
```

The HTTP API of xmrig requires to give a full config.
The current config will be requested, modified and sent back.

[^1]: https://p2pool.io/mini/api/pool/stats
[^2]: https://github.com/SChernykh/p2pool?tab=readme-ov-file#how-payouts-work-in-p2pool
14 changes: 12 additions & 2 deletions src/app/panels/bottom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,12 @@ impl crate::app::App {
.on_hover_text("Restart Xvb")
.clicked()
{
Helper::restart_xvb(&self.helper, &self.state.xvb, &self.state.p2pool);
Helper::restart_xvb(
&self.helper,
&self.state.xvb,
&self.state.p2pool,
&self.state.xmrig,
);
}
if key.is_down() && !wants_input
|| ui
Expand Down Expand Up @@ -569,7 +574,12 @@ impl crate::app::App {
.on_disabled_hover_text(XVB_NOT_CONFIGURED)
.clicked()
{
Helper::start_xvb(&self.helper, &self.state.xvb, &self.state.p2pool);
Helper::start_xvb(
&self.helper,
&self.state.xvb,
&self.state.p2pool,
&self.state.xmrig,
);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/panels/middle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ path_xmr: {:#?}\n
}
Tab::Xvb => {
debug!("App | Entering [XvB] Tab");
crate::disk::state::Xvb::show(&mut self.state.xvb, self.size, &self.state.p2pool.address, ctx, ui, &self.xvb_api, lock!(self.xvb).is_alive());
crate::disk::state::Xvb::show(&mut self.state.xvb, self.size, &self.state.p2pool.address, ctx, ui, &self.xvb_api, lock!(self.xvb).is_alive()&& !lock!(self.xvb).is_syncing() && !lock!(self.xvb).is_not_mining());
}
}
});
Expand Down
144 changes: 80 additions & 64 deletions src/app/panels/middle/xvb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex};
use egui::TextStyle::{self, Name};
use egui::{vec2, Hyperlink, Image, RichText, TextEdit, Ui, Vec2};
use log::debug;
use readable::byte::Byte;

use crate::helper::xvb::PubXvbApi;
use crate::utils::constants::{
Expand All @@ -26,7 +27,7 @@ impl crate::disk::state::Xvb {
_ctx: &egui::Context,
ui: &mut egui::Ui,
api: &Arc<Mutex<PubXvbApi>>,
xvb_is_alive: bool,
private_stats: bool,
) {
let website_height = size.y / 10.0;
let width = size.x;
Expand Down Expand Up @@ -104,75 +105,90 @@ impl crate::disk::state::Xvb {
}
// private stats
let priv_stats = &lock!(api).stats_priv;
ui.set_enabled(xvb_is_alive);
// ui.vertical_centered(|ui| {
ui.add_space(SPACE * 2.0);
ui.horizontal(|ui| {
// widget takes a third less space for two separator.
let width_stat = (ui.available_width() / 5.0)
- ((24.0 + ui.style().spacing.item_spacing.x + SPACE) / 5.0);
// 0.0 means minimum
let height_stat = 0.0;
let size_stat = vec2(width_stat, height_stat);
let round = match &priv_stats.round_participate {
Some(r) => r.to_string(),
None => "None".to_string(),
};
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.group(|ui| {
let size_stat = vec2(
ui.available_width(),
0.0, // + ui.spacing().item_spacing.y,
);
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_FAILURE_FIELD);
ui.label(priv_stats.fails.to_string());
})
.response
});
ui.separator();
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_DONATED_1H_FIELD);
ui.label(priv_stats.donor_1hr_avg.to_string());
})
.response
});
ui.separator();
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_DONATED_24H_FIELD);
ui.label(priv_stats.donor_24hr_avg.to_string());
})
.response
});
ui.separator();
ui.add_enabled_ui(priv_stats.round_participate.is_some(), |ui| {
ui.add_enabled_ui(private_stats, |ui| {
ui.add_space(SPACE * 2.0);
ui.horizontal(|ui| {
// widget takes a third less space for two separator.
let width_stat = (ui.available_width() / 5.0)
- ((24.0 + ui.style().spacing.item_spacing.x + SPACE) / 5.0);
// 0.0 means minimum
let height_stat = 0.0;
let size_stat = vec2(width_stat, height_stat);
let round = match &priv_stats.round_participate {
Some(r) => r.to_string(),
None => "None".to_string(),
};
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.group(|ui| {
let size_stat = vec2(
ui.available_width(),
0.0, // + ui.spacing().item_spacing.y,
);
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_ROUND_TYPE_FIELD);
ui.label(round);
ui.label(XVB_FAILURE_FIELD);
ui.label(priv_stats.fails.to_string());
})
.response
})
.on_disabled_hover_text("You do not yet have a share in the PPLNS Window.");
});
ui.separator();
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_WINNER_FIELD);
ui.label(
priv_stats
.win_current
.then(|| "You are Winning the round !")
.unwrap_or("You are not the winner"),
});
ui.separator();
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_DONATED_1H_FIELD);
ui.label(
[
Byte::from(priv_stats.donor_1hr_avg).to_string(),
"H/s".to_string(),
]
.concat(),
);
})
.response
});
ui.separator();
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_DONATED_24H_FIELD);
ui.label(
[
Byte::from(priv_stats.donor_24hr_avg).to_string(),
"H/s".to_string(),
]
.concat(),
);
})
.response
});
ui.separator();
ui.add_enabled_ui(priv_stats.round_participate.is_some(), |ui| {
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_ROUND_TYPE_FIELD);
ui.label(round);
})
.response
})
.on_disabled_hover_text(
"You do not yet have a share in the PPLNS Window.",
);
})
.response
});
})
.response
});
ui.separator();
ui.add_sized(size_stat, |ui: &mut Ui| {
ui.vertical_centered(|ui| {
ui.label(XVB_WINNER_FIELD);
ui.label(
priv_stats
.win_current
.then(|| "You are Winning the round !")
.unwrap_or("You are not the winner"),
);
})
.response
});
})
.response
});
});
});
// Rules link help
Expand Down
31 changes: 31 additions & 0 deletions src/disk/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,37 @@ pub enum XvbNode {
NorthAmerica,
#[default]
Europe,
P2pool,
}
impl XvbNode {
pub fn url(&self) -> String {
match self {
Self::NorthAmerica => String::from(XVB_NODE_NA),
Self::Europe => String::from(XVB_NODE_EU),
Self::P2pool => String::from("127.0.0.1:3333"),
}
}
pub fn user(&self, address: &str) -> String {
match self {
Self::NorthAmerica => address.chars().take(8).collect(),
Self::Europe => address.chars().take(8).collect(),
Self::P2pool => GUPAX_VERSION_UNDERSCORE.to_string(),
}
}
pub fn tls(&self) -> bool {
match self {
Self::NorthAmerica => true,
Self::Europe => true,
Self::P2pool => false,
}
}
pub fn keepalive(&self) -> bool {
match self {
Self::NorthAmerica => true,
Self::Europe => true,
Self::P2pool => false,
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
Loading

0 comments on commit 74c6a92

Please sign in to comment.