Skip to content

Commit 4669046

Browse files
committed
Wait for the off chain database to process all blocks
1 parent aba2bf4 commit 4669046

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

crates/fuel-core/src/p2p_test_helpers.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ use crate::{
66
CoinConfigGenerator,
77
},
88
combined_database::CombinedDatabase,
9-
database::Database,
9+
database::{
10+
database_description::off_chain::OffChain,
11+
Database,
12+
},
13+
fuel_core_graphql_api::storage::transactions::TransactionStatuses,
1014
p2p::Multiaddr,
1115
service::{
1216
Config,
@@ -33,7 +37,6 @@ use fuel_core_poa::{
3337
Trigger,
3438
};
3539
use fuel_core_storage::{
36-
tables::Transactions,
3740
transactional::AtomicView,
3841
StorageAsRef,
3942
};
@@ -59,7 +62,6 @@ use fuel_core_types::{
5962
services::p2p::GossipsubMessageAcceptance,
6063
};
6164
use futures::StreamExt;
62-
use itertools::Itertools;
6365
use rand::{
6466
rngs::StdRng,
6567
SeedableRng,
@@ -491,24 +493,27 @@ impl Node {
491493

492494
/// Wait for the node to reach consistency with the given transactions.
493495
pub async fn consistency(&mut self, txs: &HashMap<Bytes32, Transaction>) {
494-
let Self { db, .. } = self;
495-
let mut blocks = self.node.shared.block_importer.block_stream();
496-
while !not_found_txs(db, txs).is_empty() {
496+
let db = self.node.shared.database.off_chain();
497+
loop {
498+
let not_found = not_found_txs(db, txs);
499+
500+
if not_found.is_empty() {
501+
break;
502+
}
503+
504+
let tx_id = not_found[0];
505+
let mut wait_transaction =
506+
self.node.transaction_status_change(tx_id).unwrap();
507+
497508
tokio::select! {
498-
result = blocks.next() => {
499-
result.unwrap();
509+
result = wait_transaction.next() => {
510+
let _ = result.unwrap();
500511
}
501512
_ = self.node.await_shutdown() => {
502513
panic!("Got a stop signal")
503514
}
504515
}
505516
}
506-
507-
let count = db
508-
.all_transactions(None, None)
509-
.filter_ok(|tx| tx.is_script())
510-
.count();
511-
assert_eq!(count, txs.len());
512517
}
513518

514519
/// Wait for the node to reach consistency with the given transactions within 10 seconds.
@@ -570,13 +575,17 @@ impl Node {
570575
}
571576

572577
fn not_found_txs<'iter>(
573-
db: &'iter Database,
578+
db: &'iter Database<OffChain>,
574579
txs: &'iter HashMap<Bytes32, Transaction>,
575580
) -> Vec<TxId> {
576581
let mut not_found = vec![];
577582
txs.iter().for_each(|(id, tx)| {
578583
assert_eq!(id, &tx.id(&Default::default()));
579-
if !db.storage::<Transactions>().contains_key(id).unwrap() {
584+
let found = db
585+
.storage::<TransactionStatuses>()
586+
.contains_key(id)
587+
.unwrap();
588+
if !found {
580589
not_found.push(*id);
581590
}
582591
});

tests/tests/da_compression.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,13 @@ async fn da_compressed_blocks_are_available_from_non_block_producing_nodes() {
9898
)
9999
.await;
100100

101-
let mut producer = producers.pop().unwrap();
101+
let producer = producers.pop().unwrap();
102102
let mut validator = validators.pop().unwrap();
103103

104104
let v_client = FuelClient::from(validator.node.shared.graph_ql.bound_address);
105105

106106
// Insert some txs
107107
let expected = producer.insert_txs().await;
108-
producer.consistency_10s(&expected).await;
109108
validator.consistency_20s(&expected).await;
110109

111110
let block_height = 1u32.into();

0 commit comments

Comments
 (0)