Beispiel #1
0
 def stop(self):
     # self.execute_rpc('stop')
     # bash.check_output(self.execute_rpc_string(('stop', '')))
     bash.check_output(
         f"docker exec simcoin-{self._name} bitcoin-cli -regtest -rpcuser=admin -rpcpassword=admin  stop"
     )
     logging.info('Send stop to node={}'.format(self.name))
Beispiel #2
0
    def wait_until_rpc_ready(self):
        logging.debug("# Waiting for docker instances to become ready")
        while True:
            try:
                bash.check_output("nc -z -w1 {} {}".format(
                    self._ip, config.rpc_port),
                                  purpose="Wait for port beeing open")
                logging.info(f"Success for {self.ip}")
                break
            except Exception:
                logging.debug("Waiting with netcat until port is open")

        while True:
            try:
                self.execute_rpc('getnetworkinfo')
                break
            except JSONRPCError:
                logging.debug('Waiting until RPC of node={} is ready.'.format(
                    self._name))
                utils.sleep(1)
Beispiel #3
0
 def is_running(self):
     return bash.check_output(dockercmd.check_if_running(
         self._name)) == 'true'
Beispiel #4
0
 def run(self, connect_to_ips):
     bash.check_output(
         bitcoincmd.start(self._name, str(self._ip), self._docker_image,
                          self._path, connect_to_ips))
Beispiel #5
0
 def rm(self):
     return bash.check_output(dockercmd.rm_container(self._name))
Beispiel #6
0
 def add_latency(self, zones):
     for cmd in tccmd.create(self._name, zones, self._latency):
         bash.check_output(cmd)
Beispiel #7
0
 def rm_peers_file(self):
     return bash.check_output(bitcoincmd.rm_peers(self._name))
Beispiel #8
0
def run_eval_function(latency: int, nodes: int = 2) -> bool:
    #  check_output("generate nodes")
    #  check_output("simulate")
    #  forks = bash("bash ./find_\ bounds.sh")
    #  return forks == 10

    print(f"new run with latency {latency} and nodes {nodes}")

    ticks, forks_expected = ticks_forky()

    # try:
    check_output(f"""
        cd code; python3.6 simcoin.py nodes \
            --group-a {nodes} .5 {latency} simcoin/bitcoin:v15.0.1 \
            --group-b {nodes} .5 {latency} simcoin/bitcoin:v15.0.1 \
        """)
    check_output(f"""
        cd code; python3.6 simcoin.py network
        """)
    check_output(  # write ticks.csv
        f"""
        echo "{ticks}" > ./data/ticks.csv
        """)

    #  TODO explicitly write config to file

    stdout_buffer = check_output(  # TODO handle failures correctly
        f"""
        cd code; python3.6 simcoin.py simulate \
            --tick-duration=0.5 \
            2>&1 > bounds_debug.log
        """)

    if status_code != 0:
        print(f"status code was {status_code}, this failed the run")
        return False
    # TODO explicitly pass in config

    check_output("sync")
    forks = int(check_output("make getForks"))

    print(check_output("ls ./data/last_run/postprocessing/"))

    print(f"Got {forks} forks with latency {latency}")

    # except:
    #     print("fail in eval function")
    #     # raise Exception("failed run")
    #     raise

    print(f"Got {forks} forks and was expecting {forks_expected} forks")
    print("status of comparrison: " +
          str(forks == forks_expected))  # f"{forks_expected}")
    return forks == forks_expected  # f"{forks_expected}"