Skip to content

Commit 77340a2

Browse files
authored
chore(utility): make deposit calc explicit. (#469)
chore(utility): explicit deposit justification
1 parent 6ff08a0 commit 77340a2

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

runtime/mainnet/src/config/utility.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use crate::{
66
};
77

88
parameter_types! {
9-
// One storage item; key size is 32 + 32; value is size 4+4+16+32 bytes = 120 bytes.
9+
// Accounts for the base cost of creating a multisig execution.
10+
// For details, refer to `call_deposit_has_base_amount`.
1011
pub const DepositBase: Balance = deposit(1, 120);
1112
// Additional storage item size of 32 bytes.
1213
pub const DepositFactor: Balance = deposit(0, 32);
@@ -25,7 +26,9 @@ impl pallet_multisig::Config for Runtime {
2526

2627
parameter_types! {
2728
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
28-
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
29+
// Accounts for the base cost of noting a preimage.
30+
// For details, refer to `base_deposit_matches_configuration`.
31+
pub const PreimageBaseDeposit: Balance = deposit(2, 68);
2932
pub const PreimageByteDeposit: Balance = deposit(0, 1);
3033
}
3134

@@ -79,6 +82,9 @@ mod tests {
7982
use super::*;
8083

8184
mod multisig {
85+
use codec::MaxEncodedLen;
86+
use parachains_common::BlockNumber;
87+
8288
use super::*;
8389

8490
#[test]
@@ -91,6 +97,17 @@ mod tests {
9197

9298
#[test]
9399
fn call_deposit_has_base_amount() {
100+
// From pallet_multisig:
101+
// This is held for an additional storage item whose value size is 4 +
102+
// sizeof((BlockNumber, Balance, AccountId)) bytes, and whose key size is 32 +
103+
// sizeof(AccountId) bytes.
104+
let key_size = 32 + AccountId::max_encoded_len();
105+
let value_size = 4 +
106+
BlockNumber::max_encoded_len() +
107+
Balance::max_encoded_len() +
108+
AccountId::max_encoded_len();
109+
let max_size = key_size + value_size;
110+
assert_eq!(max_size, 120);
94111
assert_eq!(
95112
<<Runtime as pallet_multisig::Config>::DepositBase as Get<Balance>>::get(),
96113
deposit(1, 120)
@@ -123,11 +140,22 @@ mod tests {
123140
}
124141

125142
mod preimage {
143+
use frame_support::{Identity, StorageHasher};
144+
126145
use super::*;
127146

128147
#[test]
129148
fn base_deposit_matches_configuration() {
130-
assert_eq!(PreimageBaseDeposit::get(), deposit(2, 64));
149+
// Accounts for the key size of:
150+
// `RequestStatusFor` +
151+
// `PreimageFor`
152+
let preimage_for_key_size =
153+
Identity::max_len::<(<Runtime as frame_system::Config>::Hash, u32)>();
154+
let request_status_for_key_size =
155+
Identity::max_len::<<Runtime as frame_system::Config>::Hash>();
156+
let base_key_size = preimage_for_key_size + request_status_for_key_size;
157+
assert_eq!(base_key_size, 68);
158+
assert_eq!(PreimageBaseDeposit::get(), deposit(2, base_key_size as u32));
131159
}
132160

133161
#[test]

0 commit comments

Comments
 (0)