mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
fix(staking miner): check latest state in solution (#5744)
This commit is contained in:
@@ -249,6 +249,7 @@ enum Error<T: EPM::Config> {
|
||||
AlreadySubmitted,
|
||||
VersionMismatch,
|
||||
StrategyNotSatisfied,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl<T: EPM::Config> From<sp_core::crypto::SecretStringError> for Error<T> {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -68,6 +68,16 @@ pub trait RpcApi {
|
||||
#[method(name = "system_dryRun")]
|
||||
async fn dry_run(&self, extrinsic: &Bytes, at: Option<Hash>) -> RpcResult<Bytes>;
|
||||
|
||||
/// Get hash of the n-th block in the canon chain.
|
||||
///
|
||||
/// By default returns latest block hash.
|
||||
#[method(name = "chain_getBlockHash", aliases = ["chain_getHead"], blocking)]
|
||||
fn block_hash(&self, hash: Option<Hash>) -> RpcResult<Option<Hash>>;
|
||||
|
||||
/// Get hash of the last finalized block in the canon chain.
|
||||
#[method(name = "chain_getFinalizedHead", aliases = ["chain_getFinalisedHead"], blocking)]
|
||||
fn finalized_head(&self) -> RpcResult<Hash>;
|
||||
|
||||
/// Submit an extrinsic to watch.
|
||||
///
|
||||
/// See [`TransactionStatus`](sc_transaction_pool_api::TransactionStatus) for details on
|
||||
|
||||
Reference in New Issue
Block a user