mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 20:01:03 +00:00
fix restart issue of staking miner (#4073)
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
//! The emergency-solution command.
|
||||
|
||||
use crate::{prelude::*, Error, SharedConfig};
|
||||
use crate::{prelude::*, EmergencySolutionConfig, Error, SharedConfig};
|
||||
use codec::Encode;
|
||||
use frame_election_provider_support::SequentialPhragmen;
|
||||
use std::io::Write;
|
||||
@@ -25,25 +25,35 @@ 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,
|
||||
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(), None, vec![]).await?;
|
||||
ext.execute_with(|| {
|
||||
assert!(EPM::Pallet::<Runtime>::current_phase().is_emergency());
|
||||
|
||||
// NOTE: this internally calls feasibility_check, but we just re-do it here as an easy way
|
||||
// to get a `ReadySolution`.
|
||||
let (raw_solution, _) =
|
||||
<EPM::Pallet<Runtime>>::mine_solution::<SequentialPhragmen<AccountId, sp_runtime::Perbill>>()?;
|
||||
log::info!(target: LOG_TARGET, "mined solution with {:?}", &raw_solution.score);
|
||||
let ready_solution = EPM::Pallet::<Runtime>::feasibility_check(raw_solution, EPM::ElectionCompute::Signed)?;
|
||||
let encoded_ready = ready_solution.encode();
|
||||
let mut ready_solution = EPM::Pallet::<Runtime>::feasibility_check(raw_solution, EPM::ElectionCompute::Signed)?;
|
||||
|
||||
// maybe truncate.
|
||||
if let Some(take) = config.take {
|
||||
log::info!(target: LOG_TARGET, "truncating {} winners to {}", ready_solution.supports.len(), take);
|
||||
ready_solution.supports.sort_unstable_by_key(|(_, s)| s.total);
|
||||
ready_solution.supports.truncate(take);
|
||||
}
|
||||
|
||||
// write to file and stdout.
|
||||
let encoded_support = ready_solution.supports.encode();
|
||||
let mut solution_file = std::fs::File::create("solution.bin")?;
|
||||
let mut supports_file = std::fs::File::create("solution.supports.bin")?;
|
||||
solution_file.write_all(&encoded_ready)?;
|
||||
supports_file.write_all(&encoded_support)?;
|
||||
log::info!(target: LOG_TARGET, "ReadySolution: size {:?} / score = {:?}", encoded_ready.len(), ready_solution.score);
|
||||
|
||||
log::info!(target: LOG_TARGET, "ReadySolution: size {:?} / score = {:?}", ready_solution.encoded_size(), ready_solution.score);
|
||||
log::trace!(target: LOG_TARGET, "Supports: {}", sp_core::hexdisplay::HexDisplay::from(&encoded_support));
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user