Skip to content

Commit a7108f0

Browse files
address Copilot feedback: validate XRC timestamp, use u128 for average sum
1 parent 85f5793 commit a7108f0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

rs/nns/governance/src/timer_tasks/update_icp_xdr_rate_related_data.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ pub(crate) fn compute_average_icp_xdr_rate(
8282
if count == 0 {
8383
return None;
8484
}
85-
let sum: u64 = filtered.into_iter().sum();
86-
Some(sum / count)
85+
let sum: u128 = filtered.into_iter().map(|r| r as u128).sum();
86+
Some((sum / count as u128) as u64)
8787
}
8888

8989
/// Compute the new maturity modulation in permyriad.
@@ -256,6 +256,16 @@ impl UpdateIcpXdrRateRelatedData {
256256
return None;
257257
}
258258

259+
// Verify that XRC returned a rate for the day we requested. If not, the rate
260+
// won't fill the expected slot and backfill would loop on the same day.
261+
if exchange_rate.timestamp != timestamp {
262+
println!(
263+
"{}UpdateIcpXdrRateRelatedData: requested timestamp {} but XRC returned {}; ignoring.",
264+
LOG_PREFIX, timestamp, exchange_rate.timestamp
265+
);
266+
return None;
267+
}
268+
259269
let rate = SampledPrice::from(&exchange_rate);
260270
if rate.xdr_permyriad_per_icp == 0 {
261271
println!(

0 commit comments

Comments
 (0)