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 getters from im-online pallet #3589

Merged
merged 2 commits into from
Mar 11, 2024
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: 10 additions & 0 deletions prdoc/pr_3589.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Removed `pallet::getter` usage from `pallet-im-online`

doc:
- audience: Runtime Dev
description: |
This PR removes `pallet::getter` usage from `pallet-im-online`, and updates dependant code accordingly.
The syntax `StorageItem::<T, I>::get()` should be used instead.

crates:
- name: pallet-im-online
12 changes: 4 additions & 8 deletions substrate/frame/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,22 @@ pub mod pallet {
/// progress estimate from `NextSessionRotation`, as those estimates should be
/// more accurate then the value we calculate for `HeartbeatAfter`.
#[pallet::storage]
#[pallet::getter(fn heartbeat_after)]
pub(super) type HeartbeatAfter<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;
pub type HeartbeatAfter<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;

/// The current set of keys that may issue a heartbeat.
#[pallet::storage]
#[pallet::getter(fn keys)]
pub(super) type Keys<T: Config> =
pub type Keys<T: Config> =
StorageValue<_, WeakBoundedVec<T::AuthorityId, T::MaxKeys>, ValueQuery>;

/// For each session index, we keep a mapping of `SessionIndex` and `AuthIndex`.
#[pallet::storage]
#[pallet::getter(fn received_heartbeats)]
pub(super) type ReceivedHeartbeats<T: Config> =
pub type ReceivedHeartbeats<T: Config> =
StorageDoubleMap<_, Twox64Concat, SessionIndex, Twox64Concat, AuthIndex, bool>;

/// For each session index, we keep a mapping of `ValidatorId<T>` to the
/// number of blocks authored by the given authority.
#[pallet::storage]
#[pallet::getter(fn authored_blocks)]
pub(super) type AuthoredBlocks<T: Config> = StorageDoubleMap<
pub type AuthoredBlocks<T: Config> = StorageDoubleMap<
_,
Twox64Concat,
SessionIndex,
Expand Down
9 changes: 3 additions & 6 deletions substrate/frame/im-online/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use sp_core::offchain::{
testing::{TestOffchainExt, TestTransactionPoolExt},
OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,
};
use sp_runtime::{
testing::UintAuthorityId,
transaction_validity::{InvalidTransaction, TransactionValidityError},
};
use sp_runtime::testing::UintAuthorityId;

#[test]
fn test_unresponsiveness_slash_fraction() {
Expand Down Expand Up @@ -267,14 +264,14 @@ fn should_cleanup_received_heartbeats_on_session_end() {
let _ = heartbeat(1, 2, 0, 1.into(), Session::validators()).unwrap();

// the heartbeat is stored
assert!(!ImOnline::received_heartbeats(&2, &0).is_none());
assert!(!super::pallet::ReceivedHeartbeats::<Runtime>::get(2, 0).is_none());

advance_session();

// after the session has ended we have already processed the heartbeat
// message, so any messages received on the previous session should have
// been pruned.
assert!(ImOnline::received_heartbeats(&2, &0).is_none());
assert!(super::pallet::ReceivedHeartbeats::<Runtime>::get(2, 0).is_none());
});
}

Expand Down
Loading