From 58453b44160ea3fd3252e3abf770498ce58a1f28 Mon Sep 17 00:00:00 2001 From: Waclaw Banasik Date: Tue, 26 Nov 2024 12:54:10 +0000 Subject: [PATCH] fix(congestion) - fix the congestion level rpc (#12517) Fix and test the congestion_level rpc endpoint. cc @telezhnaya --- core/primitives/src/views.rs | 9 +++++++-- pytest/tests/sanity/congestion_control.py | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/primitives/src/views.rs b/core/primitives/src/views.rs index 466eb958d04..07568595298 100644 --- a/core/primitives/src/views.rs +++ b/core/primitives/src/views.rs @@ -2429,8 +2429,13 @@ impl From for CongestionInfoView { } impl From for CongestionInfo { - fn from(_: CongestionInfoView) -> Self { - CongestionInfo::default() + fn from(congestion_info: CongestionInfoView) -> Self { + CongestionInfo::V1(CongestionInfoV1 { + delayed_receipts_gas: congestion_info.delayed_receipts_gas, + buffered_receipts_gas: congestion_info.buffered_receipts_gas, + receipt_bytes: congestion_info.receipt_bytes, + allowed_shard: congestion_info.allowed_shard, + }) } } diff --git a/pytest/tests/sanity/congestion_control.py b/pytest/tests/sanity/congestion_control.py index 4f0b8af7fc6..4d96407f516 100644 --- a/pytest/tests/sanity/congestion_control.py +++ b/pytest/tests/sanity/congestion_control.py @@ -112,8 +112,9 @@ def __run_under_congestion(self, node): continue # Check the target shard. + shard_id = 0 - chunk = self.__get_chunk(node, hash, 0) + chunk = self.__get_chunk(node, hash, shard_id) # Check that the target is busy - always using 1000TG. gas_used = chunk['header']['gas_used'] @@ -125,8 +126,11 @@ def __run_under_congestion(self, node): self.assertGreater(int(congestion_info['delayed_receipts_gas']), 0) self.assertGreater(congestion_info['receipt_bytes'], 0) + congestion_level = self.__get_congestion_level(node, hash, shard_id) + self.assertGreater(congestion_level, 0) + logger.info( - f"#{height} target gas used: {gas_used} congestion info {congestion_info}" + f"#{height} target gas used: {gas_used} congestion level {congestion_level} congestion info {congestion_info}" ) # Check one other shard. @@ -420,6 +424,17 @@ def __get_chunk(self, node: BaseNode, block_hash, shard_id): self.assertIn('result', result, result) return result['result'] + def __get_congestion_level(self, node: BaseNode, block_hash, shard_id): + result = node.json_rpc("EXPERIMENTAL_congestion_level", { + "block_id": block_hash, + "shard_id": shard_id + }) + self.assertIn('result', result, result) + + result = result['result'] + self.assertIn('congestion_level', result, result) + return result['congestion_level'] + if __name__ == '__main__': unittest.main()