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(papyrus_p2p_sync): tx and state_diff tests wait for headers sync #3891

Open
wants to merge 1 commit into
base: noam.s/test_papyrus_p2p_sync_fix_class_from_syncing_before_state_diff_finishes
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions crates/papyrus_p2p_sync/src/client/state_diff_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ async fn state_diff_basic_flow() {
Action::ReceiveQuery(Box::new(|_query| ()), DataType::Header),
];

// Sleep so state diff sync will reach the sleep waiting for header protocol to receive new
// data.
actions.push(Action::SleepToLetSyncAdvance);
// Send headers with corresponding state diff length
for (i, (state_diff, _)) in state_diffs_and_chunks.iter().enumerate() {
actions.push(Action::SendHeader(DataOrFin(Some(random_header(
Expand All @@ -114,6 +117,24 @@ async fn state_diff_basic_flow() {
}
actions.push(Action::SendHeader(DataOrFin(None)));

let len = state_diffs_and_chunks.len();
// Wait for header sync to finish before continuing state diff sync.
actions.push(Action::CheckStorage(Box::new(move |reader| {
async move {
let block_number = BlockNumber(len.try_into().unwrap());
wait_for_marker(
DataType::Header,
&reader,
block_number,
SLEEP_DURATION_TO_LET_SYNC_ADVANCE,
TIMEOUT_FOR_TEST,
)
.await;
}
.boxed()
})));
actions.push(Action::SimulateWaitPeriodForNewData);

let len = state_diffs_and_chunks.len();
actions.push(Action::ReceiveQuery(
Box::new(move |query| {
Expand Down
21 changes: 21 additions & 0 deletions crates/papyrus_p2p_sync/src/client/transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ async fn transaction_basic_flow() {
Action::ReceiveQuery(Box::new(|_query| ()), DataType::Header),
];

// Sleep so transaction sync will reach the sleep waiting for header protocol to receive new
// data.
actions.push(Action::SleepToLetSyncAdvance);
// Send headers with corresponding transaction length
for (i, block_body) in block_bodies.iter().enumerate() {
actions.push(Action::SendHeader(DataOrFin(Some(random_header(
Expand All @@ -55,6 +58,24 @@ async fn transaction_basic_flow() {
}
actions.push(Action::SendHeader(DataOrFin(None)));

let len = block_bodies.len();
// Wait for header sync to finish before continuing transaction sync.
actions.push(Action::CheckStorage(Box::new(move |reader| {
async move {
let block_number = BlockNumber(len.try_into().unwrap());
wait_for_marker(
DataType::Header,
&reader,
block_number,
SLEEP_DURATION_TO_LET_SYNC_ADVANCE,
TIMEOUT_FOR_TEST,
)
.await;
}
.boxed()
})));
actions.push(Action::SimulateWaitPeriodForNewData);

// Send transactions for each block and then validate they were written
for (i, BlockBody { transactions, transaction_outputs, transaction_hashes }) in
block_bodies.into_iter().enumerate()
Expand Down
Loading