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

staking miner: reuse ws conn for remote-ext #4849

Merged
merged 30 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
feb0a7b
staking miner: use config for emergency solution
niklasad1 Jan 11, 2022
633ee73
bump jsonrpsee
niklasad1 Jan 11, 2022
4c2dbd6
Merge remote-tracking branch 'origin/master' into na-staking-miner-pl…
niklasad1 Jan 13, 2022
4d9644e
run `monitor_cmd_for` until the connection is closed
niklasad1 Jan 13, 2022
21546b1
new tokio task for submit_and_watch xt
niklasad1 Jan 13, 2022
00ff014
re-use header subscription
niklasad1 Jan 14, 2022
54f3bf1
Merge remote-tracking branch 'origin/master' into HEAD
niklasad1 Jan 24, 2022
ecfe004
update jsonrpsee + simplify code
niklasad1 Jan 24, 2022
5fddbbe
revert polkadot runtime changes
niklasad1 Jan 24, 2022
8ea11a3
fix grumbles
niklasad1 Jan 24, 2022
f4a3b74
Update utils/staking-miner/src/monitor.rs
niklasad1 Jan 24, 2022
6ad6106
Merge remote-tracking branch 'origin/master' into na-staking-miner-pl…
niklasad1 Jan 25, 2022
4ed8e80
Merge remote-tracking branch 'origin/master' into na-staking-miner-pl…
niklasad1 Feb 4, 2022
ee66153
staking miner: reuse ws conn for remote-ext
niklasad1 Feb 4, 2022
2c47dad
Revert "revert polkadot runtime changes"
niklasad1 Feb 4, 2022
2d1cf42
cargo fmt
niklasad1 Feb 4, 2022
a5a5cf8
revert unintentional change
niklasad1 Feb 4, 2022
f600be8
revert unintentional change
niklasad1 Feb 4, 2022
c57ee57
Merge remote-tracking branch 'origin/na-staking-miner-reuse-ws-conn' …
niklasad1 Feb 4, 2022
a54173a
Merge remote-tracking branch 'origin/master' into na-staking-miner-re…
niklasad1 Feb 7, 2022
1b44965
add type SharedRpcClient
niklasad1 Feb 7, 2022
d8a551d
cargo fmt
niklasad1 Feb 7, 2022
24b738a
fix nits
niklasad1 Feb 7, 2022
25a2781
spelling
niklasad1 Feb 7, 2022
761d538
use tracing_subcriber and cleanup
niklasad1 Feb 11, 2022
1e02980
remove some needless clones
niklasad1 Feb 11, 2022
3331094
fix some nits
niklasad1 Feb 14, 2022
fb2bca3
address grumbles
niklasad1 Feb 15, 2022
0d9d95f
Merge remote-tracking branch 'origin/master' into na-staking-miner-re…
niklasad1 Feb 18, 2022
1253184
fix spellcheck
niklasad1 Feb 18, 2022
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
50 changes: 42 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions utils/staking-miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2018"
[dependencies]
clap = { version = "3.0", features = ["derive", "env"] }
codec = { package = "parity-scale-codec", version = "2.0.0" }
env_logger = "0.9.0"
jsonrpsee = { version = "0.8", features = ["ws-client"] }
tracing-subscriber = { version = "0.3.8", features = ["env-filter"] }
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
jsonrpsee = { version = "0.8", features = ["ws-client", "macros"] }
log = "0.4.11"
paste = "1.0.6"
serde = "1.0.132"
Expand Down
32 changes: 12 additions & 20 deletions utils/staking-miner/src/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

//! The dry-run command.

use crate::{
prelude::*, rpc_helpers::*, signer::Signer, DryRunConfig, Error, SharedConfig, WsClient,
};
use crate::{prelude::*, rpc::*, signer::Signer, DryRunConfig, Error, SharedRpcClient};
use codec::Encode;
use frame_support::traits::Currency;
use jsonrpsee::rpc_params;
use sp_core::Bytes;

/// Forcefully create the snapshot. This can be used to compute the election at anytime.
fn force_create_snapshot<T: EPM::Config>(ext: &mut Ext) -> Result<(), Error<T>> {
Expand All @@ -38,10 +36,10 @@ fn force_create_snapshot<T: EPM::Config>(ext: &mut Ext) -> Result<(), Error<T>>

/// Helper method to print the encoded size of the snapshot.
async fn print_info<T: EPM::Config>(
client: &WsClient,
rpc: &SharedRpcClient,
ext: &mut Ext,
raw_solution: &EPM::RawSolution<EPM::SolutionOf<T>>,
extrinsic: sp_core::Bytes,
extrinsic: &Bytes,
) where
<T as EPM::Config>::Currency: Currency<T::AccountId, Balance = Balance>,
{
Expand Down Expand Up @@ -72,12 +70,8 @@ async fn print_info<T: EPM::Config>(
);
});

let info = rpc::<pallet_transaction_payment::RuntimeDispatchInfo<Balance>>(
client,
"payment_queryInfo",
rpc_params! { extrinsic },
)
.await;
let info = rpc.payment_query_info(&extrinsic, None).await;

log::info!(
target: LOG_TARGET,
"payment_queryInfo: (fee = {}) {:?}",
Expand Down Expand Up @@ -109,22 +103,21 @@ fn find_threshold<T: EPM::Config>(ext: &mut Ext, count: usize) {
macro_rules! dry_run_cmd_for { ($runtime:ident) => { paste::paste! {
/// Execute the dry-run command.
pub(crate) async fn [<dry_run_cmd_ $runtime>](
client: &WsClient,
shared: SharedConfig,
rpc: SharedRpcClient,
config: DryRunConfig,
signer: Signer,
) -> Result<(), Error<$crate::[<$runtime _runtime_exports>]::Runtime>> {
use $crate::[<$runtime _runtime_exports>]::*;
let mut ext = crate::create_election_ext::<Runtime, Block>(
shared.uri.clone(),
rpc.clone(),
config.at,
vec!["Staking".to_string(), "System".to_string()],
).await?;
force_create_snapshot::<Runtime>(&mut ext)?;

let (raw_solution, witness) = crate::mine_with::<Runtime>(&config.solver, &mut ext, false)?;

let nonce = crate::get_account_info::<Runtime>(client, &signer.account, config.at)
let nonce = crate::get_account_info::<Runtime>(&rpc, &signer.account, config.at.as_ref())
.await?
.map(|i| i.nonce)
.expect("signer account is checked to exist upon startup; it can only die if it \
Expand All @@ -136,7 +129,7 @@ macro_rules! dry_run_cmd_for { ($runtime:ident) => { paste::paste! {
let extrinsic = ext.execute_with(|| create_uxt(raw_solution.clone(), witness, signer.clone(), nonce, tip, era));

let bytes = sp_core::Bytes(extrinsic.encode().to_vec());
print_info::<Runtime>(client, &mut ext, &raw_solution, bytes.clone()).await;
print_info::<Runtime>(&rpc, &mut ext, &raw_solution, &bytes).await;

let feasibility_result = ext.execute_with(|| {
EPM::Pallet::<Runtime>::feasibility_check(raw_solution.clone(), EPM::ElectionCompute::Signed)
Expand All @@ -150,9 +143,8 @@ macro_rules! dry_run_cmd_for { ($runtime:ident) => { paste::paste! {
});
log::info!(target: LOG_TARGET, "dispatch result is {:?}", dispatch_result);

let outcome = rpc_decode::<sp_runtime::ApplyExtrinsicResult>(client, "system_dryRun", rpc_params!{ bytes })
.await
.map_err::<Error<Runtime>, _>(Into::into)?;
let dry_run_fut = rpc.dry_run(&bytes, None);
let outcome: sp_runtime::ApplyExtrinsicResult = await_request_and_decode(dry_run_fut).await.map_err::<Error<Runtime>, _>(Into::into)?;
log::info!(target: LOG_TARGET, "dry-run outcome is {:?}", outcome);
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions utils/staking-miner/src/emergency_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

//! The emergency-solution command.

use crate::{prelude::*, EmergencySolutionConfig, Error, SharedConfig};
use crate::{prelude::*, EmergencySolutionConfig, Error, SharedRpcClient};
use codec::Encode;
use std::io::Write;

macro_rules! emergency_solution_cmd_for { ($runtime:ident) => { paste::paste! {
/// Execute the emergency-solution command.
pub(crate) async fn [<emergency_solution_cmd_ $runtime>](
shared: SharedConfig,
client: SharedRpcClient,
config: EmergencySolutionConfig,
) -> Result<(), Error<$crate::[<$runtime _runtime_exports>]::Runtime>> {
use $crate::[<$runtime _runtime_exports>]::*;

let mut ext = crate::create_election_ext::<Runtime, Block>(shared.uri.clone(), config.at, vec![]).await?;
let mut ext = crate::create_election_ext::<Runtime, Block>(client, config.at, vec![]).await?;
let (raw_solution, _witness) = crate::mine_with::<Runtime>(&config.solver, &mut ext, false)?;

ext.execute_with(|| {
Expand Down
Loading