8000 fix: curator application consistency by functor-flow · Pull Request #95 · commune-ai/subspace · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: curator application consistency #95

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
merged 2 commits into from
Oct 17, 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
33 changes: 13 additions & 20 deletions pallets/governance/src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,37 @@ impl<T: Config> Pallet<T> {

#[must_use]
fn can_add_application_status_based(key: &T::AccountId) -> bool {
// check if there's an application with the given key
CuratorApplications::<T>::iter().find(|(_, app)| app.user_id == *key).map_or(
true,
|(_, app)| {
// if the application exists, check its status
!matches!(
app.status,
ApplicationStatus::Pending | ApplicationStatus::Accepted
)
},
)
!CuratorApplications::<T>::iter().any(|(_, app)| app.user_id == *key)
}

pub fn add_application(
key: T::AccountId,
application_key: T::AccountId,
data: Vec<u8>,
) -> DispatchResult {
// make sure application isnt already whitelisted
ensure!(
!Self::is_in_legit_whitelist(&application_key),
Error::<T>::AlreadyWhitelisted
);

// make sure application does not already exist
ensure!(
Self::can_add_application_status_based(&application_key),
Error::<T>::ApplicationKeyAlreadyUsed
);

// check if the key has enough funds to file the application
let application_cost = GeneralSubnetApplicationCost::<T>::get();
ensure!(
PalletSubspace::<T>::has_enough_balance(&key, application_cost),
Error::<T>::NotEnoughBalanceToApply
);

// 1. a remove the balance from the account
let Some(removed_balance_as_currency) =
PalletSubspace::<T>::u64_to_balance(application_cost)
else {
return Err(Error::<T>::InvalidCurrencyConversionValue.into());
};

// add the application
let application_id = Self::get_next_application_id();
let current_block = PalletSubspace::<T>::get_current_block_number();

Expand All @@ -89,6 +80,7 @@ impl<T: Config> Pallet<T> {
block_number: current_block,
};

// 1. b remove the balance from the account
PalletSubspace::<T>::remove_balance_from_account(&key, removed_balance_as_currency)?;

CuratorApplications::<T>::insert(application_id, application);
Expand Down Expand Up @@ -163,6 +155,12 @@ impl<T: Config> Pallet<T> {
let key = ensure_signed(origin)?;
ensure!(Curator::<T>::get() == key, Error::<T>::NotCurator);

// make sure application isnt already whitelisted
ensure!(
!Self::is_in_legit_whitelist(&module_key),
Error::<T>::AlreadyWhitelisted
);

let application = CuratorApplications::<T>::iter_values()
.find(|app| app.user_id == module_key)
.ok_or(Error::<T>::ApplicationNotFound)?;
Expand All @@ -172,11 +170,6 @@ impl<T: Config> Pallet<T> {
Error::<T>::ApplicationNotPending
);

ensure!(
!Self::is_in_legit_whitelist(&module_key),
Error::<T>::AlreadyWhitelisted
);

LegitWhitelist::<T>::insert(&module_key, ());

T::execute_application(&module_key)?;
Expand Down
6 changes: 0 additions & 6 deletions pallets/subnet_emission/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use sp_std::collections::btree_map::BTreeMap;

pub mod distribute_emission;
pub mod migrations;
pub mod post_runtime;
pub mod subnet_pricing {
pub mod demo;
pub mod root;
Expand Down Expand Up @@ -109,11 +108,6 @@ pub mod pallet {
}
Weight::zero()
}

fn on_idle(_n: BlockNumberFor<T>, remaining: Weight) -> Weight {
log::info!("on_idle: {remaining:?}");
Self::deregister_excess_modules(remaining)
}
}

#[pallet::event]
Expand Down
79 changes: 0 additions & 79 deletions pallets/subnet_emission/src/post_runtime.rs

This file was deleted.

Loading
0