From 7948eae54b0293d47203c88abcd395ae4bfad1d5 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Tue, 13 Jul 2021 04:02:25 +0200 Subject: [PATCH] Small tweaks to staking miner (#3460) * Fix miner * fix miner * Update utils/staking-miner/src/monitor.rs * Fix width --- polkadot/utils/staking-miner/src/main.rs | 5 +++-- polkadot/utils/staking-miner/src/monitor.rs | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/polkadot/utils/staking-miner/src/main.rs b/polkadot/utils/staking-miner/src/main.rs index 0bc83866f9..271e749f9f 100644 --- a/polkadot/utils/staking-miner/src/main.rs +++ b/polkadot/utils/staking-miner/src/main.rs @@ -299,7 +299,7 @@ async fn create_election_ext( with_staking: bool, ) -> Result { use frame_support::{storage::generator::StorageMap, traits::PalletInfo}; - let system_block_hash_key = >::prefix_hash(); + use sp_core::hashing::twox_128; Builder::::new() .mode(Mode::Online(OnlineConfig { @@ -322,7 +322,8 @@ async fn create_election_ext( }, ..Default::default() })) - .inject_hashed_prefix(&system_block_hash_key) + .inject_hashed_prefix(&>::prefix_hash()) + .inject_hashed_key(&[twox_128(b"System"), twox_128(b"Number")].concat()) .build() .await .map_err(|why| Error::RemoteExternalities(why)) diff --git a/polkadot/utils/staking-miner/src/monitor.rs b/polkadot/utils/staking-miner/src/monitor.rs index b5efabc137..b48023db7b 100644 --- a/polkadot/utils/staking-miner/src/monitor.rs +++ b/polkadot/utils/staking-miner/src/monitor.rs @@ -122,10 +122,21 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! { let mut tx_subscription: Subscription< TransactionStatus<::Hash, ::Hash> - > = client + > = match client .subscribe(&"author_submitAndWatchExtrinsic", params! { bytes }, "author_unwatchExtrinsic") .await - .unwrap(); + { + Ok(sub) => sub, + Err(why) => { + // This usually happens when we've been busy with mining for a few blocks, and now we're receiving the + // subscriptions of blocks in which we were busy. In these blocks, we still don't have a solution, so we + // re-compute a new solution and submit it with an outdated `Nonce`, which yields most often `Stale` + // error. NOTE: to improve this overall, and to be able to introduce an array of other fancy features, + // we should make this multi-threaded and do the computation outside of this callback. + log::warn!(target: LOG_TARGET, "failing to submit a transaction {:?}. continuing...", why); + continue + } + }; let _success = while let Some(status_update) = tx_subscription.next().await? { log::trace!(target: LOG_TARGET, "status update {:?}", status_update);