Skip to content

Commit

Permalink
estimator settings
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Sep 13, 2024
1 parent 9964e18 commit dc1aab7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
3 changes: 3 additions & 0 deletions core/resources/i18n/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3218,6 +3218,8 @@
"Export Wallet Data": "Export Wallet Data",
"FIRST": "FIRST",
"Faucet": "Faucet",
"Fee Market & Network Pressure": "Fee Market & Network Pressure",
"Fee Market Only": "Fee Market Only",
"Fee Rate Estimates": "Fee Rate Estimates",
"File Handles": "File Handles",
"File contents": "File contents",
Expand Down Expand Up @@ -3302,6 +3304,7 @@
"NPM Modules for NodeJS": "NPM Modules for NodeJS",
"Network": "Network",
"Network Difficulty": "Network Difficulty",
"Network Fee Estimator": "Network Fee Estimator",
"Network Fees:": "Network Fees:",
"Network Interface": "Network Interface",
"Network Load:": "Network Load:",
Expand Down
5 changes: 3 additions & 2 deletions core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ pub use crate::primitives::{
pub use crate::result::Result;
pub use crate::runtime::{runtime, spawn, spawn_with_result, Payload, Runtime, Service};
pub use crate::settings::{
KaspadNodeKind, NetworkInterfaceConfig, NetworkInterfaceKind, NodeConnectionConfigKind,
NodeMemoryScale, NodeSettings, RpcConfig, RpcOptions, Settings, UserInterfaceSettings,
EstimatorMode, EstimatorSettings, KaspadNodeKind, NetworkInterfaceConfig, NetworkInterfaceKind,
NodeConnectionConfigKind, NodeMemoryScale, NodeSettings, RpcConfig, RpcOptions, Settings,
UserInterfaceSettings,
};
pub use crate::state::State;
pub use crate::status::Status;
Expand Down
12 changes: 7 additions & 5 deletions core/src/modules/account_manager/estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'context> Estimator<'context> {
let number_of_generated_stages = actual_estimate.number_of_generated_stages;

let buckets = if let Some(fees) = core.feerate.as_ref() {
if network_below_capacity {
if network_below_capacity && core.settings.estimator.mode == EstimatorMode::NetworkPressure {
[
Some(FeeMode::Low(FeerateBucket::new(1.0,5.0))),
Some(FeeMode::Economic(fees.low.value().with_seconds(3.0))),
Expand All @@ -124,8 +124,8 @@ impl<'context> Estimator<'context> {
let fee_mode = self.context.fee_mode;
for mode in buckets.into_iter().flatten() {
let bucket = mode.bucket();
let feerate = (bucket.feerate - 1.0).max(0.0);
// let feerate = bucket.feerate;
// let feerate = (bucket.feerate - 1.0).max(0.0);
let feerate = bucket.feerate;

// let seconds = if network_below_capacity {
// match &mode {
Expand Down Expand Up @@ -162,8 +162,10 @@ impl<'context> Estimator<'context> {

if fee_selection.render(ui, &mut self.context.fee_mode).clicked() {
let bucket = self.context.fee_mode.bucket();
let priority_feerate = (bucket.feerate - 1.0).max(0.0);
let total_fees_sompi = (priority_feerate * actual_estimate.aggregate_mass as f64) as u64;
// let priority_feerate = (bucket.feerate - 1.0).max(0.0);
// let priority_feerate = bucket.feerate;
// let total_fees_sompi = (priority_feerate * actual_estimate.aggregate_mass as f64) as u64;
let total_fees_sompi = (bucket.feerate * actual_estimate.aggregate_mass as f64) as u64;
// runtime().toast(UserNotification::success(format!("selection: {:?}", self.context.fee_mode)).short());
let total_fee_kaspa = sompi_to_kaspa(total_fees_sompi);
self.context.priority_fees_text = format!("{}", total_fee_kaspa);
Expand Down
3 changes: 2 additions & 1 deletion core/src/modules/account_manager/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ async fn calculate_fee_rate(network_type : NetworkType, account_id : AccountId,
if base_mass == 0 {
1.0
} else {
(priority_fee_sompi as f64 / base_mass as f64) + 1.0
// (priority_fee_sompi as f64 / base_mass as f64) + 1.0
priority_fee_sompi as f64 / base_mass as f64
}
}
15 changes: 15 additions & 0 deletions core/src/modules/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,21 @@ impl Settings {
});
});

CollapsingHeader::new(i18n("Network Fee Estimator"))
.default_open(false)
.show(ui, |ui| {
ui.vertical(|ui|{
EstimatorMode::iter().for_each(|kind| {
ui.radio_value(&mut self.settings.estimator.mode, *kind, i18n(kind.describe()));
});

if self.settings.estimator.mode != core.settings.estimator.mode {
core.settings.estimator.mode = self.settings.estimator.mode;
core.store_settings();
}
});
});

#[cfg(not(target_arch = "wasm32"))]
core.storage.clone().render_settings(core, ui);

Expand Down
33 changes: 33 additions & 0 deletions core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,36 @@ impl DeveloperSettings {
}
}

#[derive(Describe, Default, Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum EstimatorMode {
#[describe("Fee Market Only")]
FeeMarketOnly,
#[default]
#[describe("Fee Market & Network Pressure")]
NetworkPressure,
}

#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct EstimatorSettings {
pub mode: EstimatorMode,
}

impl Default for EstimatorSettings {
fn default() -> Self {
Self {
mode: EstimatorMode::NetworkPressure,
}
}
}

impl EstimatorSettings {
pub fn track_network_load(&self) -> EstimatorMode {
self.mode
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Settings {
Expand All @@ -583,6 +613,8 @@ pub struct Settings {
pub version: String,
pub update: String,
pub developer: DeveloperSettings,
#[serde(default)]
pub estimator: EstimatorSettings,
pub node: NodeSettings,
pub user_interface: UserInterfaceSettings,
pub language_code: String,
Expand All @@ -602,6 +634,7 @@ impl Default for Settings {
version: "0.0.0".to_string(),
update: crate::app::VERSION.to_string(),
developer: DeveloperSettings::default(),
estimator: EstimatorSettings::default(),
node: NodeSettings::default(),
user_interface: UserInterfaceSettings::default(),
language_code: "en".to_string(),
Expand Down

0 comments on commit dc1aab7

Please sign in to comment.