Skip to content

Commit

Permalink
Merge pull request #717 from input-output-hk/jpraynaud/716-fix-signer…
Browse files Browse the repository at this point in the history
…-unable-to-sign-2304.0-prerelease

Fix signer unable to sign with `2304.0 prerelease`
  • Loading branch information
jpraynaud authored Jan 30, 2023
2 parents 513e09c + e3247d8 commit cd471d7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.2.9"
version = "0.2.10"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
42 changes: 41 additions & 1 deletion mithril-aggregator/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ pub trait AggregatorRunnerTrait: Sync + Send {
/// Read the stake distribution from the blockchain and store it.
async fn update_stake_distribution(&self, new_beacon: &Beacon) -> Result<(), RuntimeError>;

/// Open the signer registration round for an epoch.
/// Open the signer registration round of an epoch.
async fn open_signer_registration_round(&self, new_beacon: &Beacon)
-> Result<(), RuntimeError>;

/// Close the signer registration round of an epoch.
async fn close_signer_registration_round(&self) -> Result<(), RuntimeError>;

/// Update the multisigner with the protocol parameters from configuration.
async fn update_protocol_parameters_in_multisigner(
&self,
Expand Down Expand Up @@ -314,6 +317,17 @@ impl AggregatorRunnerTrait for AggregatorRunner {
Ok(())
}

async fn close_signer_registration_round(&self) -> Result<(), RuntimeError> {
debug!("RUNNER: close signer registration round");

self.dependencies
.signer_registration_round_opener
.close_registration_round()
.await?;

Ok(())
}

async fn update_protocol_parameters_in_multisigner(
&self,
new_beacon: &Beacon,
Expand Down Expand Up @@ -770,6 +784,32 @@ pub mod tests {
);
}

#[tokio::test]
async fn test_close_signer_registration_round() {
let (mut deps, config) = initialize_dependencies().await;
let signer_registration_round_opener = Arc::new(MithrilSignerRegisterer::new(
deps.chain_observer.clone(),
deps.verification_key_store.clone(),
));
deps.signer_registration_round_opener = signer_registration_round_opener.clone();
let deps = Arc::new(deps);
let runner = AggregatorRunner::new(config, deps.clone());

let beacon = fake_data::beacon();
runner
.open_signer_registration_round(&beacon)
.await
.expect("opening signer registration should not return an error");

runner
.close_signer_registration_round()
.await
.expect("closing signer registration should not return an error");

let saved_current_round = signer_registration_round_opener.get_current_round().await;
assert!(saved_current_round.is_none());
}

#[tokio::test]
async fn test_update_protocol_parameters_in_multisigner() {
let (deps, config) = initialize_dependencies().await;
Expand Down
9 changes: 9 additions & 0 deletions mithril-aggregator/src/runtime/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl AggregatorRuntime {

if maybe_current_beacon.is_none() || maybe_current_beacon.unwrap().epoch < new_beacon.epoch
{
self.runner.close_signer_registration_round().await?;
self.runner.update_stake_distribution(&new_beacon).await?;
self.runner
.open_signer_registration_round(&new_beacon)
Expand Down Expand Up @@ -365,6 +366,10 @@ mod tests {
.with(predicate::eq(fake_data::beacon()))
.once()
.returning(|_| Ok(()));
runner
.expect_close_signer_registration_round()
.once()
.returning(|| Ok(()));
runner
.expect_open_signer_registration_round()
.once()
Expand Down Expand Up @@ -408,6 +413,10 @@ mod tests {
.with(predicate::eq(fake_data::beacon()))
.once()
.returning(|_| Ok(()));
runner
.expect_close_signer_registration_round()
.once()
.returning(|| Ok(()));
runner
.expect_open_signer_registration_round()
.once()
Expand Down
10 changes: 10 additions & 0 deletions mithril-aggregator/src/signer_registerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub trait SignerRegistrationRoundOpener: Sync + Send {
registration_epoch: Epoch,
stake_distribution: StakeDistribution,
) -> Result<(), SignerRegistrationError>;

/// Close a signer registration round
async fn close_registration_round(&self) -> Result<(), SignerRegistrationError>;
}

/// Implementation of a [SignerRegisterer]
Expand Down Expand Up @@ -127,6 +130,13 @@ impl SignerRegistrationRoundOpener for MithrilSignerRegisterer {

Ok(())
}

async fn close_registration_round(&self) -> Result<(), SignerRegistrationError> {
let mut current_round = self.current_round.write().await;
*current_round = None;

Ok(())
}
}

#[async_trait]
Expand Down

0 comments on commit cd471d7

Please sign in to comment.