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
+2 -1
View File
@@ -27,7 +27,7 @@ use codec::{Encode, Decode};
use sp_std::prelude::*;
use sp_std::marker::PhantomData;
use sp_io::hashing::blake2_256;
use sp_runtime::traits::{Bounded, Saturating};
use sp_runtime::traits::{Bounded, Saturating, Zero};
use sp_core::crypto::UncheckedFrom;
use frame_support::{
dispatch::DispatchResult,
@@ -181,6 +181,7 @@ where
// charge rent for it during instantation.
<frame_system::Module<T>>::block_number().saturating_sub(1u32.into()),
rent_allowance: <BalanceOf<T>>::max_value(),
rent_payed: <BalanceOf<T>>::zero(),
pair_count: 0,
last_write: None,
}