Skip to content

Commit

Permalink
Increase priority of timer over txpool event (#2345)
Browse files Browse the repository at this point in the history
If TxPool has a lot of events, it will interrupt the work of the timer.

### Before requesting review
- [x] I have reviewed the code myself

---------

Co-authored-by: AurelienFT <32803821+AurelienFT@users.noreply.github.com>
Co-authored-by: AurelienFT <aurefook@gmail.com>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent a35827d commit b9e7083
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- [2350](https://github.com/FuelLabs/fuel-core/pull/2350): Added a new CLI flag `graphql-number-of-threads` to limit the number of threads used by the GraphQL service. The default value is `2`, `0` enables the old behavior.

### Changed
### Fixed
- [2345](https://github.com/FuelLabs/fuel-core/pull/2345): In PoA increase priority of block creation timer trigger compare to txpool event management

### Changed
- [2334](https://github.com/FuelLabs/fuel-core/pull/2334): Prepare the GraphQL service for the switching to `async` methods.
- [2350](https://github.com/FuelLabs/fuel-core/pull/2350): Limited the number of threads used by the GraphQL service.

Expand Down
8 changes: 4 additions & 4 deletions crates/services/consensus_module/poa/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,6 @@ where
should_continue = false;
}
}
_ = self.new_txs_watcher.changed() => {
self.on_txpool_event().await.context("While processing txpool event")?;
should_continue = true;
}
_ = next_block_production => {
match self.on_timer().await.context("While processing timer event") {
Ok(()) => should_continue = true,
Expand All @@ -587,6 +583,10 @@ where
}
};
}
_ = self.new_txs_watcher.changed() => {
self.on_txpool_event().await.context("While processing txpool event")?;
should_continue = true;
}
}

Ok(should_continue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,32 @@ async fn interval_trigger_produces_blocks_in_the_future_when_time_rewinds() {
// similarly to how it works when time is lagging.
assert_eq!(second_block_time, start_time + block_time.as_secs() * 2);
}

#[tokio::test]
async fn interval_trigger_even_if_queued_tx_events() {
let block_time = Duration::from_secs(2);
let mut ctx = DefaultContext::new(Config {
trigger: Trigger::Interval { block_time },
signer: SignMode::Key(test_signing_key()),
metrics: false,
..Default::default()
})
.await;
let block_creation_notifier = Arc::new(Notify::new());
tokio::task::spawn({
let notifier = ctx.new_txs_notifier.clone();
async move {
loop {
time::sleep(Duration::from_nanos(10)).await;
notifier.send_replace(());
}
}
});
let block_creation_waiter = block_creation_notifier.clone();
tokio::task::spawn(async move {
ctx.block_import.recv().await.unwrap();
dbg!("First block produced");
block_creation_notifier.notify_waiters();
});
block_creation_waiter.notified().await;
}

0 comments on commit b9e7083

Please sign in to comment.