Skip to content

Commit

Permalink
Gix 1259 nns function insert sns wasm upgrade path entries (#1750)
Browse files Browse the repository at this point in the history
# Motivation

Add `InsertUpgradePathEntriesRequest` nnsFunction support to the dapp.

[ic feature
PR](https://gitlab.com/dfinity-lab/public/ic/-/merge_requests/9945/diffs#3f5b735e6d6a922a29bc13958244cb4346132ddd_2921_2922)
[ic-js PR](dfinity/ic-js#262)

# Changes

- update commits to the latest blessed version
- add nnsFunction type
  • Loading branch information
mstrasinskis committed Jan 25, 2023
1 parent 93d9b17 commit d180812
Show file tree
Hide file tree
Showing 11 changed files with 695 additions and 553 deletions.
1,104 changes: 600 additions & 504 deletions Cargo.lock

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
base64 = "0.13.0"
candid = "0.8.1"
futures = "0.3.21"
itertools = "0.10.0"
itertools = "0.10.5"
lazy_static = "1.4.0"
serde = "1.0.136"
serde_bytes = "0.11.5"
Expand All @@ -26,27 +26,27 @@ hex = "0.4.3"
# 0.4.19 works and satisfies ic.
chrono = "=0.4.19"

cycles-minting-canister = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
dfn_candid = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
dfn_core = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
dfn_json = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
dfn_macro = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
dfn_protobuf = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-base-types = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
cycles-minting-canister = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
dfn_candid = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
dfn_core = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
dfn_json = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
dfn_macro = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
dfn_protobuf = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-base-types = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-certified-map = { git = "https://github.com/dfinity/cdk-rs", rev = "7676e7f"}
ic-crypto-sha = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-ic00-types = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-ledger-core = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-nervous-system-common = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-nervous-system-root = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-nns-common = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-nns-constants = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-nns-governance = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-protobuf = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-sns-swap = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-sns-wasm = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ledger-canister = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
on_wire = { git = "https://github.com/dfinity/ic", rev = "a3608ed7cf64a01dcdb82486deb7aaa25d768787" }
ic-crypto-sha = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-ic00-types = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-ledger-core = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-nervous-system-common = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-nervous-system-root = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-nns-common = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-nns-constants = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-nns-governance = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-protobuf = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-sns-swap = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
ic-sns-wasm = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
icp-ledger = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
on_wire = { git = "https://github.com/dfinity/ic", rev = "8b674edbb228acfc19923d5c914807166edcd909" }
# Registry canister deploy as of 2022-11-23, ahead of Blessed Replica Version
registry-canister = { git = "https://github.com/dfinity/ic", rev = "0a729806f2fbc717f2183b07efac19f24f32e717" }
idl2json = { git = "https://github.com/dfinity/idl2json", rev="c983dea6fc5666912218e7babf2b6b2f8b5648a4" }
Expand Down
4 changes: 2 additions & 2 deletions rs/src/accounts_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use ic_crypto_sha::Sha256;
use ic_ledger_core::timestamp::TimeStamp;
use ic_nns_common::types::NeuronId;
use ic_nns_constants::{CYCLES_MINTING_CANISTER_ID, GOVERNANCE_CANISTER_ID};
use icp_ledger::Operation::{self, Burn, Mint, Transfer};
use icp_ledger::{AccountIdentifier, BlockIndex, Memo, Subaccount, Tokens};
use itertools::Itertools;
use ledger_canister::Operation::{self, Burn, Mint, Transfer};
use ledger_canister::{AccountIdentifier, BlockIndex, Memo, Subaccount, Tokens};
use on_wire::{FromWire, IntoWire};
use serde::Deserialize;
use std::cmp::min;
Expand Down
2 changes: 1 addition & 1 deletion rs/src/accounts_store/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use ledger_canister::Tokens;
use icp_ledger::Tokens;
use std::str::FromStr;

const TEST_ACCOUNT_1: &str = "h4a5i-5vcfo-5rusv-fmb6m-vrkia-mjnkc-jpoow-h5mam-nthnm-ldqlr-bqe";
Expand Down
8 changes: 4 additions & 4 deletions rs/src/canisters/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use dfn_core::CanisterId;
use dfn_protobuf::{protobuf, ToProto};
use ic_ledger_core::block::EncodedBlock;
use ic_nns_constants::LEDGER_CANISTER_ID;
use ledger_canister::protobuf::get_blocks_response::GetBlocksContent;
use ledger_canister::protobuf::{
use icp_ledger::protobuf::get_blocks_response::GetBlocksContent;
use icp_ledger::protobuf::{
ArchiveIndexResponse as ArchiveIndexResponsePb, GetBlocksResponse as GetBlocksResponsePb,
TipOfChainRequest as TipOfChainRequestPb, TipOfChainResponse as TipOfChainResponsePb,
};
use ledger_canister::{AccountBalanceArgs, BlockIndex, GetBlocksArgs, SendArgs, Tokens};
use icp_ledger::{AccountBalanceArgs, BlockIndex, GetBlocksArgs, SendArgs, Tokens};

pub async fn send(request: SendArgs) -> Result<BlockIndex, String> {
dfn_core::call(LEDGER_CANISTER_ID, "send_pb", protobuf, request.into_proto())
Expand All @@ -16,7 +16,7 @@ pub async fn send(request: SendArgs) -> Result<BlockIndex, String> {
}

pub async fn account_balance(request: AccountBalanceArgs) -> Result<Tokens, String> {
let tokens: ledger_canister::protobuf::Tokens =
let tokens: icp_ledger::protobuf::Tokens =
dfn_core::call(LEDGER_CANISTER_ID, "account_balance_pb", protobuf, request.into_proto())
.await
.map_err(|e| e.1)?;
Expand Down
2 changes: 1 addition & 1 deletion rs/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ledger_canister::Memo;
use icp_ledger::Memo;

pub const MEMO_CREATE_CANISTER: Memo = Memo(0x41455243); // == 'CREA'
pub const MEMO_TOP_UP_CANISTER: Memo = Memo(0x50555054); // == 'TPUP'
4 changes: 2 additions & 2 deletions rs/src/ledger_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::state::STATE;
use dfn_core::CanisterId;
use ic_ledger_core::block::BlockType;
use ic_nns_constants::LEDGER_CANISTER_ID;
use icp_ledger::protobuf::ArchiveIndexEntry;
use icp_ledger::{Block, BlockIndex};
use lazy_static::lazy_static;
use ledger_canister::protobuf::ArchiveIndexEntry;
use ledger_canister::{Block, BlockIndex};
use std::cmp::{max, min};
use std::ops::RangeInclusive;
use std::sync::Mutex;
Expand Down
2 changes: 1 addition & 1 deletion rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use candid::CandidType;
use dfn_candid::{candid, candid_one};
use dfn_core::{api::trap_with, over, over_async, stable};
use ic_base_types::PrincipalId;
use ledger_canister::{AccountIdentifier, BlockIndex};
use icp_ledger::{AccountIdentifier, BlockIndex};

mod accounts_store;
mod assets;
Expand Down
4 changes: 2 additions & 2 deletions rs/src/multi_part_transactions_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::accounts_store::{CreateCanisterArgs, RefundTransactionArgs, TopUpCani
use candid::CandidType;
use ic_base_types::{CanisterId, PrincipalId};
use ic_nns_common::types::NeuronId;
use ledger_canister::AccountIdentifier;
use ledger_canister::{BlockIndex, Memo};
use icp_ledger::AccountIdentifier;
use icp_ledger::{BlockIndex, Memo};
use serde::Deserialize;
use std::collections::{BTreeMap, VecDeque};

Expand Down
2 changes: 1 addition & 1 deletion rs/src/periodic_tasks_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ic_nns_common::types::NeuronId;
use ic_nns_constants::CYCLES_MINTING_CANISTER_ID;
use ic_nns_governance::pb::v1::{claim_or_refresh_neuron_from_account_response, ClaimOrRefreshNeuronFromAccount};
use ic_sns_swap::pb::v1::RefreshBuyerTokensRequest;
use ledger_canister::{
use icp_ledger::{
AccountBalanceArgs, AccountIdentifier, BlockIndex, Memo, SendArgs, Subaccount, Tokens, DEFAULT_TRANSFER_FEE,
};

Expand Down
74 changes: 60 additions & 14 deletions rs/src/proposals.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
use crate::proposals::def::{
AddFirewallRulesPayload, AddNnsCanisterProposal, AddNnsCanisterProposalTrimmed, AddNodeOperatorPayload,
AddNodesToSubnetPayload, AddOrRemoveDataCentersProposalPayload, AddWasmRequest, AddWasmRequestTrimmed,
BlessReplicaVersionPayload, ChangeNnsCanisterProposal, ChangeNnsCanisterProposalTrimmed,
ChangeSubnetMembershipPayload, ChangeSubnetTypeAssignmentArgs, CompleteCanisterMigrationPayload,
CreateSubnetPayload, PrepareCanisterMigrationPayload, RecoverSubnetPayload, RemoveFirewallRulesPayload,
RemoveNodeOperatorsPayload, RemoveNodeOperatorsPayloadHumanReadable, RemoveNodesFromSubnetPayload,
RemoveNodesPayload, RerouteCanisterRangesPayload, RetireReplicaVersionPayload, SetAuthorizedSubnetworkListArgs,
SetFirewallConfigPayload, StopOrStartNnsCanisterProposal, UpdateAllowedPrincipalsRequest,
UpdateFirewallRulesPayload, UpdateIcpXdrConversionRatePayload, UpdateNodeOperatorConfigPayload,
UpdateNodeRewardsTableProposalPayload, UpdateSnsSubnetListRequest, UpdateSubnetPayload,
UpdateSubnetReplicaVersionPayload, UpdateSubnetTypeArgs, UpdateUnassignedNodesConfigPayload,
UpgradeRootProposalPayload, UpgradeRootProposalPayloadTrimmed,
};
use crate::proposals::def::*;
use candid::parser::types::{IDLType, PrimType};
use candid::parser::value::IDLValue;
use candid::{CandidType, Decode, Deserialize};
Expand Down Expand Up @@ -197,6 +184,7 @@ fn transform_payload_to_json(nns_function: i32, payload_bytes: &[u8]) -> Result<
34 => identity::<UpdateSnsSubnetListRequest>(payload_bytes),
35 => identity::<UpdateAllowedPrincipalsRequest>(payload_bytes),
36 => identity::<RetireReplicaVersionPayload>(payload_bytes),
37 => transform::<InsertUpgradePathEntriesRequest, InsertUpgradePathEntriesRequestHumanReadable>(payload_bytes),
_ => Err("Unrecognised NNS function".to_string()),
}
}
Expand All @@ -212,6 +200,7 @@ mod def {
use ic_crypto_sha::Sha256;
use ic_ic00_types::CanisterInstallMode;
use ic_nervous_system_common::MethodAuthzChange;
use ic_sns_wasm::pb::v1::{SnsUpgrade, SnsVersion};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use std::fmt::Write;
Expand Down Expand Up @@ -542,6 +531,63 @@ mod def {
// https://github.com/dfinity/ic/blob/c2ad499466967a9a5557d737c2b9c0b9fa8ad53f/rs/registry/canister/src/mutations/do_retire_replica_version.rs#L143
pub type RetireReplicaVersionPayload =
registry_canister::mutations::do_retire_replica_version::RetireReplicaVersionPayload;

// NNS function 37 - InsertUpgradePathEntriesRequest
// https://github.com/dfinity/ic/blob/8b674edbb228acfc19923d5c914807166edcd909/rs/nns/sns-wasm/gen/ic_sns_wasm.pb.v1.rs#L128
pub type InsertUpgradePathEntriesRequest = ic_sns_wasm::pb::v1::InsertUpgradePathEntriesRequest;

#[derive(CandidType, Serialize, Deserialize, Clone)]
pub struct SnsVersionHumanReadable {
pub root_wasm_hash: String,
pub governance_wasm_hash: String,
pub ledger_wasm_hash: String,
pub swap_wasm_hash: String,
pub archive_wasm_hash: String,
pub index_wasm_hash: String,
}

#[derive(CandidType, Serialize, Deserialize, Clone)]
pub struct SnsUpgradeHumanReadable {
pub current_version: Option<SnsVersionHumanReadable>,
pub next_version: Option<SnsVersionHumanReadable>,
}

#[derive(CandidType, Serialize, Deserialize, Clone)]
pub struct InsertUpgradePathEntriesRequestHumanReadable {
pub upgrade_path: Vec<SnsUpgradeHumanReadable>,
pub sns_governance_canister_id: Option<PrincipalId>,
}

impl From<SnsVersion> for SnsVersionHumanReadable {
fn from(payload: SnsVersion) -> Self {
SnsVersionHumanReadable {
root_wasm_hash: calculate_hash_string(&payload.root_wasm_hash),
governance_wasm_hash: calculate_hash_string(&payload.governance_wasm_hash),
ledger_wasm_hash: calculate_hash_string(&payload.ledger_wasm_hash),
swap_wasm_hash: calculate_hash_string(&payload.swap_wasm_hash),
archive_wasm_hash: calculate_hash_string(&payload.archive_wasm_hash),
index_wasm_hash: calculate_hash_string(&payload.index_wasm_hash),
}
}
}

impl From<SnsUpgrade> for SnsUpgradeHumanReadable {
fn from(payload: SnsUpgrade) -> Self {
SnsUpgradeHumanReadable {
current_version: payload.current_version.map(|v| v.into()),
next_version: payload.next_version.map(|v| v.into()),
}
}
}

impl From<InsertUpgradePathEntriesRequest> for InsertUpgradePathEntriesRequestHumanReadable {
fn from(payload: InsertUpgradePathEntriesRequest) -> Self {
InsertUpgradePathEntriesRequestHumanReadable {
upgrade_path: payload.upgrade_path.into_iter().map(|u| u.into()).collect(),
sns_governance_canister_id: payload.sns_governance_canister_id,
}
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit d180812

Please sign in to comment.