Skip to content

Commit

Permalink
Use the session list instead of top candidate and should use total st…
Browse files Browse the repository at this point in the history
…akinig
  • Loading branch information
jaypan authored and Jay Pan committed Dec 18, 2024
1 parent 3f12555 commit b4474c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion precompiles/parachain-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ authors = [ "Peaq" ]
precompile-utils = { path = "../utils", default-features = false }
parachain-staking = { path = "../../pallets/parachain-staking", default-features = false }
address-unification = { path = "../../pallets/address-unification", default-features = false }
pallet-session = { workspace = true, default-features = false }

# Substrate
parity-scale-codec = { workspace = true, features = ["max-encoded-len"] }
Expand All @@ -36,7 +37,6 @@ precompile-utils = { path = "../utils", features = [ "std", "testing" ] }
pallet-timestamp = { workspace = true, features = [ "std" ] }
scale-info = { workspace = true }
pallet-authorship = { workspace = true, default-features = false }
pallet-session = { workspace = true, default-features = false }

[features]
default = ["std", "experimental"]
Expand Down
15 changes: 7 additions & 8 deletions precompiles/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct CollatorInfo {
#[precompile_utils::precompile]
impl<Runtime> ParachainStakingPrecompile<Runtime>
where
Runtime: parachain_staking::Config + pallet_evm::Config,
Runtime: parachain_staking::Config + pallet_evm::Config + pallet_session::Config,
Runtime::RuntimeCall: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>,
Runtime::RuntimeCall: From<parachain_staking::Call<Runtime>>,
Expand All @@ -77,7 +77,7 @@ where
let all_collators = parachain_staking::CandidatePool::<Runtime>::iter()
.map(|(_id, stake_info)| CollatorInfo {
owner: H256::from(<AccountIdOf<Runtime> as Into<[u8; 32]>>::into(stake_info.id)),
amount: stake_info.stake.into(),
amount: stake_info.total.into(),
commission: U256::from(stake_info.commission.deconstruct() as u128),
})
.collect::<Vec<CollatorInfo>>();
Expand All @@ -103,18 +103,17 @@ where
let all_collators = parachain_staking::CandidatePool::<Runtime>::iter()
.map(|(_id, stake_info)| CollatorInfo {
owner: H256::from(<AccountIdOf<Runtime> as Into<[u8; 32]>>::into(stake_info.id)),
amount: stake_info.stake.into(),
amount: stake_info.total.into(),
commission: U256::from(stake_info.commission.deconstruct() as u128),
})
.collect::<Vec<CollatorInfo>>();
let top_candiate = parachain_staking::Pallet::<Runtime>::top_candidates()
let validators = pallet_session::Pallet::<Runtime>::validators()
.into_iter()
.map(|stake_info| {
H256::from(<AccountIdOf<Runtime> as Into<[u8; 32]>>::into(stake_info.owner))
.map(|info| {
H256::from(<AccountIdOf<Runtime> as Into<[u8; 32]>>::into(info))
})
.take(parachain_staking::MaxSelectedCandidates::<Runtime>::get() as usize)
.collect::<Vec<H256>>();
let candidate_list = all_collators.into_iter().filter(|x| !top_candiate.contains(&x.owner));
let candidate_list = all_collators.into_iter().filter(|x| !validators.contains(&x.owner));
Ok(candidate_list.collect::<Vec<CollatorInfo>>())
}

Expand Down

0 comments on commit b4474c3

Please sign in to comment.