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: aggregator and signer blocked during Cardano transactions import #1798

Merged
merged 4 commits into from
Jul 3, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ As a minor extension, we have adopted a slightly different versioning convention
- Chunk the Cardano transactions import in `mithril-signer` to reduce disk footprint by running the pruning process more frequently.
- Add a database connection pool on the Cardano transaction repository for increased performances of the prover.
- Import Cardano transactions with Chain Sync mini protocol and Pallas chain reader.
- Avoid aggregator and signer being blocked when importing the Cardano transactions.

- Crates versions:

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.33"
version = "0.5.34"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
23 changes: 18 additions & 5 deletions mithril-aggregator/src/services/cardano_transactions_importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::Arc;

use async_trait::async_trait;
use slog::{debug, Logger};
use tokio::{runtime::Handle, task};

use mithril_common::cardano_block_scanner::{BlockScanner, ChainScannedBlocks};
use mithril_common::crypto_helper::{MKTree, MKTreeNode};
Expand Down Expand Up @@ -174,13 +175,25 @@ impl CardanoTransactionsImporter {
.store_block_range_roots(block_ranges_with_merkle_root)
.await
}

async fn import_transactions_and_block_ranges(
&self,
up_to_beacon: BlockNumber,
) -> StdResult<()> {
self.import_transactions(up_to_beacon).await?;
self.import_block_ranges().await
}
}

#[async_trait]
impl TransactionsImporter for CardanoTransactionsImporter {
async fn import(&self, up_to_beacon: BlockNumber) -> StdResult<()> {
self.import_transactions(up_to_beacon).await?;
self.import_block_ranges().await
task::block_in_place(move || {
Handle::current().block_on(async move {
self.import_transactions_and_block_ranges(up_to_beacon)
.await
})
})
}
}

Expand Down Expand Up @@ -639,7 +652,7 @@ mod tests {
);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn importing_twice_starting_with_nothing_in_a_real_db_should_yield_transactions_in_same_order(
) {
let blocks = vec![
Expand Down Expand Up @@ -676,7 +689,7 @@ mod tests {
assert_eq!(cold_imported_transactions, warm_imported_transactions);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn when_rollbackward_should_remove_transactions() {
let connection = cardano_tx_db_connection().unwrap();
let repository = Arc::new(CardanoTransactionRepository::new(Arc::new(
Expand Down Expand Up @@ -719,7 +732,7 @@ mod tests {
assert_eq!(expected_remaining_transactions, stored_transactions);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn when_rollbackward_should_remove_block_ranges() {
let connection = cardano_tx_db_connection().unwrap();
let repository = Arc::new(CardanoTransactionRepository::new(Arc::new(
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/tests/create_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mithril_common::{
};
use test_extensions::{utilities::get_test_dir, ExpectedCertificate, RuntimeTester};

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn create_certificate() {
let protocol_parameters = ProtocolParameters {
k: 5,
Expand Down
2 changes: 1 addition & 1 deletion mithril-signer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-signer"
version = "0.2.156"
version = "0.2.157"
description = "A Mithril Signer"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
23 changes: 18 additions & 5 deletions mithril-signer/src/cardano_transactions_importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::Arc;

use async_trait::async_trait;
use slog::{debug, Logger};
use tokio::{runtime::Handle, task};

use mithril_common::cardano_block_scanner::{BlockScanner, ChainScannedBlocks};
use mithril_common::crypto_helper::{MKTree, MKTreeNode};
Expand Down Expand Up @@ -174,13 +175,25 @@ impl CardanoTransactionsImporter {
.store_block_range_roots(block_ranges_with_merkle_root)
.await
}

async fn import_transactions_and_block_ranges(
&self,
up_to_beacon: BlockNumber,
) -> StdResult<()> {
self.import_transactions(up_to_beacon).await?;
self.import_block_ranges().await
}
}

#[async_trait]
impl TransactionsImporter for CardanoTransactionsImporter {
async fn import(&self, up_to_beacon: BlockNumber) -> StdResult<()> {
self.import_transactions(up_to_beacon).await?;
self.import_block_ranges().await
task::block_in_place(move || {
Handle::current().block_on(async move {
self.import_transactions_and_block_ranges(up_to_beacon)
.await
})
})
}
}

Expand Down Expand Up @@ -639,7 +652,7 @@ mod tests {
);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn importing_twice_starting_with_nothing_in_a_real_db_should_yield_transactions_in_same_order(
) {
let blocks = vec![
Expand Down Expand Up @@ -676,7 +689,7 @@ mod tests {
assert_eq!(cold_imported_transactions, warm_imported_transactions);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn when_rollbackward_should_remove_transactions() {
let connection = cardano_tx_db_connection().unwrap();
let repository = Arc::new(CardanoTransactionRepository::new(Arc::new(
Expand Down Expand Up @@ -719,7 +732,7 @@ mod tests {
assert_eq!(expected_remaining_transactions, stored_transactions);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn when_rollbackward_should_remove_block_ranges() {
let connection = cardano_tx_db_connection().unwrap();
let repository = Arc::new(CardanoTransactionRepository::new(Arc::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mithril_common::{
use test_extensions::StateMachineTester;

#[rustfmt::skip]
#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn test_create_cardano_transaction_single_signature() {
let protocol_parameters = tests_setup::setup_protocol_parameters();
let fixture = MithrilFixtureBuilder::default()
Expand Down
Loading