def run(run_clients): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event('started') if not run_clients: # don't run clients if --norun option is set return inventory = Inventory() clients = inventory.clients start = time.time() log_event('starting.clients') start_clients(clients=clients, req_num_peers=req_peer, impls=impls, enable_mining=enable_mining) log_event('starting.clients.done') print 'let it run for %d secs...' % scenario_run_time time.sleep(scenario_run_time) if stop_clients_at_scenario_end: log_event('stopping_clients') stop_clients(clients=clients, impls=impls) log_event('stopping_clients.done') global offset offset += time.time() - start print "Total offset: %ss" % offset
def run(run_clients): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event('started') if not run_clients: # don't run clients if --norun option is set return inventory = Inventory() clients = inventory.clients start = time.time() log_event('starting.clients') start_clients(clients=clients, impls=impls, enable_mining=True) log_event('starting.clients.done') print 'let it run for %d secs...' % scenario_run_time_s time.sleep(scenario_run_time_s) log_event('stopping_clients') stop_clients(clients=clients, impls=impls) log_event('stopping_clients.done') global max_time_to_reach_consensus consensus_start = time.time() # start all clients without mining log_event('start_all_clients_again') start_clients(clients=clients, impls=impls, enable_mining=False) log_event('start_all_clients_again.done') # let them agree on a block log_event('wait_for_consensus') time.sleep(max_time_to_reach_consensus) log_event('wait_for_consensus.done') # stop all clients log_event('stop_all_clients') stop_clients(clients=clients, impls=impls) log_event('stop_all_clients.done') global offset offset += time.time() - start max_time_to_reach_consensus += time.time() - consensus_start print "Total offset: %ss" % offset print "Consensus offset: %ss" % max_time_to_reach_consensus
def run(run_clients, on_testnet): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event('started') if not run_clients: return inventory = Inventory() clients = list(inventory.clients) fillnode = clients.pop() len_clients = len(clients) total_txs = txs_per_client * len_clients log_event('starting.clients') start_clients(clients=clients, enable_mining=not on_testnet, testnet=on_testnet) log_event('starting.clients.done') # Fill testnodes with ether log_event('filling.clients') filler_privkey = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4" start_clients(clients=[fillnode], enable_mining=False, privkey=filler_privkey, testnet=on_testnet) if on_testnet: time.sleep(time_to_sync_on_testnet) else: time.sleep(15) rpc_host = inventory.clients[fillnode] rpc_port = 8545 # hard coded FIXME if we get multiple clients per ec endpoint = 'http://%s:%d' % (rpc_host, rpc_port) sender = "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826" fill_successful = 0 for client in clients: to = "0x%s" % nodeid_tool.coinbase(str(client)) tx = transact(endpoint, sender=sender, to=to, value=100000000000000000000) if tx: fill_successful += 1 time.sleep(3) log_event('filling.result', successful=fill_successful, total_txs_tried=len_clients) time.sleep(max_time_to_reach_consensus) start = time.time() # Client futures with tx loop with futures.ThreadPoolExecutor(max_workers=len_clients) as executor: future_to_client = dict( (executor.submit(client_tx, client, clients, inventory), client) for client in clients) for future in futures.as_completed(future_to_client, 300): client = future_to_client[future] if future.exception() is not None: print '%s generated an exception: %r' % (client, future.exception()) log_event('txs_result', successful=successful, total_txs_tried=total_txs_tried, max_total_txs=total_txs) log_event('waiting', delay=max_time_to_reach_consensus) time.sleep(max_time_to_reach_consensus) log_event('waiting.done') if stop_clients_at_scenario_end: log_event('stopping_clients') stop_clients(clients=clients) log_event('stopping_clients.done') global offset offset += time.time() - start print "Total offset: %s" % offset
def run(run_clients): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event('started') if not run_clients: return inventory = Inventory() clients = inventory.clients # create schedule events = [] num_clients = len(inventory.clients) num_scheduled_clients = int(num_clients * churn_ratio) if num_clients > 4 else num_clients for c in list(clients)[:num_scheduled_clients]: events.extend(mkschedule(c)) events = sorted(events, key=lambda x: x['time']) assert len(events) print '\n'.join(repr(e) for e in events) # reset client storage # use client-reset.yml playbook # start-up all clients log_event('start_all_clients') start_clients(clients=clients, impls=impls) log_event('start_all_clients.done') # run events log_event('run_churn_schedule') elapsed = 0 while events: e = events.pop(0) # sleep until time has come if elapsed < e['time']: time.sleep(e['time'] - elapsed) elapsed = e['time'] cmd = dict(running=start_clients, stopped=stop_clients)[e['state']] client = e['client'] print elapsed, cmd.__name__, client cmd(clients=[client], impls=impls) log_event('run_churn_schedule.done') # stop all clients log_event('stop_all_clients') stop_clients(clients=clients, impls=impls) log_event('stop_all_clients.done') start = time.time() # start all clients without mining log_event('start_all_clients_again') start_clients(clients=clients, impls=impls, enable_mining=False) log_event('start_all_clients_again.done') # let them agree on a block log_event('wait_for_consensus') time.sleep(max_time_to_reach_consensus) log_event('wait_for_consensus.done') # stop all clients log_event('stop_all_clients') stop_clients(clients=clients, impls=impls) log_event('stop_all_clients.done') global offset offset += time.time() - start print "Total offset: %ss" % offset
def run(run_clients): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event('started') if not run_clients: return inventory = Inventory() clients = list(inventory.clients) log_event('starting_one_client') start_clients(clients=clients[:1], impls=impls) log_event('starting_one_client.done') print 'mine a bit' blocktime = 12 # intitial difficulty is very high, takes around 2 minutes for initial mined block delay = blocktime * 14 log_event('waiting', delay=delay) time.sleep(delay) # start other clients log_event('starting_other_clients') start_clients(clients=clients[1:], impls=impls) log_event('starting_other_clients.done') # create tx sender = clients[0] recipient = clients[1] rpc_host = inventory.clients[sender] rpc_port = 8545 # hard coded FIXME if we get multiple clients per ec endpoint = 'http://%s:%d' % (rpc_host, rpc_port) sending_address = coinbase(endpoint) receiving_address = "0x%s" % nodeid_tool.coinbase(str(recipient)) print 'sending addr %s, receiving addr %s' % (sending_address, receiving_address) value = 100 # print balance(endpoint, sending_address) # this fails randomly, why ? assert value < balance(endpoint, sending_address) start = time.time() log_event('sending_transaction', show=False, sender=sending_address, to=receiving_address, value=value) tx = transact(endpoint, sender=sending_address, to=receiving_address, value=value) log_event('sending_transaction.done', show=False, result=tx) log_event('waiting', delay=max_time_to_reach_consensus) time.sleep(max_time_to_reach_consensus) log_event('waiting.done') if stop_clients_at_scenario_end: log_event('stopping_clients') stop_clients(clients=clients, impls=impls) log_event('stopping_clients.done') global offset offset += time.time() - start print "Total offset: %s" % offset
def run(run_clients): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event('started') if not run_clients: return inventory = Inventory() clients = inventory.clients # create schedule events = [] num_clients = len(inventory.clients) num_scheduled_clients = int( num_clients * churn_ratio) if num_clients > 4 else num_clients for c in list(clients)[:num_scheduled_clients]: events.extend(mkschedule(c)) events = sorted(events, key=lambda x: x['time']) assert len(events) print '\n'.join(repr(e) for e in events) # reset client storage # use client-reset.yml playbook # start-up all clients log_event('start_all_clients') start_clients(clients=clients, impls=impls) log_event('start_all_clients.done') # run events log_event('run_churn_schedule') elapsed = 0 while events: e = events.pop(0) # sleep until time has come if elapsed < e['time']: time.sleep(e['time'] - elapsed) elapsed = e['time'] cmd = dict(running=start_clients, stopped=stop_clients)[e['state']] client = e['client'] print elapsed, cmd.__name__, client cmd(clients=[client], impls=impls) log_event('run_churn_schedule.done') # stop all clients log_event('stop_all_clients') stop_clients(clients=clients, impls=impls) log_event('stop_all_clients.done') start = time.time() # start all clients without mining log_event('start_all_clients_again') start_clients(clients=clients, impls=impls, enable_mining=False) log_event('start_all_clients_again.done') # let them agree on a block log_event('wait_for_consensus') time.sleep(max_time_to_reach_consensus) log_event('wait_for_consensus.done') # stop all clients log_event('stop_all_clients') stop_clients(clients=clients, impls=impls) log_event('stop_all_clients.done') global offset offset += time.time() - start print "Total offset: %ss" % offset
def run(run_clients, on_testnet): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event("started") if not run_clients: return inventory = Inventory() clients = list(inventory.clients) fillnode = clients.pop() len_clients = len(clients) total_txs = txs_per_client * len_clients log_event("starting.clients") start_clients(clients=clients, enable_mining=not on_testnet, testnet=on_testnet) log_event("starting.clients.done") # Fill testnodes with ether log_event("filling.clients") filler_privkey = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4" start_clients(clients=[fillnode], enable_mining=False, privkey=filler_privkey, testnet=on_testnet) if on_testnet: time.sleep(time_to_sync_on_testnet) else: time.sleep(15) rpc_host = inventory.clients[fillnode] rpc_port = 8545 # hard coded FIXME if we get multiple clients per ec endpoint = "http://%s:%d" % (rpc_host, rpc_port) sender = "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826" fill_successful = 0 for client in clients: to = "0x%s" % nodeid_tool.coinbase(str(client)) tx = transact(endpoint, sender=sender, to=to, value=100000000000000000000) if tx: fill_successful += 1 time.sleep(3) log_event("filling.result", successful=fill_successful, total_txs_tried=len_clients) time.sleep(max_time_to_reach_consensus) start = time.time() # Client futures with tx loop with futures.ThreadPoolExecutor(max_workers=len_clients) as executor: future_to_client = dict((executor.submit(client_tx, client, clients, inventory), client) for client in clients) for future in futures.as_completed(future_to_client, 300): client = future_to_client[future] if future.exception() is not None: print "%s generated an exception: %r" % (client, future.exception()) log_event("txs_result", successful=successful, total_txs_tried=total_txs_tried, max_total_txs=total_txs) log_event("waiting", delay=max_time_to_reach_consensus) time.sleep(max_time_to_reach_consensus) log_event("waiting.done") if stop_clients_at_scenario_end: log_event("stopping_clients") stop_clients(clients=clients) log_event("stopping_clients.done") global offset offset += time.time() - start print "Total offset: %s" % offset