Skip to content

Commit

Permalink
Merge pull request #337 from CESSProject/refactor/pallet-tee-work-error
Browse files Browse the repository at this point in the history
refactor: tidy the `Error` of `pallet-tee-worker`
  • Loading branch information
0xbillw authored May 8, 2024
2 parents f7905f8 + ffc54a2 commit e59e378
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pallets/tee-worker/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<T: Config> Pallet<T> {
let mut weight: Weight = Weight::zero();

if let Some(first_holder) = MasterKeyFirstHolder::<T>::get() {
ensure!(first_holder != pbk, Error::<T>::CannotRemoveLastKeyfairy);
ensure!(first_holder != pbk, Error::<T>::CannotExitMasterKeyHolder);
}
weight = weight.saturating_add(T::DbWeight::get().reads(1));

Expand Down
46 changes: 15 additions & 31 deletions pallets/tee-worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ pub mod pallet {

MasterKeyLaunched,

MasterKeyApplied {
worker_pubkey: WorkerPublicKey,
},

WorkerAdded {
pubkey: WorkerPublicKey,
attestation_provider: Option<AttestationProvider>,
Expand All @@ -149,31 +153,13 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
/// Already registered
AlreadyRegistration,
/// Not a controller account
NotStash,
/// The scheduled error report has been reported once
AlreadyReport,
/// Boundedvec conversion error
BoundedVecError,
/// Error indicating that the storage has reached its limit
StorageLimitReached,
/// data overrun error
Overflow,

NotBond,

NotController,

NonTeeWorker,

VerifyCertFailed,

TeePodr2PkNotInitialized,

Existed,

CesealRejected,

InvalidIASSigningCert,
Expand All @@ -195,7 +181,7 @@ pub mod pallet {
WrongTeeType,

InvalidSender,
InvalidPubKey,
InvalidWorkerPubKey,
MalformedSignature,
InvalidSignatureLength,
InvalidSignature,
Expand All @@ -207,16 +193,14 @@ pub mod pallet {
MasterKeyAlreadyLaunched,
MasterKeyLaunching,
MasterKeyMismatch,
InvalidMasterPubkey,
MasterKeyUninitialized,
InvalidMasterKeyApplySigningTime,
/// Ceseal related
CesealAlreadyExists,
CesealNotFound,
/// Additional
NotImplemented,
CannotRemoveLastKeyfairy,
/// Endpoint related
CesealBinNotFound,

CannotExitMasterKeyHolder,

EmptyEndpoint,
InvalidEndpointSigningTime,

Expand Down Expand Up @@ -645,7 +629,7 @@ pub mod pallet {
);

// Validate the public key
ensure!(Workers::<T>::contains_key(endpoint_payload.pubkey), Error::<T>::InvalidPubKey);
ensure!(Workers::<T>::contains_key(endpoint_payload.pubkey), Error::<T>::InvalidWorkerPubKey);

Endpoints::<T>::insert(endpoint_payload.pubkey, endpoint);

Expand Down Expand Up @@ -677,10 +661,10 @@ pub mod pallet {
);

// Validate the public key
ensure!(Workers::<T>::contains_key(payload.pubkey), Error::<T>::InvalidPubKey);

Self::push_message(MasterKeyApply::Apply(payload.pubkey, payload.ecdh_pubkey));
ensure!(Workers::<T>::contains_key(payload.pubkey), Error::<T>::InvalidWorkerPubKey);

Self::push_message(MasterKeyApply::Apply(payload.pubkey.clone(), payload.ecdh_pubkey));
Self::deposit_event(Event::<T>::MasterKeyApplied { worker_pubkey: payload.pubkey });
Ok(())
}

Expand Down Expand Up @@ -713,7 +697,7 @@ pub mod pallet {
T::GovernanceOrigin::ensure_origin(origin)?;

let mut allowlist = CesealBinAllowList::<T>::get();
ensure!(allowlist.contains(&ceseal_hash), Error::<T>::CesealNotFound);
ensure!(allowlist.contains(&ceseal_hash), Error::<T>::CesealBinNotFound);

allowlist.retain(|h| *h != ceseal_hash);
CesealBinAllowList::<T>::put(allowlist);
Expand Down Expand Up @@ -951,7 +935,7 @@ impl<T: Config> TeeWorkerHandler<AccountOf<T>, BlockNumberFor<T>> for Pallet<T>
}

fn get_master_publickey() -> Result<MasterPublicKey, DispatchError> {
let pk = MasterPubkey::<T>::try_get().map_err(|_| Error::<T>::TeePodr2PkNotInitialized)?;
let pk = MasterPubkey::<T>::try_get().map_err(|_| Error::<T>::MasterKeyUninitialized)?;

Ok(pk)
}
Expand Down

0 comments on commit e59e378

Please sign in to comment.