Skip to content

Commit

Permalink
Merge branch 'master' into fix_api_bug_last
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT authored Nov 14, 2024
2 parents 0d4e7f9 + 552ba75 commit 2e0076b
Show file tree
Hide file tree
Showing 34 changed files with 1,275 additions and 147 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [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.
- [2327](https://github.com/FuelLabs/fuel-core/pull/2327): Add more services tests and more checks of the pool. Also add an high level documentation for users of the pool and contributors.
- [2416](https://github.com/FuelLabs/fuel-core/issues/2416): Define the `GasPriceServiceV1` task.


### Fixed
- [2366](https://github.com/FuelLabs/fuel-core/pull/2366): The `importer_gas_price_for_block` metric is properly collected.
Expand All @@ -29,6 +32,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### 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.
- [2377](https://github.com/FuelLabs/fuel-core/pull/2377): Add more errors that can be returned as responses when using protocol `/fuel/req_res/0.0.2`. The errors supported are `ProtocolV1EmptyResponse` (status code `0`) for converting empty responses sent via protocol `/fuel/req_res/0.0.1`, `RequestedRangeTooLarge`(status code `1`) if the client requests a range of objects such as sealed block headers or transactions too large, `Timeout` (status code `2`) if the remote peer takes too long to fulfill a request, or `SyncProcessorOutOfCapacity` if the remote peer is fulfilling too many requests concurrently.

#### Breaking
- [2389](https://github.com/FuelLabs/fuel-core/pull/2258): Updated the `messageProof` GraphQL schema to return a non-nullable `MessageProof`.

## [Version 0.40.0]

Expand Down Expand Up @@ -57,7 +64,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2324](https://github.com/FuelLabs/fuel-core/pull/2324): Added metrics for sync, async processor and for all GraphQL queries.
- [2320](https://github.com/FuelLabs/fuel-core/pull/2320): Added new CLI flag `graphql-max-resolver-recursive-depth` to limit recursion within resolver. The default value it "1".


## Fixed
- [2320](https://github.com/FuelLabs/fuel-core/issues/2320): Prevent `/health` and `/v1/health` from being throttled by the concurrency limiter.
- [2322](https://github.com/FuelLabs/fuel-core/issues/2322): Set the salt of genesis contracts to zero on execution.
Expand Down
2 changes: 1 addition & 1 deletion crates/client/assets/debugAdapterProtocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@
{ "$ref": "#/definitions/Request" },
{
"type": "object",
"description": "Replaces all existing instruction breakpoints. Typically, instruction breakpoints would be set from a diassembly window. \nTo clear all instruction breakpoints, specify an empty array.\nWhen an instruction breakpoint is hit, a 'stopped' event (with reason 'instruction breakpoint') is generated.\nClients should only call this request if the capability 'supportsInstructionBreakpoints' is true.",
"description": "Replaces all existing instruction breakpoints. Typically, instruction breakpoints would be set from a disassembly window. \nTo clear all instruction breakpoints, specify an empty array.\nWhen an instruction breakpoint is hit, a 'stopped' event (with reason 'instruction breakpoint') is generated.\nClients should only call this request if the capability 'supportsInstructionBreakpoints' is true.",
"properties": {
"command": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ type Query {
"""
owner: Address, first: Int, after: String, last: Int, before: String
): MessageConnection!
messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof
messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof!
messageStatus(nonce: Nonce!): MessageStatus!
relayedTransactionStatus(
"""
Expand Down
11 changes: 2 additions & 9 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ impl FuelClient {
nonce: &Nonce,
commit_block_id: Option<&BlockId>,
commit_block_height: Option<BlockHeight>,
) -> io::Result<Option<types::MessageProof>> {
) -> io::Result<types::MessageProof> {
let transaction_id: TransactionId = (*transaction_id).into();
let nonce: schema::Nonce = (*nonce).into();
let commit_block_id: Option<schema::BlockId> =
Expand All @@ -1153,14 +1153,7 @@ impl FuelClient {
commit_block_id,
commit_block_height,
});

let proof = self
.query(query)
.await?
.message_proof
.map(TryInto::try_into)
.transpose()?;

let proof = self.query(query).await?.message_proof.try_into()?;
Ok(proof)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/client/schema/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub struct MessageProofQuery {
commitBlockId: $commit_block_id,
commitBlockHeight: $commit_block_height
)]
pub message_proof: Option<MessageProof>,
pub message_proof: MessageProof,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions crates/fuel-core/src/schema/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl MessageQuery {
nonce: Nonce,
commit_block_id: Option<BlockId>,
commit_block_height: Option<U32>,
) -> async_graphql::Result<Option<MessageProof>> {
) -> async_graphql::Result<MessageProof> {
let query = ctx.read_view()?;
let height = match (commit_block_id, commit_block_height) {
(Some(commit_block_id), None) => {
Expand All @@ -157,7 +157,7 @@ impl MessageQuery {
height,
)?;

Ok(Some(MessageProof(proof)))
Ok(MessageProof(proof))
}

#[graphql(complexity = "query_costs().storage_read + child_complexity")]
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-gas-price-algorithm/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ impl AlgorithmUpdaterV1 {
if !height_range.is_empty() {
self.da_block_update(height_range, range_cost)?;
self.recalculate_projected_cost();
self.update_da_gas_price();
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,166 @@ fn update_da_record_data__da_block_updates_projected_total_cost_with_known_and_g
let expected = new_known_total_cost + guessed_part;
assert_eq!(actual, expected as u128);
}

#[test]
fn update_da_record_data__da_block_lowers_da_gas_price() {
// given
let da_cost_per_byte = 40;
let da_recorded_block_height = 10;
let l2_block_height = 11;
let original_known_total_cost = 150;
let unrecorded_blocks = vec![BlockBytes {
height: 11,
block_bytes: 3000,
}];
let da_p_component = 2;
let guessed_cost: u64 = unrecorded_blocks
.iter()
.map(|block| block.block_bytes * da_cost_per_byte)
.sum();
let projected_total_cost = original_known_total_cost + guessed_cost;

let mut updater = UpdaterBuilder::new()
.with_da_cost_per_byte(da_cost_per_byte as u128)
.with_da_p_component(da_p_component)
.with_last_profit(10, 0)
.with_da_recorded_block_height(da_recorded_block_height)
.with_l2_block_height(l2_block_height)
.with_projected_total_cost(projected_total_cost as u128)
.with_known_total_cost(original_known_total_cost as u128)
.with_unrecorded_blocks(unrecorded_blocks.clone())
.build();

let new_cost_per_byte = 100;
let (recorded_heights, recorded_cost) =
unrecorded_blocks
.iter()
.fold((vec![], 0), |(mut range, cost), block| {
range.push(block.height);
(range, cost + block.block_bytes * new_cost_per_byte)
});
let min = recorded_heights.iter().min().unwrap();
let max = recorded_heights.iter().max().unwrap();
let recorded_range = *min..(max + 1);

let old_da_gas_price = updater.new_scaled_da_gas_price;

// when
updater
.update_da_record_data(recorded_range, recorded_cost as u128)
.unwrap();

// then
let new_da_gas_price = updater.new_scaled_da_gas_price;
// because the profit is 10 and the da_p_component is 2, the new da gas price should be lesser than the previous one.
assert_eq!(new_da_gas_price, 0);
assert_ne!(old_da_gas_price, new_da_gas_price);
}

#[test]
fn update_da_record_data__da_block_increases_da_gas_price() {
// given
let da_cost_per_byte = 40;
let da_recorded_block_height = 10;
let l2_block_height = 11;
let original_known_total_cost = 150;
let unrecorded_blocks = vec![BlockBytes {
height: 11,
block_bytes: 3000,
}];
let da_p_component = 2;
let guessed_cost: u64 = unrecorded_blocks
.iter()
.map(|block| block.block_bytes * da_cost_per_byte)
.sum();
let projected_total_cost = original_known_total_cost + guessed_cost;

let mut updater = UpdaterBuilder::new()
.with_da_cost_per_byte(da_cost_per_byte as u128)
.with_da_p_component(da_p_component)
.with_last_profit(-10, 0)
.with_da_recorded_block_height(da_recorded_block_height)
.with_l2_block_height(l2_block_height)
.with_projected_total_cost(projected_total_cost as u128)
.with_known_total_cost(original_known_total_cost as u128)
.with_unrecorded_blocks(unrecorded_blocks.clone())
.build();

let new_cost_per_byte = 100;
let (recorded_heights, recorded_cost) =
unrecorded_blocks
.iter()
.fold((vec![], 0), |(mut range, cost), block| {
range.push(block.height);
(range, cost + block.block_bytes * new_cost_per_byte)
});
let min = recorded_heights.iter().min().unwrap();
let max = recorded_heights.iter().max().unwrap();
let recorded_range = *min..(max + 1);

let old_da_gas_price = updater.new_scaled_da_gas_price;

// when
updater
.update_da_record_data(recorded_range, recorded_cost as u128)
.unwrap();

// then
let new_da_gas_price = updater.new_scaled_da_gas_price;
// because the profit is -10 and the da_p_component is 2, the new da gas price should be greater than the previous one.
assert_eq!(new_da_gas_price, 6);
assert_ne!(old_da_gas_price, new_da_gas_price);
}

#[test]
fn update_da_record_data__da_block_will_not_change_da_gas_price() {
// given
let da_cost_per_byte = 40;
let da_recorded_block_height = 10;
let l2_block_height = 11;
let original_known_total_cost = 150;
let unrecorded_blocks = vec![BlockBytes {
height: 11,
block_bytes: 3000,
}];
let da_p_component = 2;
let guessed_cost: u64 = unrecorded_blocks
.iter()
.map(|block| block.block_bytes * da_cost_per_byte)
.sum();
let projected_total_cost = original_known_total_cost + guessed_cost;

let mut updater = UpdaterBuilder::new()
.with_da_cost_per_byte(da_cost_per_byte as u128)
.with_da_p_component(da_p_component)
.with_last_profit(0, 0)
.with_da_recorded_block_height(da_recorded_block_height)
.with_l2_block_height(l2_block_height)
.with_projected_total_cost(projected_total_cost as u128)
.with_known_total_cost(original_known_total_cost as u128)
.with_unrecorded_blocks(unrecorded_blocks.clone())
.build();

let new_cost_per_byte = 100;
let (recorded_heights, recorded_cost) =
unrecorded_blocks
.iter()
.fold((vec![], 0), |(mut range, cost), block| {
range.push(block.height);
(range, cost + block.block_bytes * new_cost_per_byte)
});
let min = recorded_heights.iter().min().unwrap();
let max = recorded_heights.iter().max().unwrap();
let recorded_range = *min..(max + 1);

let old_da_gas_price = updater.new_scaled_da_gas_price;

// when
updater
.update_da_record_data(recorded_range, recorded_cost as u128)
.unwrap();

// then
let new_da_gas_price = updater.new_scaled_da_gas_price;
assert_eq!(old_da_gas_price, new_da_gas_price);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ use crate::{
ports::MetadataStorage,
};
use fuel_core_storage::{
codec::{
postcard::Postcard,
Encode,
},
kv_store::KeyValueInspect,
structured_storage::StructuredStorage,
transactional::{
Expand Down Expand Up @@ -101,6 +105,8 @@ pub fn get_block_info(
height: (*block.header().height()).into(),
gas_used: used_gas,
block_gas_capacity: block_gas_limit,
block_bytes: Postcard::encode(block).len() as u64,
block_fees: fee,
};
Ok(info)
}
Expand Down
4 changes: 4 additions & 0 deletions crates/services/gas_price_service/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ pub enum BlockInfo {
gas_used: u64,
// Total gas capacity of the block
block_gas_capacity: u64,
// The size of block in bytes
block_bytes: u64,
// The fees the block has collected
block_fees: u64,
},
}
3 changes: 3 additions & 0 deletions crates/services/gas_price_service/src/v0/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ where
height,
gas_used,
block_gas_capacity,
..
} => {
self.handle_normal_block(height, gas_used, block_gas_capacity)
.await?;
Expand Down Expand Up @@ -225,6 +226,8 @@ mod tests {
height: block_height,
gas_used: 60,
block_gas_capacity: 100,
block_bytes: 100,
block_fees: 100,
};

let (l2_block_sender, l2_block_receiver) = mpsc::channel(1);
Expand Down
4 changes: 4 additions & 0 deletions crates/services/gas_price_service/src/v0/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ async fn next_gas_price__affected_by_new_l2_block() {
height: 1,
gas_used: 60,
block_gas_capacity: 100,
block_bytes: 100,
block_fees: 100,
};
let (l2_block_sender, l2_block_receiver) = tokio::sync::mpsc::channel(1);
let l2_block_source = FakeL2BlockSource {
Expand Down Expand Up @@ -186,6 +188,8 @@ async fn next__new_l2_block_saves_old_metadata() {
height: 1,
gas_used: 60,
block_gas_capacity: 100,
block_bytes: 100,
block_fees: 100,
};
let (l2_block_sender, l2_block_receiver) = tokio::sync::mpsc::channel(1);
let l2_block_source = FakeL2BlockSource {
Expand Down
1 change: 1 addition & 0 deletions crates/services/gas_price_service/src/v1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod algorithm;
pub mod da_source_service;
pub mod metadata;
pub mod service;
7 changes: 6 additions & 1 deletion crates/services/gas_price_service/src/v1/algorithm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::common::gas_price_algorithm::GasPriceAlgorithm;
use crate::common::gas_price_algorithm::{
GasPriceAlgorithm,
SharedGasPriceAlgo,
};
use fuel_core_types::fuel_types::BlockHeight;
use fuel_gas_price_algorithm::v1::AlgorithmV1;

Expand All @@ -11,3 +14,5 @@ impl GasPriceAlgorithm for AlgorithmV1 {
self.worst_case(block_height.into())
}
}

pub type SharedV1Algorithm = SharedGasPriceAlgo<AlgorithmV1>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod service;

#[derive(Debug, Default, Clone, Eq, Hash, PartialEq)]
pub struct DaBlockCosts {
pub l2_block_range: core::ops::Range<u64>,
pub l2_block_range: core::ops::Range<u32>,
pub blob_size_bytes: u32,
pub blob_cost_wei: u128,
}
Expand Down
Loading

0 comments on commit 2e0076b

Please sign in to comment.