mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 10:35:48 +00:00
fix restart issue of staking miner (#4073)
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
@@ -276,7 +276,7 @@ enum Command {
|
||||
/// Just compute a solution now, and don't submit it.
|
||||
DryRun(DryRunConfig),
|
||||
/// Provide a solution that can be submitted to the chain as an emergency response.
|
||||
EmergencySolution,
|
||||
EmergencySolution(EmergencySolutionConfig),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, StructOpt)]
|
||||
@@ -291,39 +291,6 @@ enum Solvers {
|
||||
},
|
||||
}
|
||||
|
||||
/// Mine a solution with the given `solver`.
|
||||
fn mine_with<T>(
|
||||
solver: &Solvers,
|
||||
ext: &mut Ext,
|
||||
) -> Result<(EPM::RawSolution<EPM::SolutionOf<T>>, u32), Error<T>>
|
||||
where
|
||||
T: EPM::Config,
|
||||
T::Solver: NposSolver<Error = sp_npos_elections::Error>,
|
||||
{
|
||||
use frame_election_provider_support::{PhragMMS, SequentialPhragmen};
|
||||
|
||||
match solver {
|
||||
Solvers::SeqPhragmen { iterations } => {
|
||||
BalanceIterations::set(*iterations);
|
||||
mine_unchecked::<
|
||||
T,
|
||||
SequentialPhragmen<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
sp_runtime::Perbill,
|
||||
Balancing,
|
||||
>,
|
||||
>(ext, false)
|
||||
},
|
||||
Solvers::PhragMMS { iterations } => {
|
||||
BalanceIterations::set(*iterations);
|
||||
mine_unchecked::<
|
||||
T,
|
||||
PhragMMS<<T as frame_system::Config>::AccountId, sp_runtime::Perbill, Balancing>,
|
||||
>(ext, false)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
frame_support::parameter_types! {
|
||||
/// Number of balancing iterations for a solution algorithm. Set based on the [`Solvers`] CLI
|
||||
/// config.
|
||||
@@ -341,16 +308,32 @@ struct MonitorConfig {
|
||||
#[structopt(long, default_value = "head", possible_values = &["head", "finalized"])]
|
||||
listen: String,
|
||||
|
||||
/// The solver algorithm to use.
|
||||
#[structopt(subcommand)]
|
||||
solver: Solvers,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, StructOpt)]
|
||||
struct EmergencySolutionConfig {
|
||||
/// The block hash at which scraping happens. If none is provided, the latest head is used.
|
||||
#[structopt(long)]
|
||||
at: Option<Hash>,
|
||||
|
||||
/// The solver algorithm to use.
|
||||
#[structopt(subcommand)]
|
||||
solver: Solvers,
|
||||
|
||||
/// The number of top backed winners to take. All are taken, if not provided.
|
||||
take: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, StructOpt)]
|
||||
struct DryRunConfig {
|
||||
/// The block hash at which scraping happens. If none is provided, the latest head is used.
|
||||
#[structopt(long)]
|
||||
at: Option<Hash>,
|
||||
|
||||
/// The solver algorithm to use.
|
||||
#[structopt(subcommand)]
|
||||
solver: Solvers,
|
||||
}
|
||||
@@ -407,9 +390,9 @@ async fn create_election_ext<T: EPM::Config, B: BlockT>(
|
||||
.map_err(|why| Error::RemoteExternalities(why))
|
||||
}
|
||||
|
||||
/// Compute the election at the given block number. It expects to NOT be `Phase::Off`. In other
|
||||
/// words, the snapshot must exists on the given externalities.
|
||||
fn mine_unchecked<T, S>(
|
||||
/// Compute the election. It expects to NOT be `Phase::Off`. In other words, the snapshot must
|
||||
/// exists on the given externalities.
|
||||
fn mine_solution<T, S>(
|
||||
ext: &mut Ext,
|
||||
do_feasibility: bool,
|
||||
) -> Result<(EPM::RawSolution<EPM::SolutionOf<T>>, u32), Error<T>>
|
||||
@@ -434,6 +417,40 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
/// Mine a solution with the given `solver`.
|
||||
fn mine_with<T>(
|
||||
solver: &Solvers,
|
||||
ext: &mut Ext,
|
||||
do_feasibility: bool,
|
||||
) -> Result<(EPM::RawSolution<EPM::SolutionOf<T>>, u32), Error<T>>
|
||||
where
|
||||
T: EPM::Config,
|
||||
T::Solver: NposSolver<Error = sp_npos_elections::Error>,
|
||||
{
|
||||
use frame_election_provider_support::{PhragMMS, SequentialPhragmen};
|
||||
|
||||
match solver {
|
||||
Solvers::SeqPhragmen { iterations } => {
|
||||
BalanceIterations::set(*iterations);
|
||||
mine_solution::<
|
||||
T,
|
||||
SequentialPhragmen<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
sp_runtime::Perbill,
|
||||
Balancing,
|
||||
>,
|
||||
>(ext, do_feasibility)
|
||||
},
|
||||
Solvers::PhragMMS { iterations } => {
|
||||
BalanceIterations::set(*iterations);
|
||||
mine_solution::<
|
||||
T,
|
||||
PhragMMS<<T as frame_system::Config>::AccountId, sp_runtime::Perbill, Balancing>,
|
||||
>(ext, do_feasibility)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn mine_dpos<T: EPM::Config>(ext: &mut Ext) -> Result<(), Error<T>> {
|
||||
ext.execute_with(|| {
|
||||
@@ -474,7 +491,6 @@ fn mine_dpos<T: EPM::Config>(ext: &mut Ext) -> Result<(), Error<T>> {
|
||||
|
||||
pub(crate) async fn check_versions<T: frame_system::Config + EPM::Config>(
|
||||
client: &WsClient,
|
||||
print: bool,
|
||||
) -> Result<(), Error<T>> {
|
||||
let linked_version = T::Version::get();
|
||||
let on_chain_version = rpc_helpers::rpc::<sp_version::RuntimeVersion>(
|
||||
@@ -485,10 +501,9 @@ pub(crate) async fn check_versions<T: frame_system::Config + EPM::Config>(
|
||||
.await
|
||||
.expect("runtime version RPC should always work; qed");
|
||||
|
||||
if print {
|
||||
log::info!(target: LOG_TARGET, "linked version {:?}", linked_version);
|
||||
log::info!(target: LOG_TARGET, "on-chain version {:?}", on_chain_version);
|
||||
}
|
||||
log::debug!(target: LOG_TARGET, "linked version {:?}", linked_version);
|
||||
log::debug!(target: LOG_TARGET, "on-chain version {:?}", on_chain_version);
|
||||
|
||||
if linked_version != on_chain_version {
|
||||
log::error!(
|
||||
target: LOG_TARGET,
|
||||
@@ -576,7 +591,7 @@ async fn main() {
|
||||
log::info!(target: LOG_TARGET, "connected to chain {:?}", chain);
|
||||
|
||||
any_runtime_unit! {
|
||||
check_versions::<Runtime>(&client, true).await
|
||||
check_versions::<Runtime>(&client).await
|
||||
};
|
||||
|
||||
let signer_account = any_runtime! {
|
||||
@@ -595,7 +610,7 @@ async fn main() {
|
||||
.map_err(|e| {
|
||||
log::error!(target: LOG_TARGET, "DryRun error: {:?}", e);
|
||||
}),
|
||||
Command::EmergencySolution => emergency_solution_cmd(shared.clone()).await
|
||||
Command::EmergencySolution(c) => emergency_solution_cmd(shared.clone(), c).await
|
||||
.map_err(|e| {
|
||||
log::error!(target: LOG_TARGET, "EmergencySolution error: {:?}", e);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user