Skip to content

Commit

Permalink
fix(congestion) - fix the congestion level rpc (near#12517)
Browse files Browse the repository at this point in the history
Fix and test the congestion_level rpc endpoint. 

cc @telezhnaya
  • Loading branch information
wacban authored Nov 26, 2024
1 parent 9407fe9 commit 58453b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 7 additions & 2 deletions core/primitives/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2429,8 +2429,13 @@ impl From<CongestionInfoV1> for CongestionInfoView {
}

impl From<CongestionInfoView> 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,
})
}
}

Expand Down
19 changes: 17 additions & 2 deletions pytest/tests/sanity/congestion_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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.
Expand Down Expand Up @@ -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()

0 comments on commit 58453b4

Please sign in to comment.