Skip to content

Commit

Permalink
Adding get setup number command.
Browse files Browse the repository at this point in the history
Fix unlock pax chunks for verifiers.
Adapt add participant to add multiple participants in one go.
  • Loading branch information
ii-cruz committed May 27, 2024
1 parent 0d76a61 commit 2c5fdf1
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions src/bin/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use setup_utils::{
DEFAULT_VERIFY_CHECK_INPUT_CORRECTNESS, DEFAULT_VERIFY_CHECK_OUTPUT_CORRECTNESS,
};
use snark_setup_operator::data_structs::{
Chunk, ChunkMetadata, Contribution, ContributionMetadata, ParticipantId, Setup,
Chunk, ChunkMetadata, Contribution, ContributionMetadata, ParticipantId, Response, Setup,

Check failure on line 23 in src/bin/control.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `Response`
};
use snark_setup_operator::error::{NewRoundError, VerifyTranscriptError};
use snark_setup_operator::utils::{
Expand Down Expand Up @@ -58,6 +58,13 @@ pub struct ChangeParticipantKeyOpts {

#[derive(Debug, Options, Clone)]
pub struct AddParticipantOpts {
help: bool,
#[options(help = "participant ID", required)]
pub participant_id: Vec<ParticipantId>,
}

#[derive(Debug, Options, Clone)]
pub struct AddVerifierOpts {
help: bool,
#[options(help = "participant ID", required)]
pub participant_id: ParticipantId,
Expand Down Expand Up @@ -129,6 +136,11 @@ pub struct GetLastContributionPkOpts {
pub chunk_index: usize,
}

#[derive(Debug, Options, Clone)]
pub struct GetNumberOfSetups {
help: bool,
}

#[derive(Debug, Options, Clone)]
pub struct ControlOpts {
help: bool,
Expand Down Expand Up @@ -214,14 +226,15 @@ pub enum Command {
ChangeParticipantKey(ChangeParticipantKeyOpts),
AddParticipant(AddParticipantOpts),
RemoveParticipant(RemoveParticipantOpts),
AddVerifier(AddParticipantOpts),
AddVerifier(AddVerifierOpts),
RemoveVerifier(RemoveParticipantOpts),
UnlockParticipantChunks(UnlockParticipantOpts),
SignalShutdown(SignalShutdownOpts),
NewRound(NewRoundOpts),
ApplyBeacon(ApplyBeaconOpts),
RemoveLastContribution(RemoveLastContributionOpts),
GetLastContributionPk(GetLastContributionPkOpts),
GetNumberOfSetups(GetNumberOfSetups),
}

pub struct Control {
Expand Down Expand Up @@ -306,18 +319,14 @@ impl Control {
Ok(())
}

async fn add_participant(&self, participant_id: ParticipantId) -> Result<()> {
async fn add_participant(&self, participant_ids: &mut Vec<ParticipantId>) -> Result<()> {
let mut ceremony = self.get_ceremony().await?;
if ceremony.contributor_ids.contains(&participant_id) {
return Err(ControlError::ParticipantAlreadyExistsError(
participant_id.clone(),
ceremony.contributor_ids.clone(),
)
.into());
}
ceremony.contributor_ids.push(participant_id.clone());
info!("participants after adding: {:?}", ceremony.contributor_ids);

ceremony.contributor_ids.append(participant_ids);
info!("New contributors {:?}", ceremony.contributor_ids);

self.put_ceremony(&ceremony).await?;

Ok(())
}

Expand Down Expand Up @@ -446,7 +455,9 @@ impl Control {
let client = reqwest::Client::new();
let mut ceremony = self.get_ceremony().await?;

if !ceremony.contributor_ids.contains(&participant_id) {
if !ceremony.contributor_ids.contains(&participant_id)
&& !ceremony.verifier_ids.contains(&participant_id)
{
return Err(ControlError::ParticipantDoesNotExistError(
participant_id.clone(),
ceremony.contributor_ids.clone(),
Expand Down Expand Up @@ -994,6 +1005,9 @@ impl Control {

Ok(participant_id_from_chunk)
}
async fn get_setups_number(&self) -> Result<usize> {
Ok(self.get_ceremony().await?.setups.len())
}

async fn remove_last_contribution(
&self,
Expand Down Expand Up @@ -1069,7 +1083,7 @@ async fn main() {
.await
.expect("Should have run command successfully"),
Command::AddParticipant(opts) => control
.add_participant(opts.participant_id)
.add_participant(&mut opts.participant_id.clone())
.await
.expect("Should have run command successfully"),
Command::RemoveParticipant(opts) => control
Expand Down Expand Up @@ -1121,5 +1135,13 @@ async fn main() {

println!("Public key: {}", pk);
}
Command::GetNumberOfSetups(_opts) => {
let n_setups = control
.get_setups_number()
.await
.expect("Should have run command successfully");

println!("{}", n_setups);
}
});
}

0 comments on commit 2c5fdf1

Please sign in to comment.