def _is_progressed_node(machine): """ Internal function to check if a machine/node is making progress. """ try: start_header = blockchain.get_latest_header( f"http://{machine['ip']}:9500/") except (rpc_exceptions.RPCError, rpc_exceptions.RequestsTimeoutError, rpc_exceptions.RequestsError) as e: log.error(traceback.format_exc()) log.error(f"error on RPC from {machine['ip']}. Error {e}") return False start_time = time.time() while time.time() - start_time < condition['max_seconds_since_last_block']: try: curr_header = blockchain.get_latest_header( f"http://{machine['ip']}:9500/") except (rpc_exceptions.RPCError, rpc_exceptions.RequestsTimeoutError, rpc_exceptions.RequestsError) as e: log.error(traceback.format_exc()) log.error(f"error on RPC from {machine['ip']}. Error {e}") return False if curr_header['blockNumber'] > start_header['blockNumber']: return True time.sleep(1) return False
def _snapshot(machine, do_bucket_sync=False): """ Internal worker to snapshot a node's DB. If `do_bucket_sync` is disabled, a dummy bucket_sync thread will be returned. Returns thread for bucket rsync process. """ log.debug( f'started snapshot on machine {machine["ip"]} (s{machine["shard"]})') try: height = blockchain.get_latest_header( f"http://{machine['ip']}:9500/" )['blockNumber'] if do_bucket_sync else -1 _stop_harmony(machine) _local_sync(machine) except Exception as e: _start_harmony(machine) raise e from e _start_harmony(machine) log.debug( f'finished local snapshot on machine {machine["ip"]} (s{machine["shard"]})' ) if not do_bucket_sync: log.debug("skipping bucket sync...") return ThreadPool().apply_async(lambda: True) return ThreadPool().apply_async(_bucket_sync, (machine, height))
def test_errors(): with pytest.raises(exceptions.RPCError): blockchain.chain_id(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_node_metadata(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_peer_info(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.protocol_version(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_shard(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_staking_epoch(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_prestaking_epoch(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_sharding_structure(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_leader_address(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.is_last_block(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.epoch_last_block(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_circulating_supply(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_total_supply(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_number(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_current_epoch(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_last_cross_links(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_gas_price(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_num_peers(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_version(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_latest_header(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_header_by_number(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_latest_chain_headers(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_by_number(0, endpoint=fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_by_hash('', endpoint=fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_transaction_count_by_number(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_transaction_count_by_hash('', fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_staking_transaction_count_by_number(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_staking_transaction_count_by_hash('', fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_blocks(0, 1, endpoint=fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_signers(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_signers_keys(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.is_block_signer(0, '', fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_signed_blocks('', fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_validators(1, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_validator_keys(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.in_sync(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.beacon_in_sync(fake_shard)