From 9ef425a072922de07dd42915de251dfaf50d7835 Mon Sep 17 00:00:00 2001 From: Aleksandr Logunov Date: Fri, 8 Oct 2021 15:46:48 +0300 Subject: [PATCH] feat: stabilize features lowering costs (#4948) Stabilize features lowering costs for new release: * https://github.com/near/nearcore/pull/4795 * https://github.com/near/nearcore/pull/4865 Quality control: * We run param estimator several times and got consistent results: * beginning of Sep 2021, my GCP instance https://hackmd.io/w6ODyKjUReuuofXTuqdyFQ * end of Sep 2021, @matklad instance https://github.com/near/nearcore/issues/4778#issuecomment-925187102 * The current fee values are explained: * Data receipt costs - investigated here https://github.com/near/nearcore/issues/4482, the reason was relatively explained and the observed issue was fixed. Note that we don't know the exact root cause, but we assume that it is related to a separate fee (touching_trie_node) for taking store size into account. This fee is problematic because it assumes the constant height of a trie, but we treat it as a separate problem. * Ecrecover cost - follow links from this one: https://github.com/near/nearcore/issues/4778#issuecomment-925187102 --- CHANGELOG.md | 5 ++++- core/primitives/Cargo.toml | 4 +--- core/primitives/src/runtime/config_store.rs | 15 +++++---------- core/primitives/src/version.rs | 14 ++++---------- nearcore/Cargo.toml | 4 +--- nearcore/res/genesis_config.json | 4 ++-- .../res/runtime_configs/{119.json => 49.json} | 0 7 files changed, 17 insertions(+), 29 deletions(-) rename nearcore/res/runtime_configs/{119.json => 49.json} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index c980c13f2d3..382a14ea33a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [unreleased] +### Protocol Changes +* Upgrade from Wasmer 0 to Wasmer 2, bringing better performance and reliability. +* Lower data receipt cost and base cost of `ecrecover` host function + ## `1.21.0` [09-06-2021] ### Protocol Changes @@ -15,7 +19,6 @@ * Address test dependency issue #4556 [#4606](https://github.com/near/nearcore/pull/4606). [#4622](https://github.com/near/nearcore/pull/4622). * Fix neard shutdown issue [#4429](https://github.com/near/nearcore/pull/4429). #[4442](https://github.com/near/nearcore/pull/4442) - ## `1.20.0` [07-26-2021] ### Protocol Changes diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index ebfde0b35e6..c1c9101c29d 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -46,10 +46,8 @@ protocol_feature_alt_bn128 = ["near-primitives-core/protocol_feature_alt_bn128", protocol_feature_simple_nightshade = [] 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"] -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_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 = [] [dev-dependencies] diff --git a/core/primitives/src/runtime/config_store.rs b/core/primitives/src/runtime/config_store.rs index 872d853e1be..17ff0a9efae 100644 --- a/core/primitives/src/runtime/config_store.rs +++ b/core/primitives/src/runtime/config_store.rs @@ -18,8 +18,7 @@ macro_rules! include_config { static CONFIGS: &[(ProtocolVersion, &[u8])] = &[ (0, include_config!("29.json")), (42, include_config!("42.json")), - #[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")] - (119, include_config!("119.json")), + (49, include_config!("49.json")), ]; /// Stores runtime config for each protocol version where it was updated. @@ -80,8 +79,7 @@ impl RuntimeConfigStore { mod tests { use super::*; use crate::serialize::to_base; - #[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")] - use crate::version::ProtocolFeature::LowerEcrecoverBaseCost; + use crate::version::ProtocolFeature::LowerDataReceiptAndEcrecoverBaseCost; use crate::version::ProtocolFeature::LowerStorageCost; use near_primitives_core::hash::hash; @@ -157,11 +155,10 @@ mod tests { } #[test] - #[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")] fn test_lower_data_receipt_cost() { let store = RuntimeConfigStore::new(None); let base_cfg = store.get_config(LowerStorageCost.protocol_version()); - let new_cfg = store.get_config(LowerEcrecoverBaseCost.protocol_version()); + let new_cfg = store.get_config(LowerDataReceiptAndEcrecoverBaseCost.protocol_version()); assert!( base_cfg.transaction_costs.data_receipt_creation_config.base_cost.send_sir > new_cfg.transaction_costs.data_receipt_creation_config.base_cost.send_sir @@ -175,7 +172,6 @@ mod tests { // Check that for protocol version with lowered data receipt cost, runtime config passed to // config store is overridden. #[test] - #[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")] fn test_override_runtime_config() { let store = RuntimeConfigStore::new(Some(&RuntimeConfig::free())); let config = store.get_config(0); @@ -189,7 +185,7 @@ mod tests { &serde_json::from_slice::(CONFIGS[1].1).unwrap() ); - let config = store.get_config(LowerEcrecoverBaseCost.protocol_version()); + let config = store.get_config(LowerDataReceiptAndEcrecoverBaseCost.protocol_version()); assert_eq!(config.account_creation_config.min_allowed_top_level_account_length, 32); assert_eq!( config.as_ref(), @@ -198,11 +194,10 @@ mod tests { } #[test] - #[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")] fn test_lower_ecrecover_base_cost() { let store = RuntimeConfigStore::new(None); let base_cfg = store.get_config(LowerStorageCost.protocol_version()); - let new_cfg = store.get_config(LowerEcrecoverBaseCost.protocol_version()); + let new_cfg = store.get_config(LowerDataReceiptAndEcrecoverBaseCost.protocol_version()); assert!( base_cfg.wasm_config.ext_costs.ecrecover_base > new_cfg.wasm_config.ext_costs.ecrecover_base diff --git a/core/primitives/src/version.rs b/core/primitives/src/version.rs index f8f85e36664..7aebbcf7b79 100644 --- a/core/primitives/src/version.rs +++ b/core/primitives/src/version.rs @@ -101,7 +101,7 @@ pub enum ProtocolFeature { /// . RestoreReceiptsAfterFix, /// This feature switch our WASM engine implementation from wasmer 0.* to - /// wasmer 2.*, brining better performance and reliability. + /// wasmer 2.*, bringing better performance and reliability. /// /// The implementations should be sufficiently similar for this to not be a /// protocol upgrade, but we conservatively do a protocol upgrade to be on @@ -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, + LowerDataReceiptAndEcrecoverBaseCost, // nightly features #[cfg(feature = "protocol_feature_block_header_v3")] @@ -120,19 +121,15 @@ pub enum ProtocolFeature { SimpleNightshade, #[cfg(feature = "protocol_feature_chunk_only_producers")] ChunkOnlyProducers, - #[cfg(feature = "protocol_feature_lower_data_receipt_cost")] - LowerDataReceiptCost, #[cfg(feature = "protocol_feature_routing_exchange_algorithm")] RoutingExchangeAlgorithm, - #[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")] - LowerEcrecoverBaseCost, } /// Current latest stable version of the protocol. /// 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 = 48; +pub const PROTOCOL_VERSION: ProtocolVersion = 49; /// Current latest nightly version of the protocol. #[cfg(feature = "nightly_protocol")] @@ -156,6 +153,7 @@ impl ProtocolFeature { ProtocolFeature::MathExtension => 46, ProtocolFeature::RestoreReceiptsAfterFix => 47, ProtocolFeature::Wasmer2 => 48, + ProtocolFeature::LowerDataReceiptAndEcrecoverBaseCost => 49, // Nightly features #[cfg(feature = "protocol_feature_alt_bn128")] @@ -166,12 +164,8 @@ impl ProtocolFeature { ProtocolFeature::SimpleNightshade => 114, #[cfg(feature = "protocol_feature_chunk_only_producers")] ProtocolFeature::ChunkOnlyProducers => 115, - #[cfg(feature = "protocol_feature_lower_data_receipt_cost")] - ProtocolFeature::LowerDataReceiptCost => 116, #[cfg(feature = "protocol_feature_routing_exchange_algorithm")] ProtocolFeature::RoutingExchangeAlgorithm => 117, - #[cfg(feature = "protocol_feature_lower_ecrecover_base_cost")] - ProtocolFeature::LowerEcrecoverBaseCost => 119, } } } diff --git a/nearcore/Cargo.toml b/nearcore/Cargo.toml index 39aa4c305a6..1610747cf25 100644 --- a/nearcore/Cargo.toml +++ b/nearcore/Cargo.toml @@ -72,10 +72,8 @@ protocol_feature_alt_bn128 = ["near-primitives/protocol_feature_alt_bn128", "nod 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_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"] -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_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 = ["near-primitives/nightly_protocol", "near-jsonrpc/nightly_protocol"] # Force usage of a specific wasm vm irrespective of protocol version. diff --git a/nearcore/res/genesis_config.json b/nearcore/res/genesis_config.json index 148bd783048..df66aa98223 100644 --- a/nearcore/res/genesis_config.json +++ b/nearcore/res/genesis_config.json @@ -1,5 +1,5 @@ { - "protocol_version": 48, + "protocol_version": 49, "genesis_time": "1970-01-01T00:00:00.000000000Z", "chain_id": "sample", "genesis_height": 0, @@ -247,4 +247,4 @@ }, "simple_nightshade_shard_layout": null, "records": [] -} \ No newline at end of file +} diff --git a/nearcore/res/runtime_configs/119.json b/nearcore/res/runtime_configs/49.json similarity index 100% rename from nearcore/res/runtime_configs/119.json rename to nearcore/res/runtime_configs/49.json