Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions utils/staking-miner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
27 changes: 25 additions & 2 deletions utils/staking-miner/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be enum? we can probably reuse the same enum in the CLI flags as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, funny thing I just did that in the other miner repo :P

) -> 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())),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is silly, should be very very unlikely not to get the best block hash ^^

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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions utils/staking-miner/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down