From d2605d117688e045390ce1d80f6aad49e58ff41e Mon Sep 17 00:00:00 2001 From: wacban Date: Thu, 17 Oct 2024 13:50:23 +0100 Subject: [PATCH 1/8] feat(congestion_control) - relax congestion control --- core/parameters/res/runtime_configs/73.yaml | 14 ++++++++++++++ core/parameters/src/config_store.rs | 1 + core/primitives-core/src/version.rs | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/parameters/res/runtime_configs/73.yaml b/core/parameters/res/runtime_configs/73.yaml index 148bdeb6c81..fa2c6fcb825 100644 --- a/core/parameters/res/runtime_configs/73.yaml +++ b/core/parameters/res/runtime_configs/73.yaml @@ -1 +1,15 @@ wasm_yield_resume_byte: { old: 1_195_627_285_210 , new: 47_683_715 } + +# Congestion Control + +# 40 PGAS +max_congestion_incoming_gas: { + old : 20_000_000_000_000_000, + new : 40_000_000_000_000_000, +} + +# 0.7 +reject_tx_congestion_threshold: { + old : { numerator: 50, denominator: 100 }, + new : { numerator: 70, denominator: 100 } +} \ No newline at end of file diff --git a/core/parameters/src/config_store.rs b/core/parameters/src/config_store.rs index 78e30e40578..d1d179577ef 100644 --- a/core/parameters/src/config_store.rs +++ b/core/parameters/src/config_store.rs @@ -49,6 +49,7 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[ (70, include_config!("70.yaml")), // Increase main_storage_proof_size_soft_limit and introduces StateStoredReceipt (72, include_config!("72.yaml")), + // Fix wasm_yield_resume_byte and relax congestion control. (73, include_config!("73.yaml")), (129, include_config!("129.yaml")), ]; diff --git a/core/primitives-core/src/version.rs b/core/primitives-core/src/version.rs index 508c8265998..6ba52de1c8f 100644 --- a/core/primitives-core/src/version.rs +++ b/core/primitives-core/src/version.rs @@ -260,7 +260,7 @@ impl ProtocolFeature { } /// Current protocol version used on the mainnet with all stable features. -const STABLE_PROTOCOL_VERSION: ProtocolVersion = 72; +const STABLE_PROTOCOL_VERSION: ProtocolVersion = 73; // On nightly, pick big enough version to support all features. const NIGHTLY_PROTOCOL_VERSION: ProtocolVersion = 145; From e572b3b141c223f057ea758e0b219e3749101499 Mon Sep 17 00:00:00 2001 From: Waclaw Banasik Date: Thu, 17 Oct 2024 17:57:30 +0100 Subject: [PATCH 2/8] Update core/parameters/res/runtime_configs/73.yaml --- core/parameters/res/runtime_configs/73.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/parameters/res/runtime_configs/73.yaml b/core/parameters/res/runtime_configs/73.yaml index fa2c6fcb825..4bb24e12662 100644 --- a/core/parameters/res/runtime_configs/73.yaml +++ b/core/parameters/res/runtime_configs/73.yaml @@ -11,5 +11,5 @@ max_congestion_incoming_gas: { # 0.7 reject_tx_congestion_threshold: { old : { numerator: 50, denominator: 100 }, - new : { numerator: 70, denominator: 100 } + new : { numerator: 80, denominator: 100 } } \ No newline at end of file From 92821794d211929b1fbcba6254abb324c41d5d23 Mon Sep 17 00:00:00 2001 From: wacban Date: Thu, 17 Oct 2024 21:51:01 +0100 Subject: [PATCH 3/8] fix tests --- core/parameters/src/config.rs | 8 ++++++-- core/primitives/src/congestion_info.rs | 4 +++- .../src/tests/client/features/congestion_control.rs | 11 ++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/core/parameters/src/config.rs b/core/parameters/src/config.rs index 4c87c69cafe..4653f269ffd 100644 --- a/core/parameters/src/config.rs +++ b/core/parameters/src/config.rs @@ -4,7 +4,7 @@ use crate::config_store::INITIAL_TESTNET_CONFIG; use crate::cost::RuntimeFeesConfig; use crate::parameter_table::ParameterTable; use near_account_id::AccountId; -use near_primitives_core::types::{Balance, Gas}; +use near_primitives_core::types::{Balance, Gas, ProtocolVersion}; use near_primitives_core::version::PROTOCOL_VERSION; use std::sync::Arc; @@ -49,8 +49,12 @@ impl RuntimeConfig { } pub fn test() -> Self { + Self::test_protocol_version(PROTOCOL_VERSION) + } + + pub fn test_protocol_version(protocol_version: ProtocolVersion) -> Self { let config_store = super::config_store::RuntimeConfigStore::new(None); - let runtime_config = config_store.get_config(PROTOCOL_VERSION); + let runtime_config = config_store.get_config(protocol_version); let mut wasm_config = crate::vm::Config::clone(&runtime_config.wasm_config); // Lower the yield timeout length so that we can observe timeouts in integration tests. diff --git a/core/primitives/src/congestion_info.rs b/core/primitives/src/congestion_info.rs index bee31ab84a2..b81731e5d51 100644 --- a/core/primitives/src/congestion_info.rs +++ b/core/primitives/src/congestion_info.rs @@ -507,8 +507,10 @@ mod tests { use super::*; fn get_config() -> CongestionControlConfig { + // Fix the initial configuration of congestion control for the tests. + let protocol_version = ProtocolFeature::CongestionControl.protocol_version(); let runtime_config_store = RuntimeConfigStore::new(None); - let runtime_config = runtime_config_store.get_config(PROTOCOL_VERSION); + let runtime_config = runtime_config_store.get_config(protocol_version); runtime_config.congestion_control_config } diff --git a/integration-tests/src/tests/client/features/congestion_control.rs b/integration-tests/src/tests/client/features/congestion_control.rs index 96e7eb44504..fe499457cc2 100644 --- a/integration-tests/src/tests/client/features/congestion_control.rs +++ b/integration-tests/src/tests/client/features/congestion_control.rs @@ -53,7 +53,7 @@ fn setup_test_runtime(sender_id: AccountId, protocol_version: ProtocolVersion) - // Chain must be sharded to test cross-shard congestion control. genesis.config.shard_layout = ShardLayout::v1_test(); - let mut config = RuntimeConfig::test(); + let mut config = RuntimeConfig::test_protocol_version(protocol_version); adjust_runtime_config(&mut config); let runtime_configs = vec![RuntimeConfigStore::with_one_config(config)]; @@ -515,11 +515,16 @@ fn submit_n_cheap_fns( /// with remote traffic. #[test] fn test_transaction_limit_for_local_congestion() { + init_test_logger(); + if !ProtocolFeature::CongestionControl.enabled(PROTOCOL_VERSION) { return; } let runtime_config_store = RuntimeConfigStore::new(None); - let config = runtime_config_store.get_config(PROTOCOL_VERSION); + + // Fix the initial configuration of congestion control for the tests. + let protocol_version = ProtocolFeature::CongestionControl.protocol_version(); + let config = runtime_config_store.get_config(protocol_version); // We don't want to go into the TX rejection limit in this test. let upper_limit_congestion = config.congestion_control_config.reject_tx_congestion_threshold; @@ -528,7 +533,7 @@ fn test_transaction_limit_for_local_congestion() { let contract_id: AccountId = CONTRACT_ID.parse().unwrap(); let sender_id = contract_id.clone(); let dummy_receiver: AccountId = "a_dummy_receiver".parse().unwrap(); - let env = setup_test_runtime("test0".parse().unwrap(), PROTOCOL_VERSION); + let env = setup_test_runtime("test0".parse().unwrap(), protocol_version); let ( remote_tx_included_without_congestion, From 2956b326dbc112f0b9faff84e42190b7753f39a6 Mon Sep 17 00:00:00 2001 From: wacban Date: Fri, 18 Oct 2024 12:04:56 +0100 Subject: [PATCH 4/8] cargo insta --- .../near_parameters__view__tests__runtime_config_view.snap | 6 +++--- .../near_primitives__views__tests__runtime_config_view.snap | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/parameters/src/snapshots/near_parameters__view__tests__runtime_config_view.snap b/core/parameters/src/snapshots/near_parameters__view__tests__runtime_config_view.snap index c2697088675..a0cdced59c3 100644 --- a/core/parameters/src/snapshots/near_parameters__view__tests__runtime_config_view.snap +++ b/core/parameters/src/snapshots/near_parameters__view__tests__runtime_config_view.snap @@ -174,7 +174,7 @@ expression: "&view" "yield_create_base": 153411779276, "yield_create_byte": 15643988, "yield_resume_base": 1195627285210, - "yield_resume_byte": 1195627285210, + "yield_resume_byte": 47683715, "bls12381_p1_sum_base": 16500000000, "bls12381_p1_sum_element": 6000000000, "bls12381_p2_sum_base": 18600000000, @@ -246,7 +246,7 @@ expression: "&view" "registrar_account_id": "registrar" }, "congestion_control_config": { - "max_congestion_incoming_gas": 20000000000000000, + "max_congestion_incoming_gas": 40000000000000000, "max_congestion_outgoing_gas": 10000000000000000, "max_congestion_memory_consumption": 1000000000, "max_congestion_missed_chunks": 5, @@ -255,7 +255,7 @@ expression: "&view" "allowed_shard_outgoing_gas": 1000000000000000, "max_tx_gas": 500000000000000, "min_tx_gas": 20000000000000, - "reject_tx_congestion_threshold": 0.5, + "reject_tx_congestion_threshold": 0.8, "outgoing_receipts_usual_size_limit": 102400, "outgoing_receipts_big_size_limit": 4718592 }, diff --git a/core/primitives/src/snapshots/near_primitives__views__tests__runtime_config_view.snap b/core/primitives/src/snapshots/near_primitives__views__tests__runtime_config_view.snap index 6b4a9c7947b..4c35cd28d8b 100644 --- a/core/primitives/src/snapshots/near_primitives__views__tests__runtime_config_view.snap +++ b/core/primitives/src/snapshots/near_primitives__views__tests__runtime_config_view.snap @@ -174,7 +174,7 @@ expression: "&view" "yield_create_base": 153411779276, "yield_create_byte": 15643988, "yield_resume_base": 1195627285210, - "yield_resume_byte": 1195627285210, + "yield_resume_byte": 47683715, "bls12381_p1_sum_base": 16500000000, "bls12381_p1_sum_element": 6000000000, "bls12381_p2_sum_base": 18600000000, @@ -246,7 +246,7 @@ expression: "&view" "registrar_account_id": "registrar" }, "congestion_control_config": { - "max_congestion_incoming_gas": 20000000000000000, + "max_congestion_incoming_gas": 40000000000000000, "max_congestion_outgoing_gas": 10000000000000000, "max_congestion_memory_consumption": 1000000000, "max_congestion_missed_chunks": 5, @@ -255,7 +255,7 @@ expression: "&view" "allowed_shard_outgoing_gas": 1000000000000000, "max_tx_gas": 500000000000000, "min_tx_gas": 20000000000000, - "reject_tx_congestion_threshold": 0.5, + "reject_tx_congestion_threshold": 0.8, "outgoing_receipts_usual_size_limit": 102400, "outgoing_receipts_big_size_limit": 4718592 }, From bc1797f35e9d41f65356bd1a768861e114e2e5b1 Mon Sep 17 00:00:00 2001 From: wacban Date: Fri, 18 Oct 2024 12:30:46 +0100 Subject: [PATCH 5/8] more insta snaps and whatnots --- chain/jsonrpc/jsonrpc-tests/res/genesis_config.json | 2 +- core/parameters/res/runtime_configs/parameters.snap | 6 +++--- .../near_parameters__config_store__tests__129.json.snap | 4 ++-- .../near_parameters__config_store__tests__73.json.snap | 4 ++-- ...r_parameters__config_store__tests__testnet_129.json.snap | 4 ++-- ...ar_parameters__config_store__tests__testnet_73.json.snap | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/chain/jsonrpc/jsonrpc-tests/res/genesis_config.json b/chain/jsonrpc/jsonrpc-tests/res/genesis_config.json index 10ba482a555..19164c774c2 100644 --- a/chain/jsonrpc/jsonrpc-tests/res/genesis_config.json +++ b/chain/jsonrpc/jsonrpc-tests/res/genesis_config.json @@ -1,5 +1,5 @@ { - "protocol_version": 72, + "protocol_version": 73, "genesis_time": "1970-01-01T00:00:00.000000000Z", "chain_id": "sample", "genesis_height": 0, diff --git a/core/parameters/res/runtime_configs/parameters.snap b/core/parameters/res/runtime_configs/parameters.snap index 6da38e85491..81e6c48202c 100644 --- a/core/parameters/res/runtime_configs/parameters.snap +++ b/core/parameters/res/runtime_configs/parameters.snap @@ -147,7 +147,7 @@ wasm_alt_bn128_g1_sum_element 5_000_000_000 wasm_yield_create_base 153_411_779_276 wasm_yield_create_byte 15_643_988 wasm_yield_resume_base 1_195_627_285_210 -wasm_yield_resume_byte 1_195_627_285_210 +wasm_yield_resume_byte 47_683_715 wasm_bls12381_p1_sum_base 16_500_000_000 wasm_bls12381_p1_sum_element 6_000_000_000 wasm_bls12381_p2_sum_base 18_600_000_000 @@ -208,7 +208,7 @@ vm_kind NearVm eth_implicit_accounts true yield_resume true discard_custom_sections true -max_congestion_incoming_gas 20_000_000_000_000_000 +max_congestion_incoming_gas 40_000_000_000_000_000 max_congestion_outgoing_gas 10_000_000_000_000_000 max_congestion_memory_consumption 1_000_000_000 max_congestion_missed_chunks 5 @@ -217,5 +217,5 @@ min_outgoing_gas 1_000_000_000_000_000 allowed_shard_outgoing_gas 1_000_000_000_000_000 max_tx_gas 500_000_000_000_000 min_tx_gas 20_000_000_000_000 -reject_tx_congestion_threshold 50 / 100 +reject_tx_congestion_threshold 80 / 100 use_state_stored_receipt true diff --git a/core/parameters/src/snapshots/near_parameters__config_store__tests__129.json.snap b/core/parameters/src/snapshots/near_parameters__config_store__tests__129.json.snap index 5cc5a524c67..084e668cea0 100644 --- a/core/parameters/src/snapshots/near_parameters__config_store__tests__129.json.snap +++ b/core/parameters/src/snapshots/near_parameters__config_store__tests__129.json.snap @@ -246,7 +246,7 @@ expression: config_view "registrar_account_id": "registrar" }, "congestion_control_config": { - "max_congestion_incoming_gas": 20000000000000000, + "max_congestion_incoming_gas": 40000000000000000, "max_congestion_outgoing_gas": 10000000000000000, "max_congestion_memory_consumption": 1000000000, "max_congestion_missed_chunks": 5, @@ -255,7 +255,7 @@ expression: config_view "allowed_shard_outgoing_gas": 1000000000000000, "max_tx_gas": 500000000000000, "min_tx_gas": 20000000000000, - "reject_tx_congestion_threshold": 0.5, + "reject_tx_congestion_threshold": 0.8, "outgoing_receipts_usual_size_limit": 102400, "outgoing_receipts_big_size_limit": 4718592 }, diff --git a/core/parameters/src/snapshots/near_parameters__config_store__tests__73.json.snap b/core/parameters/src/snapshots/near_parameters__config_store__tests__73.json.snap index f858b308c6d..0038feb868e 100644 --- a/core/parameters/src/snapshots/near_parameters__config_store__tests__73.json.snap +++ b/core/parameters/src/snapshots/near_parameters__config_store__tests__73.json.snap @@ -246,7 +246,7 @@ expression: config_view "registrar_account_id": "registrar" }, "congestion_control_config": { - "max_congestion_incoming_gas": 20000000000000000, + "max_congestion_incoming_gas": 40000000000000000, "max_congestion_outgoing_gas": 10000000000000000, "max_congestion_memory_consumption": 1000000000, "max_congestion_missed_chunks": 5, @@ -255,7 +255,7 @@ expression: config_view "allowed_shard_outgoing_gas": 1000000000000000, "max_tx_gas": 500000000000000, "min_tx_gas": 20000000000000, - "reject_tx_congestion_threshold": 0.5, + "reject_tx_congestion_threshold": 0.8, "outgoing_receipts_usual_size_limit": 102400, "outgoing_receipts_big_size_limit": 4718592 }, diff --git a/core/parameters/src/snapshots/near_parameters__config_store__tests__testnet_129.json.snap b/core/parameters/src/snapshots/near_parameters__config_store__tests__testnet_129.json.snap index 5cc5a524c67..084e668cea0 100644 --- a/core/parameters/src/snapshots/near_parameters__config_store__tests__testnet_129.json.snap +++ b/core/parameters/src/snapshots/near_parameters__config_store__tests__testnet_129.json.snap @@ -246,7 +246,7 @@ expression: config_view "registrar_account_id": "registrar" }, "congestion_control_config": { - "max_congestion_incoming_gas": 20000000000000000, + "max_congestion_incoming_gas": 40000000000000000, "max_congestion_outgoing_gas": 10000000000000000, "max_congestion_memory_consumption": 1000000000, "max_congestion_missed_chunks": 5, @@ -255,7 +255,7 @@ expression: config_view "allowed_shard_outgoing_gas": 1000000000000000, "max_tx_gas": 500000000000000, "min_tx_gas": 20000000000000, - "reject_tx_congestion_threshold": 0.5, + "reject_tx_congestion_threshold": 0.8, "outgoing_receipts_usual_size_limit": 102400, "outgoing_receipts_big_size_limit": 4718592 }, diff --git a/core/parameters/src/snapshots/near_parameters__config_store__tests__testnet_73.json.snap b/core/parameters/src/snapshots/near_parameters__config_store__tests__testnet_73.json.snap index f858b308c6d..0038feb868e 100644 --- a/core/parameters/src/snapshots/near_parameters__config_store__tests__testnet_73.json.snap +++ b/core/parameters/src/snapshots/near_parameters__config_store__tests__testnet_73.json.snap @@ -246,7 +246,7 @@ expression: config_view "registrar_account_id": "registrar" }, "congestion_control_config": { - "max_congestion_incoming_gas": 20000000000000000, + "max_congestion_incoming_gas": 40000000000000000, "max_congestion_outgoing_gas": 10000000000000000, "max_congestion_memory_consumption": 1000000000, "max_congestion_missed_chunks": 5, @@ -255,7 +255,7 @@ expression: config_view "allowed_shard_outgoing_gas": 1000000000000000, "max_tx_gas": 500000000000000, "min_tx_gas": 20000000000000, - "reject_tx_congestion_threshold": 0.5, + "reject_tx_congestion_threshold": 0.8, "outgoing_receipts_usual_size_limit": 102400, "outgoing_receipts_big_size_limit": 4718592 }, From dc123a140ac54cd2c263bd5a5823b7385ea17e25 Mon Sep 17 00:00:00 2001 From: wacban Date: Fri, 18 Oct 2024 12:30:54 +0100 Subject: [PATCH 6/8] udpated changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 904ec4eede8..7a3b17da560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,23 @@ ## [unreleased] +### Protocol Changes + +* Fixing invalid cost used for wasm_yield_resume_byte. #12192 +* Relaxing Congestion Control to allow accepting and buffering more transactions. #12241 + +### Non-protocol Changes +**No Changes** + +## [2.3.0] + ### Protocol Changes * Sets `chunk_validator_only_kickout_threshold` to 70. Uses this kickout threshold as a cutoff threshold for contribution of endorsement ratio in rewards calculation: if endorsement ratio is above 70%, the contribution of endorsement ratio in average uptime calculation is 100%, otherwise it is 0%. Endorsements received are now included in `BlockHeader` to improve kickout and reward calculation for chunk validators. ### Non-protocol Changes * Added [documentation](./docs/misc/archival_data_recovery.md) and a [reference](./scripts/recover_missing_archival_data.sh) script to recover the data lost in archival nodes at the beginning of 2024. * **Archival nodes only:** Stop saving partial chunks to `PartialChunks` column in the Cold DB. Instead, archival nodes will reconstruct partial chunks from the `Chunks` column. +* Decentralized state sync: Before, nodes that needed to download state (either because they're several epochs behind the chain or because they're going to start producing chunks for a shard they don't currently track) would download them from a centralized GCS bucket. Now, nodes will attempt to download pieces of the state from peers in the network, and only fallback to downloading from GCS if that fails. Please note that in order to participate in providing state parts to peers, your node may generate snapshots of the state. These snapshots should not take too much space, since they're hard links to database files that get cleaned up on every epoch. ### 2.2.0 From 115180725ac106bee96ff8e6c2e29dceed13760b Mon Sep 17 00:00:00 2001 From: wacban Date: Fri, 18 Oct 2024 12:46:40 +0100 Subject: [PATCH 7/8] simple chain fix --- chain/chain/src/tests/simple_chain.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chain/chain/src/tests/simple_chain.rs b/chain/chain/src/tests/simple_chain.rs index 80efaaebf9c..c74a2edbdd4 100644 --- a/chain/chain/src/tests/simple_chain.rs +++ b/chain/chain/src/tests/simple_chain.rs @@ -34,7 +34,7 @@ fn build_chain() { if cfg!(feature = "nightly") { insta::assert_snapshot!(hash, @"Hc3bWEd7ikHf9BAe2SknvH2jAAakEtBRU1FBu6Udocm3"); } else { - insta::assert_snapshot!(hash, @"dY6Z6HdATLWK3wwxkNtUs8T1GaEQqpxUCXm7TectWW7"); + insta::assert_snapshot!(hash, @"GHZFAFiMdGzAfnWTcS9u9wqFvxMrgFpyEr6Use7jk2Lo"); } for i in 1..5 { @@ -52,7 +52,7 @@ fn build_chain() { if cfg!(feature = "nightly") { insta::assert_snapshot!(hash, @"39R6bDFXkPfwdYs4crV3RyCde85ecycqP5DBwdtwyjcJ"); } else { - insta::assert_snapshot!(hash, @"6RnKeuiGmxkFxNYeEmAbK6NzwvKYuTcKCwqAmqJ6m3DG"); + insta::assert_snapshot!(hash, @"3Pdm44L71Bk8EokPHF1pxakHojsriNadBdZZSpcoDv9q"); } } From 3cbacfdaa273f739b692e62026102e1b6e80b5a7 Mon Sep 17 00:00:00 2001 From: wacban Date: Fri, 18 Oct 2024 15:27:32 +0100 Subject: [PATCH 8/8] fix nayduck maybe? --- pytest/tests/sanity/congestion_control.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pytest/tests/sanity/congestion_control.py b/pytest/tests/sanity/congestion_control.py index 20bd61b2fef..1f7ebd402b0 100644 --- a/pytest/tests/sanity/congestion_control.py +++ b/pytest/tests/sanity/congestion_control.py @@ -8,7 +8,6 @@ import unittest import pathlib import sys -import json import time import threading @@ -141,7 +140,7 @@ def __run_under_congestion(self, node): def __run_after_congestion(self, node): logger.info("Checking the chain after congestion") - for height, hash in poll_blocks(node, __target=50): + for height, hash in poll_blocks(node, __target=100): chunk = self.__get_chunk(node, hash, 0) gas_used = chunk['header']['gas_used'] @@ -200,8 +199,10 @@ def __start_load(self, node: BaseNode, accounts): self.finished = False self.lock = threading.Lock() + self.txs = [] target_account = accounts[0] - for account in accounts: + # Spawn two thread per each account to get more transactions in. + for account in accounts + accounts: thread = threading.Thread( target=self.__load, args=[node, account, target_account], @@ -221,7 +222,6 @@ def __load(self, node: BaseNode, sender_account, target_account): logger.debug( f"Starting load thread {sender_account.account_id} -> {target_account.account_id}" ) - self.txs = [] while not self.finished: tx_hash = self.__call_contract(node, sender_account, target_account) with self.lock: