コード例 #1
0
    "tracked_shards": [0]
}
nodes = start_cluster(1, 1, 1, None, [["epoch_length", EPOCH_LENGTH]], {
    0: node0_config,
    1: node1_config
}, Handler)

utils.wait_for_blocks(nodes[0], target=110, poll_interval=2)

should_sync.value = True

logger.info("sync node 1")

start = time.time()

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

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

    if should_ban:
        if tracker1.check(BAN_STRING):
            break
    else:
        cur_height = nodes[0].get_latest_block().height
        node1_height = nodes[1].get_latest_block().height
        if (abs(node1_height - cur_height) < 5 and
                status1['sync_info']['syncing'] is False):
            break
    time.sleep(2)
コード例 #2
0
#!/usr/bin/env python3
"""
Spawn a cluster with four nodes. Check that no node tries to
connect to another node that is currently connected.
"""

import sys, time
import pathlib

sys.path.append(str(pathlib.Path(__file__).resolve().parents[2] / 'lib'))

import cluster
import utils

BLOCKS = 20

nodes = cluster.start_cluster(4, 0, 4, None, [], {})
trackers = [utils.LogTracker(node) for node in nodes]
utils.wait_for_blocks(nodes[0], target=BLOCKS)
assert all(not tracker.check('Dropping handshake (Active Peer).')
           for tracker in trackers)
コード例 #3
0
ファイル: state_sync_late.py プロジェクト: near/nearcore
for observed_height, hash_ in utils.poll_blocks(boot_node,
                                                timeout=TIMEOUT,
                                                poll_interval=0.1):
    if mode == 'onetx' and not sent_txs:
        ctx.send_moar_txs(hash_, 3, False)
        sent_txs = True
    elif mode == 'manytx':
        if ctx.get_balances() == ctx.expected_balances:
            logger.info(f'Sending moar txs at height {observed_height}')
            ctx.send_moar_txs(hash_, 3, False)

if mode == 'onetx':
    assert ctx.get_balances() == ctx.expected_balances

node2 = spin_up_node(config, near_root, node_dirs[2], 2, boot_node=boot_node)
tracker = utils.LogTracker(node2)
time.sleep(3)

catch_up_height = 0
for catch_up_height, hash_ in utils.poll_blocks(node2,
                                                timeout=TIMEOUT,
                                                poll_interval=0.1):
    if catch_up_height >= observed_height:
        break

    boot_height = boot_node.get_latest_block().height
    if mode == 'manytx':
        if ctx.get_balances() == ctx.expected_balances:
            ctx.send_moar_txs(hash_, 3, False)
            logger.info(f'Sending moar txs at height {boot_height}')
コード例 #4
0
ファイル: state_sync_routed.py プロジェクト: near/nearcore
        ctx.send_moar_txs(hash_, 3, False)
        sent_txs = True
    elif mode == 'manytx' and ctx.get_balances() == ctx.expected_balances:
        ctx.send_moar_txs(hash_, 3, False)
        logger.info(f'Sending moar txs at height {observed_height}')

if mode == 'onetx':
    assert ctx.get_balances() == ctx.expected_balances

node4 = spin_up_node(config,
                     near_root,
                     node_dirs[4],
                     4,
                     boot_node=boot_node,
                     blacklist=[0, 1])
tracker4 = utils.LogTracker(node4)
time.sleep(3)

catch_up_height = 0
for catch_up_height, hash_ in utils.poll_blocks(node4,
                                                timeout=TIMEOUT,
                                                poll_interval=0.1):
    if catch_up_height >= observed_height:
        break
    assert time.time() - started < TIMEOUT, "Waiting for node 4 to catch up"
    new_height = node4.get_latest_block().height
    logger.info(f"Latest block at: {new_height}")
    if new_height > catch_up_height:
        catch_up_height = new_height
        logger.info(f"Last observer got to height {new_height}")
コード例 #5
0
BLOCKS = 25
MALICIOUS_BLOCKS = 50

nodes = start_cluster(
    2, 1, 2, None,
    [["epoch_length", 1000], ["block_producer_kickout_threshold", 80]], {})

started = time.time()

logger.info(f'Waiting for {BLOCKS} blocks...')
height, _ = utils.wait_for_blocks(nodes[1], target=BLOCKS)
logger.info(f'Got to {height} blocks, getting to fun stuff')

nodes[1].get_status(verbose=True)

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

time.sleep(10)

height = nodes[0].get_latest_block(verbose=True).height

assert height < 40

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

logger.info("Epic")
コード例 #6
0
ファイル: wrong_sync_info.py プロジェクト: near/nearcore
nodes = start_cluster(
    2, 1, 2, None,
    [["epoch_length", 7], ["block_producer_kickout_threshold", 80]], {})

started = time.time()

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

nodes[1].start(boot_node=nodes[0])
time.sleep(2)

logger.info(f'Waiting for {BLOCKS} blocks...')
height, _ = utils.wait_for_blocks(nodes[1], target=BLOCKS, timeout=TIMEOUT)
logger.info(f'Got to {height} blocks, getting to fun stuff')

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 = utils.LogTracker(nodes[2])
nodes[2].start(boot_node=nodes[1])
time.sleep(2)

utils.wait_for_blocks(nodes[2], target=BLOCKS, timeout=TIMEOUT)

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

logger.info("Epic")