fix(staking miner): check latest state in solution (#5744)

This commit is contained in:
Niklas Adolfsson
2022-07-01 17:05:01 +02:00
committed by GitHub
parent ef198a579c
commit 6d672f0951
3 changed files with 36 additions and 2 deletions
+25 -2
View File
@@ -138,6 +138,21 @@ async fn ensure_no_better_solution<T: EPM::Config, B: BlockT>(
}
}
async fn get_latest_head<T: EPM::Config>(
rpc: &SharedRpcClient,
mode: &str,
) -> Result<Hash, Error<T>> {
if mode == "head" {
match rpc.block_hash(None).await {
Ok(Some(hash)) => Ok(hash),
Ok(None) => Err(Error::Other("Best head not found".into())),
Err(e) => Err(e.into()),
}
} else {
rpc.finalized_head().await.map_err(Into::into)
}
}
macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
/// The monitor command.
@@ -291,13 +306,21 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
let rpc1 = rpc.clone();
let rpc2 = rpc.clone();
let latest_head = match get_latest_head::<Runtime>(&rpc, &config.listen).await {
Ok(hash) => hash,
Err(e) => {
log::debug!(target: LOG_TARGET, "Skipping to submit at block {}; {}", at.number, e);
return;
}
};
let ensure_no_better_fut = tokio::spawn(async move {
ensure_no_better_solution::<Runtime, Block>(&rpc1, hash, score, config.submission_strategy,
ensure_no_better_solution::<Runtime, Block>(&rpc1, latest_head, score, config.submission_strategy,
SignedMaxSubmissions::get()).await
});
let ensure_signed_phase_fut = tokio::spawn(async move {
ensure_signed_phase::<Runtime, Block>(&rpc2, hash).await
ensure_signed_phase::<Runtime, Block>(&rpc2, latest_head).await
});
// Run the calls in parallel and return once all has completed or any failed.