Pass max-total to RewardRemainder on end_era (#5697)

* Pass max-total to RewardRemainder on end_era

* add test and event

* add doc

Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Jaco Greeff
2020-04-20 13:13:45 +02:00
committed by GitHub
parent 4b1f7d187f
commit 8c52a2dae6
4 changed files with 62 additions and 6 deletions
+26 -1
View File
@@ -277,11 +277,26 @@ parameter_types! {
pub const UnsignedPriority: u64 = 1 << 20;
}
thread_local! {
pub static REWARD_REMAINDER_UNBALANCED: RefCell<u128> = RefCell::new(0);
}
pub struct RewardRemainderMock;
impl OnUnbalanced<NegativeImbalanceOf<Test>> for RewardRemainderMock {
fn on_nonzero_unbalanced(amount: NegativeImbalanceOf<Test>) {
REWARD_REMAINDER_UNBALANCED.with(|v| {
*v.borrow_mut() += amount.peek();
});
drop(amount);
}
}
impl Trait for Test {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler;
type RewardRemainder = ();
type RewardRemainder = RewardRemainderMock;
type Event = MetaEvent;
type Slash = ();
type Reward = ();
@@ -976,3 +991,13 @@ macro_rules! assert_session_era {
);
};
}
pub(crate) fn staking_events() -> Vec<Event<Test>> {
System::events().into_iter().map(|r| r.event).filter_map(|e| {
if let MetaEvent::staking(inner) = e {
Some(inner)
} else {
None
}
}).collect()
}