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

staking miner: less aggresive submissions #6978

Merged
merged 2 commits into from
Mar 30, 2023
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
17 changes: 14 additions & 3 deletions utils/staking-miner/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use jsonrpsee::core::Error as RpcError;
use sc_transaction_pool_api::TransactionStatus;
use sp_core::storage::StorageKey;
use sp_runtime::Perbill;
use tokio::sync::mpsc;
use std::sync::Arc;
use tokio::sync::{mpsc, Mutex};
use EPM::{signed::SubmissionIndicesOf, SignedSubmissionOf};

/// Ensure that now is the signed phase.
Expand Down Expand Up @@ -170,6 +171,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {

let mut subscription = heads_subscription().await?;
let (tx, mut rx) = mpsc::unbounded_channel::<StakingMinerError>();
let submit_lock = Arc::new(Mutex::new(()));

loop {
let at = tokio::select! {
Expand Down Expand Up @@ -201,9 +203,8 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
// Spawn task and non-recoverable errors are sent back to the main task
// such as if the connection has been closed.
tokio::spawn(
send_and_watch_extrinsic(rpc.clone(), tx.clone(), at, signer.clone(), config.clone())
send_and_watch_extrinsic(rpc.clone(), tx.clone(), at, signer.clone(), config.clone(), submit_lock.clone())
);

}

/// Construct extrinsic at given block and watch it.
Expand All @@ -213,6 +214,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
at: Header,
signer: Signer,
config: MonitorConfig,
submit_lock: Arc<Mutex<()>>,
) {

async fn flatten<T>(
Expand Down Expand Up @@ -255,6 +257,8 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
return;
}

let _lock = submit_lock.lock().await;

let mut ext = match crate::create_election_ext::<Runtime, Block>(rpc.clone(), Some(hash), vec![]).await {
Ok(ext) => ext,
Err(err) => {
Expand Down Expand Up @@ -302,6 +306,7 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {

let rpc1 = rpc.clone();
let rpc2 = rpc.clone();
let rpc3 = rpc.clone();

let latest_head = match get_latest_head::<Runtime>(&rpc, &config.listen).await {
Ok(hash) => hash,
Expand All @@ -325,10 +330,16 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
ensure_signed_phase::<Runtime, Block>(&rpc2, latest_head).await
});

let account = signer.account.clone();
let no_prev_sol_fut = tokio::spawn(async move {
ensure_no_previous_solution::<Runtime, Block>(&rpc3, latest_head, &account).await
});

// Run the calls in parallel and return once all has completed or any failed.
if let Err(err) = tokio::try_join!(
flatten(ensure_strategy_met_fut),
flatten(ensure_signed_phase_fut),
flatten(no_prev_sol_fut),
) {
log::debug!(target: LOG_TARGET, "Skipping to submit at block {}; {}", at.number, err);
return;
Expand Down
1 change: 1 addition & 0 deletions utils/staking-miner/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl SharedRpcClient {
.connection_timeout(connection_timeout)
.max_request_body_size(u32::MAX)
.request_timeout(request_timeout)
.max_concurrent_requests(u32::MAX as usize)
Copy link
Member Author

Choose a reason for hiding this comment

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

this was 256 before

.build(uri)
.await?;
Ok(Self(Arc::new(client)))
Expand Down