Skip to content
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
10 changes: 4 additions & 6 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ macro_rules! for_legacy_runtime {
use $crate::static_types::legacy::westend::MinerConfig;
$($code)*
},
$crate::opt::Chain::AssetHubNext => {
#[allow(unused)]
use $crate::static_types::legacy::westend::MinerConfig;
$($code)*
$crate::opt::Chain::StakingAsync => {
panic!("StakingAsync is not supported in legacy monitor");
}
$crate::opt::Chain::SubstrateNode => {
#[allow(unused)]
Expand Down Expand Up @@ -87,9 +85,9 @@ macro_rules! for_multi_block_runtime {
use $crate::static_types::multi_block::westend::MinerConfig;
$($code)*
},
$crate::opt::Chain::AssetHubNext => {
$crate::opt::Chain::StakingAsync => {
#[allow(unused)]
use $crate::static_types::multi_block::westend::MinerConfig;
use $crate::static_types::multi_block::staking_async::MinerConfig;
$($code)*
}
$crate::opt::Chain::SubstrateNode => {
Expand Down
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,15 @@ mod tests {
)
);
}

#[test]
#[should_panic(expected = "StakingAsync is not supported in legacy monitor")]
fn for_legacy_runtime_panics_on_staking_async() {
use crate::opt::Chain;
let chain = Chain::StakingAsync;
macros::for_legacy_runtime!(chain, {
// This block should never be executed
let _ = ();
});
}
}
12 changes: 9 additions & 3 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub enum Chain {
Kusama,
Polkadot,
SubstrateNode,
AssetHubNext,
StakingAsync,
}

impl fmt::Display for Chain {
Expand All @@ -61,7 +61,7 @@ impl fmt::Display for Chain {
Self::Kusama => "kusama",
Self::Westend => "westend",
Self::SubstrateNode => "node",
Self::AssetHubNext => "asset-hub-next",
Self::StakingAsync => "staking-async",
};
write!(f, "{}", chain)
}
Expand All @@ -73,9 +73,15 @@ impl std::str::FromStr for Chain {
fn from_str(s: &str) -> Result<Self, Error> {
match s {
"polkadot" => Ok(Self::Polkadot),
"statemint" => Ok(Self::Polkadot), // Polkadot AH
"kusama" => Ok(Self::Kusama),
"statemine" => Ok(Self::Kusama), // Kusama AH
"westend" => Ok(Self::Westend),
"asset-hub-next" => Ok(Self::AssetHubNext),
"westmint" => Ok(Self::Westend), // Westend AH
"staking-async-parachain" => Ok(Self::StakingAsync),
"staking-async-rc" => {
unimplemented!("multi-block mining is not supported on relay chains")
}
"node" => Ok(Self::SubstrateNode),
chain => Err(Error::InvalidChain(chain.to_string())),
}
Expand Down
37 changes: 37 additions & 0 deletions src/static_types/multi_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,40 @@ pub mod westend {
type Hash = Hash;
}
}

/// This is used to test against staking-async runtimes from the SDK.
pub mod staking_async {
use super::*;
use frame_election_provider_support::SequentialPhragmen;

// TODO: validate config https://github.com/paritytech/polkadot-staking-miner/issues/994
frame_election_provider_support::generate_solution_type!(
#[compact]
pub struct NposSolution16::<
VoterIndex = u32,
TargetIndex = u16,
Accuracy = PerU16,
MaxVoters = ConstU32::<22500>
>(16)
);

#[derive(Debug)]
pub struct MinerConfig;

// TODO: validate config https://github.com/paritytech/polkadot-staking-miner/issues/994
impl multi_block::unsigned::miner::MinerConfig for MinerConfig {
type AccountId = AccountId;
type Solution = NposSolution16;
// TODO: make it configurable via CLI https://github.com/paritytech/polkadot-staking-miner/issues/989
type Solver = SequentialPhragmen<AccountId, Accuracy>;
type Pages = Pages;
type MaxVotesPerVoter = ConstU32<16>;
type MaxWinnersPerPage = MaxWinnersPerPage;
type MaxBackersPerWinner = MaxBackersPerWinner;
type MaxBackersPerWinnerFinal = ConstU32<{ u32::MAX }>;
type VoterSnapshotPerBlock = VoterSnapshotPerBlock;
type TargetSnapshotPerBlock = TargetSnapshotPerBlock;
type MaxLength = MaxLength;
type Hash = Hash;
}
}
2 changes: 1 addition & 1 deletion tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn run_polkadot_node(chain: Chain) -> (KillChildOnDrop, String) {
Chain::Kusama => "chainspecs/kusama-dev.json",
Chain::Westend => "westend-dev",
Chain::SubstrateNode => "dev",
Chain::AssetHubNext => panic!("AssetHubNext is not supported"),
Chain::StakingAsync => panic!("StakingAsync is not supported"),
};

let mut node_cmd = KillChildOnDrop(
Expand Down
Loading