Skip to content

Commit 66e3196

Browse files
muracabkonturgithub-actions[bot]
authored
Remove pallet::getter usage from bridges/modules (#7120)
# Description Part of #3326 As per title, the `pallet:getter` usage has been removed from: - `pallet-bridge-beefy` - `pallet-bridge-grandpa` - `pallet-bridge-messages` - `pallet-bridge-relayers` - `pallet-xcm-bridge-hub-router` polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp --------- Co-authored-by: Branislav Kontur <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent ab7c608 commit 66e3196

File tree

7 files changed

+95
-25
lines changed

7 files changed

+95
-25
lines changed

bridges/modules/beefy/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ pub mod pallet {
283283
/// The `RequestCount` is decreased by one at the beginning of every block. This is to ensure
284284
/// that the pallet can always make progress.
285285
#[pallet::storage]
286-
#[pallet::getter(fn request_count)]
287286
pub type RequestCount<T: Config<I>, I: 'static = ()> = StorageValue<_, u32, ValueQuery>;
288287

289288
/// High level info about the imported commitments.
@@ -392,7 +391,7 @@ pub mod pallet {
392391
init_data: InitializationDataOf<T, I>,
393392
) -> Result<(), Error<T, I>> {
394393
if init_data.authority_set.len == 0 {
395-
return Err(Error::<T, I>::InvalidInitialAuthoritySet)
394+
return Err(Error::<T, I>::InvalidInitialAuthoritySet);
396395
}
397396
CurrentAuthoritySetInfo::<T, I>::put(init_data.authority_set);
398397

@@ -404,6 +403,13 @@ pub mod pallet {
404403

405404
Ok(())
406405
}
406+
407+
impl<T: Config<I>, I: 'static> Pallet<T, I> {
408+
/// The current number of requests which have written to storage.
409+
pub fn request_count() -> u32 {
410+
RequestCount::<T, I>::get()
411+
}
412+
}
407413
}
408414

409415
#[cfg(test)]

bridges/modules/grandpa/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ pub mod pallet {
418418

419419
/// Hash of the best finalized header.
420420
#[pallet::storage]
421-
#[pallet::getter(fn best_finalized)]
422421
pub type BestFinalized<T: Config<I>, I: 'static = ()> =
423422
StorageValue<_, BridgedBlockId<T, I>, OptionQuery>;
424423

@@ -821,6 +820,13 @@ pub fn initialize_for_benchmarks<T: Config<I>, I: 'static>(header: BridgedHeader
821820
.expect("only used from benchmarks; benchmarks are correct; qed");
822821
}
823822

823+
impl<T: Config<I>, I: 'static> Pallet<T, I> {
824+
/// Returns the hash of the best finalized header.
825+
pub fn best_finalized() -> Option<BridgedBlockId<T, I>> {
826+
BestFinalized::<T, I>::get()
827+
}
828+
}
829+
824830
#[cfg(test)]
825831
mod tests {
826832
use super::*;

bridges/modules/messages/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,12 @@ pub mod pallet {
506506
/// runtime methods may still be used to do that (i.e. democracy::referendum to update halt
507507
/// flag directly or call the `set_operating_mode`).
508508
#[pallet::storage]
509-
#[pallet::getter(fn module_owner)]
510509
pub type PalletOwner<T: Config<I>, I: 'static = ()> = StorageValue<_, T::AccountId>;
511510

512511
/// The current operating mode of the pallet.
513512
///
514513
/// Depending on the mode either all, some, or no transactions will be allowed.
515514
#[pallet::storage]
516-
#[pallet::getter(fn operating_mode)]
517515
pub type PalletOperatingMode<T: Config<I>, I: 'static = ()> =
518516
StorageValue<_, MessagesOperatingMode, ValueQuery>;
519517

@@ -733,7 +731,7 @@ fn ensure_normal_operating_mode<T: Config<I>, I: 'static>() -> Result<(), Error<
733731
if PalletOperatingMode::<T, I>::get() ==
734732
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
735733
{
736-
return Ok(())
734+
return Ok(());
737735
}
738736

739737
Err(Error::<T, I>::NotOperatingNormally)

bridges/modules/relayers/src/lib.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,30 @@ pub mod pallet {
235235
}
236236

237237
impl<T: Config<I>, I: 'static> Pallet<T, I> {
238+
/// Relayers that have reserved some of their balance to get free priority boost
239+
/// for their message delivery transactions.
240+
pub fn registered_relayer(
241+
relayer: &T::AccountId,
242+
) -> Option<Registration<BlockNumberFor<T>, T::Balance>> {
243+
RegisteredRelayers::<T, I>::get(relayer)
244+
}
245+
246+
/// Map of the relayer => accumulated reward.
247+
pub fn relayer_reward<EncodeLikeAccountId, EncodeLikeReward>(
248+
key1: EncodeLikeAccountId,
249+
key2: EncodeLikeReward,
250+
) -> Option<<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Value>
251+
where
252+
EncodeLikeAccountId: codec::EncodeLike<
253+
<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Key1,
254+
>,
255+
EncodeLikeReward: codec::EncodeLike<
256+
<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Key2,
257+
>,
258+
{
259+
RelayerRewards::<T, I>::get(key1, key2)
260+
}
261+
238262
fn do_claim_rewards(
239263
relayer: T::AccountId,
240264
reward_kind: T::Reward,
@@ -289,15 +313,15 @@ pub mod pallet {
289313

290314
// registration is inactive if relayer stake is less than required
291315
if registration.stake < Self::required_stake() {
292-
return false
316+
return false;
293317
}
294318

295319
// registration is inactive if it ends soon
296320
let remaining_lease = registration
297321
.valid_till
298322
.saturating_sub(frame_system::Pallet::<T>::block_number());
299323
if remaining_lease <= Self::required_registration_lease() {
300-
return false
324+
return false;
301325
}
302326

303327
true
@@ -319,7 +343,7 @@ pub mod pallet {
319343
relayer,
320344
);
321345

322-
return
346+
return;
323347
},
324348
};
325349
let slash_destination = slash_destination.into_account();
@@ -380,7 +404,7 @@ pub mod pallet {
380404
reward_balance: T::RewardBalance,
381405
) {
382406
if reward_balance.is_zero() {
383-
return
407+
return;
384408
}
385409

386410
RelayerRewards::<T, I>::mutate(
@@ -512,7 +536,6 @@ pub mod pallet {
512536

513537
/// Map of the relayer => accumulated reward.
514538
#[pallet::storage]
515-
#[pallet::getter(fn relayer_reward)]
516539
pub type RelayerRewards<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
517540
_,
518541
<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Hasher1,
@@ -530,7 +553,6 @@ pub mod pallet {
530553
/// priority and will be rejected (without significant tip) in case if registered
531554
/// relayer is present.
532555
#[pallet::storage]
533-
#[pallet::getter(fn registered_relayer)]
534556
pub type RegisteredRelayers<T: Config<I>, I: 'static = ()> = StorageMap<
535557
_,
536558
Blake2_128Concat,
@@ -606,7 +628,8 @@ mod tests {
606628
150,
607629
));
608630
// check if registered
609-
let registration = Pallet::<TestRuntime>::registered_relayer(REGISTER_RELAYER).unwrap();
631+
let registration =
632+
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER).unwrap();
610633
assert_eq!(registration, Registration { valid_till: 150, stake: Stake::get() });
611634

612635
// slash and deregister
@@ -787,7 +810,7 @@ mod tests {
787810
));
788811
assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get());
789812
assert_eq!(
790-
Pallet::<TestRuntime>::registered_relayer(REGISTER_RELAYER),
813+
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER),
791814
Some(Registration { valid_till: 150, stake: Stake::get() }),
792815
);
793816

@@ -855,7 +878,7 @@ mod tests {
855878
assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get());
856879
assert_eq!(Balances::free_balance(REGISTER_RELAYER), free_balance + 1);
857880
assert_eq!(
858-
Pallet::<TestRuntime>::registered_relayer(REGISTER_RELAYER),
881+
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER),
859882
Some(Registration { valid_till: 150, stake: Stake::get() }),
860883
);
861884

@@ -919,7 +942,7 @@ mod tests {
919942
assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get());
920943
assert_eq!(Balances::free_balance(REGISTER_RELAYER), free_balance - 1);
921944
assert_eq!(
922-
Pallet::<TestRuntime>::registered_relayer(REGISTER_RELAYER),
945+
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER),
923946
Some(Registration { valid_till: 150, stake: Stake::get() }),
924947
);
925948

bridges/modules/xcm-bridge-hub-router/src/lib.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@ pub mod pallet {
120120
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
121121
// if XCM channel is still congested, we don't change anything
122122
if T::LocalXcmChannelManager::is_congested(&T::SiblingBridgeHubLocation::get()) {
123-
return T::WeightInfo::on_initialize_when_congested()
123+
return T::WeightInfo::on_initialize_when_congested();
124124
}
125125

126126
// if bridge has reported congestion, we don't change anything
127127
let mut bridge = Self::bridge();
128128
if bridge.is_congested {
129-
return T::WeightInfo::on_initialize_when_congested()
129+
return T::WeightInfo::on_initialize_when_congested();
130130
}
131131

132132
// if we can't decrease the delivery fee factor anymore, we don't change anything
133133
if bridge.delivery_fee_factor == MINIMAL_DELIVERY_FEE_FACTOR {
134-
return T::WeightInfo::on_initialize_when_congested()
134+
return T::WeightInfo::on_initialize_when_congested();
135135
}
136136

137137
let previous_factor = bridge.delivery_fee_factor;
@@ -190,10 +190,14 @@ pub mod pallet {
190190
/// primitives (lane-id aka bridge-id, derived from XCM locations) to support multiple bridges
191191
/// by the same pallet instance.
192192
#[pallet::storage]
193-
#[pallet::getter(fn bridge)]
194193
pub type Bridge<T: Config<I>, I: 'static = ()> = StorageValue<_, BridgeState, ValueQuery>;
195194

196195
impl<T: Config<I>, I: 'static> Pallet<T, I> {
196+
/// Bridge that we are using.
197+
pub fn bridge() -> BridgeState {
198+
Bridge::<T, I>::get()
199+
}
200+
197201
/// Called when new message is sent (queued to local outbound XCM queue) over the bridge.
198202
pub(crate) fn on_message_sent_to_bridge(message_size: u32) {
199203
log::trace!(
@@ -208,7 +212,7 @@ pub mod pallet {
208212
// if outbound queue is not congested AND bridge has not reported congestion, do
209213
// nothing
210214
if !is_channel_with_bridge_hub_congested && !is_bridge_congested {
211-
return Err(())
215+
return Err(());
212216
}
213217

214218
// ok - we need to increase the fee factor, let's do that
@@ -276,7 +280,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
276280
target: LOG_TARGET,
277281
"Router with bridged_network_id {bridged_network:?} does not support bridging to network {network:?}!",
278282
);
279-
return None
283+
return None;
280284
}
281285
}
282286

@@ -298,7 +302,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
298302
network,
299303
remote_location,
300304
);
301-
return None
305+
return None;
302306
},
303307
};
304308

@@ -318,7 +322,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
318322
network,
319323
remote_location,
320324
);
321-
return None
325+
return None;
322326
},
323327
},
324328
None => 0,
@@ -388,7 +392,7 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
388392
// better to drop such messages here rather than at the bridge hub. Let's check the
389393
// message size."
390394
if message_size > HARD_MESSAGE_SIZE_LIMIT {
391-
return Err(SendError::ExceedsMaxMessageSize)
395+
return Err(SendError::ExceedsMaxMessageSize);
392396
}
393397

394398
// We need to ensure that the known `dest`'s XCM version can comprehend the current

bridges/primitives/runtime/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ pub trait OwnedBridgeModule<T: frame_system::Config> {
425425
log::info!(target: Self::LOG_TARGET, "Setting operating mode to {:?}.", operating_mode);
426426
Ok(())
427427
}
428+
429+
/// Pallet owner has a right to halt all module operations and then resume it. If it is `None`,
430+
/// then there are no direct ways to halt/resume module operations, but other runtime methods
431+
/// may still be used to do that (i.e. democracy::referendum to update halt flag directly
432+
/// or call the `set_operating_mode`).
433+
fn module_owner() -> Option<T::AccountId> {
434+
Self::OwnerStorage::get()
435+
}
436+
437+
/// The current operating mode of the module.
438+
/// Depending on the mode either all, some, or no transactions will be allowed.
439+
fn operating_mode() -> Self::OperatingMode {
440+
Self::OperatingModeStorage::get()
441+
}
428442
}
429443

430444
/// All extra operations with weights that we need in bridges.

prdoc/pr_7120.prdoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
title: Remove pallet::getter from bridges/modules
2+
doc:
3+
- audience: Runtime Dev
4+
description: |
5+
This PR removes all pallet::getter occurrences from pallet-bridge-grandpa, pallet-bridge-messages and pallet-bridge-relayers and replaces them with explicit implementations.
6+
7+
crates:
8+
- name: pallet-bridge-grandpa
9+
bump: patch
10+
- name: pallet-bridge-messages
11+
bump: major
12+
- name: pallet-bridge-relayers
13+
bump: minor
14+
- name: bp-runtime
15+
bump: minor
16+
- name: pallet-bridge-beefy
17+
bump: minor
18+
- name: pallet-xcm-bridge-hub-router
19+
bump: patch

0 commit comments

Comments
 (0)