# NNS Update, Nov 22, 2024

**URL:** <https://forum.dfinity.org/t/nns-update-nov-22-2024/37675>\
**Category:** Developers\
**Tags:** nns, Protocol-canister-management, Service-nervous-system-mgmt\
**Created:** [November 22, 2024, 11:03pm UTC](https://forum.dfinity.org/t/nns-update-nov-22-2024/37675 "2024-11-22T23:03:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonzhu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jasonzhu/32/12251_2.png) [@jasonzhu](https://forum.dfinity.org/u/jasonzhu)\
**Post date:** [November 22, 2024, 11:03pm UTC](https://forum.dfinity.org/t/nns-update-nov-22-2024/37675/1 "2024-11-22T23:03:28Z")

</div>

The NNS Team submitted the following proposals. DFINITY plans to vote on these proposals the following Monday.

## Proposals to be Submitted

### NNS Governance

[https://dashboard.internetcomputer.org/proposal/134261](https://dashboard.internetcomputer.org/proposal/134261)

### 

````auto

# Upgrade the Governance Canister to Commit 7e25f22

__Proposer__ : jason.zhu at dfinity.org

__Source code__ : [7e25f225129bbe6e44191b580b387362864145ee][new-commit]

[new-commit]: https://github.com/dfinity/ic/tree/7e25f225129bbe6e44191b580b387362864145ee

## New Commits

```

$ git log --format="%C(auto) %h %s" fa149557c44967f621c03224460eb6639f5c03c6..7e25f225129bbe6e44191b580b387362864145ee -- ./rs/nns/governance ./rs/sns/init

7e25f22512 feat(nns): Adjust batch limit for moving neurons to stable memory (#2778)

fbbb395308 perf(nns): Add benchmarks for periodic tasks (#2729)

2f63d24ecb fix(nns): Avoid cloning heap_neurons to avoid performance penalty (#2726)

c9065698a9 feat(nns): Move inactive neurons in the heap to stable storage through a timer (#2643)

1d73be3778 refactor(nns): Make cast_vote_and_cascade_follow async (#2670)

49000055d3 fix: Try to address spurious `unresolved import` errors (#2668)

363e697195 refactor(nns): Move cast_vote_and_cascade_follow into Governance struct (#2600)

139b0f21c0 refactor(nns): Refactor voting as precursor for more scalability (#2528)

a920fc7c4f refactor(nns): Spin out sum_weighted_voting_power. (#2619)

```

## Current Version

__Current git hash__ : fa149557c44967f621c03224460eb6639f5c03c6

__Current wasm hash__ : fe417b2c69c36ecc2b86d8e1ec33e170a2b69fc8dc612124ec89bffba53b2438

## Verification

See the general instructions on [how to verify] proposals like this. A "quick

start" guide is provided here.

[how to verify]: https://github.com/dfinity/ic/tree/7e25f225129bbe6e44191b580b387362864145ee/rs/nervous_system/docs/proposal_verification.md

### WASM Verification

See ["Building the code"][prereqs] for prerequisites.

[prereqs]: https://github.com/dfinity/ic/tree/7e25f225129bbe6e44191b580b387362864145ee/README.adoc#building-the-code

```

# 1. Get a copy of the code.

git clone git@github.com:dfinity/ic.git

cd ic

# Or, if you already have a copy of the ic repo,

git fetch

git checkout 7e25f225129bbe6e44191b580b387362864145ee

# 2. Build canisters.

./ci/container/build-ic.sh -c

# 3. Fingerprint the result.

sha256sum ./artifacts/canisters/governance-canister.wasm.gz

```

This should match `wasm_module_hash` field of this proposal.

````

---

<div class="post-metadata">

**Author:** ![cyberowl](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cyberowl/32/3635_2.png) [@cyberowl](https://forum.dfinity.org/u/cyberowl)\
**Post date:** [November 24, 2024, 9:34am UTC](https://forum.dfinity.org/t/nns-update-nov-22-2024/37675/2 "2024-11-24T09:34:06Z")

</div>

# proposal - [134261](https://dashboard.internetcomputer.org/proposal/134261)

 ![Screenshot 2024-11-24 at 1.18.38 AM](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/c/9/c90672774b251133e688ed77ceccb425b44022eb.png)

### Vote: ADOPT

### Reason:

I have successfully built governance canister and validated the hash, confirming that all commit messages accurately describe the corresponding modifications in the code.

### Hash Match: MATCH

### Feedback: NONE

### Proposer Check: MATCH

### Commits

[7e25f22512](https://github.com/dfinity/ic/commit/7e25f22512)  
Matches description of adjusting batch limit lower for moving neurons to stable memory.

[fbbb395308](https://github.com/dfinity/ic/commit/fbbb395308)  
Benchmarks for new scenarios, such as `list_ready_to_spawn_neuron_ids` and `list_neurons_ready_to_unstake_maturity`, have been added for both heap and stable storage. These tests evaluate the performance of identifying neurons ready to spawn or unstake maturity.

[2f63d24ecb](https://github.com/dfinity/ic/commit/2f63d24ecb)  
Instead of cloning neurons during iteration, the changes use `Cow` (copy-on-write) to minimize unnecessary data duplication by iterating with references where possible.

[c9065698a9](https://github.com/dfinity/ic/commit/c9065698a9)  
A new scheduling system was introduced to manage seeding and neuron storage adjustments, allowing neurons to migrate between heap and stable memory based on activity and storage policies.

The `NeuronStore` now supports batch adjustments of neuron storage, using defined batch sizes and instruction limits to optimize storage management while ensuring system stability.

[1d73be3778](https://github.com/dfinity/ic/commit/1d73be3778)  
`make_proposal`, `register_vote`, and `cast_vote_and_cascade_follow` are refactored to support asynchronous execution `async`

[49000055d3](https://github.com/dfinity/ic/commit/49000055d3)  
Matches description to resolve intermittent issues with `cargo check` complaining about the conditional exclusion of `ic_nns_governance::storage::reset_stable_memory`, the fix explicitly enables the `test` feature for the `ic-nns-governance` crate during tests.

[363e697195](https://github.com/dfinity/ic/commit/363e697195)  
Integrates the `cast_vote_and_cascade_follow` function directly into the `Governance` struct.

[139b0f21c0](https://github.com/dfinity/ic/commit/139b0f21c0)  
Refactor the voting logic by moving the `cast_vote_and_cascade_follow` function into a new `voting` module and encapsulating its behavior within a state machine, `ProposalVotingStateMachine`.

[a920fc7c4f](https://github.com/dfinity/ic/commit/a920fc7c4f)  
Refactor consolidates the calculation of voting rewards into a reusable function `sum_weighted_voting_power` within the `proposals` module.

---

<div class="post-metadata">

**Author:** ![ZackDS](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zackds/32/40368_2.png) [@ZackDS](https://forum.dfinity.org/u/ZackDS)\
**Post date:** [November 24, 2024, 9:36am UTC](https://forum.dfinity.org/t/nns-update-nov-22-2024/37675/3 "2024-11-24T09:36:56Z")

</div>

## Proposal #[134261](https://dashboard.internetcomputer.org/proposal/134261)

**Vote** : Adopted  
**Reason** : Builds fine and the hash matches., as do all listed commits.

 ![Screenshot 2024-11-23 114913](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/4/5/4526d80846a3722aac7ecb17996b6bcd412c3c6e.png)

### Review:

[7e25f22512](https://github.com/dfinity/ic/commit/7e25f22512) feat(nns):  
Done by setting lower `BATCH_SIZE_FOR_MOVING_NEURONS` to 200 from 1000 and `MAX_NUM_INSTRUCTIONS_PER_BATCH` to 1B from 5, in the `batch_adjust_neurons_storage` function.  
[fbbb395308](https://github.com/dfinity/ic/commit/fbbb395308) perf(nns):  
Added benchmarks `list_ready_to_spawn_neuron_ids` and `list_neurons_ready_to_unstake_maturity` for both heap and stable neuron since tests run show improvments for instructions.  
2f63d24ecb fix(nns):  
The previously applied hotfix, allready reviewed using `Cow` to avoid unnecessarily cloning `heap_neurons`.  
c9065698a9 feat(nns):  
Uses a timer (every hour or 5 seconds for batches) to move currently only the inactive neurons from the heap memory to stable storage.  
1d73be3778 refactor(nns):  
Sets `make_proposal`, `register_vote`, and the `cast_vote_and_cascade_follow` functions to `async` enabling to perform asynchronous operations.  
49000055d3 fix:  
Adds the `ic-nns-governance` crate as dependency when the `test` feature is enabled, to the toml file.  
363e697195 refactor(nns):  
The `cast_vote_and_cascade_follow` function is moved to the Governance struct, previously was in the `VotingStateMachines` struct, before setting it async in the future.  
139b0f21c0 refactor(nns):  
Another step towards allowing to scale voting with following that creates a state machine for voting and it uses up to one machine per proposal.  
a920fc7c4f refactor(nns):  
The `sum_weighted_voting_power` function is used for calculating the total and per neuron weighted voting power across a set of proposals.

---

<div class="post-metadata">

**Author:** ![LaCosta](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lacosta/32/20232_2.png) [@LaCosta](https://forum.dfinity.org/u/LaCosta)\
**Post date:** [November 26, 2024, 5:33pm UTC](https://forum.dfinity.org/t/nns-update-nov-22-2024/37675/4 "2024-11-26T17:33:24Z")

</div>

# [Proposal 134261](https://dashboard.internetcomputer.org/proposal/134261)

**Vote: ADOPT**

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/9/1/913c21160ff798ca541b4faf298ecd7fe37fe41d.png)

**Reason:**  
Build successful and hashes match, commits look great and match the description. Found no issues.

**Review:**

[[7e25f22512](https://github.com/dfinity/ic/commit/7e25f22512)]: Reduces the batch limit for moving neurons to stable memory from 1000 to 200 neurons per batch and the maximum number of instructions allowed per batch from 5\_000\_000\_000 to 1\_000\_000\_000 in order to cope with finalization drops on the NNS subnet when the system had a high instruction load.

[[fbbb395308](https://github.com/dfinity/ic/commit/fbbb395308)]: Adds 4 new benchamrks `list_ready_to_spawn_neuron_ids_heap`, `list_ready_to_spawn_neuron_ids_stable`, `list_neurons_ready_to_unstake_maturity_heap` and `list\_neurons\_ready\_to\_unstake\_maturity\_stable. This was done due to a recent regression on listing neurons ready to unstake or spawn in order to prevent further ones. While running against changes from the [PR #2726](https://github.com/dfinity/ic/pull/2726), it showed that the heap optimizations led to significant performance gains.

[[2f63d24ecb](https://github.com/dfinity/ic/commit/2f63d24ecb)]: Avoids unnecessary cloning of heap\_neurons to improve performance. The key change in the commit is the switch from using iterators over cloned `Neuron` objects to iterators over `Cow<Neuron>` with Cow meaning (Clone on Write), more details on this type [here](https://doc.rust-lang.org/std/borrow/enum.Cow.html). This is implemented in `with_active_neurons_iter` and `with_active_neurons_iter_sections` iterators where basically it allows to clone the data lazily only when mutation or ownership is required.

[[c9065698a9](https://github.com/dfinity/ic/commit/c9065698a9)]: Introduces a new mechanism to move inactive neurons from the heap memory to stable storage using a scheduled timer. The function `target_storage_location` is responsible for determining the location in which to store the neuron (currently only inactive neurons).

[[1d73be3778](https://github.com/dfinity/ic/commit/1d73be3778)]: Makes the function `cast_vote_and_cascade_follow` async and the functions `make_proposal` and `register_vote` that depend on it.

[[49000055d3](https://github.com/dfinity/ic/commit/49000055d3)]: `cargo check` randomly complains of `ic_nns_governance::storage::reset_stable_memory` during testing of the `ic-nns-governance` crate. The fix was to add the following line to `Cargo.toml`: `ic-nns-governance = { path = ".", features = ["test"] }` ensuring that the crate is always built when the test feature is enabled.

[[363e697195](https://github.com/dfinity/ic/commit/363e697195)]: Moves the function `cast_vote_and_cascade_follow` into the Governance struct.

[[139b0f21c0](https://github.com/dfinity/ic/commit/139b0f21c0)]: Refactors the voting process in the NNS governance module by creating a state machine to handle voting in order to improve scalability. Previously the function `cast_vote_and_cascade_follow` handled all the calculations but now it delegates this calculations to the state machine. Up to one `ProposalVotingStateMachine` is used for each proposal.

[[a920fc7c4f](https://github.com/dfinity/ic/commit/a920fc7c4f)]: Refactors the code and moves the logic for calculating the total and per neuron weighted voting power for a set of proposals into a new function `sum_weighted_voting_power` within the proposals module.

---

<div class="post-metadata">

**Author:** ![Zane](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zane/32/6541_2.png) [@Zane](https://forum.dfinity.org/u/Zane)\
**Post date:** [November 26, 2024, 7:23pm UTC](https://forum.dfinity.org/t/nns-update-nov-22-2024/37675/5 "2024-11-26T19:23:44Z")

</div>

# Proposal 134261

Vote: ADOPT  
Reason: Build is successful and both code changes and hashes match.

![134261](https://us1.discourse-cdn.com/flex023/uploads/dfn/optimized/3X/3/7/37eb7d358b4c0a8c997185f4f5556f7a20a46f58_2_690x37.png)

[7e25f22512](https://github.com/dfinity/ic/commit/7e25f22512) Reduced `BATCH_SIZE_FOR_MOVING_NEURONS` value from 1k to 200 and `MAX_NUM_INSTRUCTIONS_PER_BATCH` from 5 million to 1 million.

[fbbb395308](https://github.com/dfinity/ic/commit/fbbb395308) Moved some logic to generate a subaccount from id into its own method named `subaccount_from_id`. Added 2 helper methods to be used in benchmarks, one is used to create mock neurons that can be spawned and the other one for neurons unstakeable maturity. Added benchmarks to track resource usage of neuron spawning and unstaking maturity for both heap and stable neurons.

[2f63d24ecb](https://github.com/dfinity/ic/commit/2f63d24ecb) Avoid unnecessary clones of heap neurons when iterating from the NeuronStore, to do this the callbacks passed to `with_active_neurons_iter` and `with_active_neurons_iter_sections` now takes in a Neuron wrapped into a clone on write smart pointer, which allows to return either a reference or an owned value with stable store neurons mapped as `Cow:Owned` and heap neurons as `Borrowed`

[c9065698a9](https://github.com/dfinity/ic/commit/c9065698a9) Avoid repetition of the logic used to determine where a neuron should be fetched from by moving it to a dedicated method. Implemented a timer to move neurons from heap to stable storage. The timer calls a new method named `batch_adjust_neurons_storage`, this attempts to move up to `BATCH_SIZE_FOR_MOVING_NEURONS` neurons from heap to stable storage starting from a specified neurons id, when it is done it returns the last neuron id of the moved batch. The method also keeps track of instructions used during execution and if more than `MAX_NUM_INSTRUCTIONS_PER_BATCH` are used then it returns early. When there are no more neurons left to move `None` variant is returned. The timer runs every 5 seconds while there are still batches left to process, in case there aren’t is scheduled to run every hour to check if new neurons have been added to the heap and if so it starts processing them.

[1d73be3778](https://github.com/dfinity/ic/commit/1d73be3778) Modified `cast_vote_and_cascade_follow` method to be async and updated some code to reflect this change.

[49000055d3](https://github.com/dfinity/ic/commit/49000055d3) Explicitly define `ic-nns-governance` crate as a dev dependency when test feature is enabled.

[363e697195](https://github.com/dfinity/ic/commit/363e697195) Moved `cast_vote_and_cascade_follow` from `VotingStateMachines` to Governance struct, its interface has also slightly changed as it is no longer needed to pass the neuron store and ballots since they are already available in the governance struct, ProposalId and NeuronId are also passed by value instead of as immutable references.

[139b0f21c0](https://github.com/dfinity/ic/commit/139b0f21c0) Implement state machines to handle proposal voting and followee updates, each proposal has its own state machine and their state is preserved in global state inside `VotingStateMachines` struct which contains a map of active state machines indexed by proposal id.

[a920fc7c4f](https://github.com/dfinity/ic/commit/a920fc7c4f) Moved logic to calculate the weighted total and per neuron voting power out of `distribute_rewards` into its own dedicated method.
