Skip to content

Commit

Permalink
feat: stabilize features lowering costs (#4948)
Browse files Browse the repository at this point in the history
Stabilize features lowering costs for new release:
* #4795
* #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 #4778 (comment)

* The current fee values are explained:
  * Data receipt costs - investigated here #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: #4778 (comment)
  • Loading branch information
Longarithm authored Oct 8, 2021
1 parent 84c671d commit 9ef425a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 29 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 5 additions & 10 deletions core/primitives/src/runtime/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -189,7 +185,7 @@ mod tests {
&serde_json::from_slice::<RuntimeConfig>(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(),
Expand All @@ -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
Expand Down
14 changes: 4 additions & 10 deletions core/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub enum ProtocolFeature {
/// <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.
/// 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
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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,
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions nearcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions nearcore/res/genesis_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"protocol_version": 48,
"protocol_version": 49,
"genesis_time": "1970-01-01T00:00:00.000000000Z",
"chain_id": "sample",
"genesis_height": 0,
Expand Down Expand Up @@ -247,4 +247,4 @@
},
"simple_nightshade_shard_layout": null,
"records": []
}
}
File renamed without changes.

0 comments on commit 9ef425a

Please sign in to comment.