From dee41ff8ac7a1367fe7b8b7b84b0d975132f700d Mon Sep 17 00:00:00 2001 From: Dmitrii Novikov Date: Tue, 7 May 2024 15:30:39 +0400 Subject: [PATCH 1/3] feat(gear-bank): impl on-finalize transfers; optimise block-production gas payouts (#3840) --- gsdk/src/metadata/generated.rs | 4 + pallets/gear-bank/src/lib.rs | 98 +++++++++++++--- pallets/gear-bank/src/tests.rs | 109 +++++++++++++++++- pallets/gear-builtin/src/mock.rs | 2 + .../gear-builtin/src/tests/bad_builtin_ids.rs | 2 + pallets/gear-debug/src/mock.rs | 3 + pallets/gear-scheduler/src/mock.rs | 3 + pallets/gear/src/mock.rs | 3 + pallets/gear/src/tests.rs | 17 ++- runtime/vara/src/integration_tests.rs | 2 + utils/runtime-fuzzer/src/runtime/block.rs | 7 +- 11 files changed, 217 insertions(+), 33 deletions(-) diff --git a/gsdk/src/metadata/generated.rs b/gsdk/src/metadata/generated.rs index d7986f03edd..e939f910e93 100644 --- a/gsdk/src/metadata/generated.rs +++ b/gsdk/src/metadata/generated.rs @@ -8740,6 +8740,8 @@ pub mod storage { pub enum GearBankStorage { Bank, UnusedValue, + OnFinalizeTransfers, + OnFinalizeValue, } impl StorageInfo for GearBankStorage { const PALLET: &'static str = "GearBank"; @@ -8747,6 +8749,8 @@ pub mod storage { match self { Self::Bank => "Bank", Self::UnusedValue => "UnusedValue", + Self::OnFinalizeTransfers => "OnFinalizeTransfers", + Self::OnFinalizeValue => "OnFinalizeValue", } } } diff --git a/pallets/gear-bank/src/lib.rs b/pallets/gear-bank/src/lib.rs index 492a77e4681..a66533855bd 100644 --- a/pallets/gear-bank/src/lib.rs +++ b/pallets/gear-bank/src/lib.rs @@ -58,9 +58,11 @@ pub mod pallet { ensure, pallet_prelude::{StorageMap, StorageValue, ValueQuery}, sp_runtime::{traits::CheckedSub, Saturating}, - traits::{ExistenceRequirement, Get, ReservableCurrency, WithdrawReasons}, + traits::{ExistenceRequirement, Get, Hooks, ReservableCurrency}, + weights::Weight, Identity, }; + use frame_system::pallet_prelude::BlockNumberFor; use pallet_authorship::Pallet as Authorship; use parity_scale_codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; use scale_info::TypeInfo; @@ -158,12 +160,61 @@ pub mod pallet { // Private storage that keeps account bank details. #[pallet::storage] - pub type Bank = StorageMap<_, Identity, AccountIdOf, BankAccount>>; + type Bank = StorageMap<_, Identity, AccountIdOf, BankAccount>>; // Private storage that keeps amount of value that wasn't sent because owner is inexistent account. #[pallet::storage] pub type UnusedValue = StorageValue<_, BalanceOf, ValueQuery>; + // Private storage that keeps registry of transfers to be performed at the end of the block. + #[pallet::storage] + type OnFinalizeTransfers = StorageMap<_, Identity, AccountIdOf, BalanceOf>; + + // Private storage that represents sum of values in OnFinalizeTransfers. + #[pallet::storage] + pub(crate) type OnFinalizeValue = StorageValue<_, BalanceOf, ValueQuery>; + + #[pallet::hooks] + impl Hooks> for Pallet { + /// Start of the block. + fn on_initialize(bn: BlockNumberFor) -> Weight { + if OnFinalizeTransfers::::iter().next().is_some() { + log::error!("Block #{bn:?} started with non-empty on-finalize transfers"); + } + + if !OnFinalizeValue::::get().is_zero() { + log::error!("Block #{bn:?} started with non-zero on-finalize value"); + } + + T::DbWeight::get().reads(2) + } + + /// End of the block. + fn on_finalize(bn: BlockNumberFor) { + // Take of on-finalize value should always be performed before + // `withdraw`s, since `withdraw`s ensure bank balance, + // that relies on that value "locked". + let expected = OnFinalizeValue::::take(); + + let mut total = BalanceOf::::zero(); + + while let Some((account_id, value)) = OnFinalizeTransfers::::drain().next() { + total = total.saturating_add(value); + + if let Err(e) = Self::withdraw(&account_id, value) { + log::error!( + "Block #{bn:?} ended with unreachable error while performing on-finalize transfer to {account_id:?}: {e:?}" + ); + } + } + + if total != expected { + log::error!("Block #{bn:?} ended with unreachable error while performing cleaning of on-finalize value: \ + total tried to transfer is {total:?}, expected amount is {expected:?}") + } + } + } + impl Pallet { /// Transfers value from `account_id` to bank address. fn deposit( @@ -192,19 +243,13 @@ pub mod pallet { /// Ensures that bank account is able to transfer requested value. fn ensure_bank_can_transfer(value: BalanceOf) -> Result<(), Error> { - let bank_address = T::BankAddress::get(); + let minimum_balance = CurrencyOf::::minimum_balance() + .saturating_add(UnusedValue::::get()) + .saturating_add(OnFinalizeValue::::get()); - CurrencyOf::::free_balance(&bank_address) + CurrencyOf::::free_balance(&T::BankAddress::get()) .checked_sub(&value) - .map_or(false, |new_balance| { - CurrencyOf::::ensure_can_withdraw( - &bank_address, - value, - WithdrawReasons::TRANSFER, - new_balance, - ) - .is_ok() - }) + .map_or(false, |balance| balance >= minimum_balance) .then_some(()) .ok_or(Error::::InsufficientBankBalance) } @@ -239,6 +284,26 @@ pub mod pallet { .map_err(|_| Error::::InsufficientBankBalance) } + /// Transfers value from bank address to `account_id` on block finalize. + fn withdraw_on_finalize( + account_id: &AccountIdOf, + value: BalanceOf, + ) -> Result<(), Error> { + if value.is_zero() { + return Ok(()); + }; + + Self::ensure_bank_can_transfer(value)?; + + OnFinalizeValue::::mutate(|v| *v = v.saturating_add(value)); + OnFinalizeTransfers::::mutate(account_id, |v| { + let inner = v.get_or_insert(Zero::zero()); + *inner = inner.saturating_add(value); + }); + + Ok(()) + } + pub fn deposit_gas( account_id: &AccountIdOf, amount: u64, @@ -337,11 +402,8 @@ pub mod pallet { let value = Self::withdraw_gas_no_transfer(account_id, amount, multiplier)?; - // All the checks and internal values withdrawals performed in - // `*_no_transfer` function above. - // - // This call does only currency trait final transfer. - Self::withdraw(to, value).unwrap_or_else(|e| unreachable!("qed above: {e:?}")); + Self::withdraw_on_finalize(to, value) + .unwrap_or_else(|e| unreachable!("qed above: {e:?}")); Ok(()) } diff --git a/pallets/gear-bank/src/tests.rs b/pallets/gear-bank/src/tests.rs index 94a1d3d0d37..e52030e8ef5 100644 --- a/pallets/gear-bank/src/tests.rs +++ b/pallets/gear-bank/src/tests.rs @@ -16,8 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{mock::*, GasMultiplier, UnusedValue, *}; -use frame_support::{assert_noop, assert_ok}; +use crate::{mock::*, GasMultiplier, OnFinalizeValue, UnusedValue, *}; +use frame_support::{assert_noop, assert_ok, traits::Hooks}; use sp_runtime::{traits::Zero, StateVersion}; use utils::*; @@ -403,6 +403,7 @@ fn spend_gas_different_users() { const ALICE_BURN: u64 = ALICE_GAS - 123_456; assert_ok!(GearBank::spend_gas(&ALICE, ALICE_BURN, mult())); + GearBank::on_finalize(1); assert_bank_balance(ALICE_GAS - ALICE_BURN + BOB_GAS, 0); @@ -416,6 +417,7 @@ fn spend_gas_different_users() { const BOB_BURN: u64 = BOB_GAS - 1_234; assert_ok!(GearBank::spend_gas(&BOB, BOB_BURN, mult())); + GearBank::on_finalize(1); assert_bank_balance(ALICE_GAS - ALICE_BURN + BOB_GAS - BOB_BURN, 0); @@ -437,6 +439,7 @@ fn spend_gas_single_user() { const BURN_1: u64 = GAS_AMOUNT - 23_456; assert_ok!(GearBank::spend_gas(&ALICE, BURN_1, mult())); + GearBank::on_finalize(1); assert_bank_balance(GAS_AMOUNT - BURN_1, 0); @@ -447,6 +450,7 @@ fn spend_gas_single_user() { const BURN_2: u64 = GAS_AMOUNT - BURN_1 - 10_000; assert_ok!(GearBank::spend_gas(&ALICE, BURN_2, mult())); + GearBank::on_finalize(1); assert_bank_balance(GAS_AMOUNT - BURN_1 - BURN_2, 0); @@ -464,6 +468,7 @@ fn spend_gas_all_balance() { assert_ok!(GearBank::deposit_gas(&ALICE, GAS_AMOUNT, false)); assert_ok!(GearBank::spend_gas(&ALICE, GAS_AMOUNT, mult())); + GearBank::on_finalize(1); assert_bank_balance(0, 0); @@ -490,6 +495,7 @@ fn spend_gas_all_balance_validator_account_deleted() { )); assert_ok!(GearBank::spend_gas(&ALICE, GAS_AMOUNT, mult())); + GearBank::on_finalize(1); assert_bank_balance(0, 0); @@ -510,6 +516,7 @@ fn spend_gas_small_amount() { assert_ok!(GearBank::deposit_gas(&ALICE, GAS_AMOUNT, false)); assert_ok!(GearBank::spend_gas(&ALICE, GAS_AMOUNT, mult())); + GearBank::on_finalize(1); assert_bank_balance(0, 0); @@ -538,6 +545,7 @@ fn spend_gas_small_amount_validator_account_deleted() { )); assert_ok!(GearBank::spend_gas(&ALICE, GAS_AMOUNT, mult())); + GearBank::on_finalize(1); assert_eq!(UnusedValue::::get(), GAS_VALUE_AMOUNT); assert_balance(&BANK_ADDRESS, EXISTENTIAL_DEPOSIT + GAS_VALUE_AMOUNT); @@ -1348,6 +1356,7 @@ fn empty_accounts_deleted() { assert_ok!(GearBank::spend_gas(&ALICE, GAS_AMOUNT, mult())); assert!(GearBank::account(ALICE).is_none()); + GearBank::on_finalize(1); const VALUE: Balance = 123_456_000; @@ -1384,6 +1393,7 @@ fn empty_zero_accounts_deleted() { assert_ok!(GearBank::spend_gas(&Zero::zero(), 0, mult())); assert!(GearBank::account(::zero()).is_none()); + GearBank::on_finalize(1); assert_ok!(GearBank::deposit_value(&Zero::zero(), 0, false)); assert!(GearBank::account(::zero()).is_none()); @@ -1423,6 +1433,7 @@ fn empty_composite_accounts_deleted() { const GAS_BURN: u64 = GAS_AMOUNT / 2; assert_ok!(GearBank::spend_gas(&ALICE, GAS_BURN, mult())); + GearBank::on_finalize(1); assert_bank_balance(GAS_AMOUNT - GAS_BURN, VALUE); @@ -1452,6 +1463,94 @@ fn empty_composite_accounts_deleted() { }) } +#[test] +fn spend_gas_on_finalize_different_users() { + new_test_ext().execute_with(|| { + const ALICE_GAS: u64 = 1_234_567; + assert_ok!(GearBank::deposit_gas(&ALICE, ALICE_GAS, false)); + + const BOB_GAS: u64 = 56_789; + assert_ok!(GearBank::deposit_gas(&BOB, BOB_GAS, false)); + + assert_eq!(OnFinalizeValue::::get(), 0); + + const ALICE_BURN: u64 = ALICE_GAS - 123_456; + assert_ok!(GearBank::spend_gas(&ALICE, ALICE_BURN, mult())); + + assert_bank_balance(ALICE_GAS - ALICE_BURN + BOB_GAS, 0); + + assert_block_author_inc(0); + assert_eq!(OnFinalizeValue::::get(), gas_price(ALICE_BURN)); + + assert_alice_dec(gas_price(ALICE_GAS)); + assert_gas_value(&ALICE, ALICE_GAS - ALICE_BURN, 0); + + assert_bob_dec(gas_price(BOB_GAS)); + assert_gas_value(&BOB, BOB_GAS, 0); + + const BOB_BURN: u64 = BOB_GAS - 1_234; + assert_ok!(GearBank::spend_gas(&BOB, BOB_BURN, mult())); + + assert_bank_balance(ALICE_GAS - ALICE_BURN + BOB_GAS - BOB_BURN, 0); + + assert_block_author_inc(0); + assert_eq!( + OnFinalizeValue::::get(), + gas_price(ALICE_BURN + BOB_BURN) + ); + + assert_alice_dec(gas_price(ALICE_GAS)); + assert_gas_value(&ALICE, ALICE_GAS - ALICE_BURN, 0); + + assert_bob_dec(gas_price(BOB_GAS)); + assert_gas_value(&BOB, BOB_GAS - BOB_BURN, 0); + + /* what happens at the end of block */ + GearBank::on_finalize(1); + assert_eq!(OnFinalizeValue::::get(), 0); + assert_block_author_inc(gas_price(ALICE_BURN + BOB_BURN)); + + GearBank::on_initialize(2); + }) +} + +#[test] +fn spend_gas_on_finalize_single_user() { + new_test_ext().execute_with(|| { + const GAS_AMOUNT: u64 = 123_456; + assert_ok!(GearBank::deposit_gas(&ALICE, GAS_AMOUNT, false)); + + const BURN_1: u64 = GAS_AMOUNT - 23_456; + assert_ok!(GearBank::spend_gas(&ALICE, BURN_1, mult())); + + assert_bank_balance(GAS_AMOUNT - BURN_1, 0); + + assert_eq!(OnFinalizeValue::::get(), gas_price(BURN_1)); + assert_block_author_inc(0); + + assert_alice_dec(gas_price(GAS_AMOUNT)); + assert_gas_value(&ALICE, GAS_AMOUNT - BURN_1, 0); + + const BURN_2: u64 = GAS_AMOUNT - BURN_1 - 10_000; + assert_ok!(GearBank::spend_gas(&ALICE, BURN_2, mult())); + + assert_bank_balance(GAS_AMOUNT - BURN_1 - BURN_2, 0); + + assert_eq!(OnFinalizeValue::::get(), gas_price(BURN_1 + BURN_2)); + assert_block_author_inc(0); + + assert_alice_dec(gas_price(GAS_AMOUNT)); + assert_gas_value(&ALICE, GAS_AMOUNT - BURN_1 - BURN_2, 0); + + /* what happens at the end of block */ + GearBank::on_finalize(1); + assert_eq!(OnFinalizeValue::::get(), 0); + assert_block_author_inc(gas_price(BURN_1 + BURN_2)); + + GearBank::on_initialize(2); + }) +} + mod utils { use super::*; @@ -1491,7 +1590,11 @@ mod utils { let gas_value = gas_price(gas); assert_balance( &BANK_ADDRESS, - CurrencyOf::::minimum_balance() + UnusedValue::::get() + gas_value + value, + CurrencyOf::::minimum_balance() + + UnusedValue::::get() + + OnFinalizeValue::::get() + + gas_value + + value, ); } diff --git a/pallets/gear-builtin/src/mock.rs b/pallets/gear-builtin/src/mock.rs index b2825123748..92eeb81a0bc 100644 --- a/pallets/gear-builtin/src/mock.rs +++ b/pallets/gear-builtin/src/mock.rs @@ -302,12 +302,14 @@ pub(crate) fn on_initialize(new_block_number: BlockNumberFor) { GearGas::on_initialize(new_block_number); GearMessenger::on_initialize(new_block_number); Gear::on_initialize(new_block_number); + GearBank::on_initialize(new_block_number); } // Run on_finalize hooks (in pallets reverse order, as they appear in AllPalletsWithSystem) pub(crate) fn on_finalize(current_blk: BlockNumberFor) { Authorship::on_finalize(current_blk); Gear::on_finalize(current_blk); + GearBank::on_finalize(current_blk); assert!(!System::events().iter().any(|e| { matches!( e.event, diff --git a/pallets/gear-builtin/src/tests/bad_builtin_ids.rs b/pallets/gear-builtin/src/tests/bad_builtin_ids.rs index 0c865d1dda1..75f3d44cfa4 100644 --- a/pallets/gear-builtin/src/tests/bad_builtin_ids.rs +++ b/pallets/gear-builtin/src/tests/bad_builtin_ids.rs @@ -233,12 +233,14 @@ pub(crate) fn on_initialize(new_block_number: BlockNumberFor) { GearGas::on_initialize(new_block_number); GearMessenger::on_initialize(new_block_number); Gear::on_initialize(new_block_number); + GearBank::on_initialize(new_block_number); } // Run on_finalize hooks (in pallets reverse order, as they appear in AllPalletsWithSystem) pub(crate) fn on_finalize(current_blk: BlockNumberFor) { Authorship::on_finalize(current_blk); Gear::on_finalize(current_blk); + GearBank::on_finalize(current_blk); assert!(!System::events().iter().any(|e| { matches!( e.event, diff --git a/pallets/gear-debug/src/mock.rs b/pallets/gear-debug/src/mock.rs index 499b67a965f..fdeda91298b 100644 --- a/pallets/gear-debug/src/mock.rs +++ b/pallets/gear-debug/src/mock.rs @@ -130,11 +130,13 @@ pub fn new_test_ext() -> sp_io::TestExternalities { pub fn run_to_block(n: u64, remaining_weight: Option) { while System::block_number() < n { System::on_finalize(System::block_number()); + GearBank::on_finalize(System::block_number()); System::set_block_number(System::block_number() + 1); System::on_initialize(System::block_number()); GearGas::on_initialize(System::block_number()); GearMessenger::on_initialize(System::block_number()); Gear::on_initialize(System::block_number()); + GearBank::on_initialize(System::block_number()); if let Some(remaining_weight) = remaining_weight { GasAllowanceOf::::put(remaining_weight); @@ -153,6 +155,7 @@ pub fn run_to_block(n: u64, remaining_weight: Option) { System::register_extra_weight_unchecked(max_block_weight, DispatchClass::Mandatory); Gear::run(frame_support::dispatch::RawOrigin::None.into(), None).unwrap(); Gear::on_finalize(System::block_number()); + GearBank::on_finalize(System::block_number()); assert!(!System::events().iter().any(|e| { matches!( diff --git a/pallets/gear-scheduler/src/mock.rs b/pallets/gear-scheduler/src/mock.rs index 02a209ffeb7..e7b179d4b72 100644 --- a/pallets/gear-scheduler/src/mock.rs +++ b/pallets/gear-scheduler/src/mock.rs @@ -126,11 +126,13 @@ pub fn new_test_ext() -> sp_io::TestExternalities { pub fn run_to_block(n: u64, remaining_weight: Option) { while System::block_number() < n { System::on_finalize(System::block_number()); + GearBank::on_finalize(System::block_number()); System::set_block_number(System::block_number() + 1); System::on_initialize(System::block_number()); GearGas::on_initialize(System::block_number()); GearMessenger::on_initialize(System::block_number()); Gear::on_initialize(System::block_number()); + GearBank::on_initialize(System::block_number()); if let Some(remaining_weight) = remaining_weight { GasAllowanceOf::::put(remaining_weight); @@ -149,6 +151,7 @@ pub fn run_to_block(n: u64, remaining_weight: Option) { System::register_extra_weight_unchecked(max_block_weight, DispatchClass::Mandatory); Gear::run(frame_support::dispatch::RawOrigin::None.into(), None).unwrap(); Gear::on_finalize(System::block_number()); + GearBank::on_finalize(System::block_number()); assert!(!System::events().iter().any(|e| { matches!( diff --git a/pallets/gear/src/mock.rs b/pallets/gear/src/mock.rs index af6e543c989..c2e2adb1faf 100644 --- a/pallets/gear/src/mock.rs +++ b/pallets/gear/src/mock.rs @@ -245,11 +245,13 @@ pub fn run_to_block_maybe_with_queue( ) { while System::block_number() < n { System::on_finalize(System::block_number()); + GearBank::on_finalize(System::block_number()); System::set_block_number(System::block_number() + 1); System::on_initialize(System::block_number()); GearGas::on_initialize(System::block_number()); GearMessenger::on_initialize(System::block_number()); Gear::on_initialize(System::block_number()); + GearBank::on_initialize(System::block_number()); if let Some(remaining_weight) = remaining_weight { GasAllowanceOf::::put(remaining_weight); @@ -273,6 +275,7 @@ pub fn run_to_block_maybe_with_queue( } Gear::on_finalize(System::block_number()); + GearBank::on_finalize(System::block_number()); if gear_run.is_some() { assert!(!System::events().iter().any(|e| { diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index fd11156aa07..7b572ab3c59 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -2134,15 +2134,8 @@ fn delayed_send_user_message_with_reservation() { run_to_next_block(None); - // Check that last event is UserMessageSent. - let last_event = match get_last_event() { - MockRuntimeEvent::Gear(e) => e, - _ => panic!("Should be one Gear event"), - }; - match last_event { - Event::UserMessageSent { message, .. } => assert_eq!(delayed_id, message.id()), - _ => panic!("Test failed: expected Event::UserMessageSent"), - } + let last_mail = get_last_mail(USER_2); + assert_eq!(last_mail.id(), delayed_id); // Mailbox should not be empty. assert!(!MailboxOf::::is_empty(&USER_2)); @@ -4809,12 +4802,16 @@ fn claim_value_works() { let expected_sender_balance = sender_balance + charged_for_page_load - value_sent - gas_burned - burned_for_hold; assert_eq!(Balances::free_balance(USER_2), expected_sender_balance); + + // To trigger GearBank::on_finalize -> transfer to pool performed. + run_to_next_block(Some(0)); + assert_eq!( Balances::free_balance(RENT_POOL), balance_rent_pool + burned_for_hold ); - System::assert_last_event( + System::assert_has_event( Event::UserMessageRead { id: reply_to_id, reason: UserMessageReadRuntimeReason::MessageClaimed.into_reason(), diff --git a/runtime/vara/src/integration_tests.rs b/runtime/vara/src/integration_tests.rs index e54f426e744..cc789127e63 100644 --- a/runtime/vara/src/integration_tests.rs +++ b/runtime/vara/src/integration_tests.rs @@ -61,6 +61,7 @@ pub(crate) fn on_initialize(new_block_number: BlockNumberFor) { GearProgram::on_initialize(new_block_number); GearMessenger::on_initialize(new_block_number); Gear::on_initialize(new_block_number); + GearBank::on_initialize(new_block_number); GearGas::on_initialize(new_block_number); // Session::on_initialize(new_block_number); } @@ -71,6 +72,7 @@ pub(crate) fn on_finalize(current_blk: BlockNumberFor) { GearPayment::on_finalize(current_blk); GearGas::on_finalize(current_blk); Gear::on_finalize(current_blk); + GearBank::on_finalize(current_blk); GearMessenger::on_finalize(current_blk); GearProgram::on_finalize(current_blk); Treasury::on_finalize(current_blk); diff --git a/utils/runtime-fuzzer/src/runtime/block.rs b/utils/runtime-fuzzer/src/runtime/block.rs index fa052dcfb4c..01358bbfb3a 100644 --- a/utils/runtime-fuzzer/src/runtime/block.rs +++ b/utils/runtime-fuzzer/src/runtime/block.rs @@ -30,8 +30,8 @@ use sp_consensus_babe::{ use sp_consensus_slots::Slot; use sp_runtime::{Digest, DigestItem, Perbill}; use vara_runtime::{ - Authorship, BlockGasLimit, Gear, GearGas, GearMessenger, Runtime, RuntimeBlockWeights, - RuntimeEvent, System, TransactionPayment, + Authorship, BlockGasLimit, Gear, GearBank, GearGas, GearMessenger, Runtime, + RuntimeBlockWeights, RuntimeEvent, System, TransactionPayment, }; /// This is not set to `BlockGasLimitOf::::get`, because of the @@ -51,6 +51,7 @@ pub fn run_to_next_block() { fn run_to_block(n: u32) { while System::block_number() < n { System::on_finalize(System::block_number()); + GearBank::on_finalize(System::block_number()); initialize(System::block_number() + 1); on_initialize(); @@ -95,12 +96,14 @@ pub(super) fn on_initialize() { GearGas::on_initialize(System::block_number()); GearMessenger::on_initialize(System::block_number()); Gear::on_initialize(System::block_number()); + GearBank::on_initialize(System::block_number()); } /// Run on_finalize hooks in pallets reversed order, as they appear in `vara_runtime`. fn on_finalize_without_system() { let bn = System::block_number(); Gear::on_finalize(bn); + GearBank::on_finalize(bn); GearMessenger::on_finalize(bn); GearGas::on_finalize(bn); TransactionPayment::on_finalize(bn); From b74b8b265bbf33b169e2d00e41691b4e3a5f7b06 Mon Sep 17 00:00:00 2001 From: Dmitrii Novikov Date: Tue, 7 May 2024 15:30:50 +0400 Subject: [PATCH 2/3] chores(workspace): Bump crates and runtime spec versions (#3946) --- Cargo.lock | 128 ++++++++++++++++++++-------------------- Cargo.toml | 2 +- runtime/vara/src/lib.rs | 2 +- 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b534cd3b83..f0e2c07c465 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ dependencies = [ [[package]] name = "actor-system-error" -version = "1.3.0" +version = "1.3.1" dependencies = [ "derive_more", ] @@ -1218,7 +1218,7 @@ dependencies = [ [[package]] name = "calc-stack-height" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "env_logger", @@ -1242,7 +1242,7 @@ dependencies = [ [[package]] name = "cargo-gbuild" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "cargo_toml", @@ -1905,7 +1905,7 @@ dependencies = [ [[package]] name = "crates-io" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "cargo_metadata 0.18.1", @@ -4140,14 +4140,14 @@ dependencies = [ [[package]] name = "galloc" -version = "1.3.0" +version = "1.3.1" dependencies = [ "gear-dlmalloc", ] [[package]] name = "gbuiltin-bls381" -version = "1.3.0" +version = "1.3.1" dependencies = [ "ark-bls12-381", "ark-ec", @@ -4160,7 +4160,7 @@ dependencies = [ [[package]] name = "gcli" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "async-trait", @@ -4200,7 +4200,7 @@ dependencies = [ [[package]] name = "gclient" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "ark-bls12-381", @@ -4248,7 +4248,7 @@ dependencies = [ [[package]] name = "gcore" -version = "1.3.0" +version = "1.3.1" dependencies = [ "galloc", "gear-core-errors", @@ -4260,7 +4260,7 @@ dependencies = [ [[package]] name = "gear-authorship" -version = "1.3.0" +version = "1.3.1" dependencies = [ "demo-constructor", "env_logger", @@ -4332,7 +4332,7 @@ dependencies = [ [[package]] name = "gear-cli" -version = "1.3.0" +version = "1.3.1" dependencies = [ "clap 4.5.4", "frame-benchmarking", @@ -4363,7 +4363,7 @@ dependencies = [ [[package]] name = "gear-common" -version = "1.3.0" +version = "1.3.1" dependencies = [ "derive_more", "enum-iterator 1.5.0", @@ -4389,7 +4389,7 @@ dependencies = [ [[package]] name = "gear-common-codegen" -version = "1.3.0" +version = "1.3.1" dependencies = [ "quote", "syn 2.0.60", @@ -4397,7 +4397,7 @@ dependencies = [ [[package]] name = "gear-core" -version = "1.3.0" +version = "1.3.1" dependencies = [ "blake2-rfc", "byteorder", @@ -4424,7 +4424,7 @@ dependencies = [ [[package]] name = "gear-core-backend" -version = "1.3.0" +version = "1.3.1" dependencies = [ "actor-system-error", "blake2-rfc", @@ -4442,7 +4442,7 @@ dependencies = [ [[package]] name = "gear-core-errors" -version = "1.3.0" +version = "1.3.1" dependencies = [ "derive_more", "enum-iterator 1.5.0", @@ -4452,7 +4452,7 @@ dependencies = [ [[package]] name = "gear-core-processor" -version = "1.3.0" +version = "1.3.1" dependencies = [ "actor-system-error", "derive_more", @@ -4484,7 +4484,7 @@ dependencies = [ [[package]] name = "gear-key-finder" -version = "1.3.0" +version = "1.3.1" dependencies = [ "directories", "hex", @@ -4492,7 +4492,7 @@ dependencies = [ [[package]] name = "gear-lazy-pages" -version = "1.3.0" +version = "1.3.1" dependencies = [ "cfg-if", "derive_more", @@ -4514,7 +4514,7 @@ dependencies = [ [[package]] name = "gear-lazy-pages-common" -version = "1.3.0" +version = "1.3.1" dependencies = [ "gear-core", "num_enum", @@ -4523,7 +4523,7 @@ dependencies = [ [[package]] name = "gear-lazy-pages-interface" -version = "1.3.0" +version = "1.3.1" dependencies = [ "byteorder", "gear-common", @@ -4536,7 +4536,7 @@ dependencies = [ [[package]] name = "gear-node-loader" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "clap 4.5.4", @@ -4564,7 +4564,7 @@ dependencies = [ [[package]] name = "gear-node-testing" -version = "1.3.0" +version = "1.3.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -4644,7 +4644,7 @@ dependencies = [ [[package]] name = "gear-runtime-common" -version = "1.3.0" +version = "1.3.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -4669,7 +4669,7 @@ dependencies = [ [[package]] name = "gear-runtime-interface" -version = "1.3.0" +version = "1.3.1" dependencies = [ "byteorder", "gear-core", @@ -4687,7 +4687,7 @@ dependencies = [ [[package]] name = "gear-runtime-primitives" -version = "1.3.0" +version = "1.3.1" dependencies = [ "sp-core", "sp-runtime", @@ -4695,7 +4695,7 @@ dependencies = [ [[package]] name = "gear-sandbox" -version = "1.3.0" +version = "1.3.1" dependencies = [ "assert_matches", "gear-runtime-interface", @@ -4711,7 +4711,7 @@ dependencies = [ [[package]] name = "gear-sandbox-env" -version = "1.3.0" +version = "1.3.1" dependencies = [ "parity-scale-codec", "sp-debug-derive", @@ -4721,7 +4721,7 @@ dependencies = [ [[package]] name = "gear-sandbox-host" -version = "1.3.0" +version = "1.3.1" dependencies = [ "environmental", "gear-sandbox-env", @@ -4740,7 +4740,7 @@ dependencies = [ [[package]] name = "gear-service" -version = "1.3.0" +version = "1.3.1" dependencies = [ "frame-benchmarking", "frame-benchmarking-cli", @@ -4818,7 +4818,7 @@ dependencies = [ [[package]] name = "gear-ss58" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "blake2", @@ -4827,14 +4827,14 @@ dependencies = [ [[package]] name = "gear-stack-buffer" -version = "1.3.0" +version = "1.3.1" dependencies = [ "cc", ] [[package]] name = "gear-utils" -version = "1.3.0" +version = "1.3.1" dependencies = [ "env_logger", "gear-core", @@ -4870,7 +4870,7 @@ checksum = "bbfbfa701dc65e683fcd2fb24f046bcef22634acbdf47ad14724637dc39ad05b" [[package]] name = "gear-wasm-builder" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "cargo_metadata 0.18.1", @@ -4922,7 +4922,7 @@ dependencies = [ [[package]] name = "gear-wasm-instrument" -version = "1.3.0" +version = "1.3.1" dependencies = [ "derive_more", "enum-iterator 1.5.0", @@ -5090,7 +5090,7 @@ dependencies = [ [[package]] name = "gmeta" -version = "1.3.0" +version = "1.3.1" dependencies = [ "blake2-rfc", "derive_more", @@ -5104,7 +5104,7 @@ dependencies = [ [[package]] name = "gmeta-codegen" -version = "1.3.0" +version = "1.3.1" dependencies = [ "gmeta", "gstd", @@ -5117,7 +5117,7 @@ dependencies = [ [[package]] name = "gring" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "base64 0.21.7", @@ -5149,7 +5149,7 @@ dependencies = [ [[package]] name = "gsdk" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "base64 0.21.7", @@ -5205,7 +5205,7 @@ dependencies = [ [[package]] name = "gsdk-codegen" -version = "1.3.0" +version = "1.3.1" dependencies = [ "proc-macro2", "quote", @@ -5214,7 +5214,7 @@ dependencies = [ [[package]] name = "gstd" -version = "1.3.0" +version = "1.3.1" dependencies = [ "arrayvec 0.7.4", "const_format", @@ -5233,7 +5233,7 @@ dependencies = [ [[package]] name = "gstd-codegen" -version = "1.3.0" +version = "1.3.1" dependencies = [ "gear-ss58", "gstd", @@ -5246,11 +5246,11 @@ dependencies = [ [[package]] name = "gsys" -version = "1.3.0" +version = "1.3.1" [[package]] name = "gtest" -version = "1.3.0" +version = "1.3.1" dependencies = [ "cargo_toml", "colored", @@ -7605,7 +7605,7 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "numerated" -version = "1.3.0" +version = "1.3.1" dependencies = [ "derive_more", "env_logger", @@ -7938,7 +7938,7 @@ dependencies = [ [[package]] name = "pallet-gear" -version = "1.3.0" +version = "1.3.1" dependencies = [ "blake2-rfc", "demo-async", @@ -8037,7 +8037,7 @@ dependencies = [ [[package]] name = "pallet-gear-bank" -version = "1.3.0" +version = "1.3.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -8055,7 +8055,7 @@ dependencies = [ [[package]] name = "pallet-gear-builtin" -version = "1.3.0" +version = "1.3.1" dependencies = [ "ark-bls12-381", "ark-ec", @@ -8101,7 +8101,7 @@ dependencies = [ [[package]] name = "pallet-gear-builtin-rpc" -version = "1.3.0" +version = "1.3.1" dependencies = [ "jsonrpsee 0.16.3", "pallet-gear-builtin-rpc-runtime-api", @@ -8113,7 +8113,7 @@ dependencies = [ [[package]] name = "pallet-gear-builtin-rpc-runtime-api" -version = "1.3.0" +version = "1.3.1" dependencies = [ "sp-api", "sp-core", @@ -8121,7 +8121,7 @@ dependencies = [ [[package]] name = "pallet-gear-debug" -version = "1.3.0" +version = "1.3.1" dependencies = [ "demo-vec", "env_logger", @@ -8156,7 +8156,7 @@ dependencies = [ [[package]] name = "pallet-gear-gas" -version = "1.3.0" +version = "1.3.1" dependencies = [ "env_logger", "frame-benchmarking", @@ -8184,7 +8184,7 @@ dependencies = [ [[package]] name = "pallet-gear-messenger" -version = "1.3.0" +version = "1.3.1" dependencies = [ "env_logger", "frame-benchmarking", @@ -8209,7 +8209,7 @@ dependencies = [ [[package]] name = "pallet-gear-payment" -version = "1.3.0" +version = "1.3.1" dependencies = [ "env_logger", "frame-benchmarking", @@ -8242,7 +8242,7 @@ dependencies = [ [[package]] name = "pallet-gear-proc-macro" -version = "1.3.0" +version = "1.3.1" dependencies = [ "proc-macro2", "quote", @@ -8251,7 +8251,7 @@ dependencies = [ [[package]] name = "pallet-gear-program" -version = "1.3.0" +version = "1.3.1" dependencies = [ "frame-support", "frame-system", @@ -8275,7 +8275,7 @@ dependencies = [ [[package]] name = "pallet-gear-rpc" -version = "1.3.0" +version = "1.3.1" dependencies = [ "gear-common", "gear-core", @@ -8291,7 +8291,7 @@ dependencies = [ [[package]] name = "pallet-gear-rpc-runtime-api" -version = "1.3.0" +version = "1.3.1" dependencies = [ "pallet-gear", "sp-api", @@ -8302,7 +8302,7 @@ dependencies = [ [[package]] name = "pallet-gear-scheduler" -version = "1.3.0" +version = "1.3.1" dependencies = [ "env_logger", "frame-benchmarking", @@ -8333,7 +8333,7 @@ dependencies = [ [[package]] name = "pallet-gear-staking-rewards" -version = "1.3.0" +version = "1.3.1" dependencies = [ "env_logger", "frame-benchmarking", @@ -8368,7 +8368,7 @@ dependencies = [ [[package]] name = "pallet-gear-staking-rewards-rpc" -version = "1.3.0" +version = "1.3.1" dependencies = [ "jsonrpsee 0.16.3", "pallet-gear-staking-rewards-rpc-runtime-api", @@ -8379,7 +8379,7 @@ dependencies = [ [[package]] name = "pallet-gear-staking-rewards-rpc-runtime-api" -version = "1.3.0" +version = "1.3.1" dependencies = [ "pallet-gear-staking-rewards", "sp-api", @@ -8387,7 +8387,7 @@ dependencies = [ [[package]] name = "pallet-gear-voucher" -version = "1.3.0" +version = "1.3.1" dependencies = [ "derive_more", "env_logger", @@ -14013,7 +14013,7 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "vara-runtime" -version = "1.3.0" +version = "1.3.1" dependencies = [ "const-str", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index d39553b4d33..f469c3952a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "1.3.0" +version = "1.3.1" authors = ["Gear Technologies"] edition = "2021" license = "GPL-3.0" diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index 72358ad7943..6e73607991a 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -156,7 +156,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // The version of the runtime specification. A full node will not attempt to use its native // runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`, // `spec_version`, and `authoring_version` are the same between Wasm and native. - spec_version: 1300, + spec_version: 1310, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 9221f1a388eea46e8efbb82be41a97b479e329f9 Mon Sep 17 00:00:00 2001 From: Dmitrii Novikov Date: Tue, 7 May 2024 15:33:27 +0400 Subject: [PATCH 3/3] refactor(runtime): Dump constants (existential deposit; min voucher duration) (#3944) --- runtime/vara/src/constants.rs | 2 +- runtime/vara/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/vara/src/constants.rs b/runtime/vara/src/constants.rs index 29e30126e63..096cb3bf232 100644 --- a/runtime/vara/src/constants.rs +++ b/runtime/vara/src/constants.rs @@ -27,7 +27,7 @@ pub mod currency { pub const ECONOMIC_CENTIUNITS: Balance = ECONOMIC_UNITS / 100; /// The existential deposit. - pub const EXISTENTIAL_DEPOSIT: Balance = 10 * UNITS; // 10 Vara + pub const EXISTENTIAL_DEPOSIT: Balance = UNITS; // 1 Vara /// The program rent cost per block. pub const RENT_COST_PER_BLOCK: Balance = 125_000_000; diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index 6e73607991a..a1f3204ac18 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -1111,7 +1111,7 @@ impl pallet_gear_payment::Config for Runtime { parameter_types! { pub const VoucherPalletId: PalletId = PalletId(*b"py/vouch"); - pub const MinVoucherDuration: BlockNumber = 30 * MINUTES; + pub const MinVoucherDuration: BlockNumber = MINUTES; pub const MaxVoucherDuration: BlockNumber = 3 * MONTHS; }