Ejemplo n.º 1
0
def client_tx(client, clients, inventory):
    len_clients = len(clients)

    sender = client
    recipient_delta = random.randint(0, len_clients - 1)

    # Find our own key
    key = 0
    for i, client_ in enumerate(clients):
        if client_ == client:
            key = i

    if recipient_delta == key:  # choose neighbor if randint chose itself
        recipient_delta += 1
    recipient = clients[recipient_delta]

    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
    balance_ = balance(endpoint, sending_address)

    data = ""
    for i in xrange(0, 10000):
        data += "01"
    gas = 1000000

    total_value = value + gas * 10000000000000

    global successful
    global total_txs_tried
    for tx in xrange(1, txs_per_client):
        if total_value < balance_:
            total_txs_tried += 1
            balance_ -= value
            result = send_tx(endpoint, sending_address, receiving_address,
                             value, gas, data)
            if result:
                successful += 1
            time.sleep(3)
Ejemplo n.º 2
0
def client_tx(client, clients, inventory):
    len_clients = len(clients)

    sender = client
    recipient_delta = random.randint(0, len_clients - 1)

    # Find our own key
    key = 0
    for i, client_ in enumerate(clients):
        if client_ == client:
            key = i

    if recipient_delta == key:  # choose neighbor if randint chose itself
        recipient_delta += 1
    recipient = clients[recipient_delta]

    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
    balance_ = balance(endpoint, sending_address)

    data = ""
    for i in xrange(0, 10000):
        data += "01"
    gas = 1000000

    total_value = value + gas * 10000000000000

    global successful
    global total_txs_tried
    for tx in xrange(1, txs_per_client):
        if total_value < balance_:
            total_txs_tried += 1
            balance_ -= value
            result = send_tx(endpoint, sending_address, receiving_address, value, gas, data)
            if result:
                successful += 1
            time.sleep(3)
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
Ejemplo n.º 4
0
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