-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch main into feat/bump-sns-canister-pinned-version
- Loading branch information
Showing
15 changed files
with
330 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod cycle_management; | |
pub mod generic_proposal; | ||
pub mod monitoring; | ||
pub mod stats; | ||
pub mod snapshot; |
67 changes: 67 additions & 0 deletions
67
src/canister/platform_orchestrator/src/api/snapshot/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use ic_cdk_macros::{query, update}; | ||
|
||
use crate::{data_model::CanisterData, CANISTER_DATA, SNAPSHOT_DATA}; | ||
use shared_utils::common::utils::permissions::is_reclaim_canister_id; | ||
|
||
#[update(guard = "is_reclaim_canister_id")] | ||
fn save_snapshot_json() -> u32 { | ||
let mut state_bytes = vec![]; | ||
|
||
CANISTER_DATA.with(|canister_data_ref_cell| { | ||
let serde_str = serde_json::to_string(&*canister_data_ref_cell.borrow()).unwrap(); | ||
state_bytes = serde_str.as_bytes().to_vec(); | ||
}); | ||
|
||
let len = state_bytes.len() as u32; | ||
|
||
SNAPSHOT_DATA.with(|snapshot_data_ref_cell| { | ||
*snapshot_data_ref_cell.borrow_mut() = state_bytes; | ||
}); | ||
|
||
len | ||
} | ||
|
||
#[query(guard = "is_reclaim_canister_id")] | ||
fn download_snapshot(offset: u64, length: u64) -> Vec<u8> { | ||
let state_bytes = SNAPSHOT_DATA.with(|snapshot_data_ref_cell| { | ||
let snapshot = snapshot_data_ref_cell.borrow(); | ||
|
||
snapshot[offset as usize..(offset + length) as usize].to_vec() | ||
}); | ||
|
||
state_bytes | ||
} | ||
|
||
#[update(guard = "is_reclaim_canister_id")] | ||
fn receive_and_save_snaphot(offset: u64, state_bytes: Vec<u8>) { | ||
SNAPSHOT_DATA.with(|snapshot_data_ref_cell| { | ||
let mut snapshot = snapshot_data_ref_cell.borrow_mut(); | ||
if snapshot.len() < (offset + state_bytes.len() as u64) as usize { | ||
snapshot.resize((offset + state_bytes.len() as u64) as usize, 0); | ||
} | ||
snapshot.splice( | ||
offset as usize..(offset + state_bytes.len() as u64) as usize, | ||
state_bytes, | ||
); | ||
}); | ||
} | ||
|
||
#[update(guard = "is_reclaim_canister_id")] | ||
fn load_snapshot() { | ||
let state_bytes = | ||
SNAPSHOT_DATA.with(|snapshot_data_ref_cell| snapshot_data_ref_cell.borrow().clone()); | ||
|
||
let canister_data_snapshot: CanisterData = | ||
serde_json::from_str(std::str::from_utf8(&state_bytes).unwrap()).unwrap(); | ||
|
||
CANISTER_DATA.with(|canister_data_ref_cell| { | ||
*canister_data_ref_cell.borrow_mut() = canister_data_snapshot; | ||
}); | ||
} | ||
|
||
#[update(guard = "is_reclaim_canister_id")] | ||
fn clear_snapshot() { | ||
SNAPSHOT_DATA.with(|snapshot_data_ref_cell| { | ||
*snapshot_data_ref_cell.borrow_mut() = vec![]; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use ic_cdk_macros::{query, update}; | ||
|
||
use crate::{data_model::CanisterData, CANISTER_DATA, SNAPSHOT_DATA}; | ||
use shared_utils::common::utils::permissions::is_reclaim_canister_id; | ||
|
||
#[update(guard = "is_reclaim_canister_id")] | ||
fn save_snapshot_json() -> u32 { | ||
let mut state_bytes = vec![]; | ||
|
||
CANISTER_DATA.with(|canister_data_ref_cell| { | ||
let serde_str = serde_json::to_string(&*canister_data_ref_cell.borrow()).unwrap(); | ||
state_bytes = serde_str.as_bytes().to_vec(); | ||
}); | ||
|
||
let len = state_bytes.len() as u32; | ||
|
||
SNAPSHOT_DATA.with(|snapshot_data_ref_cell| { | ||
*snapshot_data_ref_cell.borrow_mut() = state_bytes; | ||
}); | ||
|
||
len | ||
} | ||
|
||
#[query(guard = "is_reclaim_canister_id")] | ||
fn download_snapshot(offset: u64, length: u64) -> Vec<u8> { | ||
let state_bytes = SNAPSHOT_DATA.with(|snapshot_data_ref_cell| { | ||
let snapshot = snapshot_data_ref_cell.borrow(); | ||
|
||
snapshot[offset as usize..(offset + length) as usize].to_vec() | ||
}); | ||
|
||
state_bytes | ||
} | ||
|
||
#[update(guard = "is_reclaim_canister_id")] | ||
fn receive_and_save_snaphot(offset: u64, state_bytes: Vec<u8>) { | ||
SNAPSHOT_DATA.with(|snapshot_data_ref_cell| { | ||
let mut snapshot = snapshot_data_ref_cell.borrow_mut(); | ||
if snapshot.len() < (offset + state_bytes.len() as u64) as usize { | ||
snapshot.resize((offset + state_bytes.len() as u64) as usize, 0); | ||
} | ||
snapshot.splice( | ||
offset as usize..(offset + state_bytes.len() as u64) as usize, | ||
state_bytes, | ||
); | ||
}); | ||
} | ||
|
||
#[update(guard = "is_reclaim_canister_id")] | ||
fn load_snapshot() { | ||
let state_bytes = | ||
SNAPSHOT_DATA.with(|snapshot_data_ref_cell| snapshot_data_ref_cell.borrow().clone()); | ||
|
||
let canister_data_snapshot: CanisterData = | ||
serde_json::from_str(std::str::from_utf8(&state_bytes).unwrap()).unwrap(); | ||
|
||
CANISTER_DATA.with(|canister_data_ref_cell| { | ||
*canister_data_ref_cell.borrow_mut() = canister_data_snapshot; | ||
}); | ||
} | ||
|
||
#[update(guard = "is_reclaim_canister_id")] | ||
fn clear_snapshot() { | ||
SNAPSHOT_DATA.with(|snapshot_data_ref_cell| { | ||
*snapshot_data_ref_cell.borrow_mut() = vec![]; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.