contracts: Cap the surcharge reward by the amount of rent that way payed by a contract (#7870)

* Add rent_payed field to the contract info

* Don't pay out more as reward as was spent in rent

* Make successful evictions free

* Add tests to check that surcharge reward is capped by rent payed

* review: Fixed docs
This commit is contained in:
Alexander Theißen
2021-01-14 13:45:13 +01:00
committed by GitHub
parent c2ebcae0a6
commit ad1717293d
5 changed files with 112 additions and 40 deletions
@@ -250,7 +250,7 @@ where
/// Evict this contract.
fn evict(&mut self) -> Result<(), &'static str> {
self.set_block_num_for_eviction()?;
Rent::<T>::snitch_contract_should_be_evicted(&self.contract.account_id, Zero::zero())?;
Rent::<T>::try_eviction(&self.contract.account_id, Zero::zero())?;
self.contract.ensure_tombstone()
}
}
@@ -406,8 +406,14 @@ benchmarks! {
instance.ensure_tombstone()?;
// the caller should get the reward for being a good snitch
assert_eq!(
T::Currency::free_balance(&instance.caller),
// this is capped by the maximum amount of rent payed. So we only now that it should
// have increased by at most the surcharge reward.
assert!(
T::Currency::free_balance(&instance.caller) >
caller_funding::<T>() - instance.endowment
);
assert!(
T::Currency::free_balance(&instance.caller) <
caller_funding::<T>() - instance.endowment + <T as Config>::SurchargeReward::get(),
);
}