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

chore(nns): Clean up the migration code to backfill InstallCode hashes #3809

Merged
Merged
Changes from all 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
40 changes: 2 additions & 38 deletions rs/nns/governance/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ use ic_base_types::{CanisterId, PrincipalId};
use ic_cdk::println;
#[cfg(target_arch = "wasm32")]
use ic_cdk::spawn;
use ic_crypto_sha2::Sha256;
use ic_nervous_system_common::{
cmc::CMC, ledger, ledger::IcpLedger, NervousSystemError, ONE_DAY_SECONDS, ONE_MONTH_SECONDS,
ONE_YEAR_SECONDS,
Expand Down Expand Up @@ -1865,7 +1864,7 @@ impl Governance {
env.seed_rng(rng_seed);
}

let mut governance = Self {
Self {
heap_data: heap_governance_proto,
neuron_store: NeuronStore::new_restored((heap_neurons, topic_followee_map)),
env,
Expand All @@ -1877,10 +1876,7 @@ impl Governance {
neuron_data_validator: NeuronDataValidator::new(),
minting_node_provider_rewards: false,
neuron_rate_limits: NeuronRateLimits::default(),
};
// TODO: Remove after the backfill has been run once.
governance.backfill_install_code_hashes();
governance
}
}

/// After calling this method, the proto and neuron_store (the heap neurons at least)
Expand Down Expand Up @@ -6010,38 +6006,6 @@ impl Governance {
)
}

pub fn backfill_install_code_hashes(&mut self) {
for proposal in self.heap_data.proposals.values_mut() {
let Some(proposal) = proposal.proposal.as_mut() else {
continue;
};
let Some(Action::InstallCode(install_code)) = proposal.action.as_mut() else {
continue;
};
if install_code.wasm_module_hash.is_none() {
if let Some(wasm_module) = install_code.wasm_module.as_ref() {
install_code.wasm_module_hash = Some(Sha256::hash(wasm_module).to_vec());
}
}
if install_code.arg_hash.is_none() {
let arg_hash = match install_code.arg.as_ref() {
Some(arg) => {
// We could calculate the hash of an empty arg, but it would be confusing for the
// proposal reviewers, since the arg_hash is the only thing they can see, and it would
// not be obvious that the arg is empty.
if arg.is_empty() {
Some(vec![])
} else {
Some(Sha256::hash(arg).to_vec())
}
}
None => Some(vec![]),
};
install_code.arg_hash = arg_hash;
}
}
}

/// Creates a new neuron or refreshes the stake of an existing
/// neuron from a ledger account.
///
Expand Down