Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nns): Revert spawn state when ledger unavailable and drop lock #3226

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions rs/nns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6947,16 +6947,17 @@ impl Governance {
LOG_PREFIX, neuron
);

let staked_neuron_clone = self
let (staked_neuron_clone, original_spawn_at_timestamp_seconds) = self
.with_neuron_mut(&neuron_id, |neuron| {
// Reset the neuron's maturity and set that it's spawning before we actually mint
// the stake. This is conservative to prevent a neuron having _both_ the stake and
// the maturity at any point in time.
let original_spawn_ts = neuron.spawn_at_timestamp_seconds;
neuron.maturity_e8s_equivalent = 0;
neuron.spawn_at_timestamp_seconds = None;
neuron.cached_neuron_stake_e8s = neuron_stake;

neuron.clone()
(neuron.clone(), original_spawn_ts)
})
.unwrap();

Expand Down Expand Up @@ -6991,13 +6992,30 @@ impl Governance {
// This is different from what we do in most places because we usually rely
// on trapping to retain the lock, but we can't do that here since we're not
// working on a single neuron.
lock.retain();
println!(
"{}Error spawning neuron: {:?}. Ledger update failed with err: {:?}.",
"{}Error spawning neuron: {:?}. Ledger update failed with err: {:?}. \
Reverting state, so another attempt can be made.",
LOG_PREFIX,
neuron_id,
error,
);
);
match self.with_neuron_mut(&neuron_id, |neuron| {
neuron.maturity_e8s_equivalent = neuron_stake;
neuron.cached_neuron_stake_e8s = 0;
neuron.spawn_at_timestamp_seconds =
original_spawn_at_timestamp_seconds;
}) {
Ok(_) => (),
Err(e) => {
println!(
"{} Error reverting state for neuron: {:?}. Retaining lock: {}",
LOG_PREFIX,
neuron_id,
e
);
lock.retain();
max-dfinity marked this conversation as resolved.
Show resolved Hide resolved
}
};
}
};
}
Expand Down
Loading