Skip to content

Commit a2c8c6c

Browse files
Merge branch 'alin/MR-444-retain-prev_state_hash' into 'master'
fix: [MR-444] Do not reset `SystemMetadata::prev_state_hash` `SystemMetadata::after_split()` used to reset `SystemMetadata::prev_state_hash`, on account of the post-split state being a genesis state. However, by the time `after_split()` is called, this is already the tip (the mutable state that the round will execute on) and its `prev_state_hash` has already been set to the checkpoint/CUP hash. Resetting it to None will cause `commit_and_certify()` to panic. Closes MR-444 Closes MR-444 See merge request dfinity-lab/public/ic!12656
2 parents 80fde00 + 86c816f commit a2c8c6c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

rs/replicated_state/src/metadata_state.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ impl SystemMetadata {
821821
/// in terminal states and messages addressed to local canisters.
822822
///
823823
/// Notes:
824+
/// * `prev_state_hash` has just been set by `take_tip()` to the checkpoint
825+
/// hash (checked against the hash in the CUP). It must be preserved.
824826
/// * `own_subnet_type` has just been set during `load_checkpoint()`, based on
825827
/// the registry subnet record of the subnet that this node is part of.
826828
/// * `batch_time`, `network_topology` and `own_subnet_features` will be set
@@ -841,7 +843,7 @@ impl SystemMetadata {
841843
streams,
842844
canister_allocation_ranges,
843845
last_generated_canister_id,
844-
prev_state_hash: _,
846+
prev_state_hash,
845847
// Overwritten as soon as the round begins, no explicit action needed.
846848
batch_time,
847849
// Overwritten as soon as the round begins, no explicit action needed.
@@ -872,9 +874,6 @@ impl SystemMetadata {
872874
// Prune the ingress history.
873875
ingress_history = ingress_history.prune_after_split(is_local_canister);
874876

875-
// This is a genesis state, there is no previous state hash.
876-
let prev_state_hash = None;
877-
878877
SystemMetadata {
879878
ingress_history,
880879
streams,

rs/replicated_state/src/metadata_state/tests.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ fn system_metadata_split() {
499499
assert_eq!(expected, metadata_a_phase_1);
500500

501501
// Split off subnet A', phase 2.
502+
//
503+
// Technically some parts of the `SystemMetadata` (such as `prev_state_hash` and
504+
// `own_subnet_type`) would be replaced during loading. However, we only care
505+
// that `after_split()` does not touch them.
502506
let is_canister_on_subnet_a = |canister_id: &CanisterId| *canister_id == canister_test_id(0);
503507
let metadata_a_phase_2 = metadata_a_phase_1.after_split(is_canister_on_subnet_a);
504508

@@ -507,7 +511,6 @@ fn system_metadata_split() {
507511
expected.ingress_history = expected
508512
.ingress_history
509513
.prune_after_split(is_canister_on_subnet_a);
510-
expected.prev_state_hash = None;
511514
expected.split_from = None;
512515
assert_eq!(expected, metadata_a_phase_2);
513516

@@ -521,6 +524,10 @@ fn system_metadata_split() {
521524
assert_eq!(expected, metadata_b_phase_1);
522525

523526
// Split off subnet B, phase 2.
527+
//
528+
// Technically some parts of the `SystemMetadata` (such as `prev_state_hash` and
529+
// `own_subnet_type`) would be replaced during loading. However, we only care
530+
// that `after_split()` does not touch them.
524531
let is_canister_on_subnet_b = |canister_id: &CanisterId| !is_canister_on_subnet_a(canister_id);
525532
let metadata_b_phase_2 = metadata_b_phase_1.after_split(is_canister_on_subnet_b);
526533

@@ -529,7 +536,6 @@ fn system_metadata_split() {
529536
expected.ingress_history = expected
530537
.ingress_history
531538
.prune_after_split(is_canister_on_subnet_b);
532-
expected.prev_state_hash = None;
533539
assert_eq!(expected, metadata_b_phase_2);
534540
}
535541

0 commit comments

Comments
 (0)