Skip to content

Commit

Permalink
[resharding] Add V2->V3 integration tests (near#10734)
Browse files Browse the repository at this point in the history
Please only refer to the last commit
`7b289c9e763e96b6c863baeb7b80f9ec9c638620` or changes in file
`integration-tests/src/tests/client/resharding.rs`

I'm unable to create stacked PRs for my forked repo.

To be merged only after near#10725

---------

Co-authored-by: wacban <[email protected]>
  • Loading branch information
Shreyan Gupta and wacban authored Mar 11, 2024
1 parent 0efb74b commit fe7ab16
Showing 1 changed file with 122 additions and 18 deletions.
140 changes: 122 additions & 18 deletions integration-tests/src/tests/client/resharding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const SIMPLE_NIGHTSHADE_PROTOCOL_VERSION: ProtocolVersion =
const SIMPLE_NIGHTSHADE_V2_PROTOCOL_VERSION: ProtocolVersion =
ProtocolFeature::SimpleNightshadeV2.protocol_version();

const SIMPLE_NIGHTSHADE_V3_PROTOCOL_VERSION: ProtocolVersion =
ProtocolFeature::SimpleNightshadeV3.protocol_version();

const P_CATCHUP: f64 = 0.2;

#[derive(Clone, Copy)]
Expand All @@ -50,26 +53,31 @@ enum ReshardingType {
V1,
// In the V1->V2 resharding outgoing receipts are reassigned to lowest index child.
V2,
// In the V2->V3 resharding outgoing receipts are reassigned to lowest index child.
V3,
}

fn get_target_protocol_version(resharding_type: &ReshardingType) -> ProtocolVersion {
match resharding_type {
ReshardingType::V1 => SIMPLE_NIGHTSHADE_PROTOCOL_VERSION,
ReshardingType::V2 => SIMPLE_NIGHTSHADE_V2_PROTOCOL_VERSION,
ReshardingType::V3 => SIMPLE_NIGHTSHADE_V3_PROTOCOL_VERSION,
}
}

fn get_genesis_protocol_version(resharding_type: &ReshardingType) -> ProtocolVersion {
match resharding_type {
ReshardingType::V1 => SIMPLE_NIGHTSHADE_PROTOCOL_VERSION - 1,
ReshardingType::V2 => SIMPLE_NIGHTSHADE_V2_PROTOCOL_VERSION - 1,
ReshardingType::V3 => SIMPLE_NIGHTSHADE_V3_PROTOCOL_VERSION - 1,
}
}

fn get_parent_shard_uids(resharding_type: &ReshardingType) -> Vec<ShardUId> {
let shard_layout = match resharding_type {
ReshardingType::V1 => ShardLayout::v0_single_shard(),
ReshardingType::V2 => ShardLayout::get_simple_nightshade_layout(),
ReshardingType::V3 => ShardLayout::get_simple_nightshade_layout_v2(),
};
shard_layout.shard_uids().collect()
}
Expand All @@ -80,22 +88,19 @@ fn get_expected_shards_num(
height: BlockHeight,
resharding_type: &ReshardingType,
) -> u64 {
match resharding_type {
ReshardingType::V1 => {
if height <= 2 * epoch_length {
return 1;
} else {
return 4;
}
if height <= 2 * epoch_length {
match resharding_type {
ReshardingType::V1 => 1,
ReshardingType::V2 => 4,
ReshardingType::V3 => 5,
}
ReshardingType::V2 => {
if height <= 2 * epoch_length {
return 4;
} else {
return 5;
}
} else {
match resharding_type {
ReshardingType::V1 => 4,
ReshardingType::V2 => 5,
ReshardingType::V3 => 6,
}
};
}
}

/// The condition that determines if a chunk should be produced of dropped.
Expand Down Expand Up @@ -795,6 +800,16 @@ fn check_outgoing_receipts_reassigned_impl(
assert!(outgoing_receipts.is_empty());
}
}
ReshardingType::V3 => {
// In V2->V3 resharding the outgoing receipts should be reassigned
// to the lowest index child of the parent shard.
// We can't directly check that here but we can check that the
// non-lowest-index shards are not assigned any receipts.
// We check elsewhere that no receipts are lost so this should be sufficient.
if shard_id == 3 {
assert!(outgoing_receipts.is_empty());
}
}
}
}

Expand Down Expand Up @@ -1025,11 +1040,25 @@ fn test_shard_layout_upgrade_simple_v2_seed_44() {
}

#[test]
fn test_resharding_with_different_db_kind() {
fn test_shard_layout_upgrade_simple_v3_seed_42() {
test_shard_layout_upgrade_simple_impl(ReshardingType::V3, 42, false);
}

#[test]
fn test_shard_layout_upgrade_simple_v3_seed_43() {
test_shard_layout_upgrade_simple_impl(ReshardingType::V3, 43, false);
}

#[test]
fn test_shard_layout_upgrade_simple_v3_seed_44() {
test_shard_layout_upgrade_simple_impl(ReshardingType::V3, 44, false);
}

fn test_resharding_with_different_db_kind_impl(resharding_type: ReshardingType) {
init_test_logger();

let genesis_protocol_version = get_genesis_protocol_version(&ReshardingType::V2);
let target_protocol_version = get_target_protocol_version(&ReshardingType::V2);
let genesis_protocol_version = get_genesis_protocol_version(&resharding_type);
let target_protocol_version = get_target_protocol_version(&resharding_type);

let epoch_length = 5;
let mut test_env = TestReshardingEnv::new(
Expand All @@ -1041,7 +1070,7 @@ fn test_resharding_with_different_db_kind() {
genesis_protocol_version,
42,
true,
Some(ReshardingType::V2),
Some(resharding_type),
);

// Set three different DbKind versions
Expand All @@ -1059,6 +1088,16 @@ fn test_resharding_with_different_db_kind() {
test_env.check_resharding_artifacts(2);
}

#[test]
fn test_resharding_with_different_db_kind_v2() {
test_resharding_with_different_db_kind_impl(ReshardingType::V2);
}

#[test]
fn test_resharding_with_different_db_kind_v3() {
test_resharding_with_different_db_kind_impl(ReshardingType::V3);
}

/// In this test we are checking whether we are properly deleting trie state and flat state
/// from the old shard layout after resharding. This is handled as a part of Garbage Collection (GC)
fn test_shard_layout_upgrade_gc_impl(resharding_type: ReshardingType, rng_seed: u64) {
Expand Down Expand Up @@ -1107,6 +1146,11 @@ fn test_shard_layout_upgrade_gc_v2() {
test_shard_layout_upgrade_gc_impl(ReshardingType::V2, 44);
}

#[test]
fn test_shard_layout_upgrade_gc_v3() {
test_shard_layout_upgrade_gc_impl(ReshardingType::V3, 44);
}

const GAS_1: u64 = 300_000_000_000_000;
const GAS_2: u64 = GAS_1 / 3;

Expand Down Expand Up @@ -1395,6 +1439,27 @@ fn test_shard_layout_upgrade_cross_contract_calls_v2_seed_44() {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V2, 44);
}

// Test cross contract calls
// This test case tests postponed receipts and delayed receipts
#[test]
fn test_shard_layout_upgrade_cross_contract_calls_v3_seed_42() {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V3, 42);
}

// Test cross contract calls
// This test case tests postponed receipts and delayed receipts
#[test]
fn test_shard_layout_upgrade_cross_contract_calls_v3_seed_43() {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V3, 43);
}

// Test cross contract calls
// This test case tests postponed receipts and delayed receipts
#[test]
fn test_shard_layout_upgrade_cross_contract_calls_v3_seed_44() {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V3, 44);
}

fn test_shard_layout_upgrade_incoming_receipts_impl(
resharding_type: ReshardingType,
rng_seed: u64,
Expand Down Expand Up @@ -1465,6 +1530,21 @@ fn test_shard_layout_upgrade_incoming_receipts_v2_seed_44() {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V2, 44);
}

#[test]
fn test_shard_layout_upgrade_incoming_receipts_v3_seed_42() {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V3, 42);
}

#[test]
fn test_shard_layout_upgrade_incoming_receipts_v3_seed_43() {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V3, 43);
}

#[test]
fn test_shard_layout_upgrade_incoming_receipts_v3_seed_44() {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V3, 44);
}

// Test cross contract calls
// This test case tests when there are missing chunks in the produced blocks
// This is to test that all the chunk management logic is correct, e.g. inclusion of outgoing
Expand Down Expand Up @@ -1612,6 +1692,25 @@ fn test_shard_layout_upgrade_missing_chunks_high_missing_prob_v2_seed_44() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.9, 44);
}

// V3 tests

#[test]
fn test_shard_layout_upgrade_missing_chunks_low_missing_prob_v3() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V3, 0.1, 42);
}

#[test]
fn test_shard_layout_upgrade_missing_chunks_mid_missing_prob_v3() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V3, 0.5, 42);
}

#[test]
fn test_shard_layout_upgrade_missing_chunks_high_missing_prob_v3() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V3, 0.9, 42);
}

// latest protocol

#[test]
fn test_latest_protocol_missing_chunks_low_missing_prob() {
test_latest_protocol_missing_chunks(0.1, 25);
Expand Down Expand Up @@ -1712,5 +1811,10 @@ fn test_shard_layout_upgrade_error_handling_v2() {
test_shard_layout_upgrade_error_handling_impl(ReshardingType::V2, 42, false);
}

#[test]
fn test_shard_layout_upgrade_error_handling_v3() {
test_shard_layout_upgrade_error_handling_impl(ReshardingType::V3, 42, false);
}

// TODO(resharding) add a test with missing blocks
// TODO(resharding) add a test with deleting accounts and delayed receipts check

0 comments on commit fe7ab16

Please sign in to comment.