Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bridges/modules/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ pub mod pallet {

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

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

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Returns the hash of the best finalized header.
pub fn best_finalized() -> Option<BridgedBlockId<T, I>> {
BestFinalized::<T, I>::get()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 1 addition & 3 deletions bridges/modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, 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<T: Config<I>, I: 'static = ()> =
StorageValue<_, MessagesOperatingMode, ValueQuery>;

Expand Down Expand Up @@ -733,7 +731,7 @@ fn ensure_normal_operating_mode<T: Config<I>, I: 'static>() -> Result<(), Error<
if PalletOperatingMode::<T, I>::get() ==
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
{
return Ok(())
return Ok(());
}

Err(Error::<T, I>::NotOperatingNormally)
Expand Down
35 changes: 25 additions & 10 deletions bridges/modules/relayers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ pub mod pallet {
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// 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<Registration<BlockNumberFor<T>, T::Balance>> {
RegisteredRelayers::<T, I>::get(relayer)
}

/// Map of the relayer => accumulated reward.
pub fn relayer_reward(
key1: <RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Key1,
key2: <RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Key2,
) -> Option<<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Value> {
RelayerRewards::<T, I>::get(key1, key2)
}

fn do_claim_rewards(
relayer: T::AccountId,
reward_kind: T::Reward,
Expand Down Expand Up @@ -289,15 +305,15 @@ 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
let remaining_lease = registration
.valid_till
.saturating_sub(frame_system::Pallet::<T>::block_number());
if remaining_lease <= Self::required_registration_lease() {
return false
return false;
}

true
Expand All @@ -319,7 +335,7 @@ pub mod pallet {
relayer,
);

return
return;
},
};
let slash_destination = slash_destination.into_account();
Expand Down Expand Up @@ -380,7 +396,7 @@ pub mod pallet {
reward_balance: T::RewardBalance,
) {
if reward_balance.is_zero() {
return
return;
}

RelayerRewards::<T, I>::mutate(
Expand Down Expand Up @@ -512,7 +528,6 @@ pub mod pallet {

/// Map of the relayer => accumulated reward.
#[pallet::storage]
#[pallet::getter(fn relayer_reward)]
pub type RelayerRewards<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
_,
<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Hasher1,
Expand All @@ -530,7 +545,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<T: Config<I>, I: 'static = ()> = StorageMap<
_,
Blake2_128Concat,
Expand Down Expand Up @@ -606,7 +620,8 @@ mod tests {
150,
));
// check if registered
let registration = Pallet::<TestRuntime>::registered_relayer(REGISTER_RELAYER).unwrap();
let registration =
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER).unwrap();
assert_eq!(registration, Registration { valid_till: 150, stake: Stake::get() });

// slash and deregister
Expand Down Expand Up @@ -787,7 +802,7 @@ mod tests {
));
assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get());
assert_eq!(
Pallet::<TestRuntime>::registered_relayer(REGISTER_RELAYER),
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER),
Some(Registration { valid_till: 150, stake: Stake::get() }),
);

Expand Down Expand Up @@ -855,7 +870,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::<TestRuntime>::registered_relayer(REGISTER_RELAYER),
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER),
Some(Registration { valid_till: 150, stake: Stake::get() }),
);

Expand Down Expand Up @@ -919,7 +934,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::<TestRuntime>::registered_relayer(REGISTER_RELAYER),
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER),
Some(Registration { valid_till: 150, stake: Stake::get() }),
);

Expand Down
14 changes: 14 additions & 0 deletions bridges/primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ pub trait OwnedBridgeModule<T: frame_system::Config> {
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<T::AccountId> {
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.
Expand Down
15 changes: 15 additions & 0 deletions prdoc/pr_7120.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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: major
- name: pallet-bridge-messages
bump: major
- name: pallet-bridge-relayers
bump: major
- name: bp-runtime
bump: major
Loading