Skip to content

Commit

Permalink
Remove deadline clock in POA and replace with tokio time functions. (#…
Browse files Browse the repository at this point in the history
…2109)

## Linked Issues/PRs
Closes #1917 

## Description
This PR removes the DeadlineClock structure and his usage in POA. It's
replaced by a mechanism using Tokio features.
This changes avoid the service to hangs up on an error, it will now wait
and retry a block production

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

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

### After merging, notify other teams

---------

Co-authored-by: Hannes Karppila <2204863+Dentosal@users.noreply.github.com>
Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
  • Loading branch information
3 people authored Aug 20, 2024
1 parent 3aecb45 commit 2caca61
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 353 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2096](https://github.com/FuelLabs/fuel-core/pull/2096): GraphQL endpoint to fetch blob byte code by its blob ID.

### Changed
- [2106](https://github.com/FuelLabs/fuel-core/pull/2106): Remove deadline clock in POA and replace with tokio time functions.

#### Breaking
- [2051](https://github.com/FuelLabs/fuel-core/pull/2051): Misdocumented `CONSENSUS_KEY` environ variable has been removed, use `CONSENSUS_KEY_SECRET` instead. Also raises MSRV to `1.79.0`.
Expand Down
23 changes: 13 additions & 10 deletions crates/fuel-core/src/graphql_api/worker_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub struct InitializeTask<TxPool, BlockImporter, OnChain, OffChain> {
chain_id: ChainId,
continue_on_error: bool,
tx_pool: TxPool,
blocks_events: BoxStream<SharedImportResult>,
block_importer: BlockImporter,
on_chain_database: OnChain,
off_chain_database: OffChain,
Expand Down Expand Up @@ -456,56 +457,57 @@ where
chain_id,
tx_pool,
block_importer,
blocks_events,
on_chain_database,
off_chain_database,
continue_on_error,
} = self;

let mut task = Task {
tx_pool,
block_importer: block_importer.block_events(),
block_importer: blocks_events,
database: off_chain_database,
chain_id,
continue_on_error,
};

let mut target_chain_height = on_chain_database.latest_height()?;
// Process all blocks that were imported before the service started.
// The block importer may produce some blocks on start-up during the
// genesis stage or the recovery process. In this case, we need to
// process these blocks because, without them,
// our block height will be less than on the chain database.
while let Some(Some(block)) = task.block_importer.next().now_or_never() {
target_chain_height = Some(*block.sealed_block.entity.header().height());
task.process_block(block)?;
}

sync_databases(&mut task, &on_chain_database, &block_importer)?;
sync_databases(&mut task, target_chain_height, &block_importer)?;

Ok(task)
}
}

fn sync_databases<TxPool, BlockImporter, OnChain, OffChain>(
fn sync_databases<TxPool, BlockImporter, OffChain>(
task: &mut Task<TxPool, OffChain>,
on_chain_database: &OnChain,
target_chain_height: Option<BlockHeight>,
import_result_provider: &BlockImporter,
) -> anyhow::Result<()>
where
TxPool: ports::worker::TxPool,
BlockImporter: ports::worker::BlockImporter,
OnChain: ports::worker::OnChainDatabase,
OffChain: ports::worker::OffChainDatabase,
{
loop {
let on_chain_height = on_chain_database.latest_height()?;
let off_chain_height = task.database.latest_height()?;

if on_chain_height < off_chain_height {
if target_chain_height < off_chain_height {
return Err(anyhow::anyhow!(
"The on-chain database height is lower than the off-chain database height"
));
"The target chain height is lower than the off-chain database height"
));
}

if on_chain_height == off_chain_height {
if target_chain_height == off_chain_height {
break;
}

Expand Down Expand Up @@ -587,6 +589,7 @@ where
{
ServiceRunner::new(InitializeTask {
tx_pool,
blocks_events: block_importer.block_events(),
block_importer,
on_chain_database,
off_chain_database,
Expand Down
3 changes: 2 additions & 1 deletion crates/fuel-core/src/service/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ impl Config {
#[cfg(not(feature = "rocksdb"))]
database_type: DbType::InMemory,
#[cfg(feature = "rocksdb")]
state_rewind_policy: Default::default(),
state_rewind_policy:
crate::state::historical_rocksdb::StateRewindPolicy::RewindFullRange,
};
let starting_gas_price = 0;
let gas_price_change_percent = 0;
Expand Down
230 changes: 0 additions & 230 deletions crates/services/consensus_module/poa/src/deadline_clock.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/services/consensus_module/poa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![deny(warnings)]
#![allow(clippy::blocks_in_conditions)] // False positives with tracing macros

mod deadline_clock;
mod sync;

#[cfg(test)]
Expand Down
Loading

0 comments on commit 2caca61

Please sign in to comment.