Skip to content

Commit d3a3f07

Browse files
refactor(nns): More strictly represent neuron visibility. (dfinity#3697)
This is done by introducing a native Visibility type, and making native Neuron use it. The most interesting difference between this native Visibility and pb::Visibility is that native Visibility has no Unspecified value. Also, got rid of Option. Without the possibility that visibility can be None, we are able to restore `#[derive(PartialEq)]` on Neuron. Thus, we ditch the custom `PartialEq` implementation. Also, made the `known_neuron_data` field NOT `pub` anymore. That way, Neuron can prevent it from becoming inconsistent with `visibility`. # References Closes [NNS1-3239]. [NNS1-3239]: https://dfinity.atlassian.net/browse/NNS1-3239
1 parent 4d98696 commit d3a3f07

File tree

12 files changed

+239
-222
lines changed

12 files changed

+239
-222
lines changed

rs/nns/governance/canbench/canbench_results.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ benches:
7979
scopes: {}
8080
list_active_neurons_fund_neurons_stable:
8181
total:
82-
instructions: 2757139
82+
instructions: 2820000
8383
heap_increase: 0
8484
stable_memory_increase: 0
8585
scopes: {}
@@ -97,7 +97,7 @@ benches:
9797
scopes: {}
9898
list_neurons_ready_to_unstake_maturity_stable:
9999
total:
100-
instructions: 41457093
100+
instructions: 43300000
101101
heap_increase: 0
102102
stable_memory_increase: 0
103103
scopes: {}
@@ -121,7 +121,7 @@ benches:
121121
scopes: {}
122122
list_ready_to_spawn_neuron_ids_stable:
123123
total:
124-
instructions: 41428996
124+
instructions: 43270000
125125
heap_increase: 0
126126
stable_memory_increase: 0
127127
scopes: {}

rs/nns/governance/src/governance.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
reassemble_governance_proto, split_governance_proto, HeapGovernanceData, XdrConversionRate,
1212
},
1313
migrations::maybe_run_migrations,
14-
neuron::{DissolveStateAndAge, Neuron, NeuronBuilder},
14+
neuron::{DissolveStateAndAge, Neuron, NeuronBuilder, Visibility},
1515
neuron_data_validation::{NeuronDataValidationSummary, NeuronDataValidator},
1616
neuron_store::{
1717
backfill_some_voting_power_refreshed_timestamps, metrics::NeuronSubsetMetrics,
@@ -63,7 +63,7 @@ use crate::{
6363
ProposalData, ProposalRewardStatus, ProposalStatus, RestoreAgingSummary, RewardEvent,
6464
RewardNodeProvider, RewardNodeProviders, SettleNeuronsFundParticipationRequest,
6565
SettleNeuronsFundParticipationResponse, StopOrStartCanister, Tally, Topic,
66-
UpdateCanisterSettings, UpdateNodeProvider, Visibility, Vote, VotingPowerEconomics,
66+
UpdateCanisterSettings, UpdateNodeProvider, Vote, VotingPowerEconomics,
6767
WaitForQuietState, XdrConversionRate as XdrConversionRatePb,
6868
},
6969
},
@@ -2303,7 +2303,7 @@ impl Governance {
23032303
// neuron is public, and the caller requested that
23042304
// public neurons be included (in full_neurons).
23052305
|| (include_public_neurons_in_full_neurons
2306-
&& neuron.visibility() == Some(Visibility::Public)
2306+
&& neuron.visibility() == Visibility::Public
23072307
);
23082308
if let_caller_read_full_neuron {
23092309
full_neurons.push(neuron.clone().into_api(now, self.voting_power_economics()));
@@ -2332,7 +2332,7 @@ impl Governance {
23322332
self.neuron_store
23332333
.with_neuron(&neuron_id, |n| KnownNeuron {
23342334
id: Some(n.id()),
2335-
known_neuron_data: n.known_neuron_data.clone(),
2335+
known_neuron_data: n.known_neuron_data().cloned(),
23362336
})
23372337
.map_err(|e| {
23382338
println!(
@@ -6259,7 +6259,7 @@ impl Governance {
62596259
"No neuron ID specified in the request to register a known neuron.",
62606260
)
62616261
})?;
6262-
let known_neuron_data = known_neuron.known_neuron_data.as_ref().ok_or_else(|| {
6262+
let known_neuron_data = known_neuron.known_neuron_data.ok_or_else(|| {
62636263
GovernanceError::new_with_message(
62646264
ErrorType::NotFound,
62656265
"No known neuron data specified in the register neuron request.",
@@ -6300,10 +6300,7 @@ impl Governance {
63006300
}
63016301

63026302
self.with_neuron_mut(&neuron_id, |neuron| {
6303-
neuron
6304-
.known_neuron_data
6305-
.replace(known_neuron_data.clone())
6306-
.map(|old_known_neuron_data| old_known_neuron_data.name)
6303+
neuron.set_known_neuron_data(known_neuron_data)
63076304
})?;
63086305

63096306
Ok(())

0 commit comments

Comments
 (0)