Skip to content

Commit

Permalink
fix(block_producer): immediately return error if lock cannot be acqui…
Browse files Browse the repository at this point in the history
…red during production (#2413)

## Linked Issues/PRs
<!-- List of related issues/PRs -->
fixes #2412

## Description
<!-- List of detailed changes -->
Similar to how the lock is used in the sync process, we try to lock and
immediately return an error if a block was already being produced.

## Checklist
- [ ] Breaking changes are clearly marked as such in the PR description
and changelog
- [ ] New behavior is reflected in tests
- [ ] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [ ] I have reviewed the code myself
- [ ] I have created follow-up issues caused by this PR and linked them
here

### After merging, notify other teams

[Add or remove entries as needed]

- [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/)
- [ ] [Sway compiler](https://github.com/FuelLabs/sway/)
- [ ] [Platform
documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+)
(for out-of-organization contributors, the person merging the PR will do
this)
- [ ] Someone else?
  • Loading branch information
rymnc authored Oct 30, 2024
1 parent c72afba commit ec41f56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit ec41f56

Please sign in to comment.