Skip to content

Commit

Permalink
chore(nns): Clean up the migration code to backfill InstallCode hashes (
Browse files Browse the repository at this point in the history
#3809)

Cleaning up the one-off migration code (the migration code is run after
[this
proposal](https://dashboard.internetcomputer.org/proposal/135063)). For
new proposals, the hashes are computed when they are created.
  • Loading branch information
jasonz-dfinity authored Feb 6, 2025
1 parent 5e85add commit 90acaff
Showing 1 changed file with 2 additions and 38 deletions.
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

0 comments on commit 90acaff

Please sign in to comment.