Skip to content
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

Signer signs real digest #219

Merged
merged 5 commits into from
May 31, 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
4 changes: 2 additions & 2 deletions mithril-aggregator/src/multi_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ impl MultiSigner for MultiSignerImpl {

/// Creates a multi signature from single signatures
fn create_multi_signature(&mut self) -> Result<Option<ProtocolMultiSignature>, ProtocolError> {
debug!("Create multi signature");

let message = &self
.get_current_message()
.ok_or_else(ProtocolError::UnavailableMessage)?;

debug!("Create multi signature"; "message" => ?message);
let signatures: Vec<ProtocolSingleSignature> = self
.single_signatures
.iter()
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ impl AggregatorRuntime {
Ok(digest_result) => {
let mut beacon = fake_data::beacon();
beacon.immutable_file_number = digest_result.last_immutable_file_number;
let message = fake_data::digest(&beacon);
let message = &digest_result.digest.clone().into_bytes();

match self.manage_trigger_snapshot(&message, &beacon).await {
match self.manage_trigger_snapshot(message, &beacon).await {
Ok(true) => {
let snapshot_name =
format!("{}.{}.tar.gz", self.network, &digest_result.digest);
Expand Down
9 changes: 9 additions & 0 deletions mithril-common/src/fake_data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(dead_code)]

use crate::digesters::DigesterResult;
use std::time::{SystemTime, UNIX_EPOCH};

use crate::entities;
Expand All @@ -26,6 +27,14 @@ pub fn digest(beacon: &entities::Beacon) -> Vec<u8> {
.to_vec()
}

/// Fake DigesterResult
pub fn digester_result(digest: &str) -> DigesterResult {
DigesterResult {
digest: digest.to_string(),
last_immutable_file_number: 0,
}
}

/// Fake ProtocolParameters
pub fn protocol_parameters() -> entities::ProtocolParameters {
let k = 5;
Expand Down
3 changes: 2 additions & 1 deletion mithril-signer/config/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"network": "testnet",
"aggregator_endpoint": "http://localhost:8080/aggregator",
"party_id": 0,
"run_interval": 20000
"run_interval": 20000,
"db_directory": "/db"
}
3 changes: 2 additions & 1 deletion mithril-signer/config/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"network": "testnet",
"aggregator_endpoint": "http://aggregator.api.mithril.network/aggregator",
"party_id": 0,
"run_interval": 20000
"run_interval": 20000,
"db_directory": "/db"
}
2 changes: 2 additions & 0 deletions mithril-signer/src/certificate_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ mod tests {
use super::*;
use httpmock::prelude::*;
use serde_json::json;
use std::path::Path;

use mithril_common::fake_data;

Expand All @@ -150,6 +151,7 @@ mod tests {
aggregator_endpoint: server.url(""),
party_id: 0,
run_interval: 100,
db_directory: Path::new("./").to_path_buf(),
};
(server, config)
}
Expand Down
12 changes: 12 additions & 0 deletions mithril-signer/src/entities.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cli_table::Table;
use serde::{Deserialize, Serialize};
use std::path::{Display, Path, PathBuf};

/// Client configuration
#[derive(Table, Debug, Clone, Serialize, Deserialize)]
Expand All @@ -19,4 +20,15 @@ pub struct Config {
/// Run Interval
#[table(title = "Interval between two signatures attempts")]
pub run_interval: u64,

/// Directory to snapshot
#[table(
title = "Path to the Cardano Node db directory",
display_fn = "display_path"
)]
pub db_directory: PathBuf,
}

fn display_path(path: &Path) -> Display<'_> {
path.display()
}
4 changes: 2 additions & 2 deletions mithril-signer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod certificate_handler;
mod entities;
mod signer;
mod runtime;
mod single_signer;

pub use certificate_handler::CertificateHandlerHTTPClient;
pub use entities::Config;
pub use signer::Signer;
pub use runtime::Runtime;
pub use single_signer::MithrilSingleSigner;
25 changes: 13 additions & 12 deletions mithril-signer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use clap::Parser;
use mithril_common::digesters::ImmutableDigester;
use slog::{o, Drain, Level, Logger};
use slog_scope::{debug, error, info};
use slog_scope::debug;
use std::env;
use std::sync::Arc;
use std::time::Duration;
use tokio::time::sleep;

use mithril_signer::{CertificateHandlerHTTPClient, Config, MithrilSingleSigner, Signer};
use mithril_signer::{CertificateHandlerHTTPClient, Config, MithrilSingleSigner, Runtime};

/// CLI args
#[derive(Parser)]
Expand Down Expand Up @@ -65,13 +64,15 @@ async fn main() -> Result<(), String> {
let protocol_initializer_encoded = "";
let single_signer = MithrilSingleSigner::new(config.party_id, protocol_initializer_encoded);
let certificate_handler = CertificateHandlerHTTPClient::new(config.aggregator_endpoint.clone());
let digester = ImmutableDigester::new(config.db_directory, slog_scope::logger());

let mut signer = Signer::new(Box::new(certificate_handler), Box::new(single_signer));
loop {
if let Err(e) = signer.run().await {
error!("{:?}", e)
}
info!("Sleeping for {}", config.run_interval);
sleep(Duration::from_millis(config.run_interval)).await;
}
// Should the runtime loop returns an error ? If yes should we abort the loop at the first error or is their some tolerance ?
let mut runtime = Runtime::new(
Box::new(certificate_handler),
Box::new(single_signer),
Box::new(digester),
);
runtime.infinite_loop(config.run_interval).await;

Ok(())
}
Loading