Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
check = infra.checker.Checker()
rs = log_msgs(primary, txs)
check_responses(rs, True, check, check_commit)
network.wait_for_node_commit_sync()
check_nodes_have_msgs(backups, txs)
recovered_network = test(network, args)
network.stop_all_nodes()
network = recovered_network
old_txs = Txs(args.msgs_per_recovery, recovery_idx, since_beginning=True)
check_nodes_have_msgs(recovered_network.nodes, old_txs)
LOG.success("Recovery complete on all nodes")
def print_and_upload_result(self, name, metrics, line):
with open(self.out, "rb") as out:
lines = out.read().splitlines()
result = lines[-line:]
LOG.success(f"Result for {self.name}:")
self._print_upload_perf(name, metrics, result)
def setup(self):
self.remote.setup()
LOG.success(f"Remote client {self.name} setup")
def start_in_recovery(self, args, ledger_file, sealed_secrets):
primary = self._start_all_nodes(
args, recovery=True, ledger_file=ledger_file, sealed_secrets=sealed_secrets
)
self.wait_for_all_nodes_to_catch_up(primary)
LOG.success("All nodes joined recovered public network")
self.client.remove_download_result(download.gid)
except ClientException as error:
logger.exception(error)
result.append(error)
else:
logger.success(f"Removed download result {download.gid}")
result.append(True)
else:
logger.debug(f"Try to remove download {download.gid}")
try:
removed_gid = remove_func(download.gid)
except ClientException as error:
logger.exception(error)
result.append(error)
else:
logger.success(f"Removed download {download.gid}")
result.append(True)
try:
self.client.remove_download_result(download.gid)
except ClientException as error2:
logger.debug(f"Failed to remove download result {download.gid}")
logger.opt(exception=True).trace(error2)
if removed_gid != download.gid:
logger.debug(
f"Removed download GID#{removed_gid} is different than download GID#{download.gid}"
)
try:
self.client.remove_download_result(removed_gid)
except ClientException as error2:
logger.debug(f"Failed to remove download result {removed_gid}")
logger.opt(exception=True).trace(error2)
component._stop = True
await asyncio.sleep(1)
# Cancel all of the remaining tasks
logger.trace("Cancelling all remaining tasks")
for task in pending:
task.cancel()
# Raise exceptions, if any
logger.trace("Raising exceptions, if any")
for task in done:
task.result()
# we only reach this line if things went well
logger.success(end_msg)
except RuntimeError as e:
logger.error(f"Got {repr(e)}")
logger.error("Protocol execution is stopping NOW!")
logger.critical(end_msg)
except ProtocolCancelled:
logger.error(f"Stop button pressed.")
logger.critical(end_msg)
except: # noqa
logger.exception("Failed to execute protocol due to uncaught error!")
logger.critical(end_msg)
finally:
# set some protocol metadata
LOG.debug(f"User {regulator} successfully registered as regulator")
with primary.user_client(format="msgpack", user_id=regulators[0].name) as c:
for bank in banks:
check = infra.checker.Checker()
check(
c.rpc(
"BK_register", {"bank_id": bank.ccf_id, "country": bank.country}
),
result=bank.ccf_id,
)
check(c.rpc("BK_get", {"id": bank.ccf_id}), result=bank.country)
LOG.debug(f"User {bank} successfully registered as bank")
LOG.success(
f"{len(regulators)} regulator and {len(banks)} bank(s) successfully setup"
)
tx_id = 0 # Tracks how many transactions have been issued
LOG.info(f"Loading scenario file as bank {banks[0].ccf_id} ({banks[0].name})")
with primary.user_client(format="msgpack", user_id=regulators[0].name) as reg_c:
with primary.user_client(
format="msgpack", user_id=banks[0].name, log_file=None
) as c:
with open(args.datafile, newline="") as f:
start_time = perf_counter()
datafile = csv.DictReader(f)
for row in datafile:
json_tx = {
"src": row["origin"],
log_level = VERBOSITY_LOG_LEVELS[verbosity]
if log_to_stdout:
logger.add(
sys.stdout,
level=log_level,
format=LOG_FORMAT,
backtrace=False
)
if log_to_file:
log_dir = ensure_log_dir(username=username)
log_file = (log_dir / time.strftime('%Y-%m-%d_%H-%M-%S')).with_suffix('.log')
logger.success("Logging to file: {}", log_file)
logger.add(
log_file,
level=log_level,
format=LOG_FORMAT,
backtrace=False,
encoding='utf8',
newline='\n'
)