Skip to content

Commit

Permalink
Merge pull request #1808 from input-output-hk/ensemble/1804/remove_ca…
Browse files Browse the repository at this point in the history
…ll_to_chain_observer_on_pending_certificate_route

Remove call to chain observer on pending certificate route
  • Loading branch information
sfauvel authored Jul 9, 2024
2 parents 380a4bf + e9dbe66 commit 640ee4d
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 63 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ As a minor extension, we have adopted a slightly different versioning convention

- Add prettier configuration to standardize the code formatting in the repository.

- Field `beacon` becomes optional in `CertificatePendingMessage` response of `/certificate-pending` route.

- **UNSTABLE** Cardano transactions certification:

- Optimize the performances of the computation of the proof with a Merkle map.
Expand Down
4 changes: 2 additions & 2 deletions 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.5.38"
version = "0.5.39"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
22 changes: 3 additions & 19 deletions mithril-aggregator/src/http_server/routes/certificate_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ fn certificate_pending(
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
warp::path!("certificate-pending")
.and(warp::get())
.and(middlewares::with_config(dependency_manager.clone()))
.and(middlewares::with_ticker_service(dependency_manager.clone()))
.and(middlewares::with_certificate_pending_store(
dependency_manager,
))
Expand Down Expand Up @@ -47,11 +45,10 @@ fn certificate_certificate_hash(

mod handlers {
use crate::{
http_server::routes::reply, services::MessageService, unwrap_to_internal_server_error,
CertificatePendingStore, Configuration, ToCertificatePendingMessageAdapter,
http_server::routes::reply, services::MessageService, CertificatePendingStore,
ToCertificatePendingMessageAdapter,
};

use mithril_common::TickerService;
use slog_scope::{debug, warn};
use std::convert::Infallible;
use std::sync::Arc;
Expand All @@ -61,26 +58,13 @@ mod handlers {

/// Certificate Pending
pub async fn certificate_pending(
config: Configuration,
ticker_service: Arc<dyn TickerService>,
certificate_pending_store: Arc<CertificatePendingStore>,
) -> Result<impl warp::Reply, Infallible> {
debug!("⇄ HTTP SERVER: certificate_pending");

let network =
unwrap_to_internal_server_error!(config.get_network(), "certificate_pending::error");
let time_point = unwrap_to_internal_server_error!(
ticker_service.get_current_time_point().await,
"certificate_pending::error"
);

match certificate_pending_store.get().await {
Ok(Some(certificate_pending)) => Ok(reply::json(
&ToCertificatePendingMessageAdapter::adapt(
certificate_pending,
network,
time_point.immutable_file_number,
),
&ToCertificatePendingMessageAdapter::adapt(certificate_pending),
StatusCode::OK,
)),
Ok(None) => Ok(reply::empty(StatusCode::NO_CONTENT)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
use mithril_common::entities::{CardanoDbBeacon, ImmutableFileNumber};
use mithril_common::entities::CardanoDbBeacon;
use mithril_common::{
entities::{CertificatePending, Signer},
entities::{CertificatePending, SignedEntityType, Signer},
messages::{CertificatePendingMessage, SignerMessagePart},
CardanoNetwork,
};

/// Adapter to turn [CertificatePending] instances into [CertificatePendingMessage].
pub struct ToCertificatePendingMessageAdapter;

impl ToCertificatePendingMessageAdapter {
/// Method to trigger the conversion
pub fn adapt(
certificate_pending: CertificatePending,
network: CardanoNetwork,
immutable_file_number: ImmutableFileNumber,
) -> CertificatePendingMessage {
let beacon = CardanoDbBeacon::new(
network.to_string(),
*certificate_pending.epoch,
immutable_file_number,
);
pub fn adapt(certificate_pending: CertificatePending) -> CertificatePendingMessage {
#[allow(deprecated)]
let beacon = match &certificate_pending.signed_entity_type {
SignedEntityType::CardanoImmutableFilesFull(beacon) => beacon.clone(),
_ => CardanoDbBeacon::empty(),
};

#[allow(deprecated)]
CertificatePendingMessage {
epoch: beacon.epoch,
beacon,
epoch: certificate_pending.epoch,
beacon: Some(beacon),
signed_entity_type: certificate_pending.signed_entity_type,
protocol_parameters: certificate_pending.protocol_parameters,
next_protocol_parameters: certificate_pending.next_protocol_parameters,
Expand Down Expand Up @@ -55,23 +50,50 @@ impl ToCertificatePendingMessageAdapter {

#[cfg(test)]
mod tests {
use mithril_common::test_utils::fake_data;
use mithril_common::{
entities::{Epoch, SignedEntityType},
test_utils::fake_data,
};

use super::*;

#[test]
fn adapt_ok() {
let certificate_pending = fake_data::certificate_pending();
let epoch = certificate_pending.epoch;
let message = ToCertificatePendingMessageAdapter::adapt(
certificate_pending,
fake_data::network(),
10,
);
let message = ToCertificatePendingMessageAdapter::adapt(certificate_pending);

assert_eq!(epoch, message.epoch);
}

#[test]
fn adapt_on_cardano_immutable_files_full_signed_entity_type_ok() {
let mut certificate_pending = fake_data::certificate_pending();
let beacon = fake_data::beacon();
certificate_pending.signed_entity_type =
SignedEntityType::CardanoImmutableFilesFull(beacon.clone());

let message = ToCertificatePendingMessageAdapter::adapt(certificate_pending);

#[allow(deprecated)]
let beacon_from_message = message.beacon.unwrap();
assert_eq!(beacon, beacon_from_message);
}

#[test]
fn adapt_on_other_than_cardano_immutable_files_full_signed_entity_type_ok() {
let mut certificate_pending = fake_data::certificate_pending();
let beacon = CardanoDbBeacon::new("", 0, 0);
certificate_pending.signed_entity_type =
SignedEntityType::MithrilStakeDistribution(Epoch(15));

let message = ToCertificatePendingMessageAdapter::adapt(certificate_pending);

#[allow(deprecated)]
let beacon_from_message = message.beacon.unwrap();
assert_eq!(beacon, beacon_from_message);
}

#[test]
fn adapt_signers() {
let fake_signers = fake_data::signers(5);
Expand All @@ -82,11 +104,7 @@ mod tests {
next_signers,
..fake_data::certificate_pending()
};
let message = ToCertificatePendingMessageAdapter::adapt(
certificate_pending,
fake_data::network(),
10,
);
let message = ToCertificatePendingMessageAdapter::adapt(certificate_pending);

assert_eq!(2, message.signers.len());
assert_eq!(3, message.next_signers.len());
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.4.27"
version = "0.4.28"
description = "Common types, interfaces, and utilities for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions mithril-common/src/entities/cardano_db_beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl CardanoDbBeacon {
}
}

/// Value used as a placeholder where a beacon is necessary
#[deprecated]
pub fn empty() -> Self {
Self::new("", 0, 0)
}

/// Computes the hash of a CardanoDbBeacon
pub fn compute_hash(&self) -> String {
let mut hasher = Sha256::new();
Expand Down
Loading

0 comments on commit 640ee4d

Please sign in to comment.