Skip to content

Commit b87a4c2

Browse files
authored
Merge pull request #1798 from input-output-hk/jpraynaud/1797/fix-blocking-ctx-database-insertions
Fix: aggregator and signer blocked during Cardano transactions import
2 parents e67c830 + 217f80c commit b87a4c2

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ As a minor extension, we have adopted a slightly different versioning convention
2828
- Chunk the Cardano transactions import in `mithril-signer` to reduce disk footprint by running the pruning process more frequently.
2929
- Add a database connection pool on the Cardano transaction repository for increased performances of the prover.
3030
- Import Cardano transactions with Chain Sync mini protocol and Pallas chain reader.
31+
- Avoid aggregator and signer being blocked when importing the Cardano transactions.
3132

3233
- Crates versions:
3334

mithril-aggregator/src/services/cardano_transactions_importer.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::Arc;
55

66
use async_trait::async_trait;
77
use slog::{debug, Logger};
8+
use tokio::{runtime::Handle, task};
89

910
use mithril_common::cardano_block_scanner::{BlockScanner, ChainScannedBlocks};
1011
use mithril_common::crypto_helper::{MKTree, MKTreeNode};
@@ -174,13 +175,25 @@ impl CardanoTransactionsImporter {
174175
.store_block_range_roots(block_ranges_with_merkle_root)
175176
.await
176177
}
178+
179+
async fn import_transactions_and_block_ranges(
180+
&self,
181+
up_to_beacon: BlockNumber,
182+
) -> StdResult<()> {
183+
self.import_transactions(up_to_beacon).await?;
184+
self.import_block_ranges().await
185+
}
177186
}
178187

179188
#[async_trait]
180189
impl TransactionsImporter for CardanoTransactionsImporter {
181190
async fn import(&self, up_to_beacon: BlockNumber) -> StdResult<()> {
182-
self.import_transactions(up_to_beacon).await?;
183-
self.import_block_ranges().await
191+
task::block_in_place(move || {
192+
Handle::current().block_on(async move {
193+
self.import_transactions_and_block_ranges(up_to_beacon)
194+
.await
195+
})
196+
})
184197
}
185198
}
186199

@@ -639,7 +652,7 @@ mod tests {
639652
);
640653
}
641654

642-
#[tokio::test]
655+
#[tokio::test(flavor = "multi_thread")]
643656
async fn importing_twice_starting_with_nothing_in_a_real_db_should_yield_transactions_in_same_order(
644657
) {
645658
let blocks = vec![
@@ -676,7 +689,7 @@ mod tests {
676689
assert_eq!(cold_imported_transactions, warm_imported_transactions);
677690
}
678691

679-
#[tokio::test]
692+
#[tokio::test(flavor = "multi_thread")]
680693
async fn when_rollbackward_should_remove_transactions() {
681694
let connection = cardano_tx_db_connection().unwrap();
682695
let repository = Arc::new(CardanoTransactionRepository::new(Arc::new(
@@ -719,7 +732,7 @@ mod tests {
719732
assert_eq!(expected_remaining_transactions, stored_transactions);
720733
}
721734

722-
#[tokio::test]
735+
#[tokio::test(flavor = "multi_thread")]
723736
async fn when_rollbackward_should_remove_block_ranges() {
724737
let connection = cardano_tx_db_connection().unwrap();
725738
let repository = Arc::new(CardanoTransactionRepository::new(Arc::new(

mithril-aggregator/tests/create_certificate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use mithril_common::{
1010
};
1111
use test_extensions::{utilities::get_test_dir, ExpectedCertificate, RuntimeTester};
1212

13-
#[tokio::test]
13+
#[tokio::test(flavor = "multi_thread")]
1414
async fn create_certificate() {
1515
let protocol_parameters = ProtocolParameters {
1616
k: 5,

mithril-signer/src/cardano_transactions_importer.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::Arc;
55

66
use async_trait::async_trait;
77
use slog::{debug, Logger};
8+
use tokio::{runtime::Handle, task};
89

910
use mithril_common::cardano_block_scanner::{BlockScanner, ChainScannedBlocks};
1011
use mithril_common::crypto_helper::{MKTree, MKTreeNode};
@@ -174,13 +175,25 @@ impl CardanoTransactionsImporter {
174175
.store_block_range_roots(block_ranges_with_merkle_root)
175176
.await
176177
}
178+
179+
async fn import_transactions_and_block_ranges(
180+
&self,
181+
up_to_beacon: BlockNumber,
182+
) -> StdResult<()> {
183+
self.import_transactions(up_to_beacon).await?;
184+
self.import_block_ranges().await
185+
}
177186
}
178187

179188
#[async_trait]
180189
impl TransactionsImporter for CardanoTransactionsImporter {
181190
async fn import(&self, up_to_beacon: BlockNumber) -> StdResult<()> {
182-
self.import_transactions(up_to_beacon).await?;
183-
self.import_block_ranges().await
191+
task::block_in_place(move || {
192+
Handle::current().block_on(async move {
193+
self.import_transactions_and_block_ranges(up_to_beacon)
194+
.await
195+
})
196+
})
184197
}
185198
}
186199

@@ -639,7 +652,7 @@ mod tests {
639652
);
640653
}
641654

642-
#[tokio::test]
655+
#[tokio::test(flavor = "multi_thread")]
643656
async fn importing_twice_starting_with_nothing_in_a_real_db_should_yield_transactions_in_same_order(
644657
) {
645658
let blocks = vec![
@@ -676,7 +689,7 @@ mod tests {
676689
assert_eq!(cold_imported_transactions, warm_imported_transactions);
677690
}
678691

679-
#[tokio::test]
692+
#[tokio::test(flavor = "multi_thread")]
680693
async fn when_rollbackward_should_remove_transactions() {
681694
let connection = cardano_tx_db_connection().unwrap();
682695
let repository = Arc::new(CardanoTransactionRepository::new(Arc::new(
@@ -719,7 +732,7 @@ mod tests {
719732
assert_eq!(expected_remaining_transactions, stored_transactions);
720733
}
721734

722-
#[tokio::test]
735+
#[tokio::test(flavor = "multi_thread")]
723736
async fn when_rollbackward_should_remove_block_ranges() {
724737
let connection = cardano_tx_db_connection().unwrap();
725738
let repository = Arc::new(CardanoTransactionRepository::new(Arc::new(

mithril-signer/tests/create_cardano_transaction_single_signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use mithril_common::{
99
use test_extensions::StateMachineTester;
1010

1111
#[rustfmt::skip]
12-
#[tokio::test]
12+
#[tokio::test(flavor = "multi_thread")]
1313
async fn test_create_cardano_transaction_single_signature() {
1414
let protocol_parameters = tests_setup::setup_protocol_parameters();
1515
let fixture = MithrilFixtureBuilder::default()

0 commit comments

Comments
 (0)