Skip to content

Commit 00c4b6b

Browse files
committed
test(consistency): aux database consistency in integ tests
1 parent d822904 commit 00c4b6b

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

crates/fuel-core/src/p2p_test_helpers.rs

+39-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::{
1212
},
1313
fuel_core_graphql_api::storage::transactions::TransactionStatuses,
1414
p2p::Multiaddr,
15-
schema::tx::types::TransactionStatus,
1615
service::{
1716
Config,
1817
FuelService,
@@ -40,7 +39,10 @@ use fuel_core_poa::{
4039
Trigger,
4140
};
4241
use fuel_core_storage::{
43-
transactional::AtomicView,
42+
transactional::{
43+
AtomicView,
44+
HistoricalView,
45+
},
4446
StorageAsRef,
4547
};
4648
use fuel_core_types::{
@@ -571,6 +573,7 @@ impl Node {
571573
/// Wait for the node to reach consistency with the given transactions.
572574
pub async fn consistency(&mut self, txs: &HashMap<Bytes32, Transaction>) {
573575
let db = self.node.shared.database.off_chain();
576+
let mut latest_height = None;
574577
loop {
575578
let not_found = not_found_txs(db, txs);
576579

@@ -587,9 +590,40 @@ impl Node {
587590
result = wait_transaction.next() => {
588591
let status = result.unwrap().unwrap();
589592

590-
if matches!(status, TransactionStatus::Failure { .. })
591-
|| matches!(status, TransactionStatus::Success { .. }) {
592-
break
593+
match (latest_height, status.inclusion_height()) {
594+
(Some(ref mut latest_height), Some(inclusion_height)) => {
595+
if inclusion_height > *latest_height {
596+
*latest_height = inclusion_height;
597+
}
598+
break;
599+
}
600+
(None, Some(inclusion_height)) => {
601+
latest_height = Some(inclusion_height);
602+
break;
603+
}
604+
_ => {}
605+
}
606+
}
607+
_ = self.node.await_shutdown() => {
608+
panic!("Got a stop signal")
609+
}
610+
}
611+
}
612+
}
613+
614+
if let Some(latest_height) = latest_height {
615+
let gas_price_database = self.node.shared.database.gas_price();
616+
let mut db_consistency_ticker =
617+
tokio::time::interval(std::time::Duration::from_millis(50));
618+
// let compression_database = self.node.shared.database.compression();
619+
loop {
620+
tokio::select! {
621+
_ = db_consistency_ticker.tick() => {
622+
let gas_price_height = gas_price_database.latest_height().unwrap();
623+
// let compression_height = compression_database.latest_height().unwrap();
624+
625+
if gas_price_height >= latest_height {
626+
break;
593627
}
594628
}
595629
_ = self.node.await_shutdown() => {

crates/fuel-core/src/schema/tx/types.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ use fuel_core_types::{
7676
Executable,
7777
TxId,
7878
},
79-
fuel_types::canonical::Serialize,
79+
fuel_types::{
80+
canonical::Serialize,
81+
BlockHeight,
82+
},
8083
fuel_vm::ProgramState as VmProgramState,
8184
services::{
8285
executor::{
@@ -150,6 +153,17 @@ pub enum TransactionStatus {
150153
PreconfirmationFailure(PreconfirmationFailureStatus),
151154
}
152155

156+
impl TransactionStatus {
157+
/// Returns the inclusion height of a particular transaction status
158+
pub fn inclusion_height(&self) -> Option<BlockHeight> {
159+
match self {
160+
Self::Success(success_status) => success_status.status.block_height.into(),
161+
Self::Failure(failure_status) => failure_status.status.block_height.into(),
162+
_ => None,
163+
}
164+
}
165+
}
166+
153167
#[derive(Debug)]
154168
pub struct SubmittedStatus(pub Tai64);
155169

0 commit comments

Comments
 (0)