Skip to content

Commit

Permalink
Support custom setting of algo for miner client
Browse files Browse the repository at this point in the history
  • Loading branch information
sanlee42 committed Jul 23, 2024
1 parent 6d283fc commit 6a7236b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmd/miner_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use starcoin_miner_client::stratum_client::StratumJobClient;
use starcoin_miner_client::stratum_client_service::{
StratumClientService, StratumClientServiceServiceFactory,
};
use starcoin_miner_client::ConsensusStrategy;
use starcoin_service_registry::{RegistryAsyncService, RegistryService};
use starcoin_stratum::rpc::LoginRequest;
use starcoin_time_service::RealTimeService;
Expand All @@ -25,11 +26,14 @@ pub struct StarcoinOpt {
pub thread_num: u16,
#[clap(long, short = 'p')]
pub plugin_path: Option<String>,
#[clap(long, short = 'g', default_value_t = ConsensusStrategy::Argon)]
pub algo: ConsensusStrategy,
}

fn main() {
let _logger_handle = starcoin_logger::init();
let opts: StarcoinOpt = StarcoinOpt::parse();
let algo = opts.algo;
let config = {
MinerClientConfig {
server: Some(opts.server.clone()),
Expand Down Expand Up @@ -61,7 +65,7 @@ fn main() {
algo: None,
};

let stratum_job_client = StratumJobClient::new(stratum_cli_srv, time_srv, login);
let stratum_job_client = StratumJobClient::new(stratum_cli_srv, time_srv, login, algo);
registry.put_shared(stratum_job_client).await?;
registry
.register::<MinerClientService<StratumJobClient>>()
Expand Down
10 changes: 7 additions & 3 deletions cmd/miner_client/src/stratum_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ pub struct StratumJobClient {
stratum_cli_srv: ServiceRef<StratumClientService>,
time_service: Arc<dyn TimeService>,
login: LoginRequest,
strategy: ConsensusStrategy,
}

impl StratumJobClient {
pub fn new(
stratum_cli_srv: ServiceRef<StratumClientService>,
time_service: Arc<dyn TimeService>,
login: LoginRequest,
strategy: ConsensusStrategy,
) -> Self {
Self {
stratum_cli_srv,
time_service,
login,
strategy,
}
}
}
Expand All @@ -40,21 +43,22 @@ impl JobClient for StratumJobClient {
async fn subscribe(&self) -> Result<BoxStream<'static, MintBlockEvent>> {
let srv = self.stratum_cli_srv.clone();
let login = self.login.clone();
let strategy = self.strategy.clone();
let fut = async move {
let stream = srv
.send(login)
.await?
.await
.map_err(|e| anyhow::anyhow!(format!("{}", e)))
.map(|s| {
s.filter_map(|job| {
.map(move |s| {
s.filter_map(move |job| {
let blob = hex::decode(&job.blob);
let diff = target_hex_to_difficulty(&job.target);
let extra = job.get_extra();
let event = if let (Ok(blob), Ok(diff), Ok(extra)) = (blob, diff, extra) {
Some(MintBlockEvent {
parent_hash: Default::default(),
strategy: ConsensusStrategy::CryptoNight,
strategy,
minting_blob: blob,
difficulty: diff,
block_number: job.height,
Expand Down

0 comments on commit 6a7236b

Please sign in to comment.