diff --git a/rs/consensus/src/consensus/batch_delivery.rs b/rs/consensus/src/consensus/batch_delivery.rs index 660bf86fea2..1883237f544 100644 --- a/rs/consensus/src/consensus/batch_delivery.rs +++ b/rs/consensus/src/consensus/batch_delivery.rs @@ -233,6 +233,7 @@ pub fn deliver_batches( time: block.context.time, consensus_responses, blockmaker_metrics, + replica_version: block.version.clone(), }; debug!( diff --git a/rs/determinism_test/src/lib.rs b/rs/determinism_test/src/lib.rs index e724dfb3120..14d2cb6b26e 100644 --- a/rs/determinism_test/src/lib.rs +++ b/rs/determinism_test/src/lib.rs @@ -17,7 +17,7 @@ use ic_types::{ ingress::{IngressState, IngressStatus, WasmResult}, messages::{MessageId, SignedIngress}, time::UNIX_EPOCH, - CanisterId, CryptoHashOfState, Randomness, RegistryVersion, + CanisterId, CryptoHashOfState, Randomness, RegistryVersion, ReplicaVersion, }; use setup::setup; use std::{collections::BTreeMap, convert::TryFrom, sync::Arc, thread::sleep, time::Duration}; @@ -38,6 +38,7 @@ fn build_batch(message_routing: &dyn MessageRouting, msgs: Vec) - time: UNIX_EPOCH, consensus_responses: vec![], blockmaker_metrics: BlockmakerMetrics::new_for_test(), + replica_version: ReplicaVersion::default(), } } @@ -54,6 +55,7 @@ fn build_batch_with_full_state_hash(message_routing: &dyn MessageRouting) -> Bat time: UNIX_EPOCH, consensus_responses: vec![], blockmaker_metrics: BlockmakerMetrics::new_for_test(), + replica_version: ReplicaVersion::default(), } } diff --git a/rs/drun/src/lib.rs b/rs/drun/src/lib.rs index dcd8cf3963c..55cd32fee14 100644 --- a/rs/drun/src/lib.rs +++ b/rs/drun/src/lib.rs @@ -34,7 +34,6 @@ use ic_test_utilities_consensus::fake::FakeVerifier; use ic_test_utilities_registry::{ add_subnet_record, insert_initial_dkg_transcript, SubnetRecordBuilder, }; -use ic_types::batch::{BatchMessages, BlockmakerMetrics}; use ic_types::malicious_flags::MaliciousFlags; use ic_types::{ batch::Batch, @@ -43,6 +42,10 @@ use ic_types::{ replica_config::ReplicaConfig, time, CanisterId, NodeId, NumInstructions, PrincipalId, Randomness, RegistryVersion, SubnetId, }; +use ic_types::{ + batch::{BatchMessages, BlockmakerMetrics}, + ReplicaVersion, +}; use rand::distributions::{Distribution, Uniform}; use rand::rngs::StdRng; use rand::SeedableRng; @@ -386,6 +389,7 @@ fn build_batch(message_routing: &dyn MessageRouting, msgs: Vec) - time: time::current_time(), consensus_responses: vec![], blockmaker_metrics: BlockmakerMetrics::new_for_test(), + replica_version: ReplicaVersion::default(), } } /// Block till the given ingress message has finished executing and diff --git a/rs/execution_environment/src/execution_environment.rs b/rs/execution_environment/src/execution_environment.rs index 58b2959b795..fa8fda2da06 100644 --- a/rs/execution_environment/src/execution_environment.rs +++ b/rs/execution_environment/src/execution_environment.rs @@ -72,7 +72,7 @@ use ic_types::{ }, methods::SystemMethod, nominal_cycles::NominalCycles, - CanisterId, Cycles, NumBytes, NumInstructions, SubnetId, Time, + CanisterId, Cycles, NumBytes, NumInstructions, ReplicaVersion, SubnetId, Time, }; use ic_types::{messages::MessageId, methods::WasmMethod}; use ic_wasm_types::WasmHash; @@ -472,6 +472,7 @@ impl ExecutionEnvironment { instruction_limits: InstructionLimits, rng: &mut dyn RngCore, idkg_subnet_public_keys: &BTreeMap, + _replica_version: &ReplicaVersion, registry_settings: &RegistryExecutionSettings, round_limits: &mut RoundLimits, ) -> (ReplicatedState, Option) { diff --git a/rs/execution_environment/src/scheduler.rs b/rs/execution_environment/src/scheduler.rs index ab05f221de2..36c16f9802e 100644 --- a/rs/execution_environment/src/scheduler.rs +++ b/rs/execution_environment/src/scheduler.rs @@ -37,8 +37,8 @@ use ic_types::{ ingress::{IngressState, IngressStatus}, messages::{CanisterMessage, Ingress, MessageId, Response, NO_DEADLINE}, AccumulatedPriority, CanisterId, ComputeAllocation, Cycles, ExecutionRound, LongExecutionMode, - MemoryAllocation, NumBytes, NumInstructions, NumSlices, Randomness, SubnetId, Time, - MAX_WASM_MEMORY_IN_BYTES, + MemoryAllocation, NumBytes, NumInstructions, NumSlices, Randomness, ReplicaVersion, SubnetId, + Time, MAX_WASM_MEMORY_IN_BYTES, }; use ic_types::{nominal_cycles::NominalCycles, NumMessages}; use num_rational::Ratio; @@ -481,6 +481,7 @@ impl SchedulerImpl { round_limits: &mut RoundLimits, measurement_scope: &MeasurementScope, registry_settings: &RegistryExecutionSettings, + replica_version: &ReplicaVersion, idkg_subnet_public_keys: &BTreeMap, ) -> ReplicatedState { let ongoing_long_install_code = @@ -517,6 +518,7 @@ impl SchedulerImpl { csprng, round_limits, registry_settings, + replica_version, measurement_scope, idkg_subnet_public_keys, ); @@ -548,6 +550,7 @@ impl SchedulerImpl { csprng: &mut Csprng, round_limits: &mut RoundLimits, registry_settings: &RegistryExecutionSettings, + replica_version: &ReplicaVersion, measurement_scope: &MeasurementScope, idkg_subnet_public_keys: &BTreeMap, ) -> (ReplicatedState, Option) { @@ -564,6 +567,7 @@ impl SchedulerImpl { instruction_limits, csprng, idkg_subnet_public_keys, + replica_version, registry_settings, round_limits, ); @@ -643,6 +647,7 @@ impl SchedulerImpl { root_measurement_scope: &MeasurementScope<'a>, scheduler_round_limits: &mut SchedulerRoundLimits, registry_settings: &RegistryExecutionSettings, + replica_version: &ReplicaVersion, idkg_subnet_public_keys: &BTreeMap, ) -> (ReplicatedState, BTreeSet, BTreeSet) { let measurement_scope = @@ -683,6 +688,7 @@ impl SchedulerImpl { &mut subnet_round_limits, &subnet_measurement_scope, registry_settings, + replica_version, idkg_subnet_public_keys, ); scheduler_round_limits.update_subnet_round_limits(&subnet_round_limits); @@ -1406,6 +1412,7 @@ impl Scheduler for SchedulerImpl { randomness: Randomness, idkg_subnet_public_keys: BTreeMap, idkg_pre_signature_ids: BTreeMap>, + replica_version: &ReplicaVersion, current_round: ExecutionRound, round_summary: Option, current_round_type: ExecutionRoundType, @@ -1563,6 +1570,7 @@ impl Scheduler for SchedulerImpl { &mut csprng, &mut subnet_round_limits, registry_settings, + replica_version, &measurement_scope, &idkg_subnet_public_keys, ); @@ -1621,6 +1629,7 @@ impl Scheduler for SchedulerImpl { &mut csprng, &mut subnet_round_limits, registry_settings, + replica_version, &measurement_scope, &idkg_subnet_public_keys, ); @@ -1681,6 +1690,7 @@ impl Scheduler for SchedulerImpl { &root_measurement_scope, &mut scheduler_round_limits, registry_settings, + replica_version, &idkg_subnet_public_keys, ); diff --git a/rs/execution_environment/src/scheduler/test_utilities.rs b/rs/execution_environment/src/scheduler/test_utilities.rs index 6cb10540876..2056f91e4b6 100644 --- a/rs/execution_environment/src/scheduler/test_utilities.rs +++ b/rs/execution_environment/src/scheduler/test_utilities.rs @@ -58,7 +58,7 @@ use ic_types::{ }, methods::{Callback, FuncRef, SystemMethod, WasmClosure, WasmMethod}, CanisterTimer, ComputeAllocation, Cycles, ExecutionRound, MemoryAllocation, NumInstructions, - Randomness, Time, UserId, + Randomness, ReplicaVersion, Time, UserId, }; use ic_wasm_types::CanisterModule; use maplit::btreemap; @@ -117,6 +117,8 @@ pub(crate) struct SchedulerTest { idkg_subnet_public_keys: BTreeMap, // Pre-signature IDs. idkg_pre_signature_ids: BTreeMap>, + // Version of the running replica, not the registry's Entry + replica_version: ReplicaVersion, } impl std::fmt::Debug for SchedulerTest { @@ -511,6 +513,7 @@ impl SchedulerTest { Randomness::from([0; 32]), self.idkg_subnet_public_keys.clone(), self.idkg_pre_signature_ids.clone(), + &self.replica_version, self.round, self.round_summary.clone(), round_type, @@ -559,6 +562,7 @@ impl SchedulerTest { &mut round_limits, &measurements, self.registry_settings(), + &self.replica_version, &BTreeMap::new(), ) } @@ -659,6 +663,7 @@ pub(crate) struct SchedulerTestBuilder { metrics_registry: MetricsRegistry, round_summary: Option, canister_snapshot_flag: bool, + replica_version: ReplicaVersion, } impl Default for SchedulerTestBuilder { @@ -684,6 +689,7 @@ impl Default for SchedulerTestBuilder { metrics_registry: MetricsRegistry::new(), round_summary: None, canister_snapshot_flag: true, + replica_version: ReplicaVersion::default(), } } } @@ -760,6 +766,13 @@ impl SchedulerTestBuilder { } } + pub fn with_replica_version(self, replica_version: ReplicaVersion) -> Self { + Self { + replica_version, + ..self + } + } + pub fn build(self) -> SchedulerTest { let first_xnet_canister = u64::MAX / 2; let routing_table = Arc::new( @@ -928,6 +941,7 @@ impl SchedulerTestBuilder { metrics_registry: self.metrics_registry, idkg_subnet_public_keys, idkg_pre_signature_ids: BTreeMap::new(), + replica_version: self.replica_version, } } } diff --git a/rs/execution_environment/src/scheduler/tests.rs b/rs/execution_environment/src/scheduler/tests.rs index 6b4567f38d1..125f889aa5a 100644 --- a/rs/execution_environment/src/scheduler/tests.rs +++ b/rs/execution_environment/src/scheduler/tests.rs @@ -3541,6 +3541,7 @@ fn threshold_signature_agreements_metric_is_updated() { let schnorr_key_id = make_schnorr_key_id(0); let master_schnorr_key_id = MasterPublicKeyId::Schnorr(schnorr_key_id.clone()); let mut test = SchedulerTestBuilder::new() + .with_replica_version(ReplicaVersion::default()) .with_idkg_keys(vec![ master_ecdsa_key_id.clone(), master_schnorr_key_id.clone(), diff --git a/rs/interfaces/src/execution_environment.rs b/rs/interfaces/src/execution_environment.rs index 68695166bac..bbefb9cbebd 100644 --- a/rs/interfaces/src/execution_environment.rs +++ b/rs/interfaces/src/execution_environment.rs @@ -13,7 +13,8 @@ use ic_types::{ crypto::canister_threshold_sig::MasterPublicKey, ingress::{IngressStatus, WasmResult}, messages::{CertificateDelegation, MessageId, Query, SignedIngressContent}, - CanisterLog, Cycles, ExecutionRound, Height, NumInstructions, NumOsPages, Randomness, Time, + CanisterLog, Cycles, ExecutionRound, Height, NumInstructions, NumOsPages, Randomness, + ReplicaVersion, Time, }; use serde::{Deserialize, Serialize}; use std::{ @@ -1249,6 +1250,7 @@ pub trait Scheduler: Send { randomness: Randomness, idkg_subnet_public_keys: BTreeMap, idkg_pre_signature_ids: BTreeMap>, + replica_version: &ReplicaVersion, current_round: ExecutionRound, round_summary: Option, current_round_type: ExecutionRoundType, diff --git a/rs/messaging/src/message_routing/tests.rs b/rs/messaging/src/message_routing/tests.rs index dfb65cd3447..862a07f2303 100644 --- a/rs/messaging/src/message_routing/tests.rs +++ b/rs/messaging/src/message_routing/tests.rs @@ -37,6 +37,7 @@ use ic_test_utilities_types::{ }; use ic_types::batch::BlockmakerMetrics; use ic_types::xnet::{StreamIndexedQueue, StreamSlice}; +use ic_types::ReplicaVersion; use ic_types::{ batch::{Batch, BatchMessages}, crypto::threshold_sig::ni_dkg::{NiDkgTag, NiDkgTranscript}, @@ -1043,6 +1044,7 @@ fn try_read_registry_succeeds_with_fully_specified_registry_records() { time: Time::from_nanos_since_unix_epoch(0), consensus_responses: Vec::new(), blockmaker_metrics: BlockmakerMetrics::new_for_test(), + replica_version: ReplicaVersion::default(), }); let latest_state = state_manager.get_latest_state().take(); assert_eq!(network_topology, latest_state.metadata.network_topology); @@ -1842,6 +1844,7 @@ fn process_batch_updates_subnet_metrics() { time: Time::from_nanos_since_unix_epoch(0), consensus_responses: Vec::new(), blockmaker_metrics: BlockmakerMetrics::new_for_test(), + replica_version: ReplicaVersion::default(), }); let latest_state = state_manager.get_latest_state().take(); diff --git a/rs/messaging/src/state_machine.rs b/rs/messaging/src/state_machine.rs index 395570876c1..c1a4a1cfb54 100644 --- a/rs/messaging/src/state_machine.rs +++ b/rs/messaging/src/state_machine.rs @@ -165,6 +165,7 @@ impl StateMachine for StateMachineImpl { batch.randomness, batch.idkg_subnet_public_keys, batch.idkg_pre_signature_ids, + &batch.replica_version, ExecutionRound::from(batch.batch_number.get()), round_summary, execution_round_type, diff --git a/rs/messaging/src/state_machine/tests.rs b/rs/messaging/src/state_machine/tests.rs index 63fb2dcd4cb..9e7590edef8 100644 --- a/rs/messaging/src/state_machine/tests.rs +++ b/rs/messaging/src/state_machine/tests.rs @@ -21,7 +21,7 @@ use ic_test_utilities_types::{ use ic_types::consensus::idkg::PreSigId; use ic_types::messages::SignedIngress; use ic_types::{batch::BatchMessages, crypto::canister_threshold_sig::MasterPublicKey}; -use ic_types::{Height, PrincipalId, SubnetId, Time}; +use ic_types::{Height, PrincipalId, ReplicaVersion, SubnetId, Time}; use maplit::btreemap; use mockall::{mock, predicate::*, Sequence}; use std::collections::{BTreeMap, BTreeSet}; @@ -36,6 +36,7 @@ mock! { randomness: ic_types::Randomness, idkg_subnet_public_keys: BTreeMap, idkg_pre_signature_ids: BTreeMap>, + replica_version: &ReplicaVersion, current_round: ExecutionRound, round_summary: Option, current_round_type: ExecutionRoundType, @@ -92,12 +93,13 @@ fn test_fixture(provided_batch: &Batch) -> StateMachineTestFixture { eq(provided_batch.randomness), eq(provided_batch.idkg_subnet_public_keys.clone()), eq(provided_batch.idkg_pre_signature_ids.clone()), + eq(provided_batch.replica_version.clone()), eq(round), eq(None), eq(round_type), eq(test_registry_settings()), ) - .returning(|state, _, _, _, _, _, _, _| state); + .returning(|state, _, _, _, _, _, _, _, _| state); let mut stream_builder = Box::new(MockStreamBuilder::new()); stream_builder diff --git a/rs/replay/src/player.rs b/rs/replay/src/player.rs index 1499c9ba73c..ffc82925658 100644 --- a/rs/replay/src/player.rs +++ b/rs/replay/src/player.rs @@ -728,11 +728,12 @@ impl Player { pool: Option<&ConsensusPoolImpl>, mut extra: F, ) -> (Time, Option<(Height, Vec)>) { - let (registry_version, time, randomness) = match pool { + let (registry_version, time, randomness, replica_version) = match pool { None => ( self.registry.get_latest_version(), ic_types::time::current_time(), Randomness::from([0; 32]), + ReplicaVersion::default(), ), Some(pool) => { let pool = PoolReader::new(pool); @@ -750,6 +751,7 @@ impl Player { last_block.context.registry_version, last_block.context.time + Duration::from_nanos(1), Randomness::from(crypto_hashable_to_seed(&last_block)), + last_block.version.clone(), ) } }; @@ -766,6 +768,7 @@ impl Player { time, consensus_responses: Vec::new(), blockmaker_metrics: BlockmakerMetrics::new_for_test(), + replica_version, }; let context_time = extra_batch.time; let extra_msgs = extra(self, context_time); diff --git a/rs/state_machine_tests/src/lib.rs b/rs/state_machine_tests/src/lib.rs index f15d2f81a11..4d1b8782d58 100644 --- a/rs/state_machine_tests/src/lib.rs +++ b/rs/state_machine_tests/src/lib.rs @@ -2338,6 +2338,7 @@ impl StateMachine { time: self.get_time_of_next_round(), consensus_responses: payload.consensus_responses, blockmaker_metrics: BlockmakerMetrics::new_for_test(), + replica_version: ReplicaVersion::default(), }; self.message_routing diff --git a/rs/test_utilities/execution_environment/src/lib.rs b/rs/test_utilities/execution_environment/src/lib.rs index b38aeac999f..9409db028e4 100644 --- a/rs/test_utilities/execution_environment/src/lib.rs +++ b/rs/test_utilities/execution_environment/src/lib.rs @@ -52,6 +52,7 @@ use ic_replicated_state::{ use ic_system_api::InstructionLimits; use ic_test_utilities::{crypto::mock_random_number_generator, state_manager::FakeStateManager}; use ic_test_utilities_types::messages::{IngressBuilder, RequestBuilder, SignedIngressBuilder}; +use ic_types::ReplicaVersion; use ic_types::{ batch::QueryStats, crypto::{canister_threshold_sig::MasterPublicKey, AlgorithmId}, @@ -213,6 +214,7 @@ pub struct ExecutionTest { manual_execution: bool, caller_canister_id: Option, idkg_subnet_public_keys: BTreeMap, + replica_version: ReplicaVersion, // The actual implementation. exec_env: ExecutionEnvironment, @@ -1255,6 +1257,7 @@ impl ExecutionTest { self.install_code_instruction_limits.clone(), &mut mock_random_number_generator(), &self.idkg_subnet_public_keys, + &self.replica_version, &self.registry_settings, &mut round_limits, ); @@ -1680,6 +1683,7 @@ pub struct ExecutionTestBuilder { heap_delta_rate_limit: NumBytes, upload_wasm_chunk_instructions: NumInstructions, canister_snapshot_baseline_instructions: NumInstructions, + replica_version: ReplicaVersion, } impl Default for ExecutionTestBuilder { @@ -1721,6 +1725,7 @@ impl Default for ExecutionTestBuilder { upload_wasm_chunk_instructions: scheduler_config.upload_wasm_chunk_instructions, canister_snapshot_baseline_instructions: scheduler_config .canister_snapshot_baseline_instructions, + replica_version: ReplicaVersion::default(), } } } @@ -2082,6 +2087,11 @@ impl ExecutionTestBuilder { self } + pub fn with_replica_version(mut self, replica_version: ReplicaVersion) -> Self { + self.replica_version = replica_version; + self + } + pub fn build(self) -> ExecutionTest { let own_range = CanisterIdRange { start: CanisterId::from(CANISTER_IDS_PER_SUBNET), @@ -2304,6 +2314,7 @@ impl ExecutionTestBuilder { idkg_subnet_public_keys, log: self.log, checkpoint_files: vec![], + replica_version: self.replica_version, } } } diff --git a/rs/test_utilities/types/src/batch/batch_builder.rs b/rs/test_utilities/types/src/batch/batch_builder.rs index 0e3012a2178..f7381190113 100644 --- a/rs/test_utilities/types/src/batch/batch_builder.rs +++ b/rs/test_utilities/types/src/batch/batch_builder.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use ic_types::{ batch::{Batch, BatchMessages, BlockmakerMetrics}, time::UNIX_EPOCH, - Height, Randomness, RegistryVersion, Time, + Height, Randomness, RegistryVersion, ReplicaVersion, Time, }; pub struct BatchBuilder { @@ -26,6 +26,7 @@ impl Default for BatchBuilder { time: UNIX_EPOCH, consensus_responses: vec![], blockmaker_metrics: BlockmakerMetrics::new_for_test(), + replica_version: ReplicaVersion::default(), }, } } diff --git a/rs/types/types/src/batch.rs b/rs/types/types/src/batch.rs index 65b31698f8b..400d22480e2 100644 --- a/rs/types/types/src/batch.rs +++ b/rs/types/types/src/batch.rs @@ -22,7 +22,7 @@ use crate::{ crypto::canister_threshold_sig::MasterPublicKey, messages::{CallbackId, Payload, SignedIngress}, xnet::CertifiedStreamSlice, - Height, Randomness, RegistryVersion, SubnetId, Time, + Height, Randomness, RegistryVersion, ReplicaVersion, SubnetId, Time, }; use ic_base_types::NodeId; use ic_btc_replica_types::BitcoinAdapterResponse; @@ -64,6 +64,8 @@ pub struct Batch { pub consensus_responses: Vec, /// Information about block makers pub blockmaker_metrics: BlockmakerMetrics, + /// The current replica version. + pub replica_version: ReplicaVersion, } /// The context built by Consensus for deterministic processing. Captures all