From 72ac9bf294fd36562d3a1b9c242a9572515ccb91 Mon Sep 17 00:00:00 2001 From: Matteo Muraca Date: Sun, 12 Jan 2025 15:55:24 +0100 Subject: [PATCH 1/7] removed pallet::getter from pallet-bridge-grandpa --- bridges/modules/grandpa/src/lib.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/bridges/modules/grandpa/src/lib.rs b/bridges/modules/grandpa/src/lib.rs index 22a15ec4062f..e0065fe7a3d0 100644 --- a/bridges/modules/grandpa/src/lib.rs +++ b/bridges/modules/grandpa/src/lib.rs @@ -418,7 +418,6 @@ pub mod pallet { /// Hash of the best finalized header. #[pallet::storage] - #[pallet::getter(fn best_finalized)] pub type BestFinalized, I: 'static = ()> = StorageValue<_, BridgedBlockId, OptionQuery>; @@ -789,12 +788,9 @@ where pub fn synced_headers_grandpa_info() -> Vec>> { frame_system::Pallet::::read_events_no_consensus() .filter_map(|event| { - if let Event::::UpdatedBestFinalizedHeader { grandpa_info, .. } = - event.event.try_into().ok()? - { - return Some(grandpa_info) - } - None + let Event::::UpdatedBestFinalizedHeader { grandpa_info, .. } = + event.event.try_into().ok()?; + Some(grandpa_info) }) .collect() } @@ -995,7 +991,6 @@ mod tests { fn init_storage_entries_are_correctly_initialized() { run_test(|| { assert_eq!(BestFinalized::::get(), None,); - assert_eq!(Pallet::::best_finalized(), None); assert_eq!(PalletOperatingMode::::try_get(), Err(())); let init_data = init_with_origin(RuntimeOrigin::root()).unwrap(); @@ -1637,7 +1632,7 @@ mod tests { run_test(|| { initialize_substrate_bridge(); assert_ok!(submit_finality_proof(1)); - let first_header_hash = Pallet::::best_finalized().unwrap().hash(); + let first_header_hash = BestFinalized::::get().unwrap().hash(); next_block(); assert_ok!(submit_finality_proof(2)); From c4a68d3f67f1a7a64f292f6c4ab3a2bdee40a799 Mon Sep 17 00:00:00 2001 From: Matteo Muraca Date: Sun, 12 Jan 2025 15:58:58 +0100 Subject: [PATCH 2/7] removed pallet::getter from pallet-bridge-messages --- bridges/modules/messages/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index af14257db99c..b197746ea50e 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -506,14 +506,12 @@ pub mod pallet { /// runtime methods may still be used to do that (i.e. democracy::referendum to update halt /// flag directly or call the `set_operating_mode`). #[pallet::storage] - #[pallet::getter(fn module_owner)] pub type PalletOwner, I: 'static = ()> = StorageValue<_, T::AccountId>; /// The current operating mode of the pallet. /// /// Depending on the mode either all, some, or no transactions will be allowed. #[pallet::storage] - #[pallet::getter(fn operating_mode)] pub type PalletOperatingMode, I: 'static = ()> = StorageValue<_, MessagesOperatingMode, ValueQuery>; From 91e6411c08ad228b6cc53fb4782de317bc2eefab Mon Sep 17 00:00:00 2001 From: Matteo Muraca Date: Sun, 12 Jan 2025 17:23:58 +0100 Subject: [PATCH 3/7] fix bridge hub runtimes --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 5 +++-- .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 35af034310d9..6fcdefdf4a47 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -62,6 +62,7 @@ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_state, get_preset}, + instances::{Instance3, Instance4}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, Get, TransformOrigin}, weights::{ConstantMultiplier, Weight, WeightToFee as _}, @@ -916,7 +917,7 @@ impl_runtime_apis! { impl bp_westend::WestendFinalityApi for Runtime { fn best_finalized() -> Option> { - BridgeWestendGrandpa::best_finalized() + pallet_bridge_grandpa::BestFinalized::::get() } fn free_headers_interval() -> Option { for Runtime { fn best_finalized() -> Option> { - BridgePolkadotBulletinGrandpa::best_finalized() + pallet_bridge_grandpa::BestFinalized::::get() } fn free_headers_interval() -> Option { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 2c2e01b4d21d..5ddfaff72d88 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -63,6 +63,7 @@ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_state, get_preset}, + instances::Instance1, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, Get, TransformOrigin}, weights::{ConstantMultiplier, Weight, WeightToFee as _}, @@ -849,7 +850,7 @@ impl_runtime_apis! { impl bp_rococo::RococoFinalityApi for Runtime { fn best_finalized() -> Option> { - BridgeRococoGrandpa::best_finalized() + pallet_bridge_grandpa::BestFinalized::::get() } fn free_headers_interval() -> Option { Date: Sun, 12 Jan 2025 17:29:58 +0100 Subject: [PATCH 4/7] removed pallet::getter from pallet-bridge-relayers --- bridges/modules/relayers/src/extension/mod.rs | 18 +++++++++--------- bridges/modules/relayers/src/lib.rs | 10 ++++------ .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- .../bridge-hubs/bridge-hub-westend/src/lib.rs | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/bridges/modules/relayers/src/extension/mod.rs b/bridges/modules/relayers/src/extension/mod.rs index d562ed9bcd0e..d93e45eb8b78 100644 --- a/bridges/modules/relayers/src/extension/mod.rs +++ b/bridges/modules/relayers/src/extension/mod.rs @@ -444,7 +444,7 @@ where #[cfg(test)] mod tests { use super::*; - use crate::mock::*; + use crate::{mock::*, RelayerRewards}; use bp_header_chain::{StoredHeaderDataBuilder, SubmitFinalityProofInfo}; use bp_messages::{ @@ -1788,7 +1788,7 @@ mod tests { let regular_reward = expected_delivery_reward(); run_post_dispatch(Some(pre_dispatch_data), Ok(())); assert_eq!( - RelayersPallet::::relayer_reward( + RelayerRewards::::get( relayer_account_at_this_chain(), MsgProofsRewardsAccount::get() ), @@ -1807,7 +1807,7 @@ mod tests { _ => unreachable!(), } run_post_dispatch(Some(pre_dispatch_data), Ok(())); - let reward_after_two_calls = RelayersPallet::::relayer_reward( + let reward_after_two_calls = RelayerRewards::::get( relayer_account_at_this_chain(), MsgProofsRewardsAccount::get(), ) @@ -1828,7 +1828,7 @@ mod tests { run_post_dispatch(Some(all_finality_pre_dispatch_data()), Ok(())); assert_eq!( - RelayersPallet::::relayer_reward( + RelayerRewards::::get( relayer_account_at_this_chain(), MsgProofsRewardsAccount::get() ), @@ -1837,7 +1837,7 @@ mod tests { run_post_dispatch(Some(all_finality_confirmation_pre_dispatch_data()), Ok(())); assert_eq!( - RelayersPallet::::relayer_reward( + RelayerRewards::::get( relayer_account_at_this_chain(), MsgDeliveryProofsRewardsAccount::get() ), @@ -1853,7 +1853,7 @@ mod tests { run_post_dispatch(Some(parachain_finality_pre_dispatch_data()), Ok(())); assert_eq!( - RelayersPallet::::relayer_reward( + RelayerRewards::::get( relayer_account_at_this_chain(), MsgProofsRewardsAccount::get() ), @@ -1862,7 +1862,7 @@ mod tests { run_post_dispatch(Some(parachain_finality_confirmation_pre_dispatch_data()), Ok(())); assert_eq!( - RelayersPallet::::relayer_reward( + RelayerRewards::::get( relayer_account_at_this_chain(), MsgDeliveryProofsRewardsAccount::get() ), @@ -1878,7 +1878,7 @@ mod tests { run_post_dispatch(Some(delivery_pre_dispatch_data()), Ok(())); assert_eq!( - RelayersPallet::::relayer_reward( + RelayerRewards::::get( relayer_account_at_this_chain(), MsgProofsRewardsAccount::get() ), @@ -1887,7 +1887,7 @@ mod tests { run_post_dispatch(Some(confirmation_pre_dispatch_data()), Ok(())); assert_eq!( - RelayersPallet::::relayer_reward( + RelayerRewards::::get( relayer_account_at_this_chain(), MsgDeliveryProofsRewardsAccount::get() ), diff --git a/bridges/modules/relayers/src/lib.rs b/bridges/modules/relayers/src/lib.rs index d1c71b6d3051..cb8266a9be17 100644 --- a/bridges/modules/relayers/src/lib.rs +++ b/bridges/modules/relayers/src/lib.rs @@ -238,7 +238,7 @@ pub mod pallet { /// it'll return false if registered stake is lower than required or if remaining lease /// is less than `RequiredRegistrationLease`. pub fn is_registration_active(relayer: &T::AccountId) -> bool { - let registration = match Self::registered_relayer(relayer) { + let registration = match RegisteredRelayers::::get(relayer) { Some(registration) => registration, None => return false, }; @@ -459,7 +459,6 @@ pub mod pallet { /// Map of the relayer => accumulated reward. #[pallet::storage] - #[pallet::getter(fn relayer_reward)] pub type RelayerRewards, I: 'static = ()> = StorageDoubleMap< _, as StorageDoubleMapKeyProvider>::Hasher1, @@ -477,7 +476,6 @@ pub mod pallet { /// priority and will be rejected (without significant tip) in case if registered /// relayer is present. #[pallet::storage] - #[pallet::getter(fn registered_relayer)] pub type RegisteredRelayers, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -690,7 +688,7 @@ mod tests { )); assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get()); assert_eq!( - Pallet::::registered_relayer(REGISTER_RELAYER), + RegisteredRelayers::::get(REGISTER_RELAYER), Some(Registration { valid_till: 150, stake: Stake::get() }), ); @@ -758,7 +756,7 @@ mod tests { assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get()); assert_eq!(Balances::free_balance(REGISTER_RELAYER), free_balance + 1); assert_eq!( - Pallet::::registered_relayer(REGISTER_RELAYER), + RegisteredRelayers::::get(REGISTER_RELAYER), Some(Registration { valid_till: 150, stake: Stake::get() }), ); @@ -822,7 +820,7 @@ mod tests { assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get()); assert_eq!(Balances::free_balance(REGISTER_RELAYER), free_balance - 1); assert_eq!( - Pallet::::registered_relayer(REGISTER_RELAYER), + RegisteredRelayers::::get(REGISTER_RELAYER), Some(Registration { valid_till: 150, stake: Stake::get() }), ); diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 6fcdefdf4a47..44a1832fda71 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1344,7 +1344,7 @@ impl_runtime_apis! { let bench_lane_id = >::bench_lane_id(); use bp_runtime::Chain; let bridged_chain_id =>::BridgedChain::ID; - pallet_bridge_relayers::Pallet::::relayer_reward( + pallet_bridge_relayers::RelayerRewards::::get( relayer, bp_relayers::RewardsAccountParams::new( bench_lane_id, diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 5ddfaff72d88..5bd2cf8b82d0 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -1225,7 +1225,7 @@ impl_runtime_apis! { let bench_lane_id = >::bench_lane_id(); use bp_runtime::Chain; let bridged_chain_id =>::BridgedChain::ID; - pallet_bridge_relayers::Pallet::::relayer_reward( + pallet_bridge_relayers::RelayerRewards::::get( relayer, bp_relayers::RewardsAccountParams::new( bench_lane_id, From a7abd921bccdb300ddf9037654b43c1c2f0810d3 Mon Sep 17 00:00:00 2001 From: Matteo Muraca Date: Sun, 12 Jan 2025 17:35:01 +0100 Subject: [PATCH 5/7] prdoc & fix --- prdoc/pr_7120.prdoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 prdoc/pr_7120.prdoc diff --git a/prdoc/pr_7120.prdoc b/prdoc/pr_7120.prdoc new file mode 100644 index 000000000000..d76147239b1a --- /dev/null +++ b/prdoc/pr_7120.prdoc @@ -0,0 +1,17 @@ +title: Remove pallet::getter from bridges/modules +doc: + - audience: Runtime Dev + description: | + This PR removes all pallet::getter occurrences from pallet-bridge-grandpa, pallet-bridge-messages and pallet-bridge-relayers and replaces them with explicit implementations. + +crates: + - name: pallet-bridge-grandpa + bump: patch + - name: pallet-bridge-messages + bump: patch + - name: pallet-bridge-relayers + bump: patch + - name: bridge-hub-rococo-runtime + bump: patch + - name: bridge-hub-westend-runtime + bump: patch From d6d2c498710232e287ad20b450ec90fbf4e5e043 Mon Sep 17 00:00:00 2001 From: Matteo Muraca Date: Sun, 12 Jan 2025 17:35:42 +0100 Subject: [PATCH 6/7] fix --- bridges/modules/grandpa/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bridges/modules/grandpa/src/lib.rs b/bridges/modules/grandpa/src/lib.rs index e0065fe7a3d0..1b5e6c623e36 100644 --- a/bridges/modules/grandpa/src/lib.rs +++ b/bridges/modules/grandpa/src/lib.rs @@ -788,9 +788,12 @@ where pub fn synced_headers_grandpa_info() -> Vec>> { frame_system::Pallet::::read_events_no_consensus() .filter_map(|event| { - let Event::::UpdatedBestFinalizedHeader { grandpa_info, .. } = - event.event.try_into().ok()?; - Some(grandpa_info) + if let Event::::UpdatedBestFinalizedHeader { grandpa_info, .. } = + event.event.try_into().ok()? + { + return Some(grandpa_info) + } + None }) .collect() } From dfce5dc8de9a2317a6651611c5e5f58104e1caeb Mon Sep 17 00:00:00 2001 From: Matteo Muraca Date: Sun, 12 Jan 2025 17:36:05 +0100 Subject: [PATCH 7/7] fix --- bridges/modules/grandpa/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/modules/grandpa/src/lib.rs b/bridges/modules/grandpa/src/lib.rs index 1b5e6c623e36..f89ac906c63d 100644 --- a/bridges/modules/grandpa/src/lib.rs +++ b/bridges/modules/grandpa/src/lib.rs @@ -788,7 +788,7 @@ where pub fn synced_headers_grandpa_info() -> Vec>> { frame_system::Pallet::::read_events_no_consensus() .filter_map(|event| { - if let Event::::UpdatedBestFinalizedHeader { grandpa_info, .. } = + if let Event::::UpdatedBestFinalizedHeader { grandpa_info, .. } = event.event.try_into().ok()? { return Some(grandpa_info)