Skip to content

Commit

Permalink
test(resharding) - test for getting the shard layout info by rpc (#10320
Browse files Browse the repository at this point in the history
)

We need a way for near ecosystem developers to query the current shard
layout. The EXPERIMENTAL_protocol_config allows that although with some
extra steps. It should be good enough until we have time to implement a
dedicated endpoint just for the shard layout. In this PR I extended the
resharding nayduck test to check that the mentioned rpc endpoint works
as expected and that changes in the shard layout are reflected in the
rpc.
  • Loading branch information
wacban authored Dec 12, 2023
1 parent bf49c6e commit 72d0a5a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 0 additions & 2 deletions pytest/lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import atexit
import base58
import hashlib
import json
Expand All @@ -7,7 +6,6 @@
import random
import re
import shutil
import subprocess
import sys
import tempfile
import time
Expand Down
29 changes: 27 additions & 2 deletions pytest/tests/sanity/resharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,40 @@ def test_resharding(self):

metrics_tracker = MetricsTracker(node0)

for height, _ in poll_blocks(node0):
for height, hash in poll_blocks(node0):
version = metrics_tracker.get_int_metric_value(
"near_shard_layout_version")
num_shards = metrics_tracker.get_int_metric_value(
"near_shard_layout_num_shards")

protocol_config = node0.json_rpc(
"EXPERIMENTAL_protocol_config",
{"block_id": hash},
)

self.assertTrue('error' not in protocol_config)

self.assertTrue('result' in protocol_config)
protocol_config = protocol_config.get('result')

self.assertTrue('shard_layout' in protocol_config)
shard_layout = protocol_config.get('shard_layout')

self.assertTrue('V1' in shard_layout)
shard_layout = shard_layout.get('V1')

self.assertTrue('boundary_accounts' in shard_layout)
boundary_accounts = shard_layout.get('boundary_accounts')

logger.info(
f"#{height} shard layout version: {version}, num shards: {num_shards} "
f"#{height} shard layout version: {version}, num shards: {num_shards}"
)
logger.debug(f"#{height} shard layout: {shard_layout}")

# check the shard layout versions from metrics and from json rpc are equal
self.assertEqual(version, shard_layout.get('version'))
# check the shard num from metrics and json rpc are equal
self.assertEqual(num_shards, len(boundary_accounts) + 1)

# This may be flaky - it shouldn't - but it may. We collect metrics
# after the block is processed. If there is some delay the shard
Expand Down

0 comments on commit 72d0a5a

Please sign in to comment.