Skip to content

Commit

Permalink
feat: stabilize wasmer2 protocol feature
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Oct 6, 2021
1 parent 6c8fb54 commit 291bb7d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 33 deletions.
3 changes: 1 addition & 2 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ protocol_feature_chunk_only_producers = ["protocol_feature_block_header_v3"]
protocol_feature_lower_data_receipt_cost = []
protocol_feature_lower_ecrecover_base_cost = []
protocol_feature_routing_exchange_algorithm = ["near-primitives-core/protocol_feature_routing_exchange_algorithm"]
protocol_feature_wasmer2 = []
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_lower_data_receipt_cost", "protocol_feature_routing_exchange_algorithm", "protocol_feature_wasmer2", "protocol_feature_lower_ecrecover_base_cost"]
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_lower_data_receipt_cost", "protocol_feature_routing_exchange_algorithm", "protocol_feature_lower_ecrecover_base_cost"]
nightly_protocol = []

[dev-dependencies]
Expand Down
26 changes: 12 additions & 14 deletions core/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ pub enum ProtocolFeature {
/// Restore receipts that were previously stuck because of
/// <https://github.com/near/nearcore/pull/4228>.
RestoreReceiptsAfterFix,
/// This feature switch our WASM engine implementation from wasmer 0.* to
/// wasmer 2.*, brining better performance and reliability.
///
/// The implementations should be sufficiently similar for this to not be a
/// protocol upgrade, but we concervatively do a protocol upgrade to be on
/// the safe side.
///
/// Although wasmer2 is faster, we don't change fees with this protocol
/// version -- we can safely do that in a separate step.
Wasmer2,

// nightly features
#[cfg(feature = "protocol_feature_block_header_v3")]
Expand All @@ -114,17 +124,6 @@ pub enum ProtocolFeature {
LowerDataReceiptCost,
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
RoutingExchangeAlgorithm,
/// This feature switch our WASM engine implementation from wasmer 0.* to
/// wasmer 2.*, brining better performance and reliability.
///
/// The implementations should be sufficiently similar for this to not be a
/// protocol upgrade, but we concervatively do a protocol upgrade to be on
/// the safe side.
///
/// Although wasmer2 is faster, we don't change fees with this protocol
/// version -- we can safely do that in a separate step.
#[cfg(feature = "protocol_feature_wasmer2")]
Wasmer2,
#[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")]
LowerEcrecoverBaseCost,
}
Expand All @@ -133,7 +132,7 @@ pub enum ProtocolFeature {
/// Some features (e. g. FixStorageUsage) require that there is at least one epoch with exactly
/// the corresponding version
#[cfg(not(feature = "nightly_protocol"))]
pub const PROTOCOL_VERSION: ProtocolVersion = 47;
pub const PROTOCOL_VERSION: ProtocolVersion = 48;

/// Current latest nightly version of the protocol.
#[cfg(feature = "nightly_protocol")]
Expand All @@ -156,6 +155,7 @@ impl ProtocolFeature {
ProtocolFeature::CountRefundReceiptsInGasLimit => 46,
ProtocolFeature::MathExtension => 46,
ProtocolFeature::RestoreReceiptsAfterFix => 47,
ProtocolFeature::Wasmer2 => 48,

// Nightly features
#[cfg(feature = "protocol_feature_alt_bn128")]
Expand All @@ -170,8 +170,6 @@ impl ProtocolFeature {
ProtocolFeature::LowerDataReceiptCost => 116,
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
ProtocolFeature::RoutingExchangeAlgorithm => 117,
#[cfg(feature = "protocol_feature_wasmer2")]
ProtocolFeature::Wasmer2 => 118,
#[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")]
ProtocolFeature::LowerEcrecoverBaseCost => 119,
}
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ 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"]
protocol_feature_wasmer2 = ["nearcore/protocol_feature_wasmer2", "nearcore/protocol_feature_wasmer2"]
nightly_protocol_features = ["nearcore/nightly_protocol_features", "protocol_feature_alt_bn128", "protocol_feature_block_header_v3", "protocol_feature_simple_nightshade", "protocol_feature_wasmer2"]
nightly_protocol_features = ["nearcore/nightly_protocol_features", "protocol_feature_alt_bn128", "protocol_feature_block_header_v3", "protocol_feature_simple_nightshade"]
nightly_protocol = ["nearcore/nightly_protocol"]
sandbox = ["near-network/sandbox", "near-chain/sandbox", "node-runtime/sandbox", "near-client/sandbox"]
11 changes: 1 addition & 10 deletions integration-tests/tests/client/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2573,12 +2573,8 @@ fn test_refund_receipts_processing() {
fn test_wasmer2_upgrade() {
let mut capture = near_logger_utils::TracingCapture::enable();

#[cfg(all(feature = "protocol_feature_wasmer2", feature = "nightly_protocol"))]
let old_protocol_version =
near_primitives::version::ProtocolFeature::Wasmer2.protocol_version() - 1;
#[cfg(not(feature = "protocol_feature_wasmer2"))]
let old_protocol_version = PROTOCOL_VERSION - 1;

let new_protocol_version = old_protocol_version + 1;

// Prepare TestEnv with a contract at the old protocol version.
Expand Down Expand Up @@ -2659,12 +2655,7 @@ fn test_wasmer2_upgrade() {
};

assert!(logs_at_old_version.contains(&"run_vm vm_kind=Wasmer0".to_string()));

if cfg!(all(feature = "protocol_feature_wasmer2", feature = "nightly_protocol")) {
assert!(logs_at_new_version.contains(&"run_vm vm_kind=Wasmer2".to_string()));
} else {
assert!(logs_at_new_version.contains(&"run_vm vm_kind=Wasmer0".to_string()));
}
assert!(logs_at_new_version.contains(&"run_vm vm_kind=Wasmer2".to_string()));
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions nearcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ protocol_feature_chunk_only_producers = ["protocol_feature_block_header_v3", "ne
protocol_feature_lower_data_receipt_cost = ["near-primitives/protocol_feature_lower_data_receipt_cost"]
protocol_feature_lower_ecrecover_base_cost = ["near-primitives/protocol_feature_lower_ecrecover_base_cost"]
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"]
protocol_feature_wasmer2 = ["near-primitives/protocol_feature_wasmer2", "near-vm-runner/protocol_feature_wasmer2"]
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_lower_data_receipt_cost", "protocol_feature_routing_exchange_algorithm", "protocol_feature_wasmer2", "protocol_feature_lower_ecrecover_base_cost"]
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_lower_data_receipt_cost", "protocol_feature_routing_exchange_algorithm", "protocol_feature_lower_ecrecover_base_cost"]
nightly_protocol = ["near-primitives/nightly_protocol", "near-jsonrpc/nightly_protocol"]

# Force usage of a specific wasm vm irrespective of protocol version.
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 @@ 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_routing_exchange_algorithm = ["nearcore/protocol_feature_routing_exchange_algorithm"]
protocol_feature_wasmer2 = ["nearcore/protocol_feature_wasmer2"]
nightly_protocol_features = ["nearcore/nightly_protocol_features"]
nightly_protocol = ["nearcore/nightly_protocol"]

Expand Down
1 change: 0 additions & 1 deletion runtime/near-vm-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ protocol_feature_alt_bn128 = [
"near-primitives/protocol_feature_alt_bn128",
"near-vm-errors/protocol_feature_alt_bn128"
]
protocol_feature_wasmer2 = [ "near-primitives/protocol_feature_wasmer2" ]

[package.metadata.cargo-udeps.ignore]
# `no_cache` feature leads to an unused `cached` crate
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/src/vm_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl VMKind {
return VMKind::Wasmer2;
}

if checked_feature!("protocol_feature_wasmer2", Wasmer2, protocol_version) {
if checked_feature!("stable", Wasmer2, protocol_version) {
VMKind::Wasmer2
} else {
VMKind::Wasmer0
Expand Down

0 comments on commit 291bb7d

Please sign in to comment.