Skip to content

Commit

Permalink
Fetch ConsensusParameters from the database (FuelLabs#1809)
Browse files Browse the repository at this point in the history
Related issue FuelLabs#1753

The change fetches the `ConsensusParameters` from the database and
caches it inside of the `ConsensusParametersProvider`. The
`ConsensusParametersProvider` has a service that runs in the background
and listens for a new block from the block importer. If a new block uses
a new consensus parameters version, the `ConsensusParametersProvider`
will update the internal `latest_consensus_parameters_version` variable
and cache a new `ConsensusParameters`.

### Before requesting review
- [x] I have reviewed the code myself
  • Loading branch information
xgreenx authored Apr 11, 2024
1 parent df142c6 commit e99b0b4
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Description of the upcoming release here.
- [#1812](https://github.com/FuelLabs/fuel-core/pull/1812): Follow-up PR to simplify the logic around parallel snapshot creation.

### Changed
- [#1808](https://github.com/FuelLabs/fuel-core/pull/1808): Fetch consensus parameters from the database.
- [#1809](https://github.com/FuelLabs/fuel-core/pull/1809): Fetch `ConsensusParameters` from the database
- [#1808](https://github.com/FuelLabs/fuel-core/pull/1808): Fetch consensus parameters from the provider.

## [Version 0.24.2]

Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ mod tests {

// current services: graphql, graphql worker, txpool, PoA
#[allow(unused_mut)]
let mut expected_services = 4;
let mut expected_services = 5;

// Relayer service is disabled with `Config::local_node`.
// #[cfg(feature = "relayer")]
Expand Down
10 changes: 4 additions & 6 deletions crates/fuel-core/src/service/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use fuel_core_services::stream::BoxStream;
#[cfg(feature = "p2p")]
use fuel_core_types::services::p2p::peer_reputation::AppScore;
use fuel_core_types::{
fuel_tx::ConsensusParameters,
fuel_types::BlockHeight,
services::block_importer::SharedImportResult,
};
Expand All @@ -25,6 +24,7 @@ use std::sync::Arc;

pub mod block_importer;
pub mod consensus_module;
pub mod consensus_parameters_provider;
pub mod executor;
pub mod graphql_api;
#[cfg(feature = "p2p")]
Expand All @@ -38,14 +38,12 @@ pub mod txpool;

#[derive(Debug, Clone)]
pub struct ConsensusParametersProvider {
consensus_parameters: Arc<ConsensusParameters>,
shared_state: consensus_parameters_provider::SharedState,
}

impl ConsensusParametersProvider {
pub fn new(consensus_parameters: ConsensusParameters) -> Self {
Self {
consensus_parameters: Arc::new(consensus_parameters),
}
pub fn new(shared_state: consensus_parameters_provider::SharedState) -> Self {
Self { shared_state }
}
}

Expand Down
Loading

0 comments on commit e99b0b4

Please sign in to comment.