Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix balances query endpoint cost without indexation and behavior coins to spend with one parameter at zero #2662

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed
- [2632](https://github.com/FuelLabs/fuel-core/pull/2632): Improved performance of certain async trait impls in the gas price service.
- [2662](https://github.com/FuelLabs/fuel-core/pull/2662): Fix balances query endpoint cost without indexation and behavior coins to spend with one parameter at zero.

## [Version 0.41.4]

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.

16 changes: 3 additions & 13 deletions crates/fuel-core/src/coins_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ pub enum CoinsQueryError {
IncorrectMessageForeignKeyInIndex,
#[error("error while processing the query: {0}")]
UnexpectedInternalState(&'static str),
#[error("both total and max must be greater than 0 (provided total: {provided_total}, provided max: {provided_max})")]
IncorrectQueryParameters {
provided_total: u64,
provided_max: u16,
},
#[error("coins to spend index contains incorrect key")]
IncorrectCoinsToSpendIndexKey,
}
Expand Down Expand Up @@ -300,10 +295,7 @@ pub async fn select_coins_to_spend(
const DUST_TO_BIG_COINS_FACTOR: u16 = 5;

if total == 0 || max == 0 {
return Err(CoinsQueryError::IncorrectQueryParameters {
provided_total: total,
provided_max: max,
});
return Ok(vec![])
}

let adjusted_total = total.saturating_mul(TOTAL_AMOUNT_ADJUSTMENT_FACTOR);
Expand Down Expand Up @@ -1412,8 +1404,7 @@ mod tests {
.await;

// Then
assert!(matches!(result, Err(actual_error)
if CoinsQueryError::IncorrectQueryParameters{ provided_total: 101, provided_max: 0 } == actual_error));
assert_eq!(result, Ok(Vec::new()));
}

#[tokio::test]
Expand All @@ -1440,8 +1431,7 @@ mod tests {
.await;

// Then
assert!(matches!(result, Err(actual_error)
if CoinsQueryError::IncorrectQueryParameters{ provided_total: 0, provided_max: 101 } == actual_error));
assert_eq!(result, Ok(Vec::new()));
}

#[tokio::test]
Expand Down
6 changes: 4 additions & 2 deletions crates/fuel-core/src/schema/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ impl BalanceQuery {
// Rust SDK sends a query with child_complexity ≅ 11 and we want to support slightly more
// than 10k items in a single query (so we target 11k). The total complexity would be 11k * 11 = 121k,
// but since our default limit is 80k, we need the 0.66 factor.
#[graphql(complexity = "query_costs().balance_query +
// We use the expected cost for the balance_query to differiate between indexation case and non-indexation case.
// We assume that the balance_query cost is 0 when the indexation is available.
#[graphql(complexity = "if query_costs().balance_query == 0 { \
AurelienFT marked this conversation as resolved.
Show resolved Hide resolved
(child_complexity as f32 * first.unwrap_or_default() as f32 * 0.66) as usize + \
(child_complexity as f32 * last.unwrap_or_default() as f32 * 0.66) as usize
")]
} else { query_costs().balance_query }")]
AurelienFT marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +102 to +105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather it be explicit:

if indexation_set {
    query_costs().balance_query
} else {
    ...
}

If that's not possible, let's leave a clear comment explaining the relationship between 0 and indexation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

async fn balances(
&self,
ctx: &Context<'_>,
Expand Down
Loading