Skip to content

Commit 48cc4f6

Browse files
authored
fix(state_sync_massive): Epoch length was too short (#3208)
Epoch length was too short (20) and observer when tried to sync, used old epoch, but right now, trying to sync from any epoch other than current epoch or previous epoch is considered malicious behavior. Fixes #3130 Test plan ====== state_sync_massive.py passes in nightly
1 parent f85e142 commit 48cc4f6

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

nightly/nightly.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pytest --timeout=900 sanity/state_sync3.py
1919
pytest --timeout=240 sanity/state_sync4.py
2020
pytest --timeout=600 sanity/state_sync_routed.py manytx 115
2121
pytest --timeout=300 sanity/state_sync_late.py notx
22-
pytest --timeout=900 sanity/state_sync_massive.py
22+
pytest --timeout=1500 sanity/state_sync_massive.py
2323
pytest sanity/rpc_tx_forwarding.py
2424
pytest --timeout=240 sanity/skip_epoch.py
2525
pytest --timeout=240 sanity/one_val.py

pytest/lib/cluster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ def send_tx_and_wait(self, signed_tx, timeout):
138138
[base64.b64encode(signed_tx).decode('utf8')],
139139
timeout=timeout)
140140

141-
def get_status(self):
141+
def get_status(self, check_storage=True):
142142
r = requests.get("http://%s:%s/status" % self.rpc_addr(), timeout=2)
143143
r.raise_for_status()
144144
status = json.loads(r.content)
145-
if status['sync_info']['syncing'] == False:
145+
if check_storage and status['sync_info']['syncing'] == False:
146146
# Storage is not guaranteed to be in consistent state while syncing
147147
self.check_store()
148148
return status

pytest/tests/sanity/state_sync_massive.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@
3939
# ```
4040
#
4141

42-
import sys, time, requests, os
42+
import sys, time, requests, logging
43+
from subprocess import check_output
4344
from queue import Queue
4445

4546
sys.path.append('lib')
4647

4748
from cluster import init_cluster, spin_up_node, load_config
4849
from populate import genesis_populate_all, copy_genesis
50+
from utils import LogTracker
51+
52+
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
4953

5054
if len(sys.argv) >= 2:
5155
genesis_data = sys.argv[1]
@@ -56,26 +60,32 @@
5660
config = load_config()
5761
near_root, node_dirs = init_cluster(
5862
1, 2, 1, config,
59-
[["min_gas_price", 0], ["max_inflation_rate", [0, 1]], ["epoch_length", 20],
63+
[["min_gas_price", 0], ["max_inflation_rate", [0, 1]], ["epoch_length", 300],
6064
["block_producer_kickout_threshold", 80]], {1: {
6165
"tracked_shards": [0]
6266
}, 2: {
6367
"tracked_shards": [0]
6468
}})
6569

66-
print("Populating genesis")
70+
logging.info("Populating genesis")
6771

6872
if genesis_data is None:
6973
genesis_populate_all(near_root, additional_accounts, node_dirs)
7074
else:
7175
for node_dir in node_dirs:
7276
copy_genesis(genesis_data, node_dir)
7377

74-
print("Genesis generated")
78+
logging.info("Genesis generated")
79+
80+
for node_dir in node_dirs:
81+
result = check_output(['ls', '-la', node_dir]).decode()
82+
logging.info(f'Node directory: {node_dir}')
83+
for line in result.split('\n'):
84+
logging.info(line)
7585

76-
SMALL_HEIGHT = 40
77-
LARGE_HEIGHT = 100
78-
TIMEOUT = 300 + SMALL_HEIGHT + LARGE_HEIGHT
86+
SMALL_HEIGHT = 600
87+
LARGE_HEIGHT = 660
88+
TIMEOUT = 1450
7989
start = time.time()
8090

8191
boot_node = spin_up_node(config, near_root, node_dirs[0], 0, None, None)
@@ -90,12 +100,12 @@ def wait_for_height(target_height, rpc_node, sleep_time=2, bps_threshold=-1):
90100

91101
# Check current height
92102
try:
93-
status = rpc_node.get_status()
103+
status = rpc_node.get_status(False)
94104
new_height = status['sync_info']['latest_block_height']
95-
print(f"Height: {latest_height} => {new_height}")
105+
logging.info(f"Height: {latest_height} => {new_height}")
96106
latest_height = new_height
97107
except requests.ReadTimeout:
98-
print("Timeout Error")
108+
logging.info("Timeout Error")
99109

100110
# Computing bps
101111
cur_time = time.time()
@@ -112,17 +122,21 @@ def wait_for_height(target_height, rpc_node, sleep_time=2, bps_threshold=-1):
112122
bps = (head[1] - tail[1]) / (head[0] - tail[0])
113123

114124

115-
print(f"bps: {bps} queue length: {len(queue)}")
125+
logging.info(f"bps: {bps} queue length: {len(queue)}")
116126
time.sleep(sleep_time)
117127
assert bps is None or bps >= bps_threshold
118128

119129

120130
wait_for_height(SMALL_HEIGHT, boot_node)
121131

122132
observer = spin_up_node(config, near_root, node_dirs[2], 2, boot_node.node_key.pk, boot_node.addr())
133+
tracker = LogTracker(observer)
123134

124135
# Check that bps is not degraded
125136
wait_for_height(LARGE_HEIGHT, boot_node)
126137

127138
# Make sure observer2 is able to sync
128139
wait_for_height(SMALL_HEIGHT, observer)
140+
141+
tracker.reset()
142+
assert tracker.check("transition to State Sync")

0 commit comments

Comments
 (0)