Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pallet::getter usage from bridges/modules #7120

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions 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 @@ -789,7 +788,7 @@ where
pub fn synced_headers_grandpa_info() -> Vec<StoredHeaderGrandpaInfo<BridgedHeader<T, I>>> {
frame_system::Pallet::<T>::read_events_no_consensus()
.filter_map(|event| {
if let Event::<T, I>::UpdatedBestFinalizedHeader { grandpa_info, .. } =
if let Event::<T, I>::UpdatedBestFinalizedHeader { grandpa_info, .. } =
event.event.try_into().ok()?
{
return Some(grandpa_info)
Expand Down Expand Up @@ -995,7 +994,6 @@ mod tests {
fn init_storage_entries_are_correctly_initialized() {
run_test(|| {
assert_eq!(BestFinalized::<TestRuntime>::get(), None,);
assert_eq!(Pallet::<TestRuntime>::best_finalized(), None);
assert_eq!(PalletOperatingMode::<TestRuntime>::try_get(), Err(()));

let init_data = init_with_origin(RuntimeOrigin::root()).unwrap();
Expand Down Expand Up @@ -1637,7 +1635,7 @@ mod tests {
run_test(|| {
initialize_substrate_bridge();
assert_ok!(submit_finality_proof(1));
let first_header_hash = Pallet::<TestRuntime>::best_finalized().unwrap().hash();
let first_header_hash = BestFinalized::<TestRuntime>::get().unwrap().hash();
next_block();

assert_ok!(submit_finality_proof(2));
Expand Down
2 changes: 0 additions & 2 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
18 changes: 9 additions & 9 deletions bridges/modules/relayers/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -1788,7 +1788,7 @@ mod tests {
let regular_reward = expected_delivery_reward();
run_post_dispatch(Some(pre_dispatch_data), Ok(()));
assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward(
RelayerRewards::<TestRuntime>::get(
relayer_account_at_this_chain(),
MsgProofsRewardsAccount::get()
),
Expand All @@ -1807,7 +1807,7 @@ mod tests {
_ => unreachable!(),
}
run_post_dispatch(Some(pre_dispatch_data), Ok(()));
let reward_after_two_calls = RelayersPallet::<TestRuntime>::relayer_reward(
let reward_after_two_calls = RelayerRewards::<TestRuntime>::get(
relayer_account_at_this_chain(),
MsgProofsRewardsAccount::get(),
)
Expand All @@ -1828,7 +1828,7 @@ mod tests {

run_post_dispatch(Some(all_finality_pre_dispatch_data()), Ok(()));
assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward(
RelayerRewards::<TestRuntime>::get(
relayer_account_at_this_chain(),
MsgProofsRewardsAccount::get()
),
Expand All @@ -1837,7 +1837,7 @@ mod tests {

run_post_dispatch(Some(all_finality_confirmation_pre_dispatch_data()), Ok(()));
assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward(
RelayerRewards::<TestRuntime>::get(
relayer_account_at_this_chain(),
MsgDeliveryProofsRewardsAccount::get()
),
Expand All @@ -1853,7 +1853,7 @@ mod tests {

run_post_dispatch(Some(parachain_finality_pre_dispatch_data()), Ok(()));
assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward(
RelayerRewards::<TestRuntime>::get(
relayer_account_at_this_chain(),
MsgProofsRewardsAccount::get()
),
Expand All @@ -1862,7 +1862,7 @@ mod tests {

run_post_dispatch(Some(parachain_finality_confirmation_pre_dispatch_data()), Ok(()));
assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward(
RelayerRewards::<TestRuntime>::get(
relayer_account_at_this_chain(),
MsgDeliveryProofsRewardsAccount::get()
),
Expand All @@ -1878,7 +1878,7 @@ mod tests {

run_post_dispatch(Some(delivery_pre_dispatch_data()), Ok(()));
assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward(
RelayerRewards::<TestRuntime>::get(
relayer_account_at_this_chain(),
MsgProofsRewardsAccount::get()
),
Expand All @@ -1887,7 +1887,7 @@ mod tests {

run_post_dispatch(Some(confirmation_pre_dispatch_data()), Ok(()));
assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward(
RelayerRewards::<TestRuntime>::get(
relayer_account_at_this_chain(),
MsgDeliveryProofsRewardsAccount::get()
),
Expand Down
10 changes: 4 additions & 6 deletions bridges/modules/relayers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T, I>::get(relayer) {
Some(registration) => registration,
None => return false,
};
Expand Down Expand Up @@ -459,7 +459,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 @@ -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<T: Config<I>, I: 'static = ()> = StorageMap<
_,
Blake2_128Concat,
Expand Down Expand Up @@ -690,7 +688,7 @@ mod tests {
));
assert_eq!(Balances::reserved_balance(REGISTER_RELAYER), Stake::get());
assert_eq!(
Pallet::<TestRuntime>::registered_relayer(REGISTER_RELAYER),
RegisteredRelayers::<TestRuntime>::get(REGISTER_RELAYER),
Some(Registration { valid_till: 150, stake: Stake::get() }),
);

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 _},
Expand Down Expand Up @@ -916,7 +917,7 @@ impl_runtime_apis! {

impl bp_westend::WestendFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_westend::Hash, bp_westend::BlockNumber>> {
BridgeWestendGrandpa::best_finalized()
pallet_bridge_grandpa::BestFinalized::<Runtime, Instance3>::get()
}
fn free_headers_interval() -> Option<bp_westend::BlockNumber> {
<Runtime as pallet_bridge_grandpa::Config<
Expand Down Expand Up @@ -970,7 +971,7 @@ impl_runtime_apis! {

impl bp_polkadot_bulletin::PolkadotBulletinFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<bp_runtime::HeaderId<bp_polkadot_bulletin::Hash, bp_polkadot_bulletin::BlockNumber>> {
BridgePolkadotBulletinGrandpa::best_finalized()
pallet_bridge_grandpa::BestFinalized::<Runtime, Instance4>::get()
}

fn free_headers_interval() -> Option<bp_polkadot_bulletin::BlockNumber> {
Expand Down Expand Up @@ -1343,7 +1344,7 @@ impl_runtime_apis! {
let bench_lane_id = <Self as BridgeMessagesConfig<bridge_to_westend_config::WithBridgeHubWestendMessagesInstance>>::bench_lane_id();
use bp_runtime::Chain;
let bridged_chain_id =<Self as pallet_bridge_messages::Config<bridge_to_westend_config::WithBridgeHubWestendMessagesInstance>>::BridgedChain::ID;
pallet_bridge_relayers::Pallet::<Runtime>::relayer_reward(
pallet_bridge_relayers::RelayerRewards::<Runtime>::get(
relayer,
bp_relayers::RewardsAccountParams::new(
bench_lane_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 _},
Expand Down Expand Up @@ -849,7 +850,7 @@ impl_runtime_apis! {

impl bp_rococo::RococoFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_rococo::Hash, bp_rococo::BlockNumber>> {
BridgeRococoGrandpa::best_finalized()
pallet_bridge_grandpa::BestFinalized::<Runtime, Instance1>::get()
}
fn free_headers_interval() -> Option<bp_rococo::BlockNumber> {
<Runtime as pallet_bridge_grandpa::Config<
Expand Down Expand Up @@ -1224,7 +1225,7 @@ impl_runtime_apis! {
let bench_lane_id = <Self as BridgeMessagesConfig<bridge_to_rococo_config::WithBridgeHubRococoMessagesInstance>>::bench_lane_id();
use bp_runtime::Chain;
let bridged_chain_id =<Self as pallet_bridge_messages::Config<bridge_to_rococo_config::WithBridgeHubRococoMessagesInstance>>::BridgedChain::ID;
pallet_bridge_relayers::Pallet::<Runtime>::relayer_reward(
pallet_bridge_relayers::RelayerRewards::<Runtime>::get(
relayer,
bp_relayers::RewardsAccountParams::new(
bench_lane_id,
Expand Down
17 changes: 17 additions & 0 deletions prdoc/pr_7120.prdoc
Original file line number Diff line number Diff line change
@@ -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
Loading