Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rs/cycles_account_manager/src/cycles_account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl CyclesAccountManager {
cost_schedule,
canister.system_state.reserved_balance(),
);
if canister.has_paused_execution() || canister.has_paused_install_code() {
if canister.has_paused_execution_or_install_code() {
if canister.system_state.debited_balance() < cycles + threshold {
return Err(CanisterOutOfCyclesError {
canister_id: canister.canister_id(),
Expand Down
71 changes: 29 additions & 42 deletions rs/execution_environment/src/canister_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::as_round_instructions;
use crate::canister_settings::{CanisterSettings, ValidatedCanisterSettings};
use crate::execution::common::{
validate_controller, validate_controller_or_subnet_admin, validate_snapshot_visibility,
validate_subnet_admin,
Expand All @@ -9,21 +10,15 @@ use crate::execution_environment::{
CompilationCostHandling, RoundContext, RoundCounters, RoundLimits,
};
use crate::execution_environment_metrics::ExecutionEnvironmentMetrics;
use crate::util::MIGRATION_CANISTER_ID;
use crate::{
canister_settings::{CanisterSettings, ValidatedCanisterSettings},
hypervisor::Hypervisor,
types::{IngressResponse, Response},
util::GOVERNANCE_CANISTER_ID,
};
use crate::hypervisor::Hypervisor;
use crate::types::{IngressResponse, Response};
use crate::util::{GOVERNANCE_CANISTER_ID, MIGRATION_CANISTER_ID};
use ic_base_types::NumSeconds;
use ic_config::embedders::Config as EmbeddersConfig;
use ic_config::flag_status::FlagStatus;
use ic_cycles_account_manager::{CyclesAccountManager, ResourceSaturation};
use ic_embedders::{
wasm_utils::decoding::decode_wasm,
wasmtime_embedder::system_api::{ExecutionParameters, InstructionLimits},
};
use ic_embedders::wasm_utils::decoding::decode_wasm;
use ic_embedders::wasmtime_embedder::system_api::{ExecutionParameters, InstructionLimits};
use ic_error_types::{ErrorCode, RejectCode, UserError};
use ic_interfaces::execution_environment::{MessageMemoryUsage, SubnetAvailableMemory};
use ic_limits::LOG_CANISTER_OPERATION_CYCLES_THRESHOLD;
Expand All @@ -38,35 +33,30 @@ use ic_management_canister_types_private::{
};
use ic_registry_provisional_whitelist::ProvisionalWhitelist;
use ic_replicated_state::canister_state::WASM_PAGE_SIZE_IN_BYTES;
use ic_replicated_state::canister_state::execution_state::{CustomSectionType, SandboxMemory};
use ic_replicated_state::canister_state::canister_snapshots::{
CanisterSnapshot, CanisterSnapshots, ValidatedSnapshotMetadata,
};
use ic_replicated_state::canister_state::execution_state::{
CustomSectionType, Memory, SandboxMemory, WasmExecutionMode,
};
use ic_replicated_state::canister_state::system_state::ReservationError;
use ic_replicated_state::canister_state::system_state::wasm_chunk_store::{
CHUNK_SIZE, ChunkValidationResult, WasmChunkHash,
self, CHUNK_SIZE, ChunkValidationResult, WasmChunkHash, WasmChunkStore,
};
use ic_replicated_state::page_map::Buffer;
use ic_replicated_state::metadata_state::subnet_call_context_manager::InstallCodeCallId;
use ic_replicated_state::page_map::{Buffer, PageAllocatorFileDescriptor};
use ic_replicated_state::{
CallOrigin, CanisterState, NetworkTopology, ReplicatedState, SchedulerState, SystemState,
canister_state::{
NextExecution,
canister_snapshots::{CanisterSnapshot, CanisterSnapshots, ValidatedSnapshotMetadata},
execution_state::Memory,
execution_state::WasmExecutionMode,
system_state::{
ReservationError,
wasm_chunk_store::{self, WasmChunkStore},
},
},
metadata_state::subnet_call_context_manager::InstallCodeCallId,
page_map::PageAllocatorFileDescriptor,
};
use ic_types::ingress::{IngressState, IngressStatus};
use ic_types::messages::{
CanisterCall, Payload, RejectContext, Response as CanisterResponse, SignedIngressContent,
StopCanisterCallId, StopCanisterContext,
};
use ic_types::{
CanisterId, CanisterTimer, ComputeAllocation, DEFAULT_AGGREGATE_LOG_MEMORY_LIMIT,
MAX_AGGREGATE_LOG_MEMORY_LIMIT, MemoryAllocation, NumBytes, NumInstructions, PrincipalId,
SnapshotId, Time,
ingress::{IngressState, IngressStatus},
messages::{
CanisterCall, Payload, RejectContext, Response as CanisterResponse, SignedIngressContent,
StopCanisterCallId, StopCanisterContext,
},
};
use ic_types_cycles::{
CanisterCreation, CanisterCyclesCostSchedule, CompoundCycles, Cycles, CyclesUseCase,
Expand Down Expand Up @@ -2280,17 +2270,14 @@ impl CanisterManager {
// Check the precondition:
// Unable to start executing a `load_canister_snapshot`
// if there is already a long-running message in progress for the specified canister.
match canister.next_execution() {
NextExecution::None | NextExecution::StartNew => {}
NextExecution::ContinueLong | NextExecution::ContinueInstallCode => {
metrics.long_execution_already_in_progress.inc();
error!(
self.log,
"[EXC-BUG] Attempted to start a new `load_canister_snapshot` execution while the previous execution is still in progress for {}.",
canister_id
);
return Err(CanisterManagerError::LongExecutionAlreadyInProgress { canister_id });
}
if canister.has_long_execution_or_install_code() {
metrics.long_execution_already_in_progress.inc();
error!(
self.log,
"[EXC-BUG] Attempted to start a new `load_canister_snapshot` execution while the previous execution is still in progress for {}.",
canister_id
);
return Err(CanisterManagerError::LongExecutionAlreadyInProgress { canister_id });
}

// All basic checks have passed, prepay cycles for instructions.
Expand Down
122 changes: 53 additions & 69 deletions rs/execution_environment/src/execution_environment.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
use crate::{
canister_logs::fetch_canister_logs,
canister_manager::{
CanisterManager,
types::{
CanisterManagerError, CanisterManagerResponse, DtsInstallCodeResult,
InstallCodeContext, PausedInstallCodeExecution, UploadChunkResult,
},
},
canister_settings::CanisterSettings,
execution::{
call_or_task::execute_call_or_task, common::validate_controller, inspect_message,
response::execute_response,
},
execution_environment_metrics::{
ExecutionEnvironmentMetrics, SUBMITTED_OUTCOME_LABEL, SUCCESS_STATUS_LABEL,
},
hypervisor::Hypervisor,
ic00_permissions::Ic00MethodPermissions,
metrics::{CallTreeMetrics, CallTreeMetricsImpl, IngressFilterMetrics},
use crate::canister_logs::fetch_canister_logs;
use crate::canister_manager::CanisterManager;
use crate::canister_manager::types::{
CanisterManagerError, CanisterManagerResponse, DtsInstallCodeResult, InstallCodeContext,
PausedInstallCodeExecution, UploadChunkResult,
};
use crate::canister_settings::CanisterSettings;
use crate::execution::call_or_task::execute_call_or_task;
use crate::execution::common::validate_controller;
use crate::execution::inspect_message;
use crate::execution::response::execute_response;
use crate::execution_environment_metrics::{
ExecutionEnvironmentMetrics, SUBMITTED_OUTCOME_LABEL, SUCCESS_STATUS_LABEL,
};
use crate::hypervisor::Hypervisor;
use crate::ic00_permissions::Ic00MethodPermissions;
use crate::metrics::{CallTreeMetrics, CallTreeMetricsImpl, IngressFilterMetrics};
use candid::Encode;
use ic_base_types::PrincipalId;
use ic_config::execution_environment::Config as ExecutionConfig;
Expand Down Expand Up @@ -52,37 +48,35 @@ use ic_metrics::MetricsRegistry;
use ic_registry_provisional_whitelist::ProvisionalWhitelist;
use ic_registry_resource_limits::ResourceLimits;
use ic_registry_subnet_type::SubnetType;
use ic_replicated_state::canister_state::{NextExecution, system_state::PausedExecutionId};
use ic_replicated_state::metadata_state::subnet_call_context_manager::{
EcdsaArguments, InstallCodeCall, InstallCodeCallId, PreSignatureStash, ReshareChainKeyContext,
SchnorrArguments, SetupInitialDkgContext, SignWithThresholdContext, StopCanisterCall,
SubnetCallContext, ThresholdArguments, VetKdArguments,
};
use ic_replicated_state::{
CanisterState, CanisterStatus, ExecutionTask, NetworkTopology, ReplicatedState,
canister_state::NextExecution,
canister_state::system_state::PausedExecutionId,
metadata_state::subnet_call_context_manager::{
EcdsaArguments, InstallCodeCall, InstallCodeCallId, PreSignatureStash,
ReshareChainKeyContext, SchnorrArguments, SetupInitialDkgContext, SignWithThresholdContext,
StopCanisterCall, SubnetCallContext, ThresholdArguments, VetKdArguments,
},
};
use ic_types::batch::ChainKeyData;
use ic_types::canister_http::{CanisterHttpRequestContext, MAX_CANISTER_HTTP_RESPONSE_BYTES};
use ic_types::consensus::idkg::IDkgMasterPublicKeyId;
use ic_types::crypto::{
ExtendedDerivationPath,
canister_threshold_sig::{MasterPublicKey, PublicKey},
threshold_sig::ni_dkg::{NiDkgMasterPublicKeyId, NiDkgTargetId},
};
use ic_types::ingress::{IngressState, IngressStatus, WasmResult};
use ic_types::messages::{
CanisterCall, CanisterCallOrTask, CanisterMessage, CanisterMessageOrTask, CanisterTask,
MAX_INTER_CANISTER_PAYLOAD_IN_BYTES, MessageId, Payload, RejectContext, Request, Response,
SignedIngress, StopCanisterCallId, StopCanisterContext, SubnetMessage,
extract_effective_canister_id,
};
use ic_types::methods::{Callback, SystemMethod, WasmMethod};
use ic_types::{
CanisterId, ExecutionRound, Height, NumBytes, NumInstructions, RegistryVersion, ReplicaVersion,
SubnetId, Time,
batch::ChainKeyData,
canister_http::{CanisterHttpRequestContext, MAX_CANISTER_HTTP_RESPONSE_BYTES},
consensus::idkg::IDkgMasterPublicKeyId,
crypto::{
ExtendedDerivationPath,
canister_threshold_sig::{MasterPublicKey, PublicKey},
threshold_sig::ni_dkg::{NiDkgMasterPublicKeyId, NiDkgTargetId},
},
ingress::{IngressState, IngressStatus, WasmResult},
messages::{
CanisterCall, CanisterCallOrTask, CanisterMessage, CanisterMessageOrTask, CanisterTask,
MAX_INTER_CANISTER_PAYLOAD_IN_BYTES, Payload, RejectContext, Request, Response,
SignedIngress, StopCanisterCallId, StopCanisterContext, SubnetMessage,
extract_effective_canister_id,
},
methods::{Callback, SystemMethod},
};
use ic_types::{messages::MessageId, methods::WasmMethod};
use ic_types_cycles::{
CanisterCyclesCostSchedule, CompoundCycles, Cycles, CyclesUseCase, ECDSAOutcalls, Instructions,
NominalCycles, SchnorrOutcalls, VetKd,
Expand All @@ -92,15 +86,13 @@ use ic_wasm_types::WasmHash;
use phantom_newtype::AmountOf;
use prometheus::IntCounter;
use rand::RngCore;
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::convert::{Into, TryFrom};
use std::fmt;
use std::num::NonZeroU64;
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
convert::{Into, TryFrom},
fmt,
str::FromStr,
sync::{Arc, Mutex},
time::{Duration, Instant},
};
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use strum::ParseError;

#[cfg(test)]
Expand Down Expand Up @@ -2088,16 +2080,11 @@ impl ExecutionEnvironment {
subnet_size: usize,
cost_schedule: CanisterCyclesCostSchedule,
) -> ExecuteMessageResult {
match canister.next_execution() {
NextExecution::None | NextExecution::StartNew => {}
NextExecution::ContinueLong | NextExecution::ContinueInstallCode => {
// We should never try to execute a canister message in
// replicated mode if there is a pending long execution.
panic!(
"Replicated execution with another pending DTS execution: {:?}",
canister.next_execution()
);
}
if canister.has_long_execution_or_install_code() {
panic!(
"Replicated execution with a pending DTS task: {:?}",
canister.system_state.task_queue.paused_or_aborted_task()
);
}

let round_counters = RoundCounters {
Expand Down Expand Up @@ -3830,13 +3817,10 @@ impl ExecutionEnvironment {
};

// Check the precondition.
match old_canister.next_execution() {
NextExecution::None | NextExecution::StartNew => {}
NextExecution::ContinueLong | NextExecution::ContinueInstallCode => {
panic!(
"Attempt to start a new `install_code` execution while the previous execution is still in progress."
);
}
if old_canister.has_long_execution_or_install_code() {
panic!(
"Attempt to start a new `install_code` execution while the previous execution is still in progress."
);
}

let canister_id = old_canister.canister_id();
Expand Down
Loading
Loading