Skip to content

Commit

Permalink
Fixes attestation authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco authored and Gianmarco Fraccaroli committed Nov 17, 2022
1 parent dbdc004 commit 3577e45
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 8 additions & 1 deletion phase2-coordinator/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,14 @@ impl Coordinator {
}

///
/// Returns `true` if the given participant has finished contributing
/// Returns `true` if the given participant has finished contributing in the provided round
///
pub fn is_finished_contributor_at_round(&self, participant: &Participant, round: u64) -> bool {
self.state.is_finished_contributor_at_round(participant, round)
}

///
/// Returns `true` if the given participant has finished contributing in the current round
///
#[inline]
pub fn is_finished_contributor(&self, participant: &Participant) -> bool {
Expand Down
13 changes: 13 additions & 0 deletions phase2-coordinator/src/coordinator_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,19 @@ impl CoordinatorState {
Ok(self.dropped_participants().contains(participant_info))
}

///
/// Returns `true` if the given participant has finished contributing
/// in the provided round.
///
pub fn is_finished_contributor_at_round(&self, participant: &Participant, round: u64) -> bool {
participant.is_contributor()
&& self
.finished_contributors
.get(&round)
.get_or_insert(&HashMap::new())
.contains_key(participant)
}

///
/// Returns `true` if the given participant has finished contributing
/// in the current round.
Expand Down
4 changes: 2 additions & 2 deletions phase2-coordinator/src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ pub async fn post_attestation(

let read_lock = (*coordinator).clone().read_owned().await;
task::spawn_blocking(move || {
if !read_lock.is_current_contributor(&participant) && !read_lock.is_finished_contributor(&participant) {
// Only current or finished contributors are allowed to query this endpoint
if !read_lock.is_finished_contributor_at_round(&participant, round) {
// Only finished contributors are allowed to query this endpoint
return Err(ResponseError::UnauthorizedParticipant(
participant,
"/contributor/attestation".to_string(),
Expand Down

0 comments on commit 3577e45

Please sign in to comment.