Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix flaky BABE test #13199

Merged
merged 1 commit into from
Jan 21, 2023
Merged
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
18 changes: 13 additions & 5 deletions client/consensus/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,27 @@ async fn run_one_test(mutator: impl Fn(&mut TestHeader, Stage) + Send + Sync + '
.for_each(|_| future::ready(())),
);

let client_clone = client.clone();
babe_futures.push(
start_babe(BabeParams {
block_import: data.block_import.lock().take().expect("import set up during init"),
select_chain,
client,
env: environ,
sync_oracle: DummyOracle,
create_inherent_data_providers: Box::new(|_, _| async {
let slot = InherentDataProvider::from_timestamp_and_slot_duration(
Timestamp::current(),
SlotDuration::from_millis(SLOT_DURATION_MS),
create_inherent_data_providers: Box::new(move |parent, _| {
// Get the slot of the parent header and just increase this slot.
//
// Below we will running everything in one big future. If we would use
// time based slot, it can happen that on babe instance imports a block from
// another babe instance and then tries to build a block in the same slot making
// this test fail.
let parent_header = client_clone.header(parent).ok().flatten().unwrap();
let slot = Slot::from(
find_pre_digest::<TestBlock>(&parent_header).unwrap().slot() + 1,
);
Ok((slot,))

async move { Ok((InherentDataProvider::new(slot),)) }
}),
force_authoring: false,
backoff_authoring_blocks: Some(BackoffAuthoringOnFinalizedHeadLagging::default()),
Expand Down