Skip to content

Commit

Permalink
Move SimpleNightshade from nightly to stable (#4953)
Browse files Browse the repository at this point in the history
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 near/NEPs#241
  • Loading branch information
mzhangmzz authored Oct 13, 2021
1 parent 708e629 commit e5134c2
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 1 addition & 2 deletions chain/epoch_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
13 changes: 0 additions & 13 deletions chain/epoch_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, EpochError> {
Ok(false)
}

#[cfg(feature = "protocol_feature_simple_nightshade")]
pub fn will_shard_layout_change(
&mut self,
parent_hash: &CryptoHash,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion core/chain-configs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
45 changes: 24 additions & 21 deletions core/chain-configs/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,21 +73,15 @@ fn default_num_chunk_only_producer_seats() -> u64 {
}

fn default_simple_nightshade_shard_layout() -> Option<ShardLayout> {
#[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)]
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 1 addition & 5 deletions core/primitives/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions core/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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")]
Expand All @@ -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,
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 0 additions & 1 deletion integration-tests/tests/client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ mod process_blocks;
mod runtimes;
#[cfg(feature = "sandbox")]
mod sandbox;
#[cfg(feature = "protocol_feature_simple_nightshade")]
mod sharding_upgrade;
6 changes: 6 additions & 0 deletions integration-tests/tests/client/sharding_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions nearcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions nearcore/src/shard_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion neard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit e5134c2

Please sign in to comment.