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

fix: sort on address modification #32

Merged
merged 3 commits into from
Dec 14, 2023
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
9 changes: 6 additions & 3 deletions pallets/bfc-staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::pallet::*;

use crate::{
inflation::Range, weights::WeightInfo, BalanceOf, Bond, DelayedCommissionSet,
DelayedControllerSet, DelayedPayout, ProductivityStatus, RewardDestination, RoundIndex,
TierType, TotalSnapshot, ValidatorSnapshot, ValidatorSnapshotOf,
DelayedControllerSet, DelayedPayout, ProductivityStatus, RewardDestination, RewardPoint,
RoundIndex, TierType, TotalSnapshot, ValidatorSnapshot, ValidatorSnapshotOf,
};

use pallet_session::ShouldEndSession;
Expand Down Expand Up @@ -182,20 +182,23 @@ impl<T: Config> Pallet<T> {
selected_candidates
.try_push(candidate.clone())
.expect("SelectedCandidates out of bound");
selected_candidates.sort();
<SelectedCandidates<T>>::put(selected_candidates);
match tier {
TierType::Full => {
let mut selected_full_candidates = <SelectedFullCandidates<T>>::get();
selected_full_candidates
.try_push(candidate.clone())
.expect("SelectedFullCandidates out of bound");
selected_full_candidates.sort();
<SelectedFullCandidates<T>>::put(selected_full_candidates);
},
_ => {
let mut selected_basic_candidates = <SelectedBasicCandidates<T>>::get();
selected_basic_candidates
.try_push(candidate.clone())
.expect("SelectedBasicCandidates out of bound");
selected_basic_candidates.sort();
<SelectedBasicCandidates<T>>::put(selected_basic_candidates);
},
};
Expand Down Expand Up @@ -744,7 +747,7 @@ impl<T: Config> Pallet<T> {

let score_plus_5 = <AwardedPts<T>>::get(round_index, &author) + 5;
<AwardedPts<T>>::insert(round_index, author, score_plus_5);
<Points<T>>::mutate(round_index, |x| *x += 5);
<Points<T>>::mutate(round_index, |x: &mut RewardPoint| *x += 5);
}

/// Reset every `per round` related parameters of every candidates
Expand Down
10 changes: 5 additions & 5 deletions pallets/bfc-staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,26 +552,26 @@ pub mod pallet {

#[pallet::storage]
#[pallet::getter(fn selected_candidates)]
/// The active validator set (full and basic) selected for the current round
/// The active validator set (full and basic) selected for the current round. This storage is sorted by address.
pub type SelectedCandidates<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, ConstU32<MAX_AUTHORITIES>>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn selected_full_candidates)]
/// The active full validator set selected for the current round
/// The active full validator set selected for the current round. This storage is sorted by address.
pub type SelectedFullCandidates<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, ConstU32<MAX_AUTHORITIES>>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn selected_basic_candidates)]
/// The active basic validator set selected for the current round
/// The active basic validator set selected for the current round. This storage is sorted by address.
pub type SelectedBasicCandidates<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, ConstU32<MAX_AUTHORITIES>>, ValueQuery>;
Comment on lines +555 to 569
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BoundedVec -> BoundedBTreeSet으로 변경을 고려해봐도 좋을 것 같습니다

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두개의 차이가 클까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

적용을 하려고 했는데, 아무래도 타입이 기존 벡터와 다르다보니�사용하는 곳에서 로직 수정이 많이 요구가 되긴 하네요. 다른 스토리지들과 호환이 안되는 부분도 있기도 하고요, 이를테면 CachedSelectedCandidates 처럼요.

그래서 우선은 BoundedVec으로 유지하고, 이후에 저희 스토리지 값들 전부 migration하는 것은 어떨까요? CachedSelectedCandidates 이런것들도 전부 BTreeMap 같은것으로 수정해야 될것 같아서요.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

살짝 대규모 작업이 될수도 있을것 같긴 하네요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 당장 바꾸자는 뜻은 아니었습니다. 지금 보니 더 나은 collection들을 쓸 여지가 보여서 의견남겨봤습니다.


#[pallet::storage]
#[pallet::unbounded]
#[pallet::getter(fn cached_selected_candidates)]
/// The cached active validator set selected from previous rounds
/// The cached active validator set selected from previous rounds. This storage is sorted by address.
pub type CachedSelectedCandidates<T: Config> =
StorageValue<_, Vec<(RoundIndex, Vec<T::AccountId>)>, ValueQuery>;

Expand All @@ -593,7 +593,7 @@ pub mod pallet {

#[pallet::storage]
#[pallet::getter(fn candidate_pool)]
/// The pool of validator candidates, each with their total voting power
/// The pool of validator candidates, each with their total voting power. This storage is sorted by amount.
pub(crate) type CandidatePool<T: Config> = StorageValue<
_,
BoundedVec<Bond<T::AccountId, BalanceOf<T>>, ConstU32<MAX_AUTHORITIES>>,
Expand Down
1 change: 1 addition & 0 deletions pallets/relay-manager/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ impl<T: Config> Pallet<T> {
fn add_to_selected_relayers(relayer: T::AccountId) {
let mut selected_relayers = <SelectedRelayers<T>>::get();
selected_relayers.try_push(relayer).expect("SelectedRelayers out of bound");
selected_relayers.sort();
<SelectedRelayers<T>>::put(selected_relayers);
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/relay-manager/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,27 @@ pub mod pallet {

#[pallet::storage]
#[pallet::getter(fn selected_relayers)]
/// The active relayer set selected for the current round
/// The active relayer set selected for the current round. This storage is sorted by address.
pub type SelectedRelayers<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, ConstU32<MAX_AUTHORITIES>>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn initial_selected_relayers)]
/// The active relayer set selected at the beginning of the current round
/// The active relayer set selected at the beginning of the current round. This storage is sorted by address.
pub type InitialSelectedRelayers<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, ConstU32<MAX_AUTHORITIES>>, ValueQuery>;

#[pallet::storage]
#[pallet::unbounded]
#[pallet::getter(fn cached_selected_relayers)]
/// The cached active relayer set selected from previous rounds
/// The cached active relayer set selected from previous rounds. This storage is sorted by address.
pub type CachedSelectedRelayers<T: Config> =
StorageValue<_, Vec<(RoundIndex, Vec<T::AccountId>)>, ValueQuery>;

#[pallet::storage]
#[pallet::unbounded]
#[pallet::getter(fn cached_initial_selected_relayers)]
/// The cached active relayer set selected from the beginning of each previous rounds
/// The cached active relayer set selected from the beginning of each previous rounds. This storage is sorted by address.
pub type CachedInitialSelectedRelayers<T: Config> =
StorageValue<_, Vec<(RoundIndex, Vec<T::AccountId>)>, ValueQuery>;

Expand Down
2 changes: 1 addition & 1 deletion runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// The version of the authorship interface.
authoring_version: 1,
// The version of the runtime spec.
spec_version: 460,
spec_version: 461,
// The version of the implementation of the spec.
impl_version: 1,
// A list of supported runtime APIs along with their versions.
Expand Down
4 changes: 2 additions & 2 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bifrost-platform/bifrost-node",
"version": "1.2.4",
"version": "1.2.5",
"author": "bifrost-platform",
"scripts": {
"test": "mocha -r ts-node/register tests/**/**/*.ts --exit",
Expand Down
4 changes: 2 additions & 2 deletions tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bifrost-platform/bifrost-node",
"version": "1.2.4",
"version": "1.2.5",
"author": "bifrost-platform",
"scripts": {
"set_session_keys": "ts-node src/set_session_keys.ts",
Expand Down