Skip to content

Commit

Permalink
refactor(resharding): remove the rust feature gating resharding (#10153)
Browse files Browse the repository at this point in the history
As per the discussion on
[zulip](https://near.zulipchat.com/#narrow/stream/295302-general/topic/gating.20new.20features)
we no longer require the rust feature to gate new features. Removing it
will make development and mocknet testing in particular easier.

This is not stabilization and rollout, resharding should still remain in
nightly and not get enabled by default. Dear reviewers please watch out
for any place where this is not done properly.
  • Loading branch information
wacban authored Nov 10, 2023
1 parent 8d048b6 commit 75a29e5
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 73 deletions.
4 changes: 0 additions & 4 deletions chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ new_epoch_sync = ["near-store/new_epoch_sync", "near-primitives/new_epoch_sync",
protocol_feature_reject_blocks_with_outdated_protocol_version = [
"near-primitives/protocol_feature_reject_blocks_with_outdated_protocol_version",
]
protocol_feature_simple_nightshade_v2 = [
"near-primitives/protocol_feature_simple_nightshade_v2",
]
protocol_feature_chunk_validation = [
"near-primitives/protocol_feature_chunk_validation",
]
Expand All @@ -67,7 +64,6 @@ nightly = [
"nightly_protocol",
"protocol_feature_chunk_validation",
"protocol_feature_reject_blocks_with_outdated_protocol_version",
"protocol_feature_simple_nightshade_v2",
"near-async/nightly",
"near-chain-configs/nightly",
"near-client-primitives/nightly",
Expand Down
3 changes: 0 additions & 3 deletions chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use near_cache::CellLruCache;
use near_chain_primitives::error::Error;
use near_epoch_manager::EpochManagerAdapter;
use near_primitives::block::Tip;
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
use near_primitives::checked_feature;
#[cfg(feature = "new_epoch_sync")]
use near_primitives::epoch_manager::epoch_sync::EpochSyncInfo;
Expand Down Expand Up @@ -614,7 +613,6 @@ impl ChainStore {
) -> Result<(), Error> {
tracing::trace!(target: "resharding", ?protocol_version, shard_id, receipts_shard_id, "reassign_outgoing_receipts_for_resharding");
// If simple nightshade v2 is enabled and stable use that.
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
if checked_feature!("stable", SimpleNightshadeV2, protocol_version) {
Self::reassign_outgoing_receipts_for_resharding_v2(
receipts,
Expand Down Expand Up @@ -648,7 +646,6 @@ impl ChainStore {
/// 3' will get all outgoing receipts from its parent 3
/// 4' will get no outgoing receipts from its parent 3
/// All receipts are distributed to children, each exactly once.
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
fn reassign_outgoing_receipts_for_resharding_v2(
receipts: &mut Vec<Receipt>,
shard_layout: &ShardLayout,
Expand Down
2 changes: 0 additions & 2 deletions core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ default = []
protocol_feature_fix_staking_threshold = []
protocol_feature_fix_contract_loading_cost = []
protocol_feature_reject_blocks_with_outdated_protocol_version = []
protocol_feature_simple_nightshade_v2 = []
protocol_feature_chunk_validation = []

nightly = [
Expand All @@ -44,7 +43,6 @@ nightly = [
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_fix_staking_threshold",
"protocol_feature_reject_blocks_with_outdated_protocol_version",
"protocol_feature_simple_nightshade_v2",
]

nightly_protocol = [
Expand Down
2 changes: 0 additions & 2 deletions core/primitives-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ pub enum ProtocolFeature {
FixContractLoadingCost,
#[cfg(feature = "protocol_feature_reject_blocks_with_outdated_protocol_version")]
RejectBlocksWithOutdatedProtocolVersions,
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
SimpleNightshadeV2,
RestrictTla,
/// Enables block production with post-state-root.
Expand Down Expand Up @@ -184,7 +183,6 @@ impl ProtocolFeature {
ProtocolFeature::FixContractLoadingCost => 129,
#[cfg(feature = "protocol_feature_reject_blocks_with_outdated_protocol_version")]
ProtocolFeature::RejectBlocksWithOutdatedProtocolVersions => 132,
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
ProtocolFeature::SimpleNightshadeV2 => 135,
ProtocolFeature::PostStateRoot => 136,
#[cfg(feature = "protocol_feature_chunk_validation")]
Expand Down
2 changes: 0 additions & 2 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
protocol_feature_fix_staking_threshold = ["near-primitives-core/protocol_feature_fix_staking_threshold"]
protocol_feature_fix_contract_loading_cost = ["near-primitives-core/protocol_feature_fix_contract_loading_cost"]
protocol_feature_reject_blocks_with_outdated_protocol_version = ["near-primitives-core/protocol_feature_reject_blocks_with_outdated_protocol_version"]
protocol_feature_simple_nightshade_v2 = ["near-primitives-core/protocol_feature_simple_nightshade_v2"]
protocol_feature_chunk_validation = []
nightly = [
"nightly_protocol",
"protocol_feature_chunk_validation",
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_fix_staking_threshold",
"protocol_feature_reject_blocks_with_outdated_protocol_version",
"protocol_feature_simple_nightshade_v2",
"near-fmt/nightly",
"near-o11y/nightly",
"near-primitives-core/nightly",
Expand Down
1 change: 0 additions & 1 deletion core/primitives/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ impl AllEpochConfig {
}

fn config_nightshade(config: &mut EpochConfig, protocol_version: ProtocolVersion) {
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
if checked_feature!("stable", SimpleNightshadeV2, protocol_version) {
Self::config_nightshade_impl(config, ShardLayout::get_simple_nightshade_layout_v2());
return;
Expand Down
4 changes: 0 additions & 4 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,11 @@ protocol_feature_reject_blocks_with_outdated_protocol_version = [
"near-primitives/protocol_feature_reject_blocks_with_outdated_protocol_version",
"near-chain/protocol_feature_reject_blocks_with_outdated_protocol_version",
]
protocol_feature_simple_nightshade_v2 = [
"near-primitives/protocol_feature_simple_nightshade_v2",
]

nightly = [
"nightly_protocol",
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_reject_blocks_with_outdated_protocol_version",
"protocol_feature_simple_nightshade_v2",
"near-actix-test-utils/nightly",
"near-async/nightly",
"near-chain-configs/nightly",
Expand Down
134 changes: 85 additions & 49 deletions integration-tests/src/tests/client/resharding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use near_primitives::utils::MaybeValidated;
use near_primitives::version::ProtocolFeature;
use near_primitives::version::PROTOCOL_VERSION;
use near_primitives::views::{ExecutionStatusView, FinalExecutionStatus, QueryRequest};
use near_primitives_core::checked_feature;
use near_primitives_core::num_rational::Rational32;
use near_store::flat::FlatStorageStatus;
use near_store::test_utils::{gen_account, gen_unique_accounts};
Expand All @@ -40,21 +41,16 @@ use tracing::debug;
const SIMPLE_NIGHTSHADE_PROTOCOL_VERSION: ProtocolVersion =
ProtocolFeature::SimpleNightshade.protocol_version();

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
const SIMPLE_NIGHTSHADE_V2_PROTOCOL_VERSION: ProtocolVersion =
ProtocolFeature::SimpleNightshadeV2.protocol_version();

#[cfg(not(feature = "protocol_feature_simple_nightshade_v2"))]
const SIMPLE_NIGHTSHADE_V2_PROTOCOL_VERSION: ProtocolVersion = PROTOCOL_VERSION + 1;

const P_CATCHUP: f64 = 0.2;

#[derive(Clone, Copy)]
enum ReshardingType {
// In the V0->V1 resharding outgoing receipts are reassigned to receiver.
V1,
// In the V1->V2 resharding outgoing receipts are reassigned to lowest index child.
#[allow(unused)]
V2,
}

Expand Down Expand Up @@ -1000,22 +996,28 @@ fn test_shard_layout_upgrade_simple_v1_with_snapshot_enabled() {
test_shard_layout_upgrade_simple_impl(ReshardingType::V1, 42, true);
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_simple_v2_seed_42() {
test_shard_layout_upgrade_simple_impl(ReshardingType::V2, 42, false);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_simple_impl(ReshardingType::V2, 42, false);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_simple_v2_seed_43() {
test_shard_layout_upgrade_simple_impl(ReshardingType::V2, 43, false);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_simple_impl(ReshardingType::V2, 43, false);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_simple_v2_seed_44() {
test_shard_layout_upgrade_simple_impl(ReshardingType::V2, 44, false);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_simple_impl(ReshardingType::V2, 44, false);
}
}

/// In this test we are checking whether we are properly deleting trie state and flat state
Expand Down Expand Up @@ -1061,10 +1063,12 @@ fn test_shard_layout_upgrade_gc() {
test_shard_layout_upgrade_gc_impl(ReshardingType::V1, 44);
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_gc_v2() {
test_shard_layout_upgrade_gc_impl(ReshardingType::V2, 44);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_gc_impl(ReshardingType::V2, 44);
}
}

const GAS_1: u64 = 300_000_000_000_000;
Expand Down Expand Up @@ -1342,26 +1346,32 @@ fn test_shard_layout_upgrade_cross_contract_calls_v1() {

// Test cross contract calls
// This test case tests postponed receipts and delayed receipts
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_cross_contract_calls_v2_seed_42() {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V2, 42);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V2, 42);
}
}

// Test cross contract calls
// This test case tests postponed receipts and delayed receipts
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_cross_contract_calls_v2_seed_43() {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V2, 43);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V2, 43);
}
}

// Test cross contract calls
// This test case tests postponed receipts and delayed receipts
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_cross_contract_calls_v2_seed_44() {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V2, 44);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_cross_contract_calls_impl(ReshardingType::V2, 44);
}
}

fn test_shard_layout_upgrade_incoming_receipts_impl(
Expand Down Expand Up @@ -1415,26 +1425,32 @@ fn test_shard_layout_upgrade_incoming_receipts_impl(
// is missing there aren't any other chunks so there aren't any incoming
// receipts at all.
#[test]
fn test_shard_layout_upgrade_incoming_receipts_impl_v1() {
fn test_shard_layout_upgrade_incoming_receipts_v1() {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V1, 42);
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_incoming_receipts_impl_v2_seed_42() {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V2, 42);
fn test_shard_layout_upgrade_incoming_receipts_v2_seed_42() {
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V2, 42);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_incoming_receipts_impl_v2_seed_43() {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V2, 43);
fn test_shard_layout_upgrade_incoming_receipts_v2_seed_43() {
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V2, 43);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_incoming_receipts_impl_v2_seed_44() {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V2, 44);
fn test_shard_layout_upgrade_incoming_receipts_v2_seed_44() {
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_incoming_receipts_impl(ReshardingType::V2, 44);
}
}

// Test cross contract calls
Expand Down Expand Up @@ -1535,62 +1551,80 @@ fn test_shard_layout_upgrade_missing_chunks_high_missing_prob_v1() {

// V2, low missing prob

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_low_missing_prob_v2_seed_42() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.1, 42);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.1, 42);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_low_missing_prob_v2_seed_43() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.1, 43);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.1, 43);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_low_missing_prob_v2_seed_44() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.1, 44);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.1, 44);
}
}

// V2, mid missing prob

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_mid_missing_prob_v2_seed_42() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.5, 42);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.5, 42);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_mid_missing_prob_v2_seed_43() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.5, 43);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.5, 43);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_mid_missing_prob_v2_seed_44() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.5, 44);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.5, 44);
}
}

// V2, high missing prob

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_high_missing_prob_v2_seed_42() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.9, 42);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.9, 42);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_high_missing_prob_v2_seed_43() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.9, 43);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.9, 43);
}
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_missing_chunks_high_missing_prob_v2_seed_44() {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.9, 44);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_missing_chunks(ReshardingType::V2, 0.9, 44);
}
}

#[test]
Expand Down Expand Up @@ -1688,10 +1722,12 @@ fn test_shard_layout_upgrade_error_handling_v1() {
test_shard_layout_upgrade_error_handling_impl(ReshardingType::V1, 42, false);
}

#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
#[test]
fn test_shard_layout_upgrade_error_handling_v2() {
test_shard_layout_upgrade_error_handling_impl(ReshardingType::V2, 42, false);
// TODO(resharding) remove those checks once rolled out
if checked_feature!("stable", SimpleNightshadeV2, PROTOCOL_VERSION) {
test_shard_layout_upgrade_error_handling_impl(ReshardingType::V2, 42, false);
}
}

// TODO(resharding) add a test with missing blocks
Expand Down
Loading

0 comments on commit 75a29e5

Please sign in to comment.