Skip to content

Commit

Permalink
feat: add proof of participation merkleization
Browse files Browse the repository at this point in the history
  • Loading branch information
rupansh committed Nov 3, 2024
1 parent f64f91d commit 846f9ef
Show file tree
Hide file tree
Showing 37 changed files with 1,469 additions and 152 deletions.
116 changes: 113 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions scripts/canisters/local_deploy/local_test.sh

This file was deleted.

7 changes: 6 additions & 1 deletion src/canister/individual_user_template/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,12 @@ type PostViewStatistics = record {
average_watch_percentage : nat8;
threshold_view_count : nat64;
};
type ProofOfChild = record { "principal" : principal; signature : blob };
type ProofOfChild = record {
proof_of_inclusion : vec blob;
"principal" : principal;
children_proof : ProofOfChildren;
};
type ProofOfChildren = record { signature : blob; merkle_root : blob };
type ProofOfParticipation = record { chain : vec ProofOfChild };
type RejectionCode = variant {
NoError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ic_cdk::api::call::ArgDecoderConfig;
use ic_cdk_macros::post_upgrade;
use ic_stable_structures::Memory;
use shared_utils::{
canister_specific::platform_orchestrator::types::args::PlatformOrchestratorInitArgs,
canister_specific::{platform_orchestrator::types::args::PlatformOrchestratorInitArgs, post_cache},
common::utils::system_time,
};

Expand All @@ -13,6 +13,7 @@ use crate::{data_model::memory, CANISTER_DATA};
pub fn post_upgrade() {
restore_data_from_stable_memory();
update_version_from_args();
initialize_children_merkle();
}

fn restore_data_from_stable_memory() {
Expand All @@ -38,3 +39,13 @@ fn update_version_from_args() {
canister_data.version_detail.last_update_on = system_time::get_current_system_time();
})
}

// TODO: remove this once the upgrade is complete
fn initialize_children_merkle() {
CANISTER_DATA.with_borrow_mut(|cdata| {
let mut children: Vec<_> = cdata.subnet_orchestrators().iter().copied().collect();
children.extend(cdata.post_cache_orchestrators());

cdata.children_merkle.insert_children(children)
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ use crate::{guard::is_caller::is_caller_global_admin_or_controller, CANISTER_DAT
#[update(guard = "is_caller_global_admin_or_controller")]
fn deregister_subnet_orchestrator(canister_id: Principal, remove_it_completely: bool) {
CANISTER_DATA.with_borrow_mut(|canister_data| {
canister_data
.subet_orchestrator_with_capacity_left
.remove(&canister_id);

if remove_it_completely {
canister_data
.all_subnet_orchestrator_canisters_list
.remove(&canister_id);
}
canister_data.remove_subnet_orchestrator(canister_id, remove_it_completely);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::CANISTER_DATA;
#[query]
fn get_all_subnet_orchestrators() -> Vec<Principal> {
CANISTER_DATA.with_borrow(|canister_data| {
let canisters = canister_data.all_subnet_orchestrator_canisters_list.iter().map(|canister_id| {*canister_id}).collect::<Vec<Principal>>();
let canisters = canister_data.subnet_orchestrators().iter().map(|canister_id| {*canister_id}).collect::<Vec<Principal>>();
canisters
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn issue_update_known_principal_for_all_subnet(
) {
let subnet_list: Vec<Principal> = CANISTER_DATA.with_borrow(|canister_data| {
canister_data
.all_subnet_orchestrator_canisters_list
.subnet_orchestrators()
.iter()
.copied()
.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{guard::is_caller::is_caller_global_admin_or_controller, CANISTER_DAT
#[update(guard = "is_caller_global_admin_or_controller")]
async fn populate_known_principal_for_all_subnet() {
let subnet_orchestrators: Vec<Principal> = CANISTER_DATA.with_borrow(|canister_data| {
canister_data.all_subnet_orchestrator_canisters_list.iter().copied().collect()
canister_data.subnet_orchestrators().iter().copied().collect()
});

for subnet_id in subnet_orchestrators {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,14 @@ pub async fn provision_subnet_orchestrator_canister(
);

CANISTER_DATA.with_borrow_mut(|canister_data| {
canister_data
.all_post_cache_orchestrator_list
.insert(post_cache_canister_id);
canister_data
.all_subnet_orchestrator_canisters_list
.insert(subnet_orchestrator_canister_id);
canister_data
.subet_orchestrator_with_capacity_left
.insert(subnet_orchestrator_canister_id);
canister_data.insert_subnet_orchestrator_and_post_cache(
subnet_orchestrator_canister_id,
post_cache_canister_id
);
});

let mut proof_of_participation = ProofOfParticipation::new_for_root();
proof_of_participation = proof_of_participation.derive_for_child(subnet_orchestrator_canister_id).await.unwrap();
proof_of_participation = proof_of_participation.derive_for_child(&CANISTER_DATA, subnet_orchestrator_canister_id).await.unwrap();
let user_index_init_arg = UserIndexInitArgs {
known_principal_ids: Some(known_principal_map.clone()),
access_control_map: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn register_new_subnet_orchestrator(

if let Some(first_subnet_orchestrator) = CANISTER_DATA.with_borrow(|canister_data| {
canister_data
.all_subnet_orchestrator_canisters_list
.subnet_orchestrators()
.iter()
.next()
.copied()
Expand All @@ -59,15 +59,10 @@ async fn register_new_subnet_orchestrator(
}

CANISTER_DATA.with_borrow_mut(|canister_data| {
canister_data
.all_subnet_orchestrator_canisters_list
.insert(new_subnet_orchestrator_caniter_id);

if subnet_is_available_for_provisioning_individual_canister {
canister_data
.subet_orchestrator_with_capacity_left
.insert(new_subnet_orchestrator_caniter_id);
}
canister_data.insert_subnet_orchestrator(
new_subnet_orchestrator_caniter_id,
subnet_is_available_for_provisioning_individual_canister,
);
Ok(())
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{guard::is_caller::is_caller_global_admin_or_controller, CANISTER_DAT
async fn stop_upgrades_for_individual_user_canisters() -> Result<String, String> {

let subnet_orchestrator_list = CANISTER_DATA.with_borrow(|canister_data| {
canister_data.all_subnet_orchestrator_canisters_list.clone()
canister_data.subnet_orchestrators().clone()
});

for subnet_orchestrator in subnet_orchestrator_list {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{guard::is_caller::is_caller_global_admin_or_controller, CANISTER_DAT
#[update(guard = "is_caller_global_admin_or_controller")]
async fn update_canisters_last_functionality_access_time() -> Result<String, String> {
let subnet_orchestrator_list = CANISTER_DATA
.with_borrow(|canister_data| canister_data.all_subnet_orchestrator_canisters_list.clone());
.with_borrow(|canister_data| canister_data.subnet_orchestrators().clone());

for subnet_orchestrator in subnet_orchestrator_list {
let result: CallResult<()> = call(
Expand Down
Loading

0 comments on commit 846f9ef

Please sign in to comment.