-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have NeuronController refresh 8 year neuron rather than UserIndex (#7080
- Loading branch information
Showing
8 changed files
with
59 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
52 changes: 52 additions & 0 deletions
52
backend/canisters/neuron_controller/impl/src/jobs/refresh_8_year_neuron.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters