Skip to content

Commit e85afdb

Browse files
fix(nns): remove unsafe math from neuron_data_validation (#6796)
<[Previous PR](https://github.com/dfinity/ic/pull/6795)|
1 parent 35386b2 commit e85afdb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

rs/nns/governance/src/neuron_data_validation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ impl Issues {
272272
.issue_groups_map
273273
.entry(discriminant(&issue))
274274
.or_default();
275-
issue_group.issues_count += 1;
275+
// @todo if we should log it?
276+
issue_group.issues_count = issue_group.issues_count.saturating_add(1);
276277
if issue_group.example_issues.len() < MAX_EXAMPLE_ISSUES_COUNT {
277278
issue_group.example_issues.push(issue);
278279
}
@@ -399,7 +400,7 @@ impl<Validator: CardinalityAndRangeValidator + Send + Sync> ValidationTask
399400
fn validate_next_chunk(&mut self, _neuron_store: &NeuronStore) -> Vec<ValidationIssue> {
400401
// Set a limit on the number of instructions used by this function.
401402
#[cfg(target_arch = "wasm32")]
402-
let instruction_limit = ic_cdk::api::instruction_counter() + 100_000_000;
403+
let instruction_limit = ic_cdk::api::instruction_counter().saturating_add(100_000_000);
403404
#[cfg(target_arch = "wasm32")]
404405
let keep_going = || ic_cdk::api::instruction_counter() < instruction_limit;
405406

@@ -473,7 +474,7 @@ impl CardinalityAndRangeValidator for PrincipalIndexValidator {
473474
fn validate_cardinalities(_neuron_store: &NeuronStore) -> Option<ValidationIssue> {
474475
let cardinality_primary = with_stable_neuron_store(|stable_neuron_store|
475476
// `stable_neuron_store.len()` is for the controllers.
476-
stable_neuron_store.lens().hot_keys + stable_neuron_store.len() as u64);
477+
stable_neuron_store.lens().hot_keys.saturating_add(stable_neuron_store.len() as u64));
477478
let cardinality_index =
478479
with_stable_neuron_indexes(|indexes| indexes.principal().num_entries()) as u64;
479480
// Because hot keys can also be controllers, the primary data might have larger cardinality

0 commit comments

Comments
 (0)