Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

staking-miner: CLI flag delay solution x secs #5734

Merged
merged 10 commits into from
Jun 30, 2022
3 changes: 3 additions & 0 deletions utils/staking-miner/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
return;
}


niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
let rpc1 = rpc.clone();
let rpc2 = rpc.clone();
let account = signer.account.clone();
Expand All @@ -206,6 +207,8 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
ensure_signed_phase::<Runtime, Block>(&rpc1, hash).await
});

tokio::time::sleep(std::time::Duration::from_secs(config.delay as u64)).await;

let no_prev_sol_fut = tokio::spawn(async move {
ensure_no_previous_solution::<Runtime, Block>(&rpc2, hash, &account).await
});
Expand Down
11 changes: 11 additions & 0 deletions utils/staking-miner/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ pub(crate) struct MonitorConfig {
/// `--submission-strategy "percent-better <percent>"`: submit if the submission is `n` percent better.
#[clap(long, parse(try_from_str), default_value = "if-leading")]
pub submission_strategy: SubmissionStrategy,

/// Delay in number seconds to wait until starting mining a solution.
///
/// At every block when a solution is attempted
/// a delay can be enforced to avoid submitting at
/// "same" time and risk the potentially races to other miners.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
///
/// This may mean if there are competing solutions you might not submit
/// if the scores are equal once this is enabled.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
#[clap(long, parse(try_from_str), default_value_t = 0)]
pub delay: usize,
}

#[derive(Debug, Clone, Parser)]
Expand Down