Skip to content

Commit

Permalink
remove a bunch of pubs
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Feb 25, 2025
1 parent 80b645d commit 289e934
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

//! Provides methods for building template data and storing them with timestamps.
use std::{collections::HashMap, convert::TryFrom, sync::Arc};
use std::{collections::HashMap, sync::Arc};

#[cfg(not(test))]
use chrono::Duration;
Expand All @@ -33,10 +33,7 @@ use tari_core::{proof_of_work::monero_rx::FixedByteArray, AuxChainHashes};
use tokio::sync::RwLock;
use tracing::trace;

use crate::{
block_template_manager::{FinalBlockTemplateData, NewBlockTemplateData},
error::MmProxyError,
};
use crate::{block_template_manager::FinalBlockTemplateData, error::MmProxyError};

const LOG_TARGET: &str = "minotari_mm_proxy::xmrig";

Expand All @@ -46,33 +43,9 @@ pub(crate) struct BlockTemplateRepository {
blocks: Arc<RwLock<HashMap<Vec<u8>, BlockRepositoryItem>>>,
}

/// Structure holding [NewBlockTemplate] along with a timestamp.
#[derive(Debug, Clone)]
pub(crate) struct TemplateRepositoryItem {
pub new_block_template: NewBlockTemplateData,
pub template_with_coinbase: grpc::NewBlockTemplate,
datetime: DateTime<Utc>,
}

impl TemplateRepositoryItem {
/// Create new [Self] with current time in UTC.
pub fn new(new_block_template: NewBlockTemplateData, template_with_coinbase: grpc::NewBlockTemplate) -> Self {
Self {
new_block_template,
template_with_coinbase,
datetime: Utc::now(),
}
}

/// Get the timestamp of creation.
pub fn datetime(&self) -> DateTime<Utc> {
self.datetime
}
}

/// Structure holding [FinalBlockTemplateData] along with a timestamp.
#[derive(Debug, Clone)]
pub struct BlockRepositoryItem {
pub(crate) struct BlockRepositoryItem {
pub data: FinalBlockTemplateData,
datetime: DateTime<Utc>,
}
Expand Down Expand Up @@ -113,17 +86,6 @@ impl BlockTemplateRepository {
.or_insert_with(|| BlockRepositoryItem::new(block_template));
}

/// Check if the repository contains a block template with best_previous_block_hash
pub async fn blocks_contains(&self, current_best_block_hash: FixedHash) -> Option<FinalBlockTemplateData> {
let b = self.blocks.read().await;
b.values()
.find(|item| {
let header = item.data.template.tari_block.header.clone().unwrap_or_default();
FixedHash::try_from(header.prev_hash).unwrap_or(FixedHash::default()) == current_best_block_hash
})
.map(|val| val.data.clone())
}

/// Remove any data that is older than 20 minutes.
pub async fn remove_outdated(&self) {
trace!(target: LOG_TARGET, "Removing outdated final block templates");
Expand All @@ -149,7 +111,7 @@ impl BlockTemplateRepository {

/// Setup values for the new block.
#[derive(Clone, Debug)]
pub struct BlockTemplateData {
pub(crate) struct BlockTemplateData {
pub monero_seed: FixedByteArray,
pub tari_block: grpc::Block,
pub tari_miner_data: grpc::MinerData,
Expand All @@ -164,7 +126,7 @@ impl BlockTemplateData {}

/// Builder for the [BlockTemplateData]. All fields have to be set to succeed.
#[derive(Default)]
pub struct BlockTemplateDataBuilder {
pub(crate) struct BlockTemplateDataBuilder {
monero_seed: Option<FixedByteArray>,
tari_block: Option<grpc::Block>,
tari_miner_data: Option<grpc::MinerData>,
Expand Down Expand Up @@ -255,8 +217,8 @@ impl BlockTemplateDataBuilder {
}

#[cfg(test)]
pub mod test {
use std::convert::TryInto;
mod test {
use std::convert::{TryFrom, TryInto};

use tari_core::{
blocks::{Block, BlockHeader},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::{
const LOG_TARGET: &str = "minotari_mm_proxy::proxy::block_template_protocol";

/// Structure holding grpc connections.
pub struct BlockTemplateManager<'a> {
pub(crate) struct BlockTemplateManager<'a> {
config: Arc<MergeMiningProxyConfig>,
base_node_client: &'a mut BaseNodeGrpcClient,
p2pool_client: Option<ShaP2PoolGrpcClient>,
Expand Down Expand Up @@ -80,7 +80,6 @@ impl<'a> BlockTemplateManager<'a> {
}
}

#[allow(clippy::too_many_lines)]
impl BlockTemplateManager<'_> {
/// Create [FinalBlockTemplateData] with [MoneroMiningData].
pub async fn get_next_tari_block_template(
Expand Down Expand Up @@ -330,7 +329,7 @@ fn add_monero_data(

/// Private convenience container struct for new template data
#[derive(Debug, Clone)]
pub struct NewBlockTemplateData {
pub(crate) struct NewBlockTemplateData {
pub template: grpc::NewBlockTemplate,
pub miner_data: grpc::MinerData,
}
Expand All @@ -342,10 +341,10 @@ impl NewBlockTemplateData {
}

/// The AuxChainMerkleRoot is a 32 byte hash
pub type AuxChainMr = MaxSizeBytes<32>;
pub(crate) type AuxChainMr = MaxSizeBytes<32>;
/// Final outputs for required for merge mining
#[derive(Debug, Clone)]
pub struct FinalBlockTemplateData {
pub(crate) struct FinalBlockTemplateData {
pub template: BlockTemplateData,
pub target_difficulty: Difficulty,
pub blockhashing_blob: String,
Expand All @@ -356,7 +355,7 @@ pub struct FinalBlockTemplateData {

/// Container struct for monero mining data inputs obtained from monerod
#[derive(Clone)]
pub struct MoneroMiningData {
pub(crate) struct MoneroMiningData {
pub seed_hash: FixedByteArray,
pub blocktemplate_blob: String,
pub difficulty: u64,
Expand Down
7 changes: 1 addition & 6 deletions applications/minotari_merge_mining_proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ pub use cli::Cli;
mod common;
mod config;
mod error;
mod monero_fail;
mod proxy;
mod run_merge_miner;
use run_merge_miner::start_merge_miner;
mod monero_fail;

pub async fn merge_miner(cli: Cli) -> Result<(), anyhow::Error> {
start_merge_miner(cli).await
}

0 comments on commit 289e934

Please sign in to comment.