diff --git a/bridges/modules/beefy/src/lib.rs b/bridges/modules/beefy/src/lib.rs index ccddcde920f6..cc34dbfd20ce 100644 --- a/bridges/modules/beefy/src/lib.rs +++ b/bridges/modules/beefy/src/lib.rs @@ -283,7 +283,6 @@ pub mod pallet { /// The `RequestCount` is decreased by one at the beginning of every block. This is to ensure /// that the pallet can always make progress. #[pallet::storage] - #[pallet::getter(fn request_count)] pub type RequestCount, I: 'static = ()> = StorageValue<_, u32, ValueQuery>; /// High level info about the imported commitments. @@ -392,7 +391,7 @@ pub mod pallet { init_data: InitializationDataOf, ) -> Result<(), Error> { if init_data.authority_set.len == 0 { - return Err(Error::::InvalidInitialAuthoritySet) + return Err(Error::::InvalidInitialAuthoritySet); } CurrentAuthoritySetInfo::::put(init_data.authority_set); @@ -404,6 +403,13 @@ pub mod pallet { Ok(()) } + + impl, I: 'static> Pallet { + /// The current number of requests which have written to storage. + pub fn request_count() -> u32 { + RequestCount::::get() + } + } } #[cfg(test)] diff --git a/bridges/modules/grandpa/src/lib.rs b/bridges/modules/grandpa/src/lib.rs index c2c1218418fb..12014f00c7cf 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>; @@ -821,6 +820,13 @@ pub fn initialize_for_benchmarks, I: 'static>(header: BridgedHeader .expect("only used from benchmarks; benchmarks are correct; qed"); } +impl, I: 'static> Pallet { + /// Returns the hash of the best finalized header. + pub fn best_finalized() -> Option> { + BestFinalized::::get() + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index 61763186cb02..1e5764ae957e 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>; @@ -733,7 +731,7 @@ fn ensure_normal_operating_mode, I: 'static>() -> Result<(), Error< if PalletOperatingMode::::get() == MessagesOperatingMode::Basic(BasicOperatingMode::Normal) { - return Ok(()) + return Ok(()); } Err(Error::::NotOperatingNormally) diff --git a/bridges/modules/relayers/src/lib.rs b/bridges/modules/relayers/src/lib.rs index 0d0aa1b2ddf5..444c66da96ba 100644 --- a/bridges/modules/relayers/src/lib.rs +++ b/bridges/modules/relayers/src/lib.rs @@ -235,6 +235,30 @@ pub mod pallet { } impl, I: 'static> Pallet { + /// Relayers that have reserved some of their balance to get free priority boost + /// for their message delivery transactions. + pub fn registered_relayer( + relayer: &T::AccountId, + ) -> Option, T::Balance>> { + RegisteredRelayers::::get(relayer) + } + + /// Map of the relayer => accumulated reward. + pub fn relayer_reward( + key1: EncodeLikeAccountId, + key2: EncodeLikeReward, + ) -> Option< as StorageDoubleMapKeyProvider>::Value> + where + EncodeLikeAccountId: codec::EncodeLike< + as StorageDoubleMapKeyProvider>::Key1, + >, + EncodeLikeReward: codec::EncodeLike< + as StorageDoubleMapKeyProvider>::Key2, + >, + { + RelayerRewards::::get(key1, key2) + } + fn do_claim_rewards( relayer: T::AccountId, reward_kind: T::Reward, @@ -289,7 +313,7 @@ pub mod pallet { // registration is inactive if relayer stake is less than required if registration.stake < Self::required_stake() { - return false + return false; } // registration is inactive if it ends soon @@ -297,7 +321,7 @@ pub mod pallet { .valid_till .saturating_sub(frame_system::Pallet::::block_number()); if remaining_lease <= Self::required_registration_lease() { - return false + return false; } true @@ -319,7 +343,7 @@ pub mod pallet { relayer, ); - return + return; }, }; let slash_destination = slash_destination.into_account(); @@ -380,7 +404,7 @@ pub mod pallet { reward_balance: T::RewardBalance, ) { if reward_balance.is_zero() { - return + return; } RelayerRewards::::mutate( @@ -512,7 +536,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, @@ -530,7 +553,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, @@ -606,7 +628,8 @@ mod tests { 150, )); // check if registered - let registration = Pallet::::registered_relayer(REGISTER_RELAYER).unwrap(); + let registration = + Pallet::::registered_relayer(®ISTER_RELAYER).unwrap(); assert_eq!(registration, Registration { valid_till: 150, stake: Stake::get() }); // slash and deregister @@ -787,7 +810,7 @@ mod tests { )); assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get()); assert_eq!( - Pallet::::registered_relayer(REGISTER_RELAYER), + Pallet::::registered_relayer(®ISTER_RELAYER), Some(Registration { valid_till: 150, stake: Stake::get() }), ); @@ -855,7 +878,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), + Pallet::::registered_relayer(®ISTER_RELAYER), Some(Registration { valid_till: 150, stake: Stake::get() }), ); @@ -919,7 +942,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), + Pallet::::registered_relayer(®ISTER_RELAYER), Some(Registration { valid_till: 150, stake: Stake::get() }), ); diff --git a/bridges/modules/xcm-bridge-hub-router/src/lib.rs b/bridges/modules/xcm-bridge-hub-router/src/lib.rs index 7361696faba7..a12daedd102c 100644 --- a/bridges/modules/xcm-bridge-hub-router/src/lib.rs +++ b/bridges/modules/xcm-bridge-hub-router/src/lib.rs @@ -120,18 +120,18 @@ pub mod pallet { fn on_initialize(_n: BlockNumberFor) -> Weight { // if XCM channel is still congested, we don't change anything if T::LocalXcmChannelManager::is_congested(&T::SiblingBridgeHubLocation::get()) { - return T::WeightInfo::on_initialize_when_congested() + return T::WeightInfo::on_initialize_when_congested(); } // if bridge has reported congestion, we don't change anything let mut bridge = Self::bridge(); if bridge.is_congested { - return T::WeightInfo::on_initialize_when_congested() + return T::WeightInfo::on_initialize_when_congested(); } // if we can't decrease the delivery fee factor anymore, we don't change anything if bridge.delivery_fee_factor == MINIMAL_DELIVERY_FEE_FACTOR { - return T::WeightInfo::on_initialize_when_congested() + return T::WeightInfo::on_initialize_when_congested(); } let previous_factor = bridge.delivery_fee_factor; @@ -190,10 +190,14 @@ pub mod pallet { /// primitives (lane-id aka bridge-id, derived from XCM locations) to support multiple bridges /// by the same pallet instance. #[pallet::storage] - #[pallet::getter(fn bridge)] pub type Bridge, I: 'static = ()> = StorageValue<_, BridgeState, ValueQuery>; impl, I: 'static> Pallet { + /// Bridge that we are using. + pub fn bridge() -> BridgeState { + Bridge::::get() + } + /// Called when new message is sent (queued to local outbound XCM queue) over the bridge. pub(crate) fn on_message_sent_to_bridge(message_size: u32) { log::trace!( @@ -208,7 +212,7 @@ pub mod pallet { // if outbound queue is not congested AND bridge has not reported congestion, do // nothing if !is_channel_with_bridge_hub_congested && !is_bridge_congested { - return Err(()) + return Err(()); } // ok - we need to increase the fee factor, let's do that @@ -276,7 +280,7 @@ impl, I: 'static> ExporterFor for Pallet { target: LOG_TARGET, "Router with bridged_network_id {bridged_network:?} does not support bridging to network {network:?}!", ); - return None + return None; } } @@ -298,7 +302,7 @@ impl, I: 'static> ExporterFor for Pallet { network, remote_location, ); - return None + return None; }, }; @@ -318,7 +322,7 @@ impl, I: 'static> ExporterFor for Pallet { network, remote_location, ); - return None + return None; }, }, None => 0, @@ -388,7 +392,7 @@ impl, I: 'static> SendXcm for Pallet { // better to drop such messages here rather than at the bridge hub. Let's check the // message size." if message_size > HARD_MESSAGE_SIZE_LIMIT { - return Err(SendError::ExceedsMaxMessageSize) + return Err(SendError::ExceedsMaxMessageSize); } // We need to ensure that the known `dest`'s XCM version can comprehend the current diff --git a/bridges/primitives/runtime/src/lib.rs b/bridges/primitives/runtime/src/lib.rs index 85525f0eb1bd..ca35475f727b 100644 --- a/bridges/primitives/runtime/src/lib.rs +++ b/bridges/primitives/runtime/src/lib.rs @@ -425,6 +425,20 @@ pub trait OwnedBridgeModule { log::info!(target: Self::LOG_TARGET, "Setting operating mode to {:?}.", operating_mode); Ok(()) } + + /// Pallet owner has a right to halt all module operations and then resume it. If it is `None`, + /// then there are no direct ways to halt/resume module operations, but other runtime methods + /// may still be used to do that (i.e. democracy::referendum to update halt flag directly + /// or call the `set_operating_mode`). + fn module_owner() -> Option { + Self::OwnerStorage::get() + } + + /// The current operating mode of the module. + /// Depending on the mode either all, some, or no transactions will be allowed. + fn operating_mode() -> Self::OperatingMode { + Self::OperatingModeStorage::get() + } } /// All extra operations with weights that we need in bridges. diff --git a/prdoc/pr_7120.prdoc b/prdoc/pr_7120.prdoc new file mode 100644 index 000000000000..de5e36ac2d32 --- /dev/null +++ b/prdoc/pr_7120.prdoc @@ -0,0 +1,19 @@ +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: major + - name: pallet-bridge-relayers + bump: minor + - name: bp-runtime + bump: minor + - name: pallet-bridge-beefy + bump: minor + - name: pallet-xcm-bridge-hub-router + bump: patch