Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into txpool_metrics_up…
Browse files Browse the repository at this point in the history
…date
  • Loading branch information
rafal-ch committed Oct 31, 2024
2 parents fbb0a54 + 612d867 commit 1da8913
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 116 deletions.
5 changes: 4 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
* @xgreenx @Dentosal @MitchTurner

# Code owners for the gas price algorithm
crates/fuel-gas-price-algorithm @MitchTurner @rafal-ch
crates/fuel-gas-price-algorithm @MitchTurner @rafal-ch

# Code owners for the transaction pool
crates/services/txpool_v2 @AurelienFT
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2347](https://github.com/FuelLabs/fuel-core/pull/2364): Add activity concept in order to protect against infinitely increasing DA gas price scenarios
- [2362](https://github.com/FuelLabs/fuel-core/pull/2362): Added a new request_response protocol version `/fuel/req_res/0.0.2`. In comparison with `/fuel/req/0.0.1`, which returns an empty response when a request cannot be fulfilled, this version returns more meaningful error codes. Nodes still support the version `0.0.1` of the protocol to guarantee backward compatibility with fuel-core nodes. Empty responses received from nodes using the old protocol `/fuel/req/0.0.1` are automatically converted into an error `ProtocolV1EmptyResponse` with error code 0, which is also the only error code implemented. More specific error codes will be added in the future.
- [2386](https://github.com/FuelLabs/fuel-core/pull/2386): Add a flag to define the maximum number of file descriptors that RocksDB can use. By default it's half of the OS limit.
- [2376](https://github.com/FuelLabs/fuel-core/pull/2376): Add a way to fetch transactions in P2P without specifying a peer.

### 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
- [2378](https://github.com/FuelLabs/fuel-core/pull/2378): Use cached hash of the topic instead of calculating it on each publishing gossip message.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ itertools = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
tai64 = { version = "4.0", features = ["serde"] }
tai64 = { version = "4.1", features = ["serde"] }
thiserror = "1.0"
tracing = "0.1"

Expand Down
47 changes: 9 additions & 38 deletions crates/services/gas_price_service/src/v0/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,48 +165,19 @@ mod tests {
},
ports::MetadataStorage,
v0::{
algorithm::SharedV0Algorithm,
metadata::V0AlgorithmConfig,
service::GasPriceServiceV0,
uninitialized_task::initialize_algorithm,
},
};
use fuel_core_services::{
RunnableService,
Service,
ServiceRunner,
RunnableTask,
StateWatcher,
};
use fuel_core_types::fuel_types::BlockHeight;
use std::sync::Arc;
use tokio::sync::mpsc;

#[async_trait::async_trait]
impl<L2, Metadata> RunnableService for GasPriceServiceV0<L2, Metadata>
where
L2: L2BlockSource,
Metadata: MetadataStorage,
{
const NAME: &'static str = "GasPriceServiceV0";
type SharedData = SharedV0Algorithm;
type Task = Self;
type TaskParams = ();

fn shared_data(&self) -> Self::SharedData {
self.shared_algo.clone()
}

async fn into_task(
mut self,
_state_watcher: &StateWatcher,
_params: Self::TaskParams,
) -> anyhow::Result<Self::Task> {
let algorithm = self.algorithm_updater.algorithm();
self.shared_algo.update(algorithm).await;
Ok(self)
}
}

struct FakeL2BlockSource {
l2_block: mpsc::Receiver<BlockInfo>,
}
Expand Down Expand Up @@ -255,10 +226,12 @@ mod tests {
gas_used: 60,
block_gas_capacity: 100,
};

let (l2_block_sender, l2_block_receiver) = mpsc::channel(1);
let l2_block_source = FakeL2BlockSource {
l2_block: l2_block_receiver,
};

let metadata_storage = FakeMetadata::empty();
let l2_block_height = 0;
let config = V0AlgorithmConfig {
Expand All @@ -269,25 +242,23 @@ mod tests {
};
let (algo_updater, shared_algo) =
initialize_algorithm(&config, l2_block_height, &metadata_storage).unwrap();

let service = GasPriceServiceV0::new(
let mut service = GasPriceServiceV0::new(
l2_block_source,
metadata_storage,
shared_algo,
algo_updater,
);
let read_algo = service.next_block_algorithm();
let service = ServiceRunner::new(service);
let prev = read_algo.next_gas_price();
let mut watcher = StateWatcher::default();
let initial_price = read_algo.next_gas_price();

// when
service.start_and_await().await.unwrap();
service.run(&mut watcher).await.unwrap();
l2_block_sender.send(l2_block).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
service.shutdown().await.unwrap();

// then
let actual_price = read_algo.next_gas_price();
assert_ne!(prev, actual_price);
service.stop_and_await().await.unwrap();
assert_ne!(initial_price, actual_price);
}
}
34 changes: 18 additions & 16 deletions crates/services/gas_price_service/src/v0/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use fuel_core_services::{
BoxStream,
IntoBoxStream,
},
Service,
ServiceRunner,
RunnableTask,
StateWatcher,
};
use fuel_core_storage::{
transactional::AtomicView,
Expand All @@ -59,7 +59,6 @@ use fuel_core_types::{
use std::{
ops::Deref,
sync::Arc,
time::Duration,
};
use tokio::sync::mpsc::Receiver;

Expand Down Expand Up @@ -159,25 +158,25 @@ async fn next_gas_price__affected_by_new_l2_block() {
let height = 0;
let (algo_updater, shared_algo) =
initialize_algorithm(&config, height, &metadata_storage).unwrap();
let service = GasPriceServiceV0::new(
let mut service = GasPriceServiceV0::new(
l2_block_source,
metadata_storage,
shared_algo,
algo_updater,
);
let service = ServiceRunner::new(service);
let shared = service.shared.clone();
let initial = shared.next_gas_price();

let read_algo = service.next_block_algorithm();
let initial = read_algo.next_gas_price();
let mut watcher = StateWatcher::default();

// when
service.start_and_await().await.unwrap();
service.run(&mut watcher).await.unwrap();
l2_block_sender.send(l2_block).await.unwrap();
tokio::time::sleep(Duration::from_millis(10)).await;
service.shutdown().await.unwrap();

// then
let new = shared.next_gas_price();
let new = read_algo.next_gas_price();
assert_ne!(initial, new);
service.stop_and_await().await.unwrap();
}

#[tokio::test]
Expand All @@ -202,22 +201,25 @@ async fn next__new_l2_block_saves_old_metadata() {
let (algo_updater, shared_algo) =
initialize_algorithm(&config, height, &metadata_storage).unwrap();

let service = GasPriceServiceV0::new(
let mut service = GasPriceServiceV0::new(
l2_block_source,
metadata_storage,
shared_algo,
algo_updater,
);

// when
let service = ServiceRunner::new(service);
let read_algo = service.next_block_algorithm();
let mut watcher = StateWatcher::default();
let start = read_algo.next_gas_price();

service.start_and_await().await.unwrap();
service.run(&mut watcher).await.unwrap();
l2_block_sender.send(l2_block).await.unwrap();
tokio::time::sleep(Duration::from_millis(10)).await;
service.shutdown().await.unwrap();

// then
assert!(metadata_inner.lock().unwrap().is_some());
let new = read_algo.next_gas_price();
assert_ne!(start, new);
}

#[derive(Clone)]
Expand Down
Loading

0 comments on commit 1da8913

Please sign in to comment.