Skip to content

Use verification key/beacon stores in Mithril Aggregator multi signer #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mithril-aggregator/src/beacon_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ pub struct MemoryBeaconStore {
current_beacon: Option<Beacon>,
}

impl Default for MemoryBeaconStore {
impl MemoryBeaconStore {
/// MemoryBeaconStore factory
fn default() -> Self {
pub fn new() -> Self {
Self {
current_beacon: None,
}
}
}

impl Default for MemoryBeaconStore {
fn default() -> Self {
Self::new()
}
}

#[async_trait]
impl BeaconStore for MemoryBeaconStore {
async fn get_current_beacon(&self) -> Result<Option<Beacon>, BeaconStoreError> {
Expand Down
20 changes: 12 additions & 8 deletions mithril-aggregator/src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ mod handlers {
match beacon_store.get_current_beacon().await {
Ok(Some(beacon)) => {
let multi_signer = multi_signer.read().await;
match multi_signer.get_multi_signature() {
match multi_signer.get_multi_signature().await {
Ok(None) => {
let mut certificate_pending = fake_data::certificate_pending();
certificate_pending.beacon = beacon.clone();

let protocol_parameters = multi_signer.get_protocol_parameters();
let protocol_parameters = multi_signer.get_protocol_parameters().await;
if protocol_parameters.is_none() {
return Ok(warp::reply::with_status(
warp::reply::json(&entities::Error::new(
Expand All @@ -232,7 +232,7 @@ mod handlers {

let previous_hash = certificate_pending.previous_hash;

let signers = multi_signer.get_signers();
let signers = multi_signer.get_signers().await;
if let Err(err) = signers {
return Ok(warp::reply::with_status(
warp::reply::json(&entities::Error::new(
Expand Down Expand Up @@ -437,6 +437,7 @@ mod handlers {
Ok(verification_key) => {
match multi_signer
.register_signer(signer.party_id as ProtocolPartyId, &verification_key)
.await
{
Ok(()) => Ok(warp::reply::with_status(
warp::reply::json(&Null),
Expand Down Expand Up @@ -472,11 +473,14 @@ mod handlers {
for signature in &signatures {
match key_decode_hex(&signature.signature) {
Ok(single_signature) => {
match multi_signer.register_single_signature(
signature.party_id as ProtocolPartyId,
&single_signature,
signature.index as ProtocolLotteryIndex,
) {
match multi_signer
.register_single_signature(
signature.party_id as ProtocolPartyId,
&single_signature,
signature.index as ProtocolLotteryIndex,
)
.await
{
Err(multi_signer::ProtocolError::ExistingSingleSignature(_)) => {
return Ok(warp::reply::with_status(
warp::reply::json(&Null),
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ pub use snapshot_uploaders::{LocalSnapshotUploader, RemoteSnapshotUploader};
pub use snapshotter::{SnapshotError, Snapshotter};
pub use store::{
AdapterError, CertificatePendingStore, CertificateStore, JsonFileStoreAdapter, MemoryAdapter,
StoreAdapter, VerificationKeyStore,
StoreAdapter, VerificationKeyStore, VerificationKeyStoreError,
};
18 changes: 12 additions & 6 deletions mithril-aggregator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Init dependencies
let snapshot_store = config.build_snapshot_store();
let multi_signer = Arc::new(RwLock::new(init_multi_signer()));
let beacon_store = Arc::new(RwLock::new(MemoryBeaconStore::default()));

let beacon_store = Arc::new(RwLock::new(MemoryBeaconStore::new()));
let snapshot_uploader = config.build_snapshot_uploader();
let certificate_pending_store = Arc::new(RwLock::new(CertificatePendingStore::new(Box::new(
JsonFileStoreAdapter::new(config.pending_certificate_store_directory.clone())?,
Expand All @@ -139,6 +139,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let verification_key_store = Arc::new(RwLock::new(VerificationKeyStore::new(Box::new(
JsonFileStoreAdapter::new(config.verification_key_store_directory.clone())?,
))));
let multi_signer = Arc::new(RwLock::new(MultiSignerImpl::new(
beacon_store.clone(),
verification_key_store.clone(),
)));
init_multi_signer(multi_signer.clone()).await;

// Init dependency manager
let mut dependency_manager = DependencyManager::new(config.clone());
Expand Down Expand Up @@ -187,13 +192,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

/// Init multi signer dependency
fn init_multi_signer() -> impl MultiSigner {
let mut multi_signer = MultiSignerImpl::new();
// TODO: remove this function when new runtime is implemented + remove protocol parameters from fake data
async fn init_multi_signer(multi_signer: Arc<RwLock<dyn MultiSigner>>) {
let mut multi_signer = multi_signer.write().await;

// Update protocol parameters
let protocol_parameters = fake_data::protocol_parameters();
multi_signer
.update_protocol_parameters(&protocol_parameters.into())
.await
.expect("update protocol parameters failed");

// Update stake distribution
Expand All @@ -204,7 +211,6 @@ fn init_multi_signer() -> impl MultiSigner {
.collect::<_>();
multi_signer
.update_stake_distribution(&stakes)
.await
.expect("stake distribution update failed");

multi_signer
}
Loading