mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
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:
@@ -85,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 181,
|
||||
impl_version: 182,
|
||||
impl_version: 183,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
@@ -412,6 +412,7 @@ impl contracts::Trait for Runtime {
|
||||
type ComputeDispatchFee = contracts::DefaultDispatchFeeComputor<Runtime>;
|
||||
type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;
|
||||
type GasPayment = ();
|
||||
type RentPayment = ();
|
||||
type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap;
|
||||
type TombstoneDeposit = TombstoneDeposit;
|
||||
type StorageSizeOffset = contracts::DefaultStorageSizeOffset;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user