Skip to content

Commit

Permalink
feat: [UTP-242] [v3] Make subnet replica version of latest block avai…
Browse files Browse the repository at this point in the history
…lable to execution environment (#2248)

This is an alternative to #2248 and
#2082

This PR passes the running replica version to the execution environment,
from where it can be used [in a future management canister
call.](dfinity/interface-spec#351):
#2202

---------

Co-authored-by: Michael Weigelt <michael.weigelt@dfinity.com>
  • Loading branch information
michael-weigelt and Michael Weigelt authored Oct 28, 2024
1 parent 6890158 commit 69848c6
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 12 deletions.
1 change: 1 addition & 0 deletions rs/consensus/src/consensus/batch_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pub fn deliver_batches(
time: block.context.time,
consensus_responses,
blockmaker_metrics,
replica_version: block.version.clone(),
};

debug!(
Expand Down
4 changes: 3 additions & 1 deletion rs/determinism_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -38,6 +38,7 @@ fn build_batch(message_routing: &dyn MessageRouting, msgs: Vec<SignedIngress>) -
time: UNIX_EPOCH,
consensus_responses: vec![],
blockmaker_metrics: BlockmakerMetrics::new_for_test(),
replica_version: ReplicaVersion::default(),
}
}

Expand All @@ -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(),
}
}

Expand Down
6 changes: 5 additions & 1 deletion rs/drun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -386,6 +389,7 @@ fn build_batch(message_routing: &dyn MessageRouting, msgs: Vec<SignedIngress>) -
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
Expand Down
3 changes: 2 additions & 1 deletion rs/execution_environment/src/execution_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -472,6 +472,7 @@ impl ExecutionEnvironment {
instruction_limits: InstructionLimits,
rng: &mut dyn RngCore,
idkg_subnet_public_keys: &BTreeMap<MasterPublicKeyId, MasterPublicKey>,
_replica_version: &ReplicaVersion,
registry_settings: &RegistryExecutionSettings,
round_limits: &mut RoundLimits,
) -> (ReplicatedState, Option<NumInstructions>) {
Expand Down
14 changes: 12 additions & 2 deletions rs/execution_environment/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -481,6 +481,7 @@ impl SchedulerImpl {
round_limits: &mut RoundLimits,
measurement_scope: &MeasurementScope,
registry_settings: &RegistryExecutionSettings,
replica_version: &ReplicaVersion,
idkg_subnet_public_keys: &BTreeMap<MasterPublicKeyId, MasterPublicKey>,
) -> ReplicatedState {
let ongoing_long_install_code =
Expand Down Expand Up @@ -517,6 +518,7 @@ impl SchedulerImpl {
csprng,
round_limits,
registry_settings,
replica_version,
measurement_scope,
idkg_subnet_public_keys,
);
Expand Down Expand Up @@ -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<MasterPublicKeyId, MasterPublicKey>,
) -> (ReplicatedState, Option<NumInstructions>) {
Expand All @@ -564,6 +567,7 @@ impl SchedulerImpl {
instruction_limits,
csprng,
idkg_subnet_public_keys,
replica_version,
registry_settings,
round_limits,
);
Expand Down Expand Up @@ -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<MasterPublicKeyId, MasterPublicKey>,
) -> (ReplicatedState, BTreeSet<CanisterId>, BTreeSet<CanisterId>) {
let measurement_scope =
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1406,6 +1412,7 @@ impl Scheduler for SchedulerImpl {
randomness: Randomness,
idkg_subnet_public_keys: BTreeMap<MasterPublicKeyId, MasterPublicKey>,
idkg_pre_signature_ids: BTreeMap<MasterPublicKeyId, BTreeSet<PreSigId>>,
replica_version: &ReplicaVersion,
current_round: ExecutionRound,
round_summary: Option<ExecutionRoundSummary>,
current_round_type: ExecutionRoundType,
Expand Down Expand Up @@ -1563,6 +1570,7 @@ impl Scheduler for SchedulerImpl {
&mut csprng,
&mut subnet_round_limits,
registry_settings,
replica_version,
&measurement_scope,
&idkg_subnet_public_keys,
);
Expand Down Expand Up @@ -1621,6 +1629,7 @@ impl Scheduler for SchedulerImpl {
&mut csprng,
&mut subnet_round_limits,
registry_settings,
replica_version,
&measurement_scope,
&idkg_subnet_public_keys,
);
Expand Down Expand Up @@ -1681,6 +1690,7 @@ impl Scheduler for SchedulerImpl {
&root_measurement_scope,
&mut scheduler_round_limits,
registry_settings,
replica_version,
&idkg_subnet_public_keys,
);

Expand Down
16 changes: 15 additions & 1 deletion rs/execution_environment/src/scheduler/test_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,6 +117,8 @@ pub(crate) struct SchedulerTest {
idkg_subnet_public_keys: BTreeMap<MasterPublicKeyId, MasterPublicKey>,
// Pre-signature IDs.
idkg_pre_signature_ids: BTreeMap<MasterPublicKeyId, BTreeSet<PreSigId>>,
// Version of the running replica, not the registry's Entry
replica_version: ReplicaVersion,
}

impl std::fmt::Debug for SchedulerTest {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -559,6 +562,7 @@ impl SchedulerTest {
&mut round_limits,
&measurements,
self.registry_settings(),
&self.replica_version,
&BTreeMap::new(),
)
}
Expand Down Expand Up @@ -659,6 +663,7 @@ pub(crate) struct SchedulerTestBuilder {
metrics_registry: MetricsRegistry,
round_summary: Option<ExecutionRoundSummary>,
canister_snapshot_flag: bool,
replica_version: ReplicaVersion,
}

impl Default for SchedulerTestBuilder {
Expand All @@ -684,6 +689,7 @@ impl Default for SchedulerTestBuilder {
metrics_registry: MetricsRegistry::new(),
round_summary: None,
canister_snapshot_flag: true,
replica_version: ReplicaVersion::default(),
}
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions rs/execution_environment/src/scheduler/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion rs/interfaces/src/execution_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -1249,6 +1250,7 @@ pub trait Scheduler: Send {
randomness: Randomness,
idkg_subnet_public_keys: BTreeMap<MasterPublicKeyId, MasterPublicKey>,
idkg_pre_signature_ids: BTreeMap<MasterPublicKeyId, BTreeSet<PreSigId>>,
replica_version: &ReplicaVersion,
current_round: ExecutionRound,
round_summary: Option<ExecutionRoundSummary>,
current_round_type: ExecutionRoundType,
Expand Down
3 changes: 3 additions & 0 deletions rs/messaging/src/message_routing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions rs/messaging/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions rs/messaging/src/state_machine/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -36,6 +36,7 @@ mock! {
randomness: ic_types::Randomness,
idkg_subnet_public_keys: BTreeMap<MasterPublicKeyId, MasterPublicKey>,
idkg_pre_signature_ids: BTreeMap<MasterPublicKeyId, BTreeSet<PreSigId>>,
replica_version: &ReplicaVersion,
current_round: ExecutionRound,
round_summary: Option<ExecutionRoundSummary>,
current_round_type: ExecutionRoundType,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion rs/replay/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,12 @@ impl Player {
pool: Option<&ConsensusPoolImpl>,
mut extra: F,
) -> (Time, Option<(Height, Vec<IngressWithPrinter>)>) {
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);
Expand All @@ -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(),
)
}
};
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions rs/state_machine_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 69848c6

Please sign in to comment.