Add an OnUnbalanced hook for contract rent payments (#3857)

* Add RentPayment trait to runtime

* clarify check

* improve proof

* Clarify further

* Simplify RentPayment::on_unbalance calling and get rid of NonZeroRentHook
This commit is contained in:
Ashley
2019-10-23 11:02:30 +01:00
committed by Gavin Wood
parent 5e889431d3
commit 968b24d849
4 changed files with 10 additions and 3 deletions
+3
View File
@@ -355,6 +355,9 @@ pub trait Trait: system::Trait {
/// Handler for the unbalanced reduction when making a gas payment.
type GasPayment: OnUnbalanced<NegativeImbalanceOf<Self>>;
/// Handler for rent payments.
type RentPayment: OnUnbalanced<NegativeImbalanceOf<Self>>;
/// Number of block delay an extrinsic claim surcharge has.
///
/// When claim surcharge is called by an extrinsic the rent is checked
+4 -2
View File
@@ -17,7 +17,7 @@
use crate::{BalanceOf, ContractInfo, ContractInfoOf, TombstoneContractInfo, Trait, AliveContractInfo};
use sr_primitives::traits::{Bounded, CheckedDiv, CheckedMul, Saturating, Zero,
SaturatedConversion};
use support::traits::{Currency, ExistenceRequirement, Get, WithdrawReason};
use support::traits::{Currency, ExistenceRequirement, Get, WithdrawReason, OnUnbalanced};
use support::StorageMap;
#[derive(PartialEq, Eq, Copy, Clone)]
@@ -126,7 +126,7 @@ fn try_evict_or_and_pay_rent<T: Trait>(
if can_withdraw_rent && (insufficient_rent || pay_rent) {
// Collect dues.
let _ = T::Currency::withdraw(
let imbalance = T::Currency::withdraw(
account,
dues_limited,
WithdrawReason::Fee,
@@ -137,6 +137,8 @@ fn try_evict_or_and_pay_rent<T: Trait>(
dues_limited < rent_budget < balance - subsistence < balance - existential_deposit;
qed",
);
T::RentPayment::on_unbalanced(imbalance);
}
if insufficient_rent || !can_withdraw_rent {
+1
View File
@@ -159,6 +159,7 @@ impl Trait for Test {
type ComputeDispatchFee = DummyComputeDispatchFee;
type TrieIdGenerator = DummyTrieIdGenerator;
type GasPayment = ();
type RentPayment = ();
type SignedClaimHandicap = SignedClaimHandicap;
type TombstoneDeposit = TombstoneDeposit;
type StorageSizeOffset = StorageSizeOffset;