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(block_producer): immediately return error if lock cannot be acquired during production #2413

Merged
merged 2 commits into from
Oct 30, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- [2366](https://github.com/FuelLabs/fuel-core/pull/2366): The `importer_gas_price_for_block` metric is properly collected.
- [2369](https://github.com/FuelLabs/fuel-core/pull/2369): The `transaction_insertion_time_in_thread_pool_milliseconds` metric is properly collected.
- [2413](https://github.com/FuelLabs/fuel-core/issues/2413): block production immediately errors if unable to lock the mutex.

### Changed

Expand Down
10 changes: 7 additions & 3 deletions crates/services/producer/src/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ where
where
Executor: ports::BlockProducer<Vec<Transaction>> + 'static,
{
let _production_guard = self.lock.lock().await;
let _production_guard = self.lock.try_lock().map_err(|_| {
anyhow!("Failed to acquire the production lock, block production is already in progress")
})?;

let mut transactions_source = predefined_block.transactions().to_vec();

Expand Down Expand Up @@ -185,8 +187,10 @@ where
// 2. parallel throughput
// - Execute block with production mode to correctly malleate txs outputs and block headers

// prevent simultaneous block production calls, the guard will drop at the end of this fn.
let _production_guard = self.lock.lock().await;
// prevent simultaneous block production calls
let _production_guard = self.lock.try_lock().map_err(|_| {
anyhow!("Failed to acquire the production lock, block production is already in progress")
})?;

let gas_price = self.calculate_gas_price().await?;

Expand Down
Loading