Skip to content

Commit

Permalink
Fix balances query endpoint cost without indexation and behavior cois…
Browse files Browse the repository at this point in the history
…n to spend
  • Loading branch information
AurelienFT committed Feb 3, 2025
1 parent b501db2 commit e6a8740
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
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
4 changes: 2 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,10 @@ 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 +
#[graphql(complexity = "if query_costs().balance_query == 0 { \
(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 }")]
async fn balances(
&self,
ctx: &Context<'_>,
Expand Down

0 comments on commit e6a8740

Please sign in to comment.