Skip to content

Delay aggregated staking jobs. #1556

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

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
11 changes: 9 additions & 2 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,15 @@ pub mod pallet {
StorageValue<_, u64, ValueQuery, DefaultSenateRequiredStakePercentage<T>>;

#[pallet::storage]
pub type StakeJobs<T: Config> =
StorageMap<_, Blake2_128Concat, u64, StakeJob<T::AccountId>, OptionQuery>;
pub type StakeJobs<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
BlockNumberFor<T>, // first key: current block number
Twox64Concat,
u64, // second key: unique job ID
StakeJob<T::AccountId>,
OptionQuery,
>;

#[pallet::storage]
/// Ensures unique IDs for StakeJobs storage map
Expand Down
12 changes: 6 additions & 6 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ mod dispatches {
/// price, the staking order may execute only partially or not execute
/// at all.
///
/// The operation will be delayed until the end of the block.
/// The operation will be delayed.
///
/// # Args:
/// * 'origin': (<T as frame_system::Config>Origin):
Expand Down Expand Up @@ -2086,7 +2086,7 @@ mod dispatches {
/// price, the staking order may execute only partially or not execute
/// at all.
///
/// The operation will be delayed until the end of the block.
/// The operation will be delayed.
///
/// # Args:
/// * 'origin': (<T as frame_system::Config>Origin):
Expand Down Expand Up @@ -2140,7 +2140,7 @@ mod dispatches {
/// price, the staking order may execute only partially or not execute
/// at all.
///
/// The operation will be delayed until the end of the block.
/// The operation will be delayed.
///
/// # Args:
/// * 'origin': (<T as frame_system::Config>Origin):
Expand Down Expand Up @@ -2203,7 +2203,7 @@ mod dispatches {
/// price, the staking order may execute only partially or not execute
/// at all.
///
/// The operation will be delayed until the end of the block.
/// The operation will be delayed.
///
/// # Args:
/// * 'origin': (<T as frame_system::Config>Origin):
Expand Down Expand Up @@ -2260,7 +2260,7 @@ mod dispatches {

/// ---- The implementation for the extrinsic unstake_all_aggregate: Removes all stake from a hotkey account across all subnets and adds it onto a coldkey.
///
/// The operation will be delayed until the end of the block.
/// The operation will be delayed.
///
/// # Args:
/// * `origin` - (<T as frame_system::Config>::Origin):
Expand Down Expand Up @@ -2293,7 +2293,7 @@ mod dispatches {

/// ---- The implementation for the extrinsic unstake_all_alpha_aggregate: Removes all stake from a hotkey account across all subnets and adds it onto a coldkey.
///
/// The operation will be delayed until the end of the block.
/// The operation will be delayed.
///
/// # Args:
/// * `origin` - (<T as frame_system::Config>::Origin):
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ mod hooks {
// # Args:
// * 'n': (BlockNumberFor<T>):
// - The number of the block we are finalizing.
fn on_finalize(_block_number: BlockNumberFor<T>) {
Self::do_on_finalize();
fn on_finalize(block_number: BlockNumberFor<T>) {
Self::do_on_finalize(block_number);
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
Expand Down
6 changes: 4 additions & 2 deletions pallets/subtensor/src/staking/add_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ impl<T: Config> Pallet<T> {
};

let stake_job_id = NextStakeJobId::<T>::get();
let current_blocknumber = <frame_system::Pallet<T>>::block_number();

StakeJobs::<T>::insert(stake_job_id, stake_job);
StakeJobs::<T>::insert(current_blocknumber, stake_job_id, stake_job);
NextStakeJobId::<T>::set(stake_job_id.saturating_add(1));

Ok(())
Expand Down Expand Up @@ -211,8 +212,9 @@ impl<T: Config> Pallet<T> {
};

let stake_job_id = NextStakeJobId::<T>::get();
let current_blocknumber = <frame_system::Pallet<T>>::block_number();

StakeJobs::<T>::insert(stake_job_id, stake_job);
StakeJobs::<T>::insert(current_blocknumber, stake_job_id, stake_job);
NextStakeJobId::<T>::set(stake_job_id.saturating_add(1));

Ok(())
Expand Down
12 changes: 8 additions & 4 deletions pallets/subtensor/src/staking/remove_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ impl<T: Config> Pallet<T> {
};

let stake_job_id = NextStakeJobId::<T>::get();
let current_blocknumber = <frame_system::Pallet<T>>::block_number();

StakeJobs::<T>::insert(stake_job_id, stake_job);
StakeJobs::<T>::insert(current_blocknumber, stake_job_id, stake_job);
NextStakeJobId::<T>::set(stake_job_id.saturating_add(1));

Ok(())
Expand Down Expand Up @@ -270,8 +271,9 @@ impl<T: Config> Pallet<T> {
let stake_job = StakeJob::UnstakeAll { hotkey, coldkey };

let stake_job_id = NextStakeJobId::<T>::get();
let current_blocknumber = <frame_system::Pallet<T>>::block_number();

StakeJobs::<T>::insert(stake_job_id, stake_job);
StakeJobs::<T>::insert(current_blocknumber, stake_job_id, stake_job);
NextStakeJobId::<T>::set(stake_job_id.saturating_add(1));

Ok(())
Expand Down Expand Up @@ -409,8 +411,9 @@ impl<T: Config> Pallet<T> {
let stake_job = StakeJob::UnstakeAllAlpha { hotkey, coldkey };

let stake_job_id = NextStakeJobId::<T>::get();
let current_blocknumber = <frame_system::Pallet<T>>::block_number();

StakeJobs::<T>::insert(stake_job_id, stake_job);
StakeJobs::<T>::insert(current_blocknumber, stake_job_id, stake_job);
NextStakeJobId::<T>::set(stake_job_id.saturating_add(1));

Ok(())
Expand Down Expand Up @@ -589,8 +592,9 @@ impl<T: Config> Pallet<T> {
};

let stake_job_id = NextStakeJobId::<T>::get();
let current_blocknumber = <frame_system::Pallet<T>>::block_number();

StakeJobs::<T>::insert(stake_job_id, stake_job);
StakeJobs::<T>::insert(current_blocknumber, stake_job_id, stake_job);
NextStakeJobId::<T>::set(stake_job_id.saturating_add(1));

// Done and ok.
Expand Down
Loading
Loading