Skip to content

Commit

Permalink
fix(service_registry)!: correctly handle minimum workerset size (#294)
Browse files Browse the repository at this point in the history
* fix(service_registry)!: correctly handle minimum workerset size
  • Loading branch information
cjcobb23 authored Mar 7, 2024
1 parent da01357 commit 3bdd5f4
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 118 deletions.
8 changes: 6 additions & 2 deletions contracts/service-registry/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub mod query {
.may_load(deps.storage, &service_name)?
.ok_or(ContractError::ServiceNotFound)?;

let workers = WORKERS_PER_CHAIN
let workers: Vec<_> = WORKERS_PER_CHAIN
.prefix((&service_name, &chain_name))
.range(deps.storage, None, None, Order::Ascending)
.map(|res| res.and_then(|(addr, _)| WORKERS.load(deps.storage, (&service_name, &addr))))
Expand All @@ -398,7 +398,11 @@ pub mod query {
.filter(|worker| worker.authorization_state == AuthorizationState::Authorized)
.collect();

Ok(workers)
if workers.len() < service.min_num_workers.into() {
Err(ContractError::NotEnoughWorkers)
} else {
Ok(workers)
}
}

pub fn get_worker(
Expand Down
2 changes: 2 additions & 0 deletions contracts/service-registry/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ pub enum ContractError {
WorkerNotFound,
#[error("invalid bonding state `{0:?}` for this operation")]
InvalidBondingState(BondingState),
#[error("not enough workers")]
NotEnoughWorkers,
}
Loading

0 comments on commit 3bdd5f4

Please sign in to comment.