Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Contracts remove deposit accounts #14589

Merged
merged 191 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 189 commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
7179359
contracts: refactor currency to use fungible traits
juangirini Apr 26, 2023
c0a95d2
contracts: refactor currency to use fungible traits
juangirini Apr 26, 2023
da7db01
contracts: merge master and resolve conflicts
juangirini May 2, 2023
9a1e824
Merge branch 'master' into jg/13643-contracts-migrate-to-fungible-traits
juangirini May 2, 2023
5eee859
contracts: add minor improvements
juangirini May 3, 2023
713a426
contracts: merge master and fix conflicts
juangirini May 8, 2023
4acbbe5
contracts: max holds config set
juangirini May 8, 2023
e6d82d1
contracts: fix some typos
juangirini May 8, 2023
c47ac0d
contracts: map token errors
juangirini May 8, 2023
4e8a7cc
fix typo
juangirini May 8, 2023
33229ff
contracts: add 0 balance transfer to test
juangirini May 8, 2023
a1fd020
contracts: not transfer if value is zero
juangirini May 9, 2023
0967556
contracts: [WIP] add StorageDepositHold
juangirini May 11, 2023
3acdcbb
Merge branch 'master' into jg/13643-contracts-migrate-to-fungible-traits
juangirini May 11, 2023
bcb9077
contracts: add storage deposit held event
juangirini May 11, 2023
8f244c4
contracts: clean up some code and comments
juangirini May 11, 2023
73b9285
contracts: add deposit storage released event
juangirini May 11, 2023
26472d5
contracts: update comment
juangirini May 12, 2023
c442b79
contracts: update slash cannot kill account test
juangirini May 12, 2023
3c515ab
contracts: fix tests
juangirini May 12, 2023
4d68a48
contracts: add some comments to the slashing test
juangirini May 12, 2023
78fc19e
contracts: add some comments to the slashing test
juangirini May 12, 2023
2c1e2ea
contracts: remove references to Currency
juangirini May 15, 2023
e6509d7
Merge branch 'master' into jg/13643-contracts-migrate-to-fungible-traits
juangirini May 15, 2023
1c82bef
contracts: do not transfer if from equals to
juangirini May 15, 2023
9eb19ef
wip
juangirini Jun 2, 2023
e4853e9
Merge remote-tracking branch 'origin/master' into jg/13643-contracts-…
juangirini Jun 5, 2023
921d89c
bound BalanceOf<T>
juangirini Jun 6, 2023
a103057
added FixedPointOperand to Balance trait
juangirini Jun 6, 2023
5c14529
move migrate sequence to config
juangirini Jun 6, 2023
e8c493c
remove commented out code
juangirini Jun 6, 2023
0e62930
Update frame/contracts/src/lib.rs
juangirini Jun 6, 2023
14a7175
remove Migrations generic
juangirini Jun 6, 2023
2601d79
make runtime use noop migrations
juangirini Jun 6, 2023
e88854a
restrict is_upgrade_supported
juangirini Jun 6, 2023
1400ab0
undo is_upgrade_supported change
juangirini Jun 7, 2023
cc7609c
Update bin/node/runtime/src/lib.rs
juangirini Jun 7, 2023
c173ad7
add rust doc example for `Migrations`
juangirini Jun 7, 2023
c9cf9c6
feature gate NoopMigration
juangirini Jun 7, 2023
de545a3
fix example code
juangirini Jun 7, 2023
62bec96
improve example
juangirini Jun 8, 2023
f446edc
wip
juangirini Jun 8, 2023
de67661
rebase and fix conflicts
juangirini Jun 8, 2023
a1b9d71
remove FixedPointOperand from trait
juangirini Jun 9, 2023
c68288f
trait bound BalanceOf
juangirini Jun 13, 2023
9a813ef
more trait bound BalanceOf
juangirini Jun 13, 2023
9cddbef
rebase
juangirini Jun 15, 2023
11308f5
update to use RuntimeHoldReason
juangirini Jun 16, 2023
f4e1e53
replace Fungible for Currency
juangirini Jun 16, 2023
4da6b17
update runtime
juangirini Jun 16, 2023
790a8d2
WIP
juangirini Jun 27, 2023
1922bfe
make v10 benchmark generic over currency
juangirini Jul 3, 2023
b2da991
rebase and solve conflicts
juangirini Jul 3, 2023
d3ea9e2
solve merge conflicts
juangirini Jul 4, 2023
3673892
rebase and solve conflicts
juangirini Jul 4, 2023
e6201c1
make v12 migration benchmarking generic over DepositPerItem and Depos…
juangirini Jul 6, 2023
22fd924
give some format
juangirini Jul 6, 2023
013dc41
rebase and fix conflicts
juangirini Jul 6, 2023
f8da1e0
fix tests and old migrations
juangirini Jul 7, 2023
e29f2d4
add migration v13 placholder
juangirini Jul 11, 2023
ca8772a
rebase and fix errors\
juangirini Jul 11, 2023
6df91bd
wip
juangirini Jul 11, 2023
eb9c56a
wip
juangirini Jul 12, 2023
7f18359
rebase and merge conflicts
juangirini Jul 12, 2023
ab1af04
add benchmarking
juangirini Jul 12, 2023
316ab36
add weights
juangirini Jul 13, 2023
5209d01
wip
juangirini Jul 13, 2023
0cd0830
[pallet_collective] Enforce prime is a valid member of collective in …
ToufeeqP Jul 12, 2023
de849d2
update to docify 0.2.0 / crate-relative embed paths (#14570)
sam0x17 Jul 13, 2023
adba2c9
Fix Society v2 migration (#14421)
liamaharon Jul 13, 2023
9a42019
Moves `Block` to `frame_system` instead of `construct_runtime` and re…
gupnik Jul 13, 2023
1744884
Refactor the asset-conversion-tx-payment pallet (#14558)
jsidorenko Jul 13, 2023
15634c2
wip
juangirini Jul 13, 2023
c2eb60d
rebase and fix conflicts
juangirini Jul 14, 2023
1775efa
wip
juangirini Jul 14, 2023
cb1adf3
Merge remote-tracking branch 'origin/master' into jg/13643-contracts-…
juangirini Jul 17, 2023
12c522c
wip
juangirini Jul 17, 2023
6fb9713
improve try-runtime imports
juangirini Jul 17, 2023
c13a152
remove deposit account
juangirini Jul 17, 2023
0fc900c
wip
juangirini Jul 17, 2023
bd4bb00
wip
juangirini Jul 18, 2023
cdd0ca4
fix benchmark test
juangirini Jul 18, 2023
b51c236
Merge branch 'jg/13643-contracts-migrate-to-fungible-traits' into jg/…
juangirini Jul 18, 2023
ae4fda2
improved rustdocs
juangirini Jul 18, 2023
ebafc0e
Merge branch 'jg/13643-contracts-migrate-to-fungible-traits' into jg/…
juangirini Jul 18, 2023
f5e4b20
improved rustdocs
juangirini Jul 18, 2023
cb9217d
remove log
juangirini Jul 18, 2023
36f936a
Merge branch 'master' into jg/13643-contracts-migrate-to-fungible-traits
juangirini Jul 19, 2023
632ef2e
ignore variable
juangirini Jul 19, 2023
bc8efaf
reduce caller funding
juangirini Jul 19, 2023
2b67d70
rebase
juangirini Jul 19, 2023
7fff4d2
wip
juangirini Jul 19, 2023
0bb6948
fix tests
juangirini Jul 20, 2023
685eb19
fix tests
juangirini Jul 21, 2023
7c97aae
move v13 out
juangirini Jul 21, 2023
1b68585
Merge branch 'jg/13643-contracts-migrate-to-fungible-traits' into jg/…
juangirini Jul 21, 2023
22c74c1
add v14
juangirini Jul 21, 2023
a96a50e
update v13 migration
juangirini Jul 21, 2023
c67ea9f
v13 migration
juangirini Jul 24, 2023
ad7fa61
benchmark v13_migration
juangirini Jul 24, 2023
6e6fdb3
fix broken compilation
juangirini Jul 24, 2023
49a7b00
Merge branch 'jg/13643-contracts-migrate-to-fungible-traits' into jg/…
juangirini Jul 24, 2023
ae5d558
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jul 24, 2023
90de832
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jul 24, 2023
55fd7ce
remove all the `where BalanceOf`
juangirini Jul 25, 2023
50e0348
add Balance to Config
juangirini Jul 25, 2023
199a6f5
Merge remote-tracking branch 'origin/master' into jg/13643-contracts-…
juangirini Jul 25, 2023
05299ae
Merge remote-tracking branch 'origin/master' into jg/13643-contracts-…
juangirini Jul 25, 2023
a741737
improve docs
juangirini Jul 25, 2023
3950327
add new deposit storage error
juangirini Jul 25, 2023
0a790a6
remove todo message
juangirini Jul 25, 2023
26a1aef
rebaes and merge conflicts
juangirini Jul 25, 2023
7808759
wip
juangirini Jul 25, 2023
0c57451
rename migration v13 pre rebase
juangirini Jul 26, 2023
ec5415f
rebase
juangirini Jul 26, 2023
560d190
fix tests
juangirini Jul 26, 2023
ed3b399
add missing migration;
juangirini Jul 26, 2023
8186e21
bump storage version
juangirini Jul 27, 2023
08619a0
apply review suggestions
juangirini Jul 27, 2023
9435d4b
improved comment
juangirini Jul 27, 2023
06f7941
remove unnecessary code
juangirini Jul 27, 2023
eec1d20
simplify migrations
juangirini Jul 27, 2023
8b69d3e
mock balance
juangirini Jul 28, 2023
38c044c
mock more for benchmarks
juangirini Jul 28, 2023
48ce88c
rebase and merge conflicts
juangirini Jul 28, 2023
3cdd94d
make room for rebaes
juangirini Jul 28, 2023
e17b87e
make room for rebase
juangirini Jul 28, 2023
4cd120f
fix benchmarking tests
juangirini Jul 28, 2023
f08f844
fix benchmarking tests with caller
juangirini Jul 28, 2023
da6e8c1
improve cargo toml
juangirini Jul 28, 2023
3e6ce6a
solve nit
juangirini Jul 28, 2023
0ce5815
Update frame/contracts/src/lib.rs
juangirini Jul 31, 2023
3054dce
Update frame/contracts/src/exec.rs
juangirini Jul 31, 2023
b0a6d39
Update frame/contracts/src/exec.rs
juangirini Jul 31, 2023
49d8f7f
Update frame/contracts/src/storage/meter.rs
juangirini Jul 31, 2023
432ea07
review improvements
juangirini Jul 31, 2023
ae7ddf7
Merge remote-tracking branch 'origin/master' into jg/13643-contracts-…
juangirini Jul 31, 2023
a7bf911
remove extra events
juangirini Jul 31, 2023
41812ef
update cargo
juangirini Jul 31, 2023
2ed2c85
undo update cargo
juangirini Jul 31, 2023
2ab448a
rebaes and fix conflicts
juangirini Jul 31, 2023
49efe87
review updates
juangirini Aug 1, 2023
c9673f6
rebase and fix conflicts
juangirini Aug 1, 2023
7a8e0b3
wip
juangirini Aug 1, 2023
979d7ae
wip
juangirini Aug 1, 2023
394d5b8
fix test
juangirini Aug 1, 2023
90c4c84
rebase and fix conflicts
juangirini Aug 2, 2023
5c668aa
remove type Balance
juangirini Aug 2, 2023
39e83cc
add extra fields to events
juangirini Aug 2, 2023
aae16cc
fix zepter ci
juangirini Aug 2, 2023
9570bf8
rebase and fix conflicts
juangirini Aug 2, 2023
860d758
rebase and fix conflicts
juangirini Aug 2, 2023
96b0456
fix tests
juangirini Aug 2, 2023
2526bb5
remove commented out code
juangirini Aug 2, 2023
d9164a3
remove deposit_account from benchmarking
juangirini Aug 3, 2023
1d524fa
update v15 migration
juangirini Aug 3, 2023
a05aaa6
wip
juangirini Aug 3, 2023
6e5821d
remove deposit account from codebase
juangirini Aug 3, 2023
5101979
add contract info to v15
juangirini Aug 4, 2023
9327323
Merge remote-tracking branch 'origin/master' into jg/contracts-remove…
juangirini Aug 4, 2023
d878ed0
make try-runtime fixes
juangirini Aug 4, 2023
2a9d275
fix wrong v14 logs
juangirini Aug 4, 2023
6f699b2
add extra post upgrade steps
juangirini Aug 4, 2023
04d4553
remove old comments
juangirini Aug 4, 2023
92e4957
wip
juangirini Aug 4, 2023
d574756
fix delegate deposit test
juangirini Aug 4, 2023
1dc642a
Merge branch 'master' of https://github.com/paritytech/substrate into…
Aug 4, 2023
405ad81
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 4, 2023
5801429
wip
juangirini Aug 7, 2023
c74262e
wip
juangirini Aug 7, 2023
19b047c
wip
juangirini Aug 7, 2023
f8a1c84
implement review updates
juangirini Aug 7, 2023
67cbcbe
Merge branch 'master' of https://github.com/paritytech/substrate into…
Aug 7, 2023
b91c960
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 7, 2023
f3cdd8d
fix documentation
juangirini Aug 8, 2023
be1ec79
fix consumers/providers
juangirini Aug 8, 2023
810af1c
fix consumers/providers
juangirini Aug 8, 2023
5740afb
do not check consumers in migration
juangirini Aug 14, 2023
7f73759
review comments addressed
juangirini Aug 14, 2023
8ed3b66
update fully qualified System
juangirini Aug 14, 2023
c3cf6fa
Merge remote-tracking branch 'origin/master' into jg/contracts-remove…
Aug 14, 2023
0202477
wip
juangirini Aug 15, 2023
7c4f0c1
Merge remote-tracking branch 'origin/master' into jg/contracts-remove…
juangirini Aug 15, 2023
8d75ebc
wip
juangirini Aug 16, 2023
f22b70b
Transfer to beneficiary after `transfer_on_hold` (#14767)
juangirini Aug 17, 2023
155dc66
defer storage deposit charge
juangirini Aug 17, 2023
f826196
Merge branch 'master' into jg/contracts-remove-deposit-account
juangirini Aug 17, 2023
e2da7b6
".git/.scripts/commands/fmt/fmt.sh"
Aug 17, 2023
70fb25a
remove unused imports
juangirini Aug 17, 2023
6597a09
Update frame/contracts/src/migration/v15.rs
juangirini Aug 18, 2023
63ae66a
Update frame/contracts/src/storage/meter.rs
juangirini Aug 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions frame/contracts/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ pub trait AddressGenerator<T: Config> {
input_data: &[u8],
salt: &[u8],
) -> T::AccountId;

/// The address of the deposit account of `contract_addr`.
///
/// The address is generated once on instantiation and then stored in the contracts
/// metadata. Hence changes do only affect newly created contracts.
fn deposit_address(contract_addr: &T::AccountId) -> T::AccountId;
}

/// Default address generator.
Expand All @@ -71,11 +65,4 @@ impl<T: Config> AddressGenerator<T> for DefaultAddressGenerator {
Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
.expect("infinite length input; no invalid inputs for type; qed")
}

/// Formula: `hash("contract_depo_v1" ++ contract_addr)`
fn deposit_address(contract_addr: &T::AccountId) -> T::AccountId {
let entropy = (b"contract_depo_v1", contract_addr).using_encoded(T::Hashing::hash);
Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
.expect("infinite length input; no invalid inputs for type; qed")
}
}
34 changes: 22 additions & 12 deletions frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ use self::{
};
use crate::{
exec::{AccountIdOf, Key},
migration::{codegen::LATEST_MIGRATION_VERSION, v09, v10, v11, v12, v13, v14, MigrationStep},
migration::{
codegen::LATEST_MIGRATION_VERSION, v09, v10, v11, v12, v13, v14, v15, MigrationStep,
},
wasm::CallFlags,
Pallet as Contracts, *,
};
Expand Down Expand Up @@ -296,6 +298,19 @@ benchmarks! {
m.step();
}

// This benchmarks the v15 migration step (remove deposit account).
#[pov_mode = Measured]
v15_migration_step {
let contract = <Contract<T>>::with_caller(
whitelisted_caller(), WasmModule::dummy(), vec![],
)?;

v15::store_old_contract_info::<T>(contract.account_id.clone(), contract.info()?);
let mut m = v15::Migration::<T>::default();
}: {
m.step();
}

// This benchmarks the weight of executing Migration::migrate to execute a noop migration.
#[pov_mode = Measured]
migration_noop {
Expand Down Expand Up @@ -397,10 +412,9 @@ benchmarks! {
let addr = Contracts::<T>::contract_address(&caller, &hash, &input, &salt);
}: _(origin, value, Weight::MAX, None, code, input, salt)
verify {
let deposit_account = Contract::<T>::address_info(&addr)?.deposit_account().clone();
let deposit = T::Currency::balance(&deposit_account);
let deposit = T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &addr);
// uploading the code reserves some balance in the callers account
let code_deposit = T::Currency::total_balance_on_hold(&caller);
let code_deposit = T::Currency::balance_on_hold(&HoldReason::CodeUploadDepositReserve.into(), &caller);
assert_eq!(
T::Currency::balance(&caller),
caller_funding::<T>() - value - deposit - code_deposit - Pallet::<T>::min_balance(),
Expand All @@ -427,8 +441,7 @@ benchmarks! {
Contracts::<T>::store_code_raw(code, caller.clone())?;
}: _(origin, value, Weight::MAX, None, hash, input, salt)
verify {
let deposit_account = Contract::<T>::address_info(&addr)?.deposit_account().clone();
let deposit = T::Currency::balance(&deposit_account);
let deposit = T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &addr);
// value was removed from the caller
assert_eq!(
T::Currency::balance(&caller),
Expand All @@ -451,15 +464,13 @@ benchmarks! {
let instance = Contract::<T>::with_caller(
whitelisted_caller(), WasmModule::dummy(), vec![],
)?;
let deposit_account = instance.info()?.deposit_account().clone();
let value = Pallet::<T>::min_balance();
let origin = RawOrigin::Signed(instance.caller.clone());
let callee = instance.addr.clone();
let before = T::Currency::balance(&instance.account_id);
let before_deposit = T::Currency::balance(&deposit_account);
}: _(origin, callee, value, Weight::MAX, None, data)
verify {
let deposit = T::Currency::balance(&deposit_account);
let deposit = T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id);
// value and value transferred via call should be removed from the caller
assert_eq!(
T::Currency::balance(&instance.caller),
Expand Down Expand Up @@ -930,15 +941,14 @@ benchmarks! {
});
let instance = Contract::<T>::new(code, vec![])?;
let origin = RawOrigin::Signed(instance.caller.clone());
let deposit_account = instance.info()?.deposit_account().clone();
assert_eq!(T::Currency::total_balance(&beneficiary), 0u32.into());
assert_eq!(T::Currency::balance(&instance.account_id), Pallet::<T>::min_balance() * 2u32.into());
assert_ne!(T::Currency::balance(&deposit_account), 0u32.into());
assert_ne!(T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id), 0u32.into());
}: call(origin, instance.addr.clone(), 0u32.into(), Weight::MAX, None, vec![])
verify {
if r > 0 {
assert_eq!(T::Currency::total_balance(&instance.account_id), 0u32.into());
assert_eq!(T::Currency::total_balance(&deposit_account), 0u32.into());
assert_eq!(T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id), 0u32.into());
assert_eq!(T::Currency::total_balance(&beneficiary), Pallet::<T>::min_balance() * 2u32.into());
}
}
Expand Down
60 changes: 14 additions & 46 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
use crate::unsafe_debug::ExecutionObserver;
use crate::{
gas::GasMeter,
storage::{self, meter::Diff, DepositAccount, WriteOutcome},
storage::{self, meter::Diff, WriteOutcome},
BalanceOf, CodeHash, CodeInfo, CodeInfoOf, Config, ContractInfo, ContractInfoOf,
DebugBufferVec, Determinism, Error, Event, Nonce, Origin, Pallet as Contracts, Schedule,
System, WasmBlob, LOG_TARGET,
WasmBlob, LOG_TARGET,
};
use frame_support::{
crypto::ecdsa::ECDSAExt,
Expand All @@ -33,7 +33,7 @@ use frame_support::{
storage::{with_transaction, TransactionOutcome},
traits::{
fungible::{Inspect, Mutate},
tokens::{Fortitude::Polite, Preservation},
tokens::Preservation,
Contains, OriginTrait, Randomness, Time,
},
weights::Weight,
Expand Down Expand Up @@ -547,7 +547,7 @@ enum CachedContract<T: Config> {
///
/// In this case a reload is neither allowed nor possible. Please note that recursive
/// calls cannot remove a contract as this is checked and denied.
Terminated(DepositAccount<T>),
Terminated,
}

impl<T: Config> CachedContract<T> {
Expand All @@ -568,15 +568,6 @@ impl<T: Config> CachedContract<T> {
None
}
}

/// Returns `Some` iff the contract is not `Cached::Invalidated`.
fn deposit_account(&self) -> Option<&DepositAccount<T>> {
match self {
CachedContract::Cached(contract) => Some(contract.deposit_account()),
CachedContract::Terminated(deposit_account) => Some(&deposit_account),
CachedContract::Invalidated => None,
}
}
}

impl<T: Config> Frame<T> {
Expand Down Expand Up @@ -655,9 +646,7 @@ impl<T: Config> CachedContract<T> {
/// Terminate and return the contract info.
fn terminate(&mut self, account_id: &T::AccountId) -> ContractInfo<T> {
self.load(account_id);
let contract = get_cached_or_panic_after_load!(self);
let deposit_account = contract.deposit_account().clone();
get_cached_or_panic_after_load!(mem::replace(self, Self::Terminated(deposit_account)))
get_cached_or_panic_after_load!(mem::replace(self, Self::Terminated))
}
}

Expand Down Expand Up @@ -955,7 +944,7 @@ where
match (entry_point, delegated_code_hash) {
(ExportedFunction::Constructor, _) => {
// It is not allowed to terminate a contract inside its constructor.
if matches!(frame.contract_info, CachedContract::Terminated(_)) {
if matches!(frame.contract_info, CachedContract::Terminated) {
return Err(Error::<T>::TerminatedInConstructor.into())
}

Expand Down Expand Up @@ -1059,18 +1048,8 @@ where
// in its contract info. The load is necessary to pull it from storage in case
// it was invalidated.
frame.contract_info.load(account_id);
let deposit_account = frame
.contract_info
.deposit_account()
.expect(
"Is only `None` when the info is invalidated.
We just re-loaded from storage which either makes the state `Cached` or `Terminated`.
qed",
)
.clone();
let mut contract = frame.contract_info.into_contract();
prev.nested_storage
.absorb(frame.nested_storage, deposit_account, contract.as_mut());
prev.nested_storage.absorb(frame.nested_storage, account_id, contract.as_mut());

// In case the contract wasn't terminated we need to persist changes made to it.
if let Some(contract) = contract {
Expand Down Expand Up @@ -1105,14 +1084,10 @@ where
if !persist {
return
}
let deposit_account = self.first_frame.contract_info.deposit_account().expect(
"Is only `None` when the info is invalidated. The first frame can't be invalidated.
qed",
).clone();
let mut contract = self.first_frame.contract_info.as_contract();
self.storage_meter.absorb(
mem::take(&mut self.first_frame.nested_storage),
deposit_account,
&self.first_frame.account_id,
contract.as_deref_mut(),
);
if let Some(contract) = contract {
Expand Down Expand Up @@ -1311,14 +1286,8 @@ where
}
let frame = self.top_frame_mut();
let info = frame.terminate();
frame.nested_storage.terminate(&info);
System::<T>::dec_consumers(&frame.account_id);
Self::transfer(
Preservation::Expendable,
&frame.account_id,
beneficiary,
T::Currency::reducible_balance(&frame.account_id, Preservation::Expendable, Polite),
)?;
frame.nested_storage.terminate(&info, beneficiary.clone());

info.queue_trie_for_deletion();
ContractInfoOf::<T>::remove(&frame.account_id);
E::decrement_refcount(info.code_hash);
Expand All @@ -1327,7 +1296,7 @@ where
E::decrement_refcount(*code_hash);
frame
.nested_storage
.charge_deposit(info.deposit_account().clone(), StorageDeposit::Refund(*deposit));
.charge_deposit(frame.account_id.clone(), StorageDeposit::Refund(*deposit));
}

Contracts::<T>::deposit_event(
Expand Down Expand Up @@ -1521,8 +1490,7 @@ where
let deposit = StorageDeposit::Charge(new_base_deposit)
.saturating_sub(&StorageDeposit::Charge(old_base_deposit));

let deposit_account = info.deposit_account().clone();
frame.nested_storage.charge_deposit(deposit_account, deposit);
frame.nested_storage.charge_deposit(frame.account_id.clone(), deposit);

E::increment_refcount(hash)?;
E::decrement_refcount(prev_hash);
Expand Down Expand Up @@ -1573,7 +1541,7 @@ where
<WasmBlob<T>>::increment_refcount(code_hash)?;
frame
.nested_storage
.charge_deposit(info.deposit_account().clone(), StorageDeposit::Charge(deposit));
.charge_deposit(frame.account_id.clone(), StorageDeposit::Charge(deposit));
Ok(())
}

Expand All @@ -1589,7 +1557,7 @@ where

frame
.nested_storage
.charge_deposit(info.deposit_account().clone(), StorageDeposit::Refund(deposit));
.charge_deposit(frame.account_id.clone(), StorageDeposit::Refund(deposit));
Ok(())
}
}
Expand Down
18 changes: 17 additions & 1 deletion frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub mod pallet {
use sp_runtime::Perbill;

/// The current storage version.
pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(14);
pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(15);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down Expand Up @@ -899,6 +899,20 @@ pub mod pallet {
/// The code hash that was delegate called.
code_hash: CodeHash<T>,
},

/// Some funds have been transferred and held as storage deposit.
StorageDepositTransferredAndHeld {
from: T::AccountId,
to: T::AccountId,
amount: BalanceOf<T>,
},

/// Some storage deposit funds have been transferred and released.
StorageDepositTransferredAndReleased {
from: T::AccountId,
to: T::AccountId,
amount: BalanceOf<T>,
},
}

#[pallet::error]
Expand Down Expand Up @@ -999,6 +1013,8 @@ pub mod pallet {
pub enum HoldReason {
/// The Pallet has reserved it for storing code on-chain.
CodeUploadDepositReserve,
/// The Pallet has reserved it for storage deposit.
StorageDepositReserve,
}

/// A mapping from a contract's code hash to its code.
Expand Down
1 change: 1 addition & 0 deletions frame/contracts/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub mod v11;
pub mod v12;
pub mod v13;
pub mod v14;
pub mod v15;
include!(concat!(env!("OUT_DIR"), "/migration_codegen.rs"));

use crate::{weights::WeightInfo, Config, Error, MigrationInProgress, Pallet, Weight, LOG_TARGET};
Expand Down
19 changes: 15 additions & 4 deletions frame/contracts/src/migration/v10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! See <https://github.com/paritytech/substrate/pull/13369>.

use crate::{
address::AddressGenerator,
exec::AccountIdOf,
migration::{IsFinished, MigrationStep},
weights::WeightInfo,
Expand All @@ -40,7 +39,10 @@ use frame_support::{
use sp_core::hexdisplay::HexDisplay;
#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;
use sp_runtime::{traits::Zero, Perbill, Saturating};
use sp_runtime::{
traits::{Hash, TrailingZeroInput, Zero},
Perbill, Saturating,
};
use sp_std::{ops::Deref, prelude::*};

mod old {
Expand Down Expand Up @@ -135,6 +137,16 @@ type ContractInfoOf<T: Config, OldCurrency> = StorageMap<
ContractInfo<T, OldCurrency>,
>;

/// Formula: `hash("contract_depo_v1" ++ contract_addr)`
fn deposit_address<T: Config>(
contract_addr: &<T as frame_system::Config>::AccountId,
) -> <T as frame_system::Config>::AccountId {
let entropy = (b"contract_depo_v1", contract_addr)
.using_encoded(<T as frame_system::Config>::Hashing::hash);
Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
.expect("infinite length input; no invalid inputs for type; qed")
}
pgherveou marked this conversation as resolved.
Show resolved Hide resolved

impl<T: Config, OldCurrency: 'static> MigrationStep for Migration<T, OldCurrency>
where
OldCurrency: ReservableCurrency<<T as frame_system::Config>::AccountId>
Expand Down Expand Up @@ -162,8 +174,7 @@ where
log::debug!(target: LOG_TARGET, "Account: 0x{} ", HexDisplay::from(&account.encode()));

// Get the new deposit account address
let deposit_account: DepositAccount<T> =
DepositAccount(T::AddressGenerator::deposit_address(&account));
let deposit_account: DepositAccount<T> = DepositAccount(deposit_address::<T>(&account));
pgherveou marked this conversation as resolved.
Show resolved Hide resolved

// Calculate the existing deposit, that should be reserved on the contract account
let old_deposit = contract
Expand Down
Loading