Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
max-dfinity committed Nov 22, 2024
1 parent 731ad76 commit ce116e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rs/nns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ impl Governance {
// we are using a circular buffer to store them. This solution is not ideal, but
// we need to do a larger refactoring to use the correct API types instead of the internal
// governance proto at this level.
proto.recent_ballots = neuron.recent_ballots();
proto.recent_ballots = neuron.sorted_recent_ballots();
full_neurons.push(proto);
}
});
Expand Down
13 changes: 7 additions & 6 deletions rs/nns/governance/src/neuron/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct Neuron {
/// Map `Topic` to followees. The key is represented by an integer as
/// Protobuf does not support enum keys in maps.
pub followees: HashMap<i32, Followees>,
// TODO DO NOT MERGE make this private
/// Information about how this neuron voted in the recent past. It
/// only contains proposals that the neuron voted yes or no on.
pub recent_ballots: Vec<BallotInfo>,
Expand Down Expand Up @@ -436,18 +437,18 @@ impl Neuron {
std::cmp::min(ad_stake, u64::MAX as u128) as u64
}

pub(crate) fn recent_ballots(&self) -> Vec<BallotInfo> {
if self.recent_ballots_next_entry_index.is_none() {
self.recent_ballots.clone()
} else {
/// Get the recent ballots, with most recent ballots first
pub(crate) fn sorted_recent_ballots(&self) -> Vec<BallotInfo> {
if let Some(index) = self.recent_ballots_next_entry_index {
let recent_ballots = &self.recent_ballots;
let index = self.recent_ballots_next_entry_index.unwrap();
recent_ballots[index..]
.iter()
.chain(recent_ballots[..index].iter())
.rev()
.cloned()
.collect()
} else {
self.recent_ballots.clone()
}
}

Expand Down Expand Up @@ -906,7 +907,7 @@ impl Neuron {
|| self.visibility() == Some(Visibility::Public)
|| self.is_hotkey_or_controller(&requester);
if show_full {
recent_ballots.append(&mut self.recent_ballots());
recent_ballots.append(&mut self.sorted_recent_ballots());
joined_community_fund_timestamp_seconds = self.joined_community_fund_timestamp_seconds;
}

Expand Down
4 changes: 2 additions & 2 deletions rs/nns/governance/src/neuron/types/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ fn test_recent_ballots_accessor_pre_and_post_migration() {
.build();
neuron.recent_ballots_next_entry_index = None;

assert_eq!(neuron.recent_ballots(), recent_ballots);
assert_eq!(neuron.sorted_recent_ballots(), recent_ballots);

neuron.register_recent_ballot(Topic::NetworkEconomics, &ProposalId { id: 100 }, Vote::No);
assert_eq!(neuron.recent_ballots_next_entry_index, Some(1));
Expand All @@ -766,5 +766,5 @@ fn test_recent_ballots_accessor_pre_and_post_migration() {
recent_ballots
};

assert_eq!(neuron.recent_ballots(), expected_updated_ballots);
assert_eq!(neuron.sorted_recent_ballots(), expected_updated_ballots);
}

0 comments on commit ce116e8

Please sign in to comment.