Skip to content

Commit

Permalink
feat: add monerod fallback strategy (#6764)
Browse files Browse the repository at this point in the history
Description
---
- Added a monerod fallback strategy whereby static monerod responses can
be loaded if monerod goes offline. Options are always use monerod, use
static monerod responses when monerod goes offline, or always use static
monerod responses. With this implementation, it is possible to merge
mine offline from monerod.
- Reduced the general connection monerod timeout from 5s to 2s; this
improves overall monerod responsiveness in event of a monerod connection
error.
- Fixed a bug whereby the same monerod entry would be retried over and
over in the event of a monerod connection error.

Closes #6756

Motivation and Context
---
This could improve merge mining with Tari Universe.

How Has This Been Tested?
---
System-level testing
Added unit tests

What process can a PR reviewer use to test or verify this change?
---
Code review
System-level testing

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->

---------

Co-authored-by: SW van Heerden <swvheerden@gmail.com>
  • Loading branch information
hansieodendaal and SWvheerden authored Feb 3, 2025
1 parent af2a803 commit f5365ca
Show file tree
Hide file tree
Showing 15 changed files with 1,815 additions and 608 deletions.
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

0 comments on commit f5365ca

Please sign in to comment.