Skip to content

Commit

Permalink
feat: UpdateSnsWasmSnsSubnetIds proposal support (#1463)
Browse files Browse the repository at this point in the history
# Motivation

Add `UpdateSnsWasmSnsSubnetIds` nnsFunction support.

https://dfinity.atlassian.net/browse/GIX-1083
[related `ic`
update](https://gitlab.com/dfinity-lab/public/ic/-/merge_requests/8107/diffs)

# Changes

- add nnsFunction labels
- updated revision hashes
- add `UpdateSnsSubnetListRequest` proposal


# Testing

- tested manually with available demo proposals
  • Loading branch information
mstrasinskis authored Oct 18, 2022
1 parent a6db8c5 commit b6538e0
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 284 deletions.
380 changes: 178 additions & 202 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/src/lib/i18n/en.governance.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"ChangeSubnetMembership": "Change Subnet Membership",
"UpdateSubnetType": "Update Subnet Type",
"ChangeSubnetTypeAssignment": "Change Subnet Type Assignment",
"UpdateSnsWasmSnsSubnetIds": "Update SNS Wasm Subnet Ids",
"RetireReplicaVersion": "Retire Replica Version"
},
"nns_functions_description": {
Expand Down Expand Up @@ -164,6 +165,7 @@
"ChangeSubnetMembership": "Change the membership (list) of nodes in a subnet by adding and/or removing nodes from the subnet. At the time the proposal is executed, the added nodes (if provided in the proposal) need to be unassigned and the removed nodes (if provided in the proposal) need to be assigned to the subnet. After the proposal is executed, the removed nodes become unassigned, and can be reassigned to other subnets via future proposals or completely removed from the network.",
"UpdateSubnetType": "Add or remove a subnet type. A new subnet type can be added if it doesn’t already exist. An existing subnet type can be removed if no subnets are assigned to it. Subnet types can be used to choose the kind of subnet a canister should be created on.",
"ChangeSubnetTypeAssignment": "Change the assignment of subnets to subnet types by either adding subnets to or removing subnets from a subnet type. A subnet can be assigned to a subnet type if the subnet is not already assigned to a different subnet type and is not already in the authorized subnets list (i.e., subnets authorized for certain principals) or the default subnets list (i.e., default subnets that new canisters are randomly created on). Once a subnet is assigned to a subnet type, it becomes available to users who can specify that they want their canisters to be created on subnets of that type.",
"UpdateSnsWasmSnsSubnetIds": "Update the list of SNS subnet IDs that SNS WASM will deploy SNS instances to.",
"RetireReplicaVersion": "A proposal to retire previously elected and unused replica versions. The specified versions are removed from the list of blessed replica versions in the registry. This ensures that a replica can no longer be upgraded to these versions. The proposal will fail to remove replica version if that version is currently used by a subnet or unassigned node."
}
}
2 changes: 2 additions & 0 deletions frontend/src/lib/types/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ interface I18nNns_functions {
ChangeSubnetMembership: string;
UpdateSubnetType: string;
ChangeSubnetTypeAssignment: string;
UpdateSnsWasmSnsSubnetIds: string;
RetireReplicaVersion: string;
}

Expand Down Expand Up @@ -862,6 +863,7 @@ interface I18nNns_functions_description {
ChangeSubnetMembership: string;
UpdateSubnetType: string;
ChangeSubnetTypeAssignment: string;
UpdateSnsWasmSnsSubnetIds: string;
RetireReplicaVersion: string;
}

Expand Down
44 changes: 22 additions & 22 deletions rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"

[dependencies]
base64 = "0.13.0"
candid = "0.7.15"
candid = "0.8.1"
futures = "0.3.21"
itertools = "0.10.0"
lazy_static = "1.4.0"
Expand All @@ -26,28 +26,28 @@ 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 = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
dfn_candid = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
dfn_core = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
dfn_json = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
dfn_macro = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
dfn_protobuf = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-base-types = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
cycles-minting-canister = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
dfn_candid = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
dfn_core = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
dfn_json = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
dfn_macro = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
dfn_protobuf = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-base-types = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-certified-map = { git = "https://github.com/dfinity/cdk-rs", rev = "7676e7f"}
ic-crypto-sha = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-ic00-types = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-ledger-core = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-nervous-system-common = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-nervous-system-root = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-nns-common = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-nns-constants = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-nns-governance = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-protobuf = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-sns-swap = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-sns-wasm = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ledger-canister = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
on_wire = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
registry-canister = { git = "https://github.com/dfinity/ic", rev = "8ebd832a470195cc52fbb107a908985cbaadc00c" }
ic-crypto-sha = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-ic00-types = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-ledger-core = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-nervous-system-common = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-nervous-system-root = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-nns-common = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-nns-constants = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-nns-governance = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-protobuf = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-sns-swap = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ic-sns-wasm = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
ledger-canister = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
on_wire = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }
registry-canister = { git = "https://github.com/dfinity/ic", rev = "f818cf1eb89bcbc9aecb1fb73de8c8de6c258c42" }

[dev-dependencies]
maplit = "1.0.2"
Expand Down
50 changes: 25 additions & 25 deletions rs/src/accounts_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ic_nns_common::types::NeuronId;
use ic_nns_constants::{CYCLES_MINTING_CANISTER_ID, GOVERNANCE_CANISTER_ID};
use itertools::Itertools;
use ledger_canister::Operation::{self, Burn, Mint, Transfer};
use ledger_canister::{AccountIdentifier, BlockHeight, Memo, Subaccount, Tokens};
use ledger_canister::{AccountIdentifier, BlockIndex, Memo, Subaccount, Tokens};
use on_wire::{FromWire, IntoWire};
use serde::Deserialize;
use std::cmp::min;
Expand All @@ -36,7 +36,7 @@ pub struct AccountsStore {

transactions: VecDeque<Transaction>,
neuron_accounts: HashMap<AccountIdentifier, NeuronDetails>,
block_height_synced_up_to: Option<BlockHeight>,
block_height_synced_up_to: Option<BlockIndex>,
multi_part_transactions_processor: MultiPartTransactionsProcessor,

sub_accounts_count: u64,
Expand Down Expand Up @@ -84,7 +84,7 @@ pub struct NamedCanister {
#[derive(CandidType, Deserialize)]
struct Transaction {
transaction_index: TransactionIndex,
block_height: BlockHeight,
block_height: BlockIndex,
timestamp: TimeStamp,
memo: Memo,
transfer: Operation,
Expand Down Expand Up @@ -117,7 +117,7 @@ pub struct RefundTransactionArgs {
pub recipient_principal: PrincipalId,
pub from_sub_account: Subaccount,
pub amount: Tokens,
pub original_transaction_block_height: BlockHeight,
pub original_transaction_block_height: BlockIndex,
pub refund_address: AccountIdentifier,
pub error_message: String,
}
Expand Down Expand Up @@ -526,7 +526,7 @@ impl AccountsStore {
&mut self,
from: AccountIdentifier,
to: AccountIdentifier,
block_height: BlockHeight,
block_height: BlockIndex,
) {
self.multi_part_transactions_processor
.update_status(block_height, MultiPartTransactionStatus::Complete);
Expand All @@ -544,7 +544,7 @@ impl AccountsStore {
&mut self,
transfer: Operation,
memo: Memo,
block_height: BlockHeight,
block_height: BlockIndex,
timestamp: TimeStamp,
) -> Result<bool, String> {
if let Some(block_height_synced_up_to) = self.get_block_height_synced_up_to() {
Expand Down Expand Up @@ -635,7 +635,7 @@ impl AccountsStore {
.as_nanos() as u64;
}

pub fn init_block_height_synced_up_to(&mut self, block_height: BlockHeight) {
pub fn init_block_height_synced_up_to(&mut self, block_height: BlockIndex) {
if self.block_height_synced_up_to.is_some() {
panic!("This can only be called to initialize the 'block_height_synced_up_to' value");
}
Expand Down Expand Up @@ -776,7 +776,7 @@ impl AccountsStore {
pub fn attach_newly_created_canister(
&mut self,
principal: PrincipalId,
block_height: BlockHeight,
block_height: BlockIndex,
canister_id: CanisterId,
) {
let account_identifier = AccountIdentifier::from(principal).to_vec();
Expand All @@ -803,8 +803,8 @@ impl AccountsStore {

pub fn process_transaction_refund_completed(
&mut self,
original_transaction_block_height: BlockHeight,
refund_block_height: BlockHeight,
original_transaction_block_height: BlockIndex,
refund_block_height: BlockIndex,
error_message: String,
) {
self.multi_part_transactions_processor.update_status(
Expand All @@ -815,7 +815,7 @@ impl AccountsStore {

pub fn process_multi_part_transaction_error(
&mut self,
block_height: BlockHeight,
block_height: BlockIndex,
error: String,
refund_pending: bool,
) {
Expand All @@ -836,14 +836,14 @@ impl AccountsStore {
}
}

pub fn get_block_height_synced_up_to(&self) -> Option<BlockHeight> {
pub fn get_block_height_synced_up_to(&self) -> Option<BlockIndex> {
self.block_height_synced_up_to
}

pub fn get_multi_part_transaction_status(
&self,
caller: PrincipalId,
block_height: BlockHeight,
block_height: BlockIndex,
) -> MultiPartTransactionStatus {
if self.get_block_height_synced_up_to().unwrap_or(0) < block_height {
MultiPartTransactionStatus::PendingSync
Expand All @@ -856,14 +856,14 @@ impl AccountsStore {
self.multi_part_transactions_processor.get_errors()
}

pub fn try_take_next_transaction_to_process(&mut self) -> Option<(BlockHeight, MultiPartTransactionToBeProcessed)> {
pub fn try_take_next_transaction_to_process(&mut self) -> Option<(BlockIndex, MultiPartTransactionToBeProcessed)> {
self.multi_part_transactions_processor.take_next()
}

pub fn mark_neuron_created(
&mut self,
principal: &PrincipalId,
block_height: BlockHeight,
block_height: BlockIndex,
memo: Memo,
neuron_id: NeuronId,
) {
Expand All @@ -873,13 +873,13 @@ impl AccountsStore {
.update_status(block_height, MultiPartTransactionStatus::NeuronCreated(neuron_id));
}

pub fn mark_neuron_topped_up(&mut self, block_height: BlockHeight) {
pub fn mark_neuron_topped_up(&mut self, block_height: BlockIndex) {
self.neurons_topped_up_count += 1;
self.multi_part_transactions_processor
.update_status(block_height, MultiPartTransactionStatus::Complete);
}

pub fn mark_canister_topped_up(&mut self, original_transaction_block_height: BlockHeight) {
pub fn mark_canister_topped_up(&mut self, original_transaction_block_height: BlockIndex) {
self.multi_part_transactions_processor
.update_status(original_transaction_block_height, MultiPartTransactionStatus::Complete);
}
Expand Down Expand Up @@ -925,7 +925,7 @@ impl AccountsStore {
pub fn enqueue_multi_part_transaction(
&mut self,
principal: PrincipalId,
block_height: BlockHeight,
block_height: BlockIndex,
transaction: MultiPartTransactionToBeProcessed,
) {
self.multi_part_transactions_processor
Expand Down Expand Up @@ -1127,7 +1127,7 @@ impl AccountsStore {
}
}

fn get_transaction_index(&self, block_height: BlockHeight) -> Option<TransactionIndex> {
fn get_transaction_index(&self, block_height: BlockIndex) -> Option<TransactionIndex> {
if let Some(latest_transaction) = self.transactions.back() {
let max_block_height = latest_transaction.block_height;
if block_height <= max_block_height {
Expand Down Expand Up @@ -1300,7 +1300,7 @@ impl AccountsStore {
to: AccountIdentifier,
memo: Memo,
amount: Tokens,
block_height: BlockHeight,
block_height: BlockIndex,
) {
match transaction_type {
TransactionType::ParticipateSwap(swap_canister_id) => {
Expand Down Expand Up @@ -1415,7 +1415,7 @@ impl StableState for AccountsStore {
HashMap<(AccountIdentifier, AccountIdentifier), (TransactionType, u64)>,
VecDeque<Transaction>,
HashMap<AccountIdentifier, NeuronDetails>,
Option<BlockHeight>,
Option<BlockIndex>,
MultiPartTransactionsProcessor,
u64,
u64,
Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl Account {
impl Transaction {
pub fn new(
transaction_index: TransactionIndex,
block_height: BlockHeight,
block_height: BlockIndex,
timestamp: TimeStamp,
memo: Memo,
transfer: Operation,
Expand Down Expand Up @@ -1569,7 +1569,7 @@ pub struct GetTransactionsResponse {

#[derive(CandidType)]
pub struct TransactionResult {
block_height: BlockHeight,
block_height: BlockIndex,
timestamp: TimeStamp,
memo: Memo,
transfer: TransferResult,
Expand Down Expand Up @@ -1646,9 +1646,9 @@ pub struct Stats {
transactions_count: u64,
block_height_synced_up_to: Option<u64>,
earliest_transaction_timestamp_nanos: u64,
earliest_transaction_block_height: BlockHeight,
earliest_transaction_block_height: BlockIndex,
latest_transaction_timestamp_nanos: u64,
latest_transaction_block_height: BlockHeight,
latest_transaction_block_height: BlockIndex,
seconds_since_last_ledger_sync: u64,
neurons_created_count: u64,
neurons_topped_up_count: u64,
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 @@ -7,9 +7,9 @@ use ledger_canister::protobuf::{
ArchiveIndexResponse as ArchiveIndexResponsePb, GetBlocksResponse as GetBlocksResponsePb,
TipOfChainRequest as TipOfChainRequestPb, TipOfChainResponse as TipOfChainResponsePb,
};
use ledger_canister::{AccountBalanceArgs, BlockHeight, GetBlocksArgs, SendArgs, Tokens};
use ledger_canister::{AccountBalanceArgs, BlockIndex, GetBlocksArgs, SendArgs, Tokens};

pub async fn send(request: SendArgs) -> Result<BlockHeight, String> {
pub async fn send(request: SendArgs) -> Result<BlockIndex, String> {
dfn_core::call(LEDGER_CANISTER_ID, "send_pb", protobuf, request.into_proto())
.await
.map_err(|e| e.1)
Expand All @@ -24,7 +24,7 @@ pub async fn account_balance(request: AccountBalanceArgs) -> Result<Tokens, Stri
Ok(Tokens::from_e8s(tokens.e8s))
}

pub async fn tip_of_chain() -> Result<BlockHeight, String> {
pub async fn tip_of_chain() -> Result<BlockIndex, String> {
let response: TipOfChainResponsePb =
dfn_core::call(LEDGER_CANISTER_ID, "tip_of_chain_pb", protobuf, TipOfChainRequestPb {})
.await
Expand All @@ -39,7 +39,7 @@ pub async fn get_archive_index() -> Result<ArchiveIndexResponsePb, String> {
.map_err(|e| e.1)
}

pub async fn get_blocks(canister_id: CanisterId, from: BlockHeight, length: u32) -> Result<Vec<EncodedBlock>, String> {
pub async fn get_blocks(canister_id: CanisterId, from: BlockIndex, length: u32) -> Result<Vec<EncodedBlock>, String> {
let response: GetBlocksResponsePb = dfn_core::call(
canister_id,
"get_blocks_pb",
Expand Down
12 changes: 6 additions & 6 deletions rs/src/ledger_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ic_ledger_core::block::BlockType;
use ic_nns_constants::LEDGER_CANISTER_ID;
use lazy_static::lazy_static;
use ledger_canister::protobuf::ArchiveIndexEntry;
use ledger_canister::{Block, BlockHeight};
use ledger_canister::{Block, BlockIndex};
use std::cmp::{max, min};
use std::ops::RangeInclusive;
use std::sync::Mutex;
Expand Down Expand Up @@ -65,11 +65,11 @@ async fn sync_transactions_within_lock() -> Result<u32, String> {
}
}

fn get_block_height_synced_up_to() -> Option<BlockHeight> {
fn get_block_height_synced_up_to() -> Option<BlockIndex> {
STATE.with(|s| s.accounts_store.borrow().get_block_height_synced_up_to())
}

async fn get_blocks(from: BlockHeight, tip_of_chain: BlockHeight) -> Result<Vec<(BlockHeight, Block)>, String> {
async fn get_blocks(from: BlockIndex, tip_of_chain: BlockIndex) -> Result<Vec<(BlockIndex, Block)>, String> {
let archive_index_entries = ledger::get_archive_index().await?.entries;

let (canister_id, range) = determine_canister_for_blocks(from, tip_of_chain, archive_index_entries);
Expand All @@ -89,10 +89,10 @@ async fn get_blocks(from: BlockHeight, tip_of_chain: BlockHeight) -> Result<Vec<
}

fn determine_canister_for_blocks(
from: BlockHeight,
tip_of_chain: BlockHeight,
from: BlockIndex,
tip_of_chain: BlockIndex,
archive_index_entries: Vec<ArchiveIndexEntry>,
) -> (CanisterId, RangeInclusive<BlockHeight>) {
) -> (CanisterId, RangeInclusive<BlockIndex>) {
for archive_index_entry in archive_index_entries.into_iter().rev() {
if archive_index_entry.height_to < from {
break;
Expand Down
6 changes: 3 additions & 3 deletions 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, BlockHeight};
use ledger_canister::{AccountIdentifier, BlockIndex};

mod accounts_store;
mod assets;
Expand Down Expand Up @@ -227,14 +227,14 @@ fn add_pending_notify_swap_impl(request: AddPendingNotifySwapRequest) -> AddPend
/// these actions.
#[export_name = "canister_query get_multi_part_transaction_status"]
pub fn get_multi_part_transaction_status() {
over(candid, |(principal, block_height): (PrincipalId, BlockHeight)| {
over(candid, |(principal, block_height): (PrincipalId, BlockIndex)| {
get_multi_part_transaction_status_impl(principal, block_height)
});
}

fn get_multi_part_transaction_status_impl(
principal: PrincipalId,
block_height: BlockHeight,
block_height: BlockIndex,
) -> MultiPartTransactionStatus {
// Returns true if `p2` is a principal of an account owned by `p1`.
fn is_principal_in_account(account_owner: PrincipalId, principal: PrincipalId) -> bool {
Expand Down
Loading

0 comments on commit b6538e0

Please sign in to comment.