Skip to content

Commit

Permalink
Have NeuronController refresh 8 year neuron rather than UserIndex (#7080
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hpeebles authored Dec 18, 2024
1 parent 12a8679 commit 761c95b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 34 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/canisters/neuron_controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Expose size of each virtual stable memory in metrics ([#6981](https://github.com/open-chat-labs/open-chat/pull/6981))
- Have NeuronController refresh 8 year neuron rather than UserIndex ([#7080](https://github.com/open-chat-labs/open-chat/pull/7080))

## [[2.0.1484](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1484-neuron_controller)] - 2024-11-29

Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/neuron_controller/impl/src/jobs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::RuntimeState;

pub mod process_neurons;
mod refresh_8_year_neuron;

pub(crate) fn start(_state: &RuntimeState) {
process_neurons::start_job();
refresh_8_year_neuron::start_job();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use crate::read_state;
use constants::DAY_IN_MS;
use nns_governance_canister::types::manage_neuron::claim_or_refresh::By;
use nns_governance_canister::types::manage_neuron::{ClaimOrRefresh, Command};
use nns_governance_canister::types::neuron::DissolveState;
use nns_governance_canister::types::Empty;
use std::time::Duration;
use tracing::info;
use types::Milliseconds;
use utils::canister_timers::run_now_then_interval;

const REFRESH_NEURON_INTERVAL: Milliseconds = DAY_IN_MS;

pub fn start_job() {
run_now_then_interval(Duration::from_millis(REFRESH_NEURON_INTERVAL), run);
}

fn run() {
ic_cdk::spawn(run_async());
}

async fn run_async() {
if let Some((nns_governance_canister_id, neuron_id)) = read_state(|state| {
state
.data
.neurons
.active_neurons
.iter()
.max_by_key(|n| {
n.dissolve_state
.as_ref()
.map(|ds| if let DissolveState::DissolveDelaySeconds(dd) = ds { *dd } else { 0 })
})
.map(|n| (state.data.nns_governance_canister_id, n.id.clone()))
}) {
if nns_governance_canister_c2c_client::manage_neuron(
nns_governance_canister_id,
&nns_governance_canister::manage_neuron::Args {
id: neuron_id.clone(),
neuron_id_or_subaccount: None,
command: Some(Command::ClaimOrRefresh(ClaimOrRefresh {
by: Some(By::NeuronIdOrSubaccount(Empty {})),
})),
},
)
.await
.is_ok()
{
info!(?neuron_id, "Refreshed neuron");
}
}
}
1 change: 1 addition & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Allow Registry to add additional LocalUserIndexes ([#7072](https://github.com/open-chat-labs/open-chat/pull/7072))
- Add `update_bot` endpoint only callable by bot owner ([#7073](https://github.com/open-chat-labs/open-chat/pull/7073))
- Handle installing large wasms onto new subnets ([#7078](https://github.com/open-chat-labs/open-chat/pull/7078))
- Have NeuronController refresh 8 year neuron rather than UserIndex ([#7080](https://github.com/open-chat-labs/open-chat/pull/7080))

### Removed

Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/user_index/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ p256_key_pair = { path = "../../../libraries/p256_key_pair" }
modclub_canister = { path = "../../../external_canisters/modclub/api" }
modclub_canister_c2c_client = { path = "../../../external_canisters/modclub/c2c_client" }
msgpack = { path = "../../../libraries/msgpack" }
nns_governance_canister = { path = "../../../external_canisters/nns_governance/api" }
nns_governance_canister_c2c_client = { path = "../../../external_canisters/nns_governance/c2c_client" }
online_users_canister = { path = "../../online_users/api" }
online_users_canister_c2c_client = { path = "../../online_users/c2c_client" }
proof_of_unique_personhood = { path = "../../../libraries/proof_of_unique_personhood" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ async fn process_payment(pending_payment: PendingPayment) {

mutate_state(|state| {
match result {
Ok(Ok(block_index)) => match reason {
PendingPaymentReason::ReferralReward => {
Ok(Ok(block_index)) => {
if matches!(reason, PendingPaymentReason::ReferralReward) {
inform_referrer(&pending_payment, block_index, state);
}
PendingPaymentReason::TopUpNeuron => {
state.data.refresh_nns_neuron();
}
_ => {}
},
}
Ok(Err(_)) => {}
Err(_) => {
state.data.pending_payments_queue.push(pending_payment);
Expand Down
23 changes: 0 additions & 23 deletions backend/canisters/user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ use model::pending_modclub_submissions_queue::{PendingModclubSubmission, Pending
use model::pending_payments_queue::{PendingPayment, PendingPaymentsQueue};
use model::reported_messages::{ReportedMessages, ReportingMetrics};
use model::user::SuspensionDetails;
use nns_governance_canister::types::manage_neuron::claim_or_refresh::By;
use nns_governance_canister::types::manage_neuron::{ClaimOrRefresh, Command};
use nns_governance_canister::types::{Empty, ManageNeuron, NeuronId};
use p256_key_pair::P256KeyPair;
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
Expand Down Expand Up @@ -503,26 +500,6 @@ impl Data {
})
}

pub fn refresh_nns_neuron(&self) {
if let Some(neuron_id) = self.nns_8_year_neuron.as_ref().map(|n| n.neuron_id) {
ic_cdk::spawn(refresh_nns_neuron_inner(self.nns_governance_canister_id, neuron_id));
}

async fn refresh_nns_neuron_inner(nns_governance_canister_id: CanisterId, neuron_id: u64) {
let _ = nns_governance_canister_c2c_client::manage_neuron(
nns_governance_canister_id,
&ManageNeuron {
id: Some(NeuronId { id: neuron_id }),
neuron_id_or_subaccount: None,
command: Some(Command::ClaimOrRefresh(ClaimOrRefresh {
by: Some(By::NeuronIdOrSubaccount(Empty {})),
})),
},
)
.await;
}
}

pub fn chit_bands(&self, size: u32, year: u32, month: u8) -> BTreeMap<u32, u32> {
let mut bands = BTreeMap::new();
let month_key = MonthKey::new(year, month);
Expand Down

0 comments on commit 761c95b

Please sign in to comment.