Skip to content

Commit

Permalink
RUN-845: Enable chunked install
Browse files Browse the repository at this point in the history
  • Loading branch information
adambratschikaye committed Jan 22, 2024
1 parent 4fd322d commit 42cfbcf
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 40 deletions.
2 changes: 1 addition & 1 deletion rs/config/src/execution_environment.rs
Expand Up @@ -316,7 +316,7 @@ impl Default for Config {
max_compilation_cache_size: MAX_COMPILATION_CACHE_SIZE,
query_stats_aggregation: FlagStatus::Disabled,
query_stats_epoch_length: QUERY_STATS_EPOCH_LENGTH,
wasm_chunk_store: FlagStatus::Disabled,
wasm_chunk_store: FlagStatus::Enabled,
stop_canister_timeout_duration: STOP_CANISTER_TIMEOUT_DURATION,
canister_snapshots: FlagStatus::Disabled,
}
Expand Down
66 changes: 47 additions & 19 deletions rs/execution_environment/src/canister_manager/tests.rs
Expand Up @@ -6750,7 +6750,9 @@ fn canister_status_contains_reserved_cycles_limit() {
fn upload_chunk_works_from_white_list() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand All @@ -6774,7 +6776,9 @@ fn upload_chunk_works_from_white_list() {
fn upload_chunk_works_from_controller() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);
let uc = test
Expand Down Expand Up @@ -6812,7 +6816,9 @@ fn upload_chunk_works_from_controller() {
fn chunk_store_methods_fail_from_non_controller() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);
let uc = test
Expand Down Expand Up @@ -6897,7 +6903,9 @@ fn upload_chunk_fails_when_allocation_exceeded() {

const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);
let memory_needed_for_history = history_memory_usage_from_one_settings_update();
Expand Down Expand Up @@ -6944,7 +6952,7 @@ fn upload_chunk_fails_when_subnet_memory_exceeded() {
let chunk_size = wasm_chunk_store::chunk_size();
let default_subnet_memory_reservation = Config::default().subnet_memory_reservation;
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store()
.with_wasm_chunk_store(FlagStatus::Enabled)
.with_subnet_execution_memory(
(default_subnet_memory_reservation.get() + chunk_size.get()) as i64,
)
Expand Down Expand Up @@ -6983,7 +6991,9 @@ fn upload_chunk_counts_to_memory_usage() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);
let chunk_size = wasm_chunk_store::chunk_size();

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -7046,7 +7056,9 @@ fn upload_chunk_counts_to_memory_usage() {
fn chunk_store_methods_fail_with_feature_disabled() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Disabled)
.build();
let canister_id = test.create_canister(CYCLES);
let initial_subnet_available_memory = test.subnet_available_memory();

Expand Down Expand Up @@ -7091,7 +7103,9 @@ fn chunk_store_methods_fail_with_feature_disabled() {
fn uninstall_clears_wasm_chunk_store() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();
let canister_id = test.create_canister(CYCLES);

// Upload a chunk
Expand Down Expand Up @@ -7123,7 +7137,9 @@ fn upload_chunk_fails_when_freeze_threshold_triggered() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);
let instructions = SchedulerConfig::application_subnet().upload_wasm_chunk_instructions;

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();
let canister_id = test.create_canister(CYCLES);
let initial_subnet_available_memory = test.subnet_available_memory();

Expand Down Expand Up @@ -7168,7 +7184,9 @@ fn upload_chunk_fails_when_freeze_threshold_triggered() {
fn upload_chunk_fails_when_it_exceeds_chunk_size() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();
let canister_id = test.create_canister(CYCLES);
let initial_subnet_available_memory = test.subnet_available_memory();

Expand Down Expand Up @@ -7206,7 +7224,7 @@ fn upload_chunk_reserves_cycles() {
.with_subnet_execution_memory(CAPACITY)
.with_subnet_memory_reservation(0)
.with_subnet_memory_threshold(0)
.with_wasm_chunk_store()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();
let canister_id = test.create_canister(CYCLES);

Expand All @@ -7223,7 +7241,7 @@ fn upload_chunk_reserves_cycles() {
};

let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store()
.with_wasm_chunk_store(FlagStatus::Enabled)
.with_subnet_memory_reservation(0)
.with_subnet_memory_threshold(memory_usage_after_uploading_one_chunk + 1)
.build();
Expand Down Expand Up @@ -7274,7 +7292,9 @@ fn upload_chunk_reserves_cycles() {
fn clear_chunk_store_works() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -7323,7 +7343,9 @@ fn stored_chunks_works() {

const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -7408,7 +7430,7 @@ fn upload_chunk_fails_when_heap_delta_rate_limited() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store()
.with_wasm_chunk_store(FlagStatus::Enabled)
.with_heap_delta_rate_limit(wasm_chunk_store::chunk_size())
.build();
let canister_id = test.create_canister(CYCLES);
Expand Down Expand Up @@ -7453,7 +7475,9 @@ fn upload_chunk_fails_when_heap_delta_rate_limited() {
fn upload_chunk_increases_subnet_heap_delta() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();
let canister_id = test.create_canister(CYCLES);
assert_eq!(test.state().metadata.heap_delta_estimate, NumBytes::from(0));

Expand All @@ -7477,7 +7501,9 @@ fn upload_chunk_charges_canister_cycles() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);
let instructions = SchedulerConfig::application_subnet().upload_wasm_chunk_instructions;

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();
let canister_id = test.create_canister(CYCLES);
let initial_balance = test.canister_state(canister_id).system_state.balance();

Expand Down Expand Up @@ -7505,7 +7531,7 @@ fn upload_chunk_charges_if_failing() {
let instructions = SchedulerConfig::application_subnet().upload_wasm_chunk_instructions;

let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store()
.with_wasm_chunk_store(FlagStatus::Enabled)
.with_subnet_memory_reservation(0)
.with_subnet_execution_memory(10)
.build();
Expand Down Expand Up @@ -7536,7 +7562,9 @@ fn upload_chunk_charges_if_failing() {
fn chunk_store_methods_succeed_from_canister_itself() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let uc = test
.canister_from_cycles_and_binary(CYCLES, UNIVERSAL_CANISTER_WASM.into())
Expand Down
45 changes: 34 additions & 11 deletions rs/execution_environment/src/execution/install_code/tests.rs
@@ -1,5 +1,6 @@
use assert_matches::assert_matches;
use ic_base_types::PrincipalId;
use ic_config::flag_status::FlagStatus;
use ic_error_types::{ErrorCode, UserError};
use ic_registry_routing_table::{CanisterIdRange, RoutingTable};
use ic_replicated_state::canister_state::system_state::wasm_chunk_store;
Expand Down Expand Up @@ -1436,7 +1437,9 @@ fn install_code_args(canister_id: CanisterId) -> InstallCodeArgs {
fn install_chunked_works_from_whitelist() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -1497,7 +1500,9 @@ fn install_chunked_works_from_whitelist() {
fn install_chunked_defaults_to_using_target_as_store() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -1545,7 +1550,9 @@ fn install_chunked_defaults_to_using_target_as_store() {
fn install_chunked_recorded_in_history() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -1613,7 +1620,9 @@ fn install_chunked_recorded_in_history() {
fn install_chunked_works_from_other_canister() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let target_canister = test.create_canister(CYCLES);
let store_canister = test.create_canister(CYCLES);
Expand Down Expand Up @@ -1660,7 +1669,9 @@ fn install_chunked_works_from_other_canister() {
fn install_chunked_fails_with_wrong_chunk_hash() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -1706,7 +1717,9 @@ fn install_chunked_fails_with_wrong_chunk_hash() {
fn install_chunked_fails_with_wrong_wasm_hash() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -1752,7 +1765,9 @@ fn install_chunked_fails_with_wrong_wasm_hash() {
fn install_chunked_fails_when_store_canister_not_found() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let target_canister = test.create_canister(CYCLES);
// Store canister doesn't actually exist.
Expand Down Expand Up @@ -1783,7 +1798,9 @@ fn install_chunked_fails_when_store_canister_not_found() {
fn install_chunked_works_from_controller_of_store() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let store_canister = test.create_canister(CYCLES);
let target_canister = test.create_canister(CYCLES);
Expand Down Expand Up @@ -1838,7 +1855,9 @@ fn install_chunked_works_from_controller_of_store() {
fn install_chunked_fails_from_noncontroller_of_store() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let store_canister = test.create_canister(CYCLES);
let target_canister = test.create_canister(CYCLES);
Expand Down Expand Up @@ -2167,7 +2186,9 @@ fn upgrade_with_dts_correctly_updates_system_state() {
fn failed_install_chunked_charges_for_wasm_assembly() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();

let canister_id = test.create_canister(CYCLES);

Expand Down Expand Up @@ -2225,7 +2246,9 @@ fn failed_install_chunked_charges_for_wasm_assembly() {
fn successful_install_chunked_charges_for_wasm_assembly() {
const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new().with_wasm_chunk_store().build();
let mut test = ExecutionTestBuilder::new()
.with_wasm_chunk_store(FlagStatus::Enabled)
.build();
let wasm = wat::parse_str("(module)").unwrap();

// Get the charges for a normal install
Expand Down
4 changes: 2 additions & 2 deletions rs/test_utilities/execution_environment/src/lib.rs
Expand Up @@ -1887,8 +1887,8 @@ impl ExecutionTestBuilder {
self
}

pub fn with_wasm_chunk_store(mut self) -> Self {
self.execution_config.wasm_chunk_store = FlagStatus::Enabled;
pub fn with_wasm_chunk_store(mut self, status: FlagStatus) -> Self {
self.execution_config.wasm_chunk_store = status;
self
}

Expand Down
16 changes: 9 additions & 7 deletions rs/tests/execution/general_execution_test.rs
Expand Up @@ -23,6 +23,9 @@ use ic_tests::execution::ingress_rate_limiting::*;
use ic_tests::execution::malicious_input::malicious_input_test;
use ic_tests::execution::nns_shielding::*;
use ic_tests::execution::queries::query_reply_sizes;
use ic_tests::execution::wasm_chunk_store::install_large_wasm;
use ic_tests::execution::wasm_chunk_store::install_large_wasm_with_other_store;
use ic_tests::execution::wasm_chunk_store::install_large_wasm_with_other_store_fails_cross_subnet;
use ic_tests::systest;

fn main() -> Result<()> {
Expand Down Expand Up @@ -103,13 +106,12 @@ fn main() -> Result<()> {
canister_heartbeat_can_call_multiple_canisters_xnet
))
.add_test(systest!(canister_heartbeat_can_stop))
.add_test(systest!(canister_heartbeat_cannot_reply)),
// Enable tests when feature is enabled.
// .add_test(systest!(install_large_wasm))
// .add_test(systest!(install_large_wasm_with_other_store))
// .add_test(systest!(
// install_large_wasm_with_other_store_fails_cross_subnet
// )),
.add_test(systest!(canister_heartbeat_cannot_reply))
.add_test(systest!(install_large_wasm))
.add_test(systest!(install_large_wasm_with_other_store))
.add_test(systest!(
install_large_wasm_with_other_store_fails_cross_subnet
)),
)
.execute_from_args()?;

Expand Down

0 comments on commit 42cfbcf

Please sign in to comment.