Exemple #1
0
async def main():
    key_pair_0 = nacl.signing.SigningKey(key_seed())
    tracker = LogTracker(nodes[0])
    conn = await connect(nodes[0].addr())
    await run_handshake(conn,
                        nodes[0].node_key.pk,
                        key_pair_0,
                        listen_port=12345)

    num_nodes = 300

    def create_update():
        key_pairs = [key_pair_0] + [
            nacl.signing.SigningKey(key_seed()) for _ in range(num_nodes - 1)
        ]
        nonces = [[1] * num_nodes for _ in range(num_nodes)]

        edges = []
        for i in range(num_nodes):
            for j in range(i):
                edge = create_edge(key_pairs[i], key_pairs[j], nonces[i][j])
                edges.append(edge)
        return create_sync_data(edges=edges)

    asyncio.get_event_loop().create_task(consume(conn))

    for i in range(3):
        update = create_update()
        print("Sending update...")
        await conn.send(update)
        print("Sent...")
        await asyncio.sleep(1)

    assert tracker.check("delay_detector: LONG DELAY!") is False
Exemple #2
0
while True:
    assert time.time() - started < TIMEOUT
    status = nodes[1].get_status()
    height = status['sync_info']['latest_block_height']
    print(status)
    if height >= BLOCKS:
        break
    time.sleep(1)

print("Got to %s blocks, getting to fun stuff" % BLOCKS)

status = nodes[1].get_status()
print(status)

tracker0 = LogTracker(nodes[0])
res = nodes[1].json_rpc('adv_produce_blocks',
                        [MALICIOUS_BLOCKS, valid_blocks_only])
assert 'result' in res, res
print("Generated %s malicious blocks" % MALICIOUS_BLOCKS)

time.sleep(10)
status = nodes[0].get_status()
print(status)
height = status['sync_info']['latest_block_height']

assert height < 40

assert tracker0.check("Banned(BadBlockHeader)")

print("Epic")
Exemple #3
0
started = time.time()

print("Waiting for %s blocks..." % BLOCKS)

while True:
    assert time.time() - started < TIMEOUT
    status = nodes[1].get_status()
    height = status['sync_info']['latest_block_height']
    if height >= BLOCKS:
        break
    time.sleep(1)

print("Got to %s blocks, rebooting the first node" % BLOCKS)

nodes[0].kill()
nodes[0].reset_data()
tracker = LogTracker(nodes[0])
nodes[0].start(nodes[1].node_key.pk, nodes[1].addr())

while True:
    assert time.time() - started < TIMEOUT
    status = nodes[0].get_status()
    height = status['sync_info']['latest_block_height']
    if height >= BLOCKS:
        break
    time.sleep(1)

# make sure `nodes[0]` actually state synced
assert tracker.check("transition to State Sync")

Exemple #4
0
target_height = 60
while cur_height < target_height:
    status = nodes[0].get_status()
    cur_height = status['sync_info']['latest_block_height']
    time.sleep(1)

genesis_block = nodes[0].json_rpc('block', [0])
genesis_hash = genesis_block['result']['header']['hash']

nodes[1].start(nodes[1].node_key.pk, nodes[1].addr())
tracker = LogTracker(nodes[1])
time.sleep(1)

start_time = time.time()
node1_height = 0
nonce = 1
while node1_height <= cur_height:
    if time.time() - start_time > MAX_SYNC_WAIT:
        assert False, "state sync timed out"
    if nonce % 5 == 0:
        status1 = nodes[1].get_status()
        logger.info(status1)
        node1_height = status1['sync_info']['latest_block_height']
    tx = sign_payment_tx(nodes[0].signer_key, 'test1', 1, nonce,
                         base58.b58decode(genesis_hash.encode('utf8')))
    nodes[1].send_tx(tx)
    nonce += 1
    time.sleep(0.05)

assert tracker.check('transition to State Sync')
Exemple #5
0
nodes = start_cluster(
    2, 1, 2, None,
    [["epoch_length", 7], ["block_producer_kickout_threshold", 80]], {})

started = time.time()

nodes[1].kill()
nodes[2].kill()

corrupt_node(nodes[1])
tracker = LogTracker(nodes[1])

nodes[1].start(nodes[0].node_key.pk, nodes[0].addr())
time.sleep(2)
assert tracker.check("ADVERSARIAL")

print("Waiting for %s blocks..." % BLOCKS)

while True:
    assert time.time() - started < TIMEOUT
    status = nodes[1].get_status()
    height = status['sync_info']['latest_block_height']
    if height >= BLOCKS:
        break
    time.sleep(1)

print("Got to %s blocks, getting to fun stuff" % BLOCKS)

res = nodes[1].json_rpc('adv_set_weight', [1000, LARGE_WEIGHT, LARGE_WEIGHT])
assert 'result' in res, res
    if mode == 'manytx':
        if ctx.get_balances() == ctx.expected_balances:
            ctx.send_moar_txs(hash_, 3, False)
            print("Sending moar txs at height %s" % boot_height)
    time.sleep(0.1)

boot_heights = boot_node.get_all_heights()

assert catch_up_height in boot_heights, "%s not in %s" % (catch_up_height,
                                                          boot_heights)

tracker4.reset(
)  # the transition might have happened before we initialized the tracker
if catch_up_height >= 100:
    assert tracker4.check("transition to State Sync")
elif catch_up_height <= 30:
    assert not tracker4.check("transition to State Sync")

while True:
    assert time.time(
    ) - started < TIMEOUT, "Waiting for node 4 to connect to two peers"
    tracker4.reset()
    if tracker4.count("Consolidated connection with FullPeerInfo") == 2:
        break
    time.sleep(0.1)

tracker4.reset()
# Check that no message is dropped because a peer is disconnected
assert tracker4.count("Reason Disconnected") == 0
Exemple #7
0
while True:
    assert time.time() - started < TIMEOUT
    status = nodes[1].get_status()
    height = status['sync_info']['latest_block_height']
    if height >= BLOCKS:
        break
    time.sleep(1)

logger.info("Got to %s blocks, getting to fun stuff" % BLOCKS)

res = nodes[1].json_rpc('adv_set_weight', 1000)
assert 'result' in res, res
res = nodes[1].json_rpc('adv_disable_header_sync', [])
assert 'result' in res, res

tracker = LogTracker(nodes[2])
nodes[2].start(nodes[1].node_key.pk, nodes[1].addr())
time.sleep(2)

while True:
    assert time.time() - started < TIMEOUT
    status = nodes[2].get_status()
    height = status['sync_info']['latest_block_height']
    if height >= BLOCKS:
        break

assert tracker.check('ban a fraudulent peer')

logger.info("Epic")
Exemple #8
0
    time.sleep(2)

should_sync.value = True

logger.info("sync node 1")

start = time.time()

tracker0 = LogTracker(nodes[0])
tracker1 = LogTracker(nodes[1])

while True:
    assert time.time() - start < TIMEOUT

    if should_ban:
        if tracker1.check(BAN_STRING):
            break
    else:
        status = nodes[0].get_status()
        cur_height = status['sync_info']['latest_block_height']

        status1 = nodes[1].get_status()
        node1_height = status1['sync_info']['latest_block_height']
        if abs(node1_height -
               cur_height) < 5 and status1['sync_info']['syncing'] is False:
            break
    time.sleep(2)

if not should_ban and (tracker0.check(BAN_STRING)
                       or tracker1.check(BAN_STRING)):
    assert False, "unexpected ban of peers"
Exemple #9
0
    status = boot_node.get_status()
    boot_height = status['sync_info']['latest_block_height']
    seen_boot_heights.add(boot_height)

    if mode == 'manytx':
        if ctx.get_balances() == ctx.expected_balances:
            ctx.send_moar_txs(hash_, 3, False)
            print("Sending moar txs at height %s" % boot_height)
    time.sleep(0.1)

assert catch_up_height in seen_boot_heights, "%s not in %s" % (
    catch_up_height, seen_boot_heights)

if catch_up_height >= 100:
    assert tracker.check("State 0")
elif catch_up_height <= 30:
    assert not tracker.check("State 0")

if mode == 'manytx':
    while ctx.get_balances() != ctx.expected_balances:
        assert time.time() - started < TIMEOUT
        print(
            "Waiting for the old node to catch up. Current balances: %s; Expected balances: %s"
            % (ctx.get_balances(), ctx.expected_balances))
        time.sleep(1)

    # requery the balances from the newly started node
    ctx.nodes.append(node2)
    ctx.act_to_val = [2, 2, 2]