Skip to content

Commit

Permalink
fix: add storage item for feature control
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfaisal committed Jan 5, 2024
1 parent 51ab270 commit a2ba7e7
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions pallets/teerex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ pub mod pallet {
#[pallet::getter(fn enclave_count)]
pub type EnclaveCount<T: Config> = StorageValue<_, u64, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn schedule_enclave)]
pub type ScheduleEnclave<T: Config> = StorageValue<_, bool, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn quoting_enclave)]
pub type QuotingEnclaveRegistry<T: Config> = StorageValue<_, QuotingEnclave, ValueQuery>;
Expand Down Expand Up @@ -282,11 +286,15 @@ pub mod pallet {
// TODO: imagine this fn is not called for the first time (e.g. when worker restarts),
// should we check the current sidechain_blocknumber >= registered
// sidechain_blocknumber?
#[cfg(not(feature = "skip-scheduled-enclave-check"))]
ensure!(
ScheduledEnclave::<T>::iter_values().any(|m| m == enclave.mr_enclave),
Error::<T>::EnclaveNotInSchedule
);
// Dev setup -> SkipScheduledEnclave Extrinsic -> Does it make sense to set in dev
// setup?
let schedule_enclave = ScheduleEnclave::<T>::get();
if schedule_enclave {
ensure!(
ScheduledEnclave::<T>::iter_values().any(|m| m == enclave.mr_enclave),
Error::<T>::EnclaveNotInSchedule
);
}

Self::add_enclave(&sender, &enclave)?;
Self::deposit_event(Event::AddedEnclave(sender, worker_url));
Expand Down Expand Up @@ -637,6 +645,18 @@ pub mod pallet {
// Do not pay a fee
Ok(Pays::No.into())
}

#[pallet::call_index(31)]
#[pallet::weight(100)]
pub fn set_schedule_enclave(
origin: OriginFor<T>,
schedule_enclave: bool,
) -> DispatchResultWithPostInfo {
let sender = ensure_root(origin)?;

<ScheduleEnclave<T>>::set(schedule_enclave);
Ok(().into())
}
}

#[pallet::error]
Expand Down

0 comments on commit a2ba7e7

Please sign in to comment.