mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
Reward validators for participating in parachains (#2089)
* plumbing for rewarding backers * give validators reward points for participating * fix tests * add bitfield rewarding * add mocks for backing rewards * add testing for backing & availability rewards * implement RewardValidators on top of staking * add to test-runtime and rococo * add to test-runtime & rococo * point to source on rewards values * fix common tests * do not reward availability anymore
This commit is contained in:
committed by
GitHub
parent
34e5812171
commit
f4e930529b
@@ -21,11 +21,13 @@ use sp_core::H256;
|
||||
use sp_runtime::traits::{
|
||||
BlakeTwo256, IdentityLookup,
|
||||
};
|
||||
use primitives::v1::{AuthorityDiscoveryId, BlockNumber, Header};
|
||||
use primitives::v1::{AuthorityDiscoveryId, BlockNumber, Header, ValidatorIndex};
|
||||
use frame_support::{
|
||||
impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types,
|
||||
traits::Randomness as RandomnessT,
|
||||
};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use crate::inclusion;
|
||||
use crate as parachains;
|
||||
|
||||
@@ -114,6 +116,7 @@ impl crate::scheduler::Config for Test { }
|
||||
|
||||
impl crate::inclusion::Config for Test {
|
||||
type Event = TestEvent;
|
||||
type RewardValidators = TestRewardValidators;
|
||||
}
|
||||
|
||||
impl crate::session_info::Config for Test { }
|
||||
@@ -124,6 +127,43 @@ impl crate::session_info::AuthorityDiscoveryConfig for Test {
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
pub static BACKING_REWARDS: RefCell<HashMap<ValidatorIndex, usize>>
|
||||
= RefCell::new(HashMap::new());
|
||||
|
||||
pub static AVAILABILITY_REWARDS: RefCell<HashMap<ValidatorIndex, usize>>
|
||||
= RefCell::new(HashMap::new());
|
||||
}
|
||||
|
||||
pub fn backing_rewards() -> HashMap<ValidatorIndex, usize> {
|
||||
BACKING_REWARDS.with(|r| r.borrow().clone())
|
||||
}
|
||||
|
||||
pub fn availability_rewards() -> HashMap<ValidatorIndex, usize> {
|
||||
AVAILABILITY_REWARDS.with(|r| r.borrow().clone())
|
||||
}
|
||||
|
||||
pub struct TestRewardValidators;
|
||||
|
||||
impl inclusion::RewardValidators for TestRewardValidators {
|
||||
fn reward_backing(v: impl IntoIterator<Item = ValidatorIndex>) {
|
||||
BACKING_REWARDS.with(|r| {
|
||||
let mut r = r.borrow_mut();
|
||||
for i in v {
|
||||
*r.entry(i).or_insert(0) += 1;
|
||||
}
|
||||
})
|
||||
}
|
||||
fn reward_bitfields(v: impl IntoIterator<Item = ValidatorIndex>) {
|
||||
AVAILABILITY_REWARDS.with(|r| {
|
||||
let mut r = r.borrow_mut();
|
||||
for i in v {
|
||||
*r.entry(i).or_insert(0) += 1;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub type System = frame_system::Module<Test>;
|
||||
|
||||
/// Mocked initializer.
|
||||
@@ -155,6 +195,9 @@ pub type SessionInfo = crate::session_info::Module<Test>;
|
||||
|
||||
/// Create a new set of test externalities.
|
||||
pub fn new_test_ext(state: GenesisConfig) -> TestExternalities {
|
||||
BACKING_REWARDS.with(|r| r.borrow_mut().clear());
|
||||
AVAILABILITY_REWARDS.with(|r| r.borrow_mut().clear());
|
||||
|
||||
let mut t = state.system.build_storage::<Test>().unwrap();
|
||||
state.configuration.assimilate_storage(&mut t).unwrap();
|
||||
state.paras.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user