Skip to content

Commit

Permalink
Populate ScheduledEnclave upon registration for dev worker (#2514)
Browse files Browse the repository at this point in the history
* Populate ScheduledEnclave entry in dev mode

* add test

* comment
  • Loading branch information
Kailai-Wang committed Feb 21, 2024
1 parent 15f13f4 commit 5ab7b29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pallets/teebag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn scheduled_enclave)]
pub type ScheduledEnclave<T: Config> =
StorageMap<_, Blake2_128Concat, (WorkerType, SidechainBlockNumber), MrEnclave>;
StorageMap<_, Blake2_128Concat, (WorkerType, SidechainBlockNumber), MrEnclave, OptionQuery>;

#[pallet::storage]
#[pallet::getter(fn latest_sidechain_block_confirmation)]
Expand Down Expand Up @@ -468,7 +468,12 @@ pub mod pallet {
Error::<T>::EnclaveNotInSchedule
);
},
OperationalMode::Development => (),
OperationalMode::Development => {
// populate the registry if the entry doesn't exist
if !ScheduledEnclave::<T>::contains_key((worker_type, 0)) {
ScheduledEnclave::<T>::insert((worker_type, 0), enclave.mrenclave);
}
},
};
Self::add_enclave(&sender, &enclave)?;
Ok(().into())
Expand Down
4 changes: 4 additions & 0 deletions pallets/teebag/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ fn register_enclave_dev_works_with_no_scheduled_enclave() {
assert_eq!(Teebag::enclave_count(WorkerType::Identity), 1);
assert_eq!(Teebag::enclave_count(WorkerType::BitAcross), 0);
assert_eq!(EnclaveRegistry::<Test>::get(alice()).unwrap(), enclave);
assert_eq!(
ScheduledEnclave::<Test>::get((WorkerType::default(), 0)).unwrap().to_vec(),
TEST4_MRENCLAVE.to_vec()
);
})
}

Expand Down

0 comments on commit 5ab7b29

Please sign in to comment.