Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions bridges/modules/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static = ()> = StorageValue<_, u32, ValueQuery>;

/// High level info about the imported commitments.
Expand Down Expand Up @@ -392,7 +391,7 @@ pub mod pallet {
init_data: InitializationDataOf<T, I>,
) -> Result<(), Error<T, I>> {
if init_data.authority_set.len == 0 {
return Err(Error::<T, I>::InvalidInitialAuthoritySet)
return Err(Error::<T, I>::InvalidInitialAuthoritySet);
}
CurrentAuthoritySetInfo::<T, I>::put(init_data.authority_set);

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

Ok(())
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// The current number of requests which have written to storage.
pub fn request_count() -> u32 {
RequestCount::<T, I>::get()
}
}
}

#[cfg(test)]
Expand Down
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
43 changes: 33 additions & 10 deletions bridges/modules/relayers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,30 @@ 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<EncodeLikeAccountId, EncodeLikeReward>(
key1: EncodeLikeAccountId,
key2: EncodeLikeReward,
) -> Option<<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Value>
where
EncodeLikeAccountId: codec::EncodeLike<
<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Key1,
>,
EncodeLikeReward: codec::EncodeLike<
<RelayerRewardsKeyProviderOf<T, I> as StorageDoubleMapKeyProvider>::Key2,
>,
{
RelayerRewards::<T, I>::get(key1, key2)
}

fn do_claim_rewards(
relayer: T::AccountId,
reward_kind: T::Reward,
Expand Down Expand Up @@ -289,15 +313,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 +343,7 @@ pub mod pallet {
relayer,
);

return
return;
},
};
let slash_destination = slash_destination.into_account();
Expand Down Expand Up @@ -380,7 +404,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 +536,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 +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<T: Config<I>, I: 'static = ()> = StorageMap<
_,
Blake2_128Concat,
Expand Down Expand Up @@ -606,7 +628,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 +810,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 +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::<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 +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::<TestRuntime>::registered_relayer(REGISTER_RELAYER),
Pallet::<TestRuntime>::registered_relayer(&REGISTER_RELAYER),
Some(Registration { valid_till: 150, stake: Stake::get() }),
);

Expand Down
22 changes: 13 additions & 9 deletions bridges/modules/xcm-bridge-hub-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ pub mod pallet {
fn on_initialize(_n: BlockNumberFor<T>) -> 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;
Expand Down Expand Up @@ -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<T: Config<I>, I: 'static = ()> = StorageValue<_, BridgeState, ValueQuery>;

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Bridge that we are using.
pub fn bridge() -> BridgeState {
Bridge::<T, I>::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!(
Expand All @@ -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
Expand Down Expand Up @@ -276,7 +280,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
target: LOG_TARGET,
"Router with bridged_network_id {bridged_network:?} does not support bridging to network {network:?}!",
);
return None
return None;
}
}

Expand All @@ -298,7 +302,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
network,
remote_location,
);
return None
return None;
},
};

Expand All @@ -318,7 +322,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
network,
remote_location,
);
return None
return None;
},
},
None => 0,
Expand Down Expand Up @@ -388,7 +392,7 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
// 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
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
19 changes: 19 additions & 0 deletions prdoc/pr_7120.prdoc
Original file line number Diff line number Diff line change
@@ -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
Loading