Skip to content

Commit

Permalink
Spawn maturity from neurons that are dissolving and can no longer vote (
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Nov 28, 2024
1 parent e926f66 commit cef55ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backend/canisters/neuron_controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Spawn maturity from neurons that are dissolving and can no longer vote ([#6920](https://github.com/open-chat-labs/open-chat/pull/6920))

## [[2.0.1467](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1467-neuron_controller)] - 2024-11-24

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ic_cdk::api::call::CallResult;
use ic_ledger_types::{AccountIdentifier, DEFAULT_SUBACCOUNT};
use icrc_ledger_types::icrc1::account::Account;
use nns_governance_canister::types::manage_neuron::{Command, Disburse, Spawn};
use nns_governance_canister::types::neuron::DissolveState;
use nns_governance_canister::types::ListNeurons;
use std::time::Duration;
use tracing::info;
Expand Down Expand Up @@ -37,11 +38,24 @@ async fn run_async() {
.await
{
let now = read_state(|state| state.env.now());
// Neurons can vote if their dissolve delay is >= 6 months, but when they start dissolving
// they can still earn maturity for a few days as the rewards are distributed for
// proposals they have already voted on.
// Hence, this is set to 6 months minus a few days.
let cut_off_no_longer_accrue_maturity = now.saturating_sub(175 * DAY_IN_MS);

let neurons_to_spawn: Vec<_> = response
.full_neurons
.iter()
.filter(|n| n.spawn_at_timestamp_seconds.is_none() && n.maturity_e8s_equivalent > 1000 * E8S_PER_ICP)
.filter(|n| n.spawn_at_timestamp_seconds.is_none() && n.maturity_e8s_equivalent > E8S_PER_ICP)
.filter(|n| {
// Spawn a new neuron if there is over 1000 ICP maturity or
// if the neuron is now dissolving and can no longer vote
n.maturity_e8s_equivalent > 1000 * E8S_PER_ICP
|| n.dissolve_state.as_ref().is_some_and(
|ds| matches!(ds, DissolveState::WhenDissolvedTimestampSeconds(ts) if *ts < cut_off_no_longer_accrue_maturity),
)
})
.filter_map(|n| n.id.as_ref().map(|id| id.id))
.collect();

Expand Down

0 comments on commit cef55ad

Please sign in to comment.