From f3b4e8bc05c7f6e06fca0939df72c0987090af26 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Mon, 16 Sep 2024 11:09:14 +0200 Subject: [PATCH 1/3] fix: reset Cardano transactions store with a migration This will avoid data inconsistency with nodes running previous unstable versions. --- .../src/database/cardano_transaction_migration.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/mithril-persistence/src/database/cardano_transaction_migration.rs b/internal/mithril-persistence/src/database/cardano_transaction_migration.rs index 45d036551c6..6d266d9152f 100644 --- a/internal/mithril-persistence/src/database/cardano_transaction_migration.rs +++ b/internal/mithril-persistence/src/database/cardano_transaction_migration.rs @@ -106,6 +106,17 @@ vacuum; r#" drop index cardano_tx_immutable_file_number_index; alter table cardano_tx drop column immutable_file_number; + "#, + ), + // Migration 9 + // Truncate Cardano transaction related tables to avoid data inconsistency + // with previous versions of the nodes. + SqlMigration::new( + 9, + r#" +delete from cardano_tx; +delete from block_range_root; +vacuum; "#, ), ] From 6795b3b13b0b15a1f205fbf882c6371140fbf0a2 Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:54:20 +0200 Subject: [PATCH 2/3] Add debug logs to `PallasChainReader` --- .../src/dependency_injection/builder.rs | 1 + .../src/chain_reader/pallas_chain_reader.rs | 32 +++++++++++++++---- .../src/dependency_injection/builder.rs | 7 ++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/mithril-aggregator/src/dependency_injection/builder.rs b/mithril-aggregator/src/dependency_injection/builder.rs index 5c3f043be19..2e9750a83b4 100644 --- a/mithril-aggregator/src/dependency_injection/builder.rs +++ b/mithril-aggregator/src/dependency_injection/builder.rs @@ -731,6 +731,7 @@ impl DependenciesBuilder { let chain_block_reader = PallasChainReader::new( &self.configuration.cardano_node_socket_path, self.configuration.get_network()?, + self.get_logger()?, ); Ok(Arc::new(Mutex::new(chain_block_reader))) diff --git a/mithril-common/src/chain_reader/pallas_chain_reader.rs b/mithril-common/src/chain_reader/pallas_chain_reader.rs index b3972c0adee..6336dfbe72b 100644 --- a/mithril-common/src/chain_reader/pallas_chain_reader.rs +++ b/mithril-common/src/chain_reader/pallas_chain_reader.rs @@ -7,6 +7,7 @@ use pallas_network::{ miniprotocols::chainsync::{BlockContent, NextResponse}, }; use pallas_traverse::MultiEraBlock; +use slog::{debug, Logger}; use crate::{cardano_block_scanner::ScannedBlock, entities::ChainPoint, CardanoNetwork, StdResult}; @@ -17,15 +18,17 @@ pub struct PallasChainReader { socket: PathBuf, network: CardanoNetwork, client: Option, + logger: Logger, } impl PallasChainReader { /// Creates a new `PallasChainReader` with the specified socket and network. - pub fn new(socket: &Path, network: CardanoNetwork) -> Self { + pub fn new(socket: &Path, network: CardanoNetwork, logger: Logger) -> Self { Self { socket: socket.to_owned(), network, client: None, + logger, } } @@ -42,6 +45,7 @@ impl PallasChainReader { async fn get_client(&mut self) -> StdResult<&mut NodeClient> { if self.client.is_none() { self.client = Some(self.new_client().await?); + debug!(self.logger, "PallasChainReader connected to a new client"); } self.client @@ -51,13 +55,17 @@ impl PallasChainReader { /// Intersects the point of the chain with the given point. async fn find_intersect_point(&mut self, point: &ChainPoint) -> StdResult<()> { + let logger = self.logger.clone(); let client = self.get_client().await?; let chainsync = client.chainsync(); if chainsync.has_agency() { + debug!(logger, "PallasChainReader has agency, finding intersect point..."; "point" => ?point); chainsync .find_intersect(vec![point.to_owned().into()]) .await?; + } else { + debug!(logger, "PallasChainReader doesn't have agency, no need to find intersect point";); } Ok(()) @@ -130,6 +138,7 @@ mod tests { use super::*; + use crate::test_utils::TestLogger; use crate::{entities::BlockNumber, test_utils::TempDir}; /// Enum representing the action to be performed by the server. @@ -253,8 +262,11 @@ mod tests { ) .await; let client = tokio::spawn(async move { - let mut chain_reader = - PallasChainReader::new(socket_path.as_path(), CardanoNetwork::TestNet(10)); + let mut chain_reader = PallasChainReader::new( + socket_path.as_path(), + CardanoNetwork::TestNet(10), + TestLogger::stdout(), + ); chain_reader .set_chain_point(&ChainPoint::from(known_point.clone())) @@ -285,8 +297,11 @@ mod tests { ) .await; let client = tokio::spawn(async move { - let mut chain_reader = - PallasChainReader::new(socket_path.as_path(), CardanoNetwork::TestNet(10)); + let mut chain_reader = PallasChainReader::new( + socket_path.as_path(), + CardanoNetwork::TestNet(10), + TestLogger::stdout(), + ); chain_reader .set_chain_point(&ChainPoint::from(known_point.clone())) @@ -317,8 +332,11 @@ mod tests { ) .await; let client = tokio::spawn(async move { - let mut chain_reader = - PallasChainReader::new(socket_path.as_path(), CardanoNetwork::TestNet(10)); + let mut chain_reader = PallasChainReader::new( + socket_path.as_path(), + CardanoNetwork::TestNet(10), + TestLogger::stdout(), + ); chain_reader .set_chain_point(&ChainPoint::from(known_point.clone())) diff --git a/mithril-signer/src/dependency_injection/builder.rs b/mithril-signer/src/dependency_injection/builder.rs index 7db8828a0a1..636fad2d4c6 100644 --- a/mithril-signer/src/dependency_injection/builder.rs +++ b/mithril-signer/src/dependency_injection/builder.rs @@ -264,8 +264,11 @@ impl<'a> DependenciesBuilder<'a> { let transaction_store = Arc::new(CardanoTransactionRepository::new( sqlite_connection_cardano_transaction_pool.clone(), )); - let chain_block_reader = - PallasChainReader::new(&self.config.cardano_node_socket_path, network); + let chain_block_reader = PallasChainReader::new( + &self.config.cardano_node_socket_path, + network, + slog_scope::logger(), + ); let block_scanner = Arc::new(CardanoBlockScanner::new( Arc::new(Mutex::new(chain_block_reader)), self.config From 99e2300855edce5ffe725cbbaa68229ae71a5cd8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Mon, 16 Sep 2024 11:24:28 +0200 Subject: [PATCH 3/3] chore: bump crates versions - 'mithril-persistence' from '0.2.26' to '0.2.27' - 'mithril-aggregator' from '0.5.62' to '0.5.63' - 'mithril-signer' from '0.2.181' to '0.2.182' --- Cargo.lock | 6 +++--- internal/mithril-persistence/Cargo.toml | 2 +- mithril-aggregator/Cargo.toml | 2 +- mithril-signer/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 250ac9305ab..fb919e833bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3403,7 +3403,7 @@ dependencies = [ [[package]] name = "mithril-aggregator" -version = "0.5.62" +version = "0.5.63" dependencies = [ "anyhow", "async-trait", @@ -3657,7 +3657,7 @@ dependencies = [ [[package]] name = "mithril-persistence" -version = "0.2.26" +version = "0.2.27" dependencies = [ "anyhow", "async-trait", @@ -3704,7 +3704,7 @@ dependencies = [ [[package]] name = "mithril-signer" -version = "0.2.181" +version = "0.2.182" dependencies = [ "anyhow", "async-trait", diff --git a/internal/mithril-persistence/Cargo.toml b/internal/mithril-persistence/Cargo.toml index 7e3c787eb82..8815531ad7b 100644 --- a/internal/mithril-persistence/Cargo.toml +++ b/internal/mithril-persistence/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-persistence" -version = "0.2.26" +version = "0.2.27" description = "Common types, interfaces, and utilities to persist data for Mithril nodes." authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index 4d83d7f065b..ac7e9395526 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-aggregator" -version = "0.5.62" +version = "0.5.63" description = "A Mithril Aggregator server" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-signer/Cargo.toml b/mithril-signer/Cargo.toml index bcc96e048b2..6d8f1d04625 100644 --- a/mithril-signer/Cargo.toml +++ b/mithril-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-signer" -version = "0.2.181" +version = "0.2.182" description = "A Mithril Signer" authors = { workspace = true } edition = { workspace = true }