The num_currency_pairs is not incremented
Description
The put_price_for_currency_pair function is responsible for either updating the price of an existing CurrencyPair or creating a new CurrencyPairState if a currency pair does not exist. However, when a new CurrencyPairState is created, the num_currency_pairs state, which keeps track of the total number of currency pairs, is not incremented.
#[instrument(skip_all)]
async fn put_price_for_currency_pair(
&mut self,
currency_pair: CurrencyPair,
price: QuotePrice,
) -> Result<()> {
let state = if let Some(mut state) = self
.get_currency_pair_state(¤cy_pair)
.await
.wrap_err("failed to get currency pair state")?
{
// price update logic ..
// [..]
} else {
let id = self
.get_next_currency_pair_id()
.await
.wrap_err("failed to read next currency pair ID")?;
let next_id = id.increment().wrap_err("increment ID overflowed")?;
self.put_next_currency_pair_id(next_id)
.wrap_err("failed to put next currency pair ID")?;
CurrencyPairState {
price: Some(price),
nonce: CurrencyPairNonce::new(0),
id,
}
// no put_num_currency_pairs here
};
self.put_currency_pair_state(currency_pair, state)
.wrap_err("failed to put currency pair state")
}Impact
This mismatch could lead to issues in parts of the application that depend on an accurate num_currency_pairs count. It may cause skipped entries in reports and incorrect indexing when iterating over currency pairs.
Recommendations
Consider updating the put_price_for_currency_pair function to increment the num_currency_pairs state when a new CurrencyPairState is created.
Remediation
This issue has been acknowledged by Astria, and a fix was implemented in commit 7057387e↗.