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 monerod fallback strategy #6764

Merged
Merged
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
12 changes: 12 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion applications/minotari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ hyper = { version = "0.14.12", features = ["default"] }
jsonrpc = "0.12.0"
log = { version = "0.4.8", features = ["std"] }
markup5ever = "0.12.1"
monero = { version = "0.21.0" }
monero = { version = "0.21.0" , features = ["serde"] }
reqwest = { version = "0.11.4", features = ["json"] }
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.57"
Expand All @@ -50,6 +50,8 @@ tonic = "0.12.3"
tracing = "0.1"
url = "2.1.1"
scraper = "0.19.0"
toml = "0.8.19"
regex = "1.11.1"

[build-dependencies]
tari_features = { path = "../../common/tari_features", version = "1.11.1-pre.1" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'a> BlockTemplateProtocol<'a> {
#[allow(clippy::too_many_lines)]
impl BlockTemplateProtocol<'_> {
/// Create [FinalBlockTemplateData] with [MoneroMiningData].
pub async fn get_next_block_template(
pub async fn get_next_tari_block_template(
mut self,
monero_mining_data: MoneroMiningData,
block_templates: &BlockTemplateRepository,
Expand Down
59 changes: 55 additions & 4 deletions applications/minotari_merge_mining_proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
// 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 std::path::{Path, PathBuf};
use std::{
path::{Path, PathBuf},
time::Duration,
};

use minotari_wallet_grpc_client::GrpcAuthentication;
use serde::{Deserialize, Serialize};
use tari_common::{
configuration::{Network, StringList},
configuration::{serializers, Network, StringList},
SubConfigPath,
};
use tari_common_types::tari_address::TariAddress;
Expand Down Expand Up @@ -94,8 +97,22 @@ pub struct MergeMiningProxyConfig {
pub wallet_payment_address: String,
/// Range proof type - revealed_value or bullet_proof_plus: (default = revealed_value)
pub range_proof_type: RangeProofType,
/// Use p2pool to submit and get block templates
/// Use p2pool to submit and get block templates (default = false)
pub p2pool_enabled: bool,
/// Monero fallback strategy(default = MonerodFallback::MonerodOnly)
pub monerod_fallback: MonerodFallback,
/// The timeout duration for connecting to monerod (default = 2s)
#[serde(with = "serializers::seconds")]
pub monerod_connection_timeout: Duration,
}

#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub(crate) enum MonerodFallback {
MonerodOnly,
#[default]
StaticWhenMonerodFails,
StaticOnly,
}

impl Default for MergeMiningProxyConfig {
Expand Down Expand Up @@ -157,6 +174,8 @@ impl Default for MergeMiningProxyConfig {
wallet_payment_address: TariAddress::default().to_base58(),
range_proof_type: RangeProofType::RevealedValue,
p2pool_enabled: false,
monerod_fallback: Default::default(),
monerod_connection_timeout: Duration::from_secs(2),
}
}
}
Expand All @@ -179,10 +198,11 @@ impl SubConfigPath for MergeMiningProxyConfig {
mod test {
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use tari_common::DefaultConfigLoader;
use tari_comms::multiaddr::Multiaddr;

use crate::config::MergeMiningProxyConfig;
use crate::config::{MergeMiningProxyConfig, MonerodFallback};

fn get_config(override_from: &str) -> config::Config {
let s = r#"
Expand Down Expand Up @@ -241,4 +261,35 @@ mod test {
assert!(!config.monerod_use_auth);
assert!(config.submit_to_origin);
}

#[derive(Clone, Serialize, Deserialize, Debug)]
#[allow(clippy::struct_excessive_bools)]
struct TestConfig {
name: String,
inner_config_1: TestInnerConfig,
inner_config_2: TestInnerConfig,
inner_config_3: TestInnerConfig,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
#[allow(clippy::struct_excessive_bools)]
struct TestInnerConfig {
monerod: MonerodFallback,
}

#[test]
fn it_deserializes_enums() {
let config_str = r#"
name = "blockchain champion"
inner_config_1.monerod = "monerod_only"
inner_config_2.monerod = "static_when_monerod_fails"
inner_config_3.monerod = "static_only"
"#;
let config = toml::from_str::<TestConfig>(config_str).unwrap();

// Enums in the config
assert_eq!(config.inner_config_1.monerod, MonerodFallback::MonerodOnly);
assert_eq!(config.inner_config_2.monerod, MonerodFallback::StaticWhenMonerodFails);
assert_eq!(config.inner_config_3.monerod, MonerodFallback::StaticOnly);
}
}
Loading
Loading