Registrar: Deposit covering max code size (#3020)

This PR implements phase 1 of:
https://github.com/paritytech/polkadot-sdk/pull/2372#discussion_r1461873933

NOTE: This means that all the current parachains can upgrade their code
to the maximum size for free.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Radha <86818441+DrW3RK@users.noreply.github.com>
This commit is contained in:
Sergej Sakac
2024-01-24 14:10:15 +01:00
committed by GitHub
parent a817d310bb
commit 488cbe6896
3 changed files with 45 additions and 9 deletions
@@ -930,8 +930,18 @@ fn basic_swap_works() {
// Deposit is appropriately taken // Deposit is appropriately taken
// ----------------------------------------- para deposit --- crowdloan // ----------------------------------------- para deposit --- crowdloan
assert_eq!(Balances::reserved_balance(&account_id(1)), (500 + 10 * 2 * 1) + 100); let crowdloan_deposit = 100;
assert_eq!(Balances::reserved_balance(&account_id(2)), 500 + 20 * 2 * 1); let para_id_deposit = <Test as paras_registrar::Config>::ParaDeposit::get();
let code_deposit = configuration::Pallet::<Test>::config().max_code_size *
<Test as paras_registrar::Config>::DataDepositPerByte::get();
// Para 2000 has a genesis head size of 10.
assert_eq!(
Balances::reserved_balance(&account_id(1)),
crowdloan_deposit + para_id_deposit + code_deposit + 10
);
// Para 2001 has a genesis head size of 20.
assert_eq!(Balances::reserved_balance(&account_id(2)), para_id_deposit + code_deposit + 20);
assert_eq!(Balances::reserved_balance(&crowdloan_account), total); assert_eq!(Balances::reserved_balance(&crowdloan_account), total);
// Crowdloan is appropriately set // Crowdloan is appropriately set
assert!(Crowdloan::funds(ParaId::from(2000)).is_some()); assert!(Crowdloan::funds(ParaId::from(2000)).is_some());
@@ -973,8 +983,8 @@ fn basic_swap_works() {
// Deregister on-demand parachain // Deregister on-demand parachain
assert_ok!(Registrar::deregister(para_origin(2000).into(), ParaId::from(2000))); assert_ok!(Registrar::deregister(para_origin(2000).into(), ParaId::from(2000)));
// Correct deposit is unreserved // Correct deposit is unreserved
assert_eq!(Balances::reserved_balance(&account_id(1)), 100); // crowdloan deposit left over assert_eq!(Balances::reserved_balance(&account_id(1)), crowdloan_deposit);
assert_eq!(Balances::reserved_balance(&account_id(2)), 500 + 20 * 2 * 1); assert_eq!(Balances::reserved_balance(&account_id(2)), para_id_deposit + code_deposit + 20);
// Crowdloan ownership is swapped // Crowdloan ownership is swapped
assert!(Crowdloan::funds(ParaId::from(2000)).is_none()); assert!(Crowdloan::funds(ParaId::from(2000)).is_none());
assert!(Crowdloan::funds(ParaId::from(2001)).is_some()); assert!(Crowdloan::funds(ParaId::from(2001)).is_some());
@@ -1005,7 +1015,7 @@ fn basic_swap_works() {
// Dissolve returns the balance of the person who put a deposit for crowdloan // Dissolve returns the balance of the person who put a deposit for crowdloan
assert_ok!(Crowdloan::dissolve(signed(1), ParaId::from(2001))); assert_ok!(Crowdloan::dissolve(signed(1), ParaId::from(2001)));
assert_eq!(Balances::reserved_balance(&account_id(1)), 0); assert_eq!(Balances::reserved_balance(&account_id(1)), 0);
assert_eq!(Balances::reserved_balance(&account_id(2)), 500 + 20 * 2 * 1); assert_eq!(Balances::reserved_balance(&account_id(2)), para_id_deposit + code_deposit + 20);
// Final deregister sets everything back to the start // Final deregister sets everything back to the start
assert_ok!(Registrar::deregister(para_origin(2001).into(), ParaId::from(2001))); assert_ok!(Registrar::deregister(para_origin(2001).into(), ParaId::from(2001)));
@@ -239,7 +239,13 @@ pub mod pallet {
/// - `validation_code`: The initial validation code of the parachain/thread. /// - `validation_code`: The initial validation code of the parachain/thread.
/// ///
/// ## Deposits/Fees /// ## Deposits/Fees
/// The origin signed account must reserve a corresponding deposit for the registration. /// The account with the originating signature must reserve a deposit.
///
/// The deposit is required to cover the costs associated with storing the genesis head
/// data and the validation code.
/// This accounts for the potential to store validation code of a size up to the
/// `max_code_size`, as defined in the configuration pallet
///
/// Anything already reserved previously for this para ID is accounted for. /// Anything already reserved previously for this para ID is accounted for.
/// ///
/// ## Events /// ## Events
@@ -661,7 +667,7 @@ impl<T: Config> Pallet<T> {
let per_byte_fee = T::DataDepositPerByte::get(); let per_byte_fee = T::DataDepositPerByte::get();
let deposit = T::ParaDeposit::get() let deposit = T::ParaDeposit::get()
.saturating_add(per_byte_fee.saturating_mul((genesis_head.0.len() as u32).into())) .saturating_add(per_byte_fee.saturating_mul((genesis_head.0.len() as u32).into()))
.saturating_add(per_byte_fee.saturating_mul((validation_code.0.len() as u32).into())); .saturating_add(per_byte_fee.saturating_mul(config.max_code_size.into()));
Ok((ParaGenesisArgs { genesis_head, validation_code, para_kind }, deposit)) Ok((ParaGenesisArgs { genesis_head, validation_code, para_kind }, deposit))
} }
@@ -1013,10 +1019,16 @@ mod tests {
run_to_session(START_SESSION_INDEX + 2); run_to_session(START_SESSION_INDEX + 2);
assert!(Parachains::is_parathread(para_id)); assert!(Parachains::is_parathread(para_id));
// Even though the registered validation code has a smaller size than the maximum the
// para manager's deposit is reserved as though they registered the maximum-sized code.
// Consequently, they can upgrade their code to the maximum size at any point without
// additional cost.
let validation_code_deposit =
max_code_size() as BalanceOf<Test> * <Test as Config>::DataDepositPerByte::get();
let head_deposit = 32 * <Test as Config>::DataDepositPerByte::get();
assert_eq!( assert_eq!(
Balances::reserved_balance(&1), Balances::reserved_balance(&1),
<Test as Config>::ParaDeposit::get() + <Test as Config>::ParaDeposit::get() + head_deposit + validation_code_deposit
64 * <Test as Config>::DataDepositPerByte::get()
); );
}); });
} }
+14
View File
@@ -0,0 +1,14 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
title: Para registration deposit covering max code size
doc:
- audience: Runtime User
description: |
With this PR all newly registered parachains must pay a deposit equivalent to the cost of
registering validation code of the maximum size. Consequently, they can upgrade their code
to the maximum size at any point without additional cost.
crates:
- name: polkadot-runtime-common