Skip to content

Commit

Permalink
Updated miner and made block conversion public
Browse files Browse the repository at this point in the history
  • Loading branch information
ksrichard committed Sep 2, 2024
1 parent a091f87 commit b0aafcf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion applications/minotari_app_grpc/src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

mod aggregate_body;
mod base_node_state;
mod block;
pub mod block;
mod block_header;
mod chain_metadata;
mod com_and_pub_signature;
Expand Down
49 changes: 25 additions & 24 deletions applications/minotari_miner/src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@

use std::{convert::TryFrom, str::FromStr, sync::Arc, thread, time::Instant};

use crate::{
cli::Cli,
config::MinerConfig,
errors::{err_empty, MinerError},
miner::{Miner, MiningReport},
stratum::stratum_controller::controller::Controller,
};
use futures::stream::StreamExt;
use log::*;
use minotari_app_grpc::tari_rpc::pow_algo::PowAlgos;
use minotari_app_grpc::tari_rpc::PowAlgo;
use minotari_app_grpc::{
authentication::ClientAuthenticationInterceptor,
tari_rpc::{
Expand Down Expand Up @@ -65,14 +74,6 @@ use tari_utilities::hex::Hex;
use tokio::{sync::Mutex, time::sleep};
use tonic::transport::{Certificate, ClientTlsConfig, Endpoint};

use crate::{
cli::Cli,
config::MinerConfig,
errors::{err_empty, MinerError},
miner::{Miner, MiningReport},
stratum::stratum_controller::controller::Controller,
};

pub const LOG_TARGET: &str = "minotari::miner::main";
pub const LOG_TARGET_FILE: &str = "minotari::logging::miner::main";

Expand Down Expand Up @@ -178,7 +179,7 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
&wallet_payment_address,
&consensus_manager,
)
.await
.await
{
err @ Err(MinerError::GrpcConnection(_)) | err @ Err(MinerError::GrpcStatus(_)) => {
// Any GRPC error we will try to reconnect with a standard delay
Expand All @@ -191,31 +192,31 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
base_node_client = nc.base_node_client;
p2pool_node_client = nc.p2pool_node_client;
break;
},
}
Err(err) => {
error!(target: LOG_TARGET, "Connection error: {:?}", err);
continue;
},
}
}
}
},
}
Err(MinerError::MineUntilHeightReached(h)) => {
warn!(
target: LOG_TARGET,
"Prescribed blockchain height {} reached. Aborting ...", h
);
return Ok(());
},
}
Err(MinerError::MinerLostBlock(h)) => {
warn!(
target: LOG_TARGET,
"Height {} already mined by other node. Restarting ...", h
);
},
}
Err(err) => {
error!(target: LOG_TARGET, "Error: {:?}", err);
sleep(config.wait_timeout()).await;
},
}
Ok(submitted) => {
info!(target: LOG_TARGET, "💰 Found block");
if submitted {
Expand All @@ -226,7 +227,7 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
return Ok(());
}
}
},
}
}
}
}
Expand All @@ -247,7 +248,7 @@ async fn connect(config: &MinerConfig) -> Result<NodeClientResult, MinerError> {
`--enable-grpc` or enable it in the config.";
println!("{}", msg);
return Err(e);
},
}
};

// init client to sha p2pool grpc if enabled
Expand All @@ -261,7 +262,7 @@ async fn connect(config: &MinerConfig) -> Result<NodeClientResult, MinerError> {
`--enable-grpc` or enable it in the config.";
println!("{}", msg);
return Err(e);
},
}
};
}

Expand Down Expand Up @@ -380,7 +381,7 @@ async fn get_new_block(
wallet_payment_address,
consensus_manager,
)
.await
.await
}

async fn get_new_block_base_node(
Expand Down Expand Up @@ -430,8 +431,8 @@ async fn get_new_block_base_node(
config.range_proof_type,
PaymentId::Empty,
)
.await
.map_err(|e| MinerError::CoinbaseError(e.to_string()))?;
.await
.map_err(|e| MinerError::CoinbaseError(e.to_string()))?;
debug!(target: LOG_TARGET, "Coinbase kernel: {}", coinbase_kernel);
debug!(target: LOG_TARGET, "Coinbase output: {}", coinbase_output);

Expand All @@ -456,7 +457,7 @@ async fn get_new_block_p2pool_node(
sha_p2pool_client: &mut ShaP2PoolGrpcClient,
) -> Result<GetNewBlockResponse, MinerError> {
let block_result = sha_p2pool_client
.get_new_block(GetNewBlockRequest::default())
.get_new_block(GetNewBlockRequest { pow: Some(PowAlgo { pow_algo: i32::from(PowAlgos::Sha3x) }) })
.await?
.into_inner();
let new_block_result = block_result.block.ok_or_else(|| err_empty("block result"))?;
Expand Down Expand Up @@ -514,7 +515,7 @@ async fn mining_cycle(
wallet_payment_address,
consensus_manager,
)
.await?;
.await?;
let block = block_result.block;
let header = block.clone().header.ok_or_else(|| err_empty("block.header"))?;

Expand Down Expand Up @@ -567,7 +568,7 @@ async fn mining_cycle(
mined_block,
wallet_payment_address,
)
.await?;
.await?;
block_submitted = true;
break;
} else {
Expand Down

0 comments on commit b0aafcf

Please sign in to comment.