async def main(): key_pair_0 = nacl.signing.SigningKey(key_seed()) tracker = LogTracker(nodes[0]) conn = await connect(nodes[0].addr()) await run_handshake(conn, nodes[0].node_key.pk, key_pair_0, listen_port=12345) num_nodes = 300 def create_update(): key_pairs = [key_pair_0] + [ nacl.signing.SigningKey(key_seed()) for _ in range(num_nodes - 1) ] nonces = [[1] * num_nodes for _ in range(num_nodes)] edges = [] for i in range(num_nodes): for j in range(i): edge = create_edge(key_pairs[i], key_pairs[j], nonces[i][j]) edges.append(edge) return create_sync_data(edges=edges) asyncio.get_event_loop().create_task(consume(conn)) for i in range(3): update = create_update() print("Sending update...") await conn.send(update) print("Sent...") await asyncio.sleep(1) assert tracker.check("delay_detector: LONG DELAY!") is False
while True: assert time.time() - started < TIMEOUT status = nodes[1].get_status() height = status['sync_info']['latest_block_height'] print(status) if height >= BLOCKS: break time.sleep(1) print("Got to %s blocks, getting to fun stuff" % BLOCKS) status = nodes[1].get_status() print(status) tracker0 = LogTracker(nodes[0]) res = nodes[1].json_rpc('adv_produce_blocks', [MALICIOUS_BLOCKS, valid_blocks_only]) assert 'result' in res, res print("Generated %s malicious blocks" % MALICIOUS_BLOCKS) time.sleep(10) status = nodes[0].get_status() print(status) height = status['sync_info']['latest_block_height'] assert height < 40 assert tracker0.check("Banned(BadBlockHeader)") print("Epic")
started = time.time() print("Waiting for %s blocks..." % BLOCKS) while True: assert time.time() - started < TIMEOUT status = nodes[1].get_status() height = status['sync_info']['latest_block_height'] if height >= BLOCKS: break time.sleep(1) print("Got to %s blocks, rebooting the first node" % BLOCKS) nodes[0].kill() nodes[0].reset_data() tracker = LogTracker(nodes[0]) nodes[0].start(nodes[1].node_key.pk, nodes[1].addr()) while True: assert time.time() - started < TIMEOUT status = nodes[0].get_status() height = status['sync_info']['latest_block_height'] if height >= BLOCKS: break time.sleep(1) # make sure `nodes[0]` actually state synced assert tracker.check("transition to State Sync")
status = nodes[0].get_status() block_hash = status['sync_info']['latest_block_hash'] cur_height = status['sync_info']['latest_block_height'] target_height = 60 while cur_height < target_height: status = nodes[0].get_status() cur_height = status['sync_info']['latest_block_height'] time.sleep(1) genesis_block = nodes[0].json_rpc('block', [0]) genesis_hash = genesis_block['result']['header']['hash'] nodes[1].start(nodes[1].node_key.pk, nodes[1].addr()) tracker = LogTracker(nodes[1]) time.sleep(1) start_time = time.time() node1_height = 0 nonce = 1 while node1_height <= cur_height: if time.time() - start_time > MAX_SYNC_WAIT: assert False, "state sync timed out" if nonce % 5 == 0: status1 = nodes[1].get_status() logger.info(status1) node1_height = status1['sync_info']['latest_block_height'] tx = sign_payment_tx(nodes[0].signer_key, 'test1', 1, nonce, base58.b58decode(genesis_hash.encode('utf8'))) nodes[1].send_tx(tx)
Spawn a cluster with four nodes. Check that no node tries to connect to another node that is currently connected. """ import sys, time sys.path.append('lib') from cluster import start_cluster from utils import LogTracker TIMEOUT = 150 BLOCKS = 20 nodes = start_cluster(4, 0, 4, None, [], {}) started = time.time() trackers = [LogTracker(node) for node in nodes] while True: assert time.time() - started < TIMEOUT status = nodes[0].get_status() height = status['sync_info']['latest_block_height'] if height >= BLOCKS: break assert all(not tracker.check('Dropping handshake (Active Peer).') for tracker in trackers)
if mode == 'onetx' and not sent_txs: ctx.send_moar_txs(hash_, 3, False) sent_txs = True elif mode == 'manytx': if ctx.get_balances() == ctx.expected_balances: ctx.send_moar_txs(hash_, 3, False) print("Sending moar txs at height %s" % new_height) time.sleep(0.1) if mode == 'onetx': assert ctx.get_balances() == ctx.expected_balances node2 = spin_up_node(config, near_root, node_dirs[2], 2, boot_node.node_key.pk, boot_node.addr()) tracker = LogTracker(node2) time.sleep(3) catch_up_height = 0 while catch_up_height < observed_height: assert time.time() - started < TIMEOUT status = node2.get_status() new_height = status['sync_info']['latest_block_height'] if new_height > catch_up_height: catch_up_height = new_height print("Second node got to height %s" % new_height); status = boot_node.get_status() boot_height = status['sync_info']['latest_block_height'] if mode == 'manytx':
TIMEOUT = 300 BLOCKS = 30 LARGE_WEIGHT = '1267650600228229401496703205376' nodes = start_cluster( 2, 1, 2, None, [["epoch_length", 7], ["block_producer_kickout_threshold", 80]], {}) started = time.time() nodes[1].kill() nodes[2].kill() corrupt_node(nodes[1]) tracker = LogTracker(nodes[1]) nodes[1].start(nodes[0].node_key.pk, nodes[0].addr()) time.sleep(2) assert tracker.check("ADVERSARIAL") print("Waiting for %s blocks..." % BLOCKS) while True: assert time.time() - started < TIMEOUT status = nodes[1].get_status() height = status['sync_info']['latest_block_height'] if height >= BLOCKS: break time.sleep(1)
queue.append((cur_time, latest_height)) while len(queue) > 2 and queue[0][0] <= cur_time - 7: queue.pop(0) if len(queue) <= 1: bps = None else: head = queue[-1] tail = queue[0] bps = (head[1] - tail[1]) / (head[0] - tail[0]) logging.info(f"bps: {bps} queue length: {len(queue)}") time.sleep(sleep_time) assert bps is None or bps >= bps_threshold wait_for_height(SMALL_HEIGHT, boot_node) observer = spin_up_node(config, near_root, node_dirs[2], 2, boot_node=boot_node) tracker = LogTracker(observer) # Check that bps is not degraded wait_for_height(LARGE_HEIGHT, boot_node) # Make sure observer2 is able to sync wait_for_height(SMALL_HEIGHT, observer) tracker.reset() assert tracker.check("transition to State Sync")
if mode == 'onetx' and not sent_txs: ctx.send_moar_txs(hash_, 3, False) sent_txs = True elif mode == 'manytx': if ctx.get_balances() == ctx.expected_balances: ctx.send_moar_txs(hash_, 3, False) print("Sending moar txs at height %s" % new_height) time.sleep(0.1) if mode == 'onetx': assert ctx.get_balances() == ctx.expected_balances node4 = spin_up_node(config, near_root, node_dirs[4], 4, boot_node.node_key.pk, boot_node.addr(), [0, 1]) tracker4 = LogTracker(node4) time.sleep(3) catch_up_height = 0 while catch_up_height < observed_height: assert time.time() - started < TIMEOUT, "Waiting for node 4 to catch up" status = node4.get_status() new_height = status['sync_info']['latest_block_height'] print("Latest block at:", new_height) if new_height > catch_up_height: catch_up_height = new_height print("Last observer got to height %s" % new_height) status = boot_node.get_status() boot_height = status['sync_info']['latest_block_height']
while True: assert time.time() - started < TIMEOUT status = nodes[1].get_status() height = status['sync_info']['latest_block_height'] if height >= BLOCKS: break time.sleep(1) logger.info("Got to %s blocks, getting to fun stuff" % BLOCKS) res = nodes[1].json_rpc('adv_set_weight', 1000) assert 'result' in res, res res = nodes[1].json_rpc('adv_disable_header_sync', []) assert 'result' in res, res tracker = LogTracker(nodes[2]) nodes[2].start(nodes[1].node_key.pk, nodes[1].addr()) time.sleep(2) while True: assert time.time() - started < TIMEOUT status = nodes[2].get_status() height = status['sync_info']['latest_block_height'] if height >= BLOCKS: break assert tracker.check('ban a fraudulent peer') logger.info("Epic")
status = nodes[0].get_status() cur_height = status['sync_info']['latest_block_height'] while cur_height <= 110: status = nodes[0].get_status() cur_height = status['sync_info']['latest_block_height'] time.sleep(2) should_sync.value = True logger.info("sync node 1") start = time.time() tracker0 = LogTracker(nodes[0]) tracker1 = LogTracker(nodes[1]) while True: assert time.time() - start < TIMEOUT if should_ban: if tracker1.check(BAN_STRING): break else: status = nodes[0].get_status() cur_height = status['sync_info']['latest_block_height'] status1 = nodes[1].get_status() node1_height = status1['sync_info']['latest_block_height'] if abs(node1_height -
if mode == 'onetx' and not sent_txs: ctx.send_moar_txs(hash_, 3, False) sent_txs = True elif mode == 'manytx': if ctx.get_balances() == ctx.expected_balances: ctx.send_moar_txs(hash_, 3, False) print("Sending moar txs at height %s" % new_height) time.sleep(0.1) if mode == 'onetx': assert ctx.get_balances() == ctx.expected_balances node4 = spin_up_node(config, near_root, node_dirs[4], 4, boot_node.node_key.pk, boot_node.addr(), [0, 1]) tracker4 = LogTracker(node4) time.sleep(3) catch_up_height = 0 while catch_up_height < observed_height: assert time.time() - started < TIMEOUT status = node4.get_status() new_height = status['sync_info']['latest_block_height'] print("Latest block at:", new_height) if new_height > catch_up_height: catch_up_height = new_height print("Last observer got to height %s" % new_height) status = boot_node.get_status() boot_height = status['sync_info']['latest_block_height']
if mode == 'onetx' and not sent_txs: ctx.send_moar_txs(hash_, 3, False) sent_txs = True elif mode == 'manytx': if ctx.get_balances() == ctx.expected_balances: ctx.send_moar_txs(hash_, 3, False) print("Sending moar txs at height %s" % new_height) time.sleep(0.1) if mode == 'onetx': assert ctx.get_balances() == ctx.expected_balances node2 = spin_up_node(config, near_root, node_dirs[2], 2, boot_node.node_key.pk, boot_node.addr()) tracker = LogTracker(node2) catch_up_height = 0 while catch_up_height < observed_height: assert time.time() - started < TIMEOUT status = node2.get_status() new_height = status['sync_info']['latest_block_height'] if new_height > catch_up_height: catch_up_height = new_height print("Second node got to height %s" % new_height) status = boot_node.get_status() boot_height = status['sync_info']['latest_block_height'] seen_boot_heights.add(boot_height) if mode == 'manytx':
if mode == 'onetx' and not sent_txs: ctx.send_moar_txs(hash_, 3, False) sent_txs = True elif mode == 'manytx': if ctx.get_balances() == ctx.expected_balances: ctx.send_moar_txs(hash_, 3, False) print("Sending moar txs at height %s" % new_height) time.sleep(0.1) if mode == 'onetx': assert ctx.get_balances() == ctx.expected_balances node2 = spin_up_node(config, near_root, node_dirs[2], 2, boot_node.node_key.pk, boot_node.addr()) tracker = LogTracker(node2) time.sleep(3) catch_up_height = 0 while catch_up_height < observed_height: assert time.time() - started < TIMEOUT status = node2.get_status() new_height = status['sync_info']['latest_block_height'] if new_height > catch_up_height: catch_up_height = new_height print("Second node got to height %s" % new_height) status = boot_node.get_status() boot_height = status['sync_info']['latest_block_height'] if mode == 'manytx':