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

Fix: add migration to resolve deserialization issue with cardano_transactions_signing_config #1971

Merged
merged 2 commits into from
Oct 1, 2024
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
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.5.71"
version = "0.5.72"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::sync::Arc;

use async_trait::async_trait;

use mithril_common::entities::{Epoch, ProtocolParameters};
use mithril_common::entities::{CardanoTransactionsSigningConfig, Epoch, ProtocolParameters};
use mithril_common::StdResult;
use mithril_persistence::sqlite::{ConnectionExtensions, SqliteConnection};
use mithril_persistence::store::adapter::AdapterError;
use sqlite::Value;

use crate::database::query::{
DeleteEpochSettingsQuery, GetEpochSettingsQuery, UpdateEpochSettingsQuery,
Expand All @@ -30,6 +31,28 @@ impl EpochSettingsStore {
retention_limit,
}
}

#[deprecated(since = "0.5.72", note = "temporary fix, should be removed")]
/// Replace empty JSON values '{}' injected with Migration #28
pub fn replace_cardano_signing_config_empty_values(
&self,
cardano_signing_config: CardanoTransactionsSigningConfig,
) -> StdResult<()> {
let query = r#"
update epoch_setting
set cardano_transactions_signing_config = ?
where cardano_transactions_signing_config == '{}'"#;

let mut statement = self.connection.prepare(query)?;
statement.bind::<&[(_, Value)]>(&[(
1,
serde_json::to_string(&cardano_signing_config)?.into(),
)])?;

statement.next()?;

Ok(())
}
}

#[async_trait]
Expand Down Expand Up @@ -81,10 +104,73 @@ impl EpochSettingsStorer for EpochSettingsStore {

#[cfg(test)]
mod tests {
use mithril_common::entities::BlockNumber;

use crate::database::test_helper::{insert_epoch_settings, main_db_connection};

use super::*;

#[tokio::test]
async fn replace_cardano_signing_config_empty_values_updates_only_empty_values() {
let connection = main_db_connection().unwrap();
connection.execute(
r#"insert into epoch_setting (epoch_setting_id, protocol_parameters, cardano_transactions_signing_config)
values (
1,
'{"k": 5, "m": 100, "phi_f": 0.65}',
'{"security_parameter": 70, "step": 20}'
)"#,
).unwrap();
connection.execute(
r#"insert into epoch_setting (epoch_setting_id, protocol_parameters, cardano_transactions_signing_config)
values (
2,
'{"k": 73, "m": 100, "phi_f": 0.65}',
'{}'
)"#,
).unwrap();

let store = EpochSettingsStore::new(Arc::new(connection), None);

let epoch_settings = store.get_epoch_settings(Epoch(1)).await.unwrap().unwrap();
assert_eq!(
CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(70),
step: BlockNumber(20),
},
epoch_settings.cardano_transactions_signing_config
);

#[allow(deprecated)]
store
.replace_cardano_signing_config_empty_values(CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(50),
step: BlockNumber(10),
})
.unwrap();

{
let epoch_settings = store.get_epoch_settings(Epoch(1)).await.unwrap().unwrap();
assert_eq!(
CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(70),
step: BlockNumber(20),
},
epoch_settings.cardano_transactions_signing_config
);
}
{
let epoch_settings = store.get_epoch_settings(Epoch(2)).await.unwrap().unwrap();
assert_eq!(
CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(50),
step: BlockNumber(10),
},
epoch_settings.cardano_transactions_signing_config
);
}
}

#[tokio::test]
async fn save_epoch_settings_prune_older_epoch_settings() {
const EPOCH_SETTINGS_PRUNE_EPOCH_THRESHOLD: u64 = 5;
Expand Down
12 changes: 12 additions & 0 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,18 @@ impl DependenciesBuilder {
message: "cannot build aggregator runner: no epoch returned.".to_string(),
error: None,
})?;

{
// Temporary fix, should be removed
// Replace empty JSON values '{}' injected with Migration #28
let cardano_signing_config = self
.get_signed_entity_config()?
.cardano_transactions_signing_config;
#[allow(deprecated)]
epoch_settings_store
.replace_cardano_signing_config_empty_values(cardano_signing_config)?;
}

epoch_settings_store
.handle_discrepancies_at_startup(
current_epoch,
Expand Down
Loading