#!/usr/bin/env python3 """Node executable of the math topology. The orchestrator starts this program once per turn, writes the incoming envelope as JSON on stdin and reads the outgoing envelope from stdout. The behaviour is selected by --role, which the topology sets to the node id (formalizer_a, formalizer_b, solver_a, solver_b, verifier, adversary or arbiter). Extra arguments added by the orchestrator are accepted and ignored. """ import argparse import json import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lgmath import agents, faults # noqa: E402 def main() -> int: parser = argparse.ArgumentParser(description="Math topology node") parser.add_argument("--role", required=True, choices=sorted(agents.STEPS)) parser.add_argument("--node-id", default=None) args, _ignored = parser.parse_known_args() faults.from_env() incoming = json.loads(sys.stdin.read()) outgoing = agents.run_step(args.role, incoming, args.node_id or args.role) sys.stdout.write(json.dumps(outgoing)) return 0 if __name__ == "__main__": sys.exit(main())