From e5134c25b4482b920c48a80334b9925c6b72f6b2 Mon Sep 17 00:00:00 2001 From: mzhangmzz <34969888+mzhangmzz@users.noreply.github.com> Date: Wed, 13 Oct 2021 17:51:54 -0400 Subject: [PATCH] Move SimpleNightshade from nightly to stable (#4953) Move SimpleNIghtshade from nightly to stable. This feature enables the transition from one shard to four shards. For more details, see https://near.org/blog/near-launches-simple-nightshade-the-first-step-towards-a-sharded-blockchain/ and https://github.com/near/NEPs/pull/241 --- CHANGELOG.md | 1 + chain/epoch_manager/Cargo.toml | 3 +- chain/epoch_manager/src/lib.rs | 13 ------ core/chain-configs/Cargo.toml | 1 - core/chain-configs/src/genesis_config.rs | 45 ++++++++++--------- core/primitives/Cargo.toml | 3 +- core/primitives/src/epoch_manager.rs | 6 +-- core/primitives/src/version.rs | 8 ++-- integration-tests/Cargo.toml | 3 +- integration-tests/tests/client/main.rs | 1 - .../tests/client/sharding_upgrade.rs | 6 +++ nearcore/Cargo.toml | 3 +- nearcore/src/shard_tracker.rs | 5 --- neard/Cargo.toml | 1 - 14 files changed, 39 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97aa58fceca..0c20b1968ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Upgrade from Wasmer 0 to Wasmer 2, bringing better performance and reliability. [#4934](https://github.com/near/nearcore/pull/4934) * Lower regular_op_cost (execution of a single WASM instruction) from 3_856_371 to 2_207_874. [#4979](https://github.com/near/nearcore/pull/4979) * Lower data receipt cost and base cost of `ecrecover` host function. +* Upgrade from one shard to four shards (Simple Nightshade Phase 0) ## `1.21.0` [09-06-2021] diff --git a/chain/epoch_manager/Cargo.toml b/chain/epoch_manager/Cargo.toml index 43bb8c93ac0..0710bac1183 100644 --- a/chain/epoch_manager/Cargo.toml +++ b/chain/epoch_manager/Cargo.toml @@ -28,8 +28,7 @@ near-chain-configs = { path = "../../core/chain-configs" } [features] expensive_tests = [] -protocol_feature_simple_nightshade = ["near-primitives/protocol_feature_simple_nightshade"] protocol_feature_block_header_v3 = ["near-primitives/protocol_feature_block_header_v3", "near-store/protocol_feature_block_header_v3", "near-chain/protocol_feature_block_header_v3"] protocol_feature_chunk_only_producers = ["protocol_feature_block_header_v3", "near-primitives/protocol_feature_chunk_only_producers", "near-chain-configs/protocol_feature_chunk_only_producers", "near-chain/protocol_feature_chunk_only_producers"] -nightly_protocol_features = ["nightly_protocol", "near-primitives/nightly_protocol_features", "protocol_feature_block_header_v3", "protocol_feature_chunk_only_producers", "protocol_feature_simple_nightshade"] +nightly_protocol_features = ["nightly_protocol", "near-primitives/nightly_protocol_features", "protocol_feature_block_header_v3", "protocol_feature_chunk_only_producers"] nightly_protocol = ["near-primitives/nightly_protocol"] diff --git a/chain/epoch_manager/src/lib.rs b/chain/epoch_manager/src/lib.rs index 0f8963b6c76..3e0737d334a 100644 --- a/chain/epoch_manager/src/lib.rs +++ b/chain/epoch_manager/src/lib.rs @@ -1267,15 +1267,6 @@ impl EpochManager { Ok(shard_layout) } - #[cfg(not(feature = "protocol_feature_simple_nightshade"))] - pub fn will_shard_layout_change( - &mut self, - _parent_hash: &CryptoHash, - ) -> Result { - Ok(false) - } - - #[cfg(feature = "protocol_feature_simple_nightshade")] pub fn will_shard_layout_change( &mut self, parent_hash: &CryptoHash, @@ -1503,12 +1494,9 @@ mod tests { use super::*; use crate::reward_calculator::NUM_NS_IN_SECOND; use near_primitives::epoch_manager::EpochConfig; - #[cfg(feature = "protocol_feature_simple_nightshade")] use near_primitives::epoch_manager::ShardConfig; use near_primitives::shard_layout::ShardLayout; - #[cfg(feature = "protocol_feature_simple_nightshade")] use near_primitives::utils::get_num_seats_per_shard; - #[cfg(feature = "protocol_feature_simple_nightshade")] use near_primitives::version::ProtocolFeature::SimpleNightshade; impl EpochManager { @@ -3771,7 +3759,6 @@ mod tests { } #[test] - #[cfg(feature = "protocol_feature_simple_nightshade")] fn test_protocol_version_switch_with_shard_layout_change() { let store = create_test_store(); let shard_layout = ShardLayout::v1( diff --git a/core/chain-configs/Cargo.toml b/core/chain-configs/Cargo.toml index 574a2ee60ff..cc4a1f1ce10 100644 --- a/core/chain-configs/Cargo.toml +++ b/core/chain-configs/Cargo.toml @@ -19,5 +19,4 @@ near-primitives = { path = "../primitives" } [features] default = [] -protocol_feature_simple_nightshade = ["near-primitives/protocol_feature_simple_nightshade"] protocol_feature_chunk_only_producers = ["near-primitives/protocol_feature_chunk_only_producers"] diff --git a/core/chain-configs/src/genesis_config.rs b/core/chain-configs/src/genesis_config.rs index 9454f228783..91a2e573cfa 100644 --- a/core/chain-configs/src/genesis_config.rs +++ b/core/chain-configs/src/genesis_config.rs @@ -22,6 +22,7 @@ use crate::genesis_validate::validate_genesis; use near_primitives::epoch_manager::{AllEpochConfig, EpochConfig, ShardConfig}; use near_primitives::shard_layout::ShardLayout; use near_primitives::types::validator_stake::ValidatorStake; +use near_primitives::version::ProtocolFeature; use near_primitives::{ hash::CryptoHash, runtime::config::RuntimeConfig, @@ -72,21 +73,15 @@ fn default_num_chunk_only_producer_seats() -> u64 { } fn default_simple_nightshade_shard_layout() -> Option { - #[cfg(feature = "protocol_feature_simple_nightshade")] - { - info!("load simple nightshade shard layout from genesis config"); - return Some(ShardLayout::v1( - vec![], - vec!["aurora", "aurora-0", "kkuuue2akv_1630967379.near"] - .into_iter() - .map(|s| s.parse().unwrap()) - .collect(), - Some(vec![vec![0, 1, 2, 3]]), - 1, - )); - } - #[cfg(not(feature = "protocol_feature_simple_nightshade"))] - None + return Some(ShardLayout::v1( + vec![], + vec!["aurora", "aurora-0", "kkuuue2akv_1630967379.near"] + .into_iter() + .map(|s| s.parse().unwrap()) + .collect(), + Some(vec![vec![0, 1, 2, 3]]), + 1, + )); } #[derive(Debug, Clone, SmartDefault, Serialize, Deserialize)] @@ -224,8 +219,12 @@ impl From<&GenesisConfig> for EpochConfig { impl From<&GenesisConfig> for AllEpochConfig { fn from(genesis_config: &GenesisConfig) -> Self { let initial_epoch_config = EpochConfig::from(genesis_config); - let shard_config = - if let Some(shard_layout) = &genesis_config.simple_nightshade_shard_layout { + let shard_config = if let Some(shard_layout) = + &genesis_config.simple_nightshade_shard_layout + { + if genesis_config.protocol_version + < ProtocolFeature::SimpleNightshade.protocol_version() + { info!(target: "genesis", "setting epoch config simple nightshade"); let num_shards = shard_layout.num_shards() as usize; Some(ShardConfig { @@ -234,15 +233,19 @@ impl From<&GenesisConfig> for AllEpochConfig { num_shards ], avg_hidden_validator_seats_per_shard: vec![ - genesis_config.avg_hidden_validator_seats_per_shard[0]; - num_shards - ], + genesis_config.avg_hidden_validator_seats_per_shard[0]; + num_shards + ], shard_layout: shard_layout.clone(), }) } else { info!(target: "genesis", "no simple nightshade"); None - }; + } + } else { + info!(target: "genesis", "no simple nightshade"); + None + }; let epoch_config = Self::new(initial_epoch_config.clone(), shard_config); assert_eq!( initial_epoch_config, diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index 601ed3e276b..8215f1fa163 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -43,10 +43,9 @@ default = ["jemallocator"] dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"] protocol_feature_block_header_v3 = [] protocol_feature_alt_bn128 = ["near-primitives-core/protocol_feature_alt_bn128", "near-vm-errors/protocol_feature_alt_bn128"] -protocol_feature_simple_nightshade = [] protocol_feature_chunk_only_producers = ["protocol_feature_block_header_v3"] protocol_feature_routing_exchange_algorithm = ["near-primitives-core/protocol_feature_routing_exchange_algorithm"] -nightly_protocol_features = ["nightly_protocol", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_chunk_only_producers", "protocol_feature_simple_nightshade", "protocol_feature_routing_exchange_algorithm"] +nightly_protocol_features = ["nightly_protocol", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_chunk_only_producers", "protocol_feature_routing_exchange_algorithm"] nightly_protocol = [] [dev-dependencies] diff --git a/core/primitives/src/epoch_manager.rs b/core/primitives/src/epoch_manager.rs index e0fc021fd16..f552f745430 100644 --- a/core/primitives/src/epoch_manager.rs +++ b/core/primitives/src/epoch_manager.rs @@ -90,11 +90,7 @@ impl AllEpochConfig { } pub fn for_protocol_version(&self, protocol_version: ProtocolVersion) -> &EpochConfig { - if checked_feature!( - "protocol_feature_simple_nightshade", - SimpleNightshade, - protocol_version - ) { + if checked_feature!("stable", SimpleNightshade, protocol_version) { &self.simple_nightshade_epoch_config } else { &self.genesis_epoch_config diff --git a/core/primitives/src/version.rs b/core/primitives/src/version.rs index e6c78cf9f24..de71564d3be 100644 --- a/core/primitives/src/version.rs +++ b/core/primitives/src/version.rs @@ -110,6 +110,7 @@ pub enum ProtocolFeature { /// Although wasmer2 is faster, we don't change fees with this protocol /// version -- we can safely do that in a separate step. Wasmer2, + SimpleNightshade, LowerDataReceiptAndEcrecoverBaseCost, /// Lowers the cost of wasm instruction due to switch to wasmer2. LowerRegularOpCost, @@ -123,8 +124,6 @@ pub enum ProtocolFeature { ChunkOnlyProducers, #[cfg(feature = "protocol_feature_routing_exchange_algorithm")] RoutingExchangeAlgorithm, - #[cfg(feature = "protocol_feature_simple_nightshade")] - SimpleNightshade, } /// Current latest stable version of the protocol. @@ -156,7 +155,8 @@ impl ProtocolFeature { ProtocolFeature::RestoreReceiptsAfterFix => 47, ProtocolFeature::Wasmer2 | ProtocolFeature::LowerDataReceiptAndEcrecoverBaseCost - | ProtocolFeature::LowerRegularOpCost => 48, + | ProtocolFeature::LowerRegularOpCost + | ProtocolFeature::SimpleNightshade => 48, // Nightly features #[cfg(feature = "protocol_feature_alt_bn128")] @@ -167,8 +167,6 @@ impl ProtocolFeature { ProtocolFeature::ChunkOnlyProducers => 115, #[cfg(feature = "protocol_feature_routing_exchange_algorithm")] ProtocolFeature::RoutingExchangeAlgorithm => 117, - #[cfg(feature = "protocol_feature_simple_nightshade")] - ProtocolFeature::SimpleNightshade => 122, } } } diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 4250b345c81..ffef17d152e 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -58,9 +58,8 @@ protocol_feature_alt_bn128 = [ "node-runtime/protocol_feature_alt_bn128", "near-vm-errors/protocol_feature_alt_bn128", ] -protocol_feature_simple_nightshade = ["near-primitives/protocol_feature_simple_nightshade", "nearcore/protocol_feature_simple_nightshade"] protocol_feature_block_header_v3 = ["near-primitives/protocol_feature_block_header_v3", "near-chain/protocol_feature_block_header_v3", "near-store/protocol_feature_block_header_v3"] protocol_feature_chunk_only_producers = ["near-client/protocol_feature_chunk_only_producers"] -nightly_protocol_features = ["nearcore/nightly_protocol_features", "protocol_feature_alt_bn128", "protocol_feature_block_header_v3", "protocol_feature_simple_nightshade"] +nightly_protocol_features = ["nearcore/nightly_protocol_features", "protocol_feature_alt_bn128", "protocol_feature_block_header_v3"] nightly_protocol = ["nearcore/nightly_protocol"] sandbox = ["near-network/sandbox", "near-chain/sandbox", "node-runtime/sandbox", "near-client/sandbox"] diff --git a/integration-tests/tests/client/main.rs b/integration-tests/tests/client/main.rs index 5c8fccf2e00..9e14f61b2ec 100644 --- a/integration-tests/tests/client/main.rs +++ b/integration-tests/tests/client/main.rs @@ -5,5 +5,4 @@ mod process_blocks; mod runtimes; #[cfg(feature = "sandbox")] mod sandbox; -#[cfg(feature = "protocol_feature_simple_nightshade")] mod sharding_upgrade; diff --git a/integration-tests/tests/client/sharding_upgrade.rs b/integration-tests/tests/client/sharding_upgrade.rs index eee59eb641d..6ba068c9049 100644 --- a/integration-tests/tests/client/sharding_upgrade.rs +++ b/integration-tests/tests/client/sharding_upgrade.rs @@ -294,6 +294,9 @@ fn setup_genesis( // test some shard layout upgrade with some simple transactions to create accounts #[test] fn test_shard_layout_upgrade_simple() { + if cfg!(feature = "protocol_feature_block_header_v3") { + return; + } init_test_logger(); let mut rng = thread_rng(); @@ -411,6 +414,9 @@ fn gen_cross_contract_transaction( // This test case tests postponed receipts and delayed receipts #[test] fn test_shard_layout_upgrade_cross_contract_calls() { + if cfg!(feature = "protocol_feature_block_header_v3") { + return; + } init_test_logger(); // setup diff --git a/nearcore/Cargo.toml b/nearcore/Cargo.toml index 1610747cf25..868c7a80bbf 100644 --- a/nearcore/Cargo.toml +++ b/nearcore/Cargo.toml @@ -70,10 +70,9 @@ rosetta_rpc = ["near-rosetta-rpc"] json_rpc = ["near-jsonrpc"] protocol_feature_alt_bn128 = ["near-primitives/protocol_feature_alt_bn128", "node-runtime/protocol_feature_alt_bn128"] protocol_feature_block_header_v3 = ["near-epoch-manager/protocol_feature_block_header_v3", "near-store/protocol_feature_block_header_v3", "near-primitives/protocol_feature_block_header_v3", "near-chain/protocol_feature_block_header_v3", "near-client/protocol_feature_block_header_v3"] -protocol_feature_simple_nightshade = ["near-primitives/protocol_feature_simple_nightshade", "near-epoch-manager/protocol_feature_simple_nightshade", "near-chain-configs/protocol_feature_simple_nightshade"] protocol_feature_chunk_only_producers = ["protocol_feature_block_header_v3", "near-chain-configs/protocol_feature_chunk_only_producers", "near-epoch-manager/protocol_feature_chunk_only_producers", "near-chain/protocol_feature_chunk_only_producers", "near-client/protocol_feature_chunk_only_producers", "node-runtime/protocol_feature_chunk_only_producers", "near-rosetta-rpc/protocol_feature_chunk_only_producers"] protocol_feature_routing_exchange_algorithm = ["near-primitives/protocol_feature_routing_exchange_algorithm", "near-chain/protocol_feature_routing_exchange_algorithm", "near-network/protocol_feature_routing_exchange_algorithm", "near-client/protocol_feature_routing_exchange_algorithm", "near-jsonrpc/protocol_feature_routing_exchange_algorithm"] -nightly_protocol_features = ["nightly_protocol", "near-primitives/nightly_protocol_features", "near-client/nightly_protocol_features", "near-epoch-manager/nightly_protocol_features", "near-store/nightly_protocol_features", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_chunk_only_producers", "protocol_feature_simple_nightshade", "protocol_feature_routing_exchange_algorithm"] +nightly_protocol_features = ["nightly_protocol", "near-primitives/nightly_protocol_features", "near-client/nightly_protocol_features", "near-epoch-manager/nightly_protocol_features", "near-store/nightly_protocol_features", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_chunk_only_producers", "protocol_feature_routing_exchange_algorithm"] nightly_protocol = ["near-primitives/nightly_protocol", "near-jsonrpc/nightly_protocol"] # Force usage of a specific wasm vm irrespective of protocol version. diff --git a/nearcore/src/shard_tracker.rs b/nearcore/src/shard_tracker.rs index 58f395ffe7f..53e5473f717 100644 --- a/nearcore/src/shard_tracker.rs +++ b/nearcore/src/shard_tracker.rs @@ -153,13 +153,9 @@ mod tests { use near_primitives::shard_layout::ShardLayout; use crate::shard_tracker::TrackedConfig; - #[cfg(feature = "protocol_feature_simple_nightshade")] use crate::shard_tracker::POISONED_LOCK_ERR; - #[cfg(feature = "protocol_feature_simple_nightshade")] use near_epoch_manager::test_utils::hash_range; - #[cfg(feature = "protocol_feature_simple_nightshade")] use near_primitives::utils::get_num_seats_per_shard; - #[cfg(feature = "protocol_feature_simple_nightshade")] use near_primitives::version::ProtocolFeature::SimpleNightshade; use near_primitives::version::PROTOCOL_VERSION; use num_rational::Rational; @@ -311,7 +307,6 @@ mod tests { } #[test] - #[cfg(feature = "protocol_feature_simple_nightshade")] fn test_track_shards_shard_layout_change() { let simple_nightshade_version = SimpleNightshade.protocol_version(); let shard_layout = ShardLayout::v1( diff --git a/neard/Cargo.toml b/neard/Cargo.toml index 7d9575c39a3..867a604fc58 100644 --- a/neard/Cargo.toml +++ b/neard/Cargo.toml @@ -45,7 +45,6 @@ json_rpc = ["nearcore/json_rpc"] protocol_feature_alt_bn128 = ["nearcore/protocol_feature_alt_bn128"] protocol_feature_block_header_v3 = ["nearcore/protocol_feature_block_header_v3"] protocol_feature_chunk_only_producers = ["nearcore/protocol_feature_chunk_only_producers"] -protocol_feature_simple_nightshade = ["nearcore/protocol_feature_simple_nightshade"] protocol_feature_routing_exchange_algorithm = ["nearcore/protocol_feature_routing_exchange_algorithm"] nightly_protocol_features = ["nearcore/nightly_protocol_features"] nightly_protocol = ["nearcore/nightly_protocol"]