Example #1
0
async def test_beam_syncer_with_checkpoint_too_close_to_tip(
        caplog, request, event_loop, event_bus, chaindb_fresh,
        chaindb_churner):

    checkpoint = Checkpoint(
        block_hash=decode_hex(
            '0x814aca8a5855f216fee0f627945f70b3c019ae2c8b3aeb528ea7049ed83cfc82'
        ),
        score=645,
    )

    caplog.set_level(logging.INFO)
    try:
        await test_beam_syncer(
            request,
            event_loop,
            event_bus,
            chaindb_fresh,
            chaindb_churner,
            beam_to_block=66,
            checkpoint=checkpoint,
        )
    except asyncio.TimeoutError as e:
        # Beam syncer timing out and printing an info to the user is the expected behavior.
        # Our checkpoint is right before the tip and the chain doesn't advance forward.
        assert "Checkpoint is too near" in caplog.text
Example #2
0
File: cli.py Project: veox/trinity
def parse_byhash_uri(parsed: urllib.parse.ParseResult) -> Checkpoint:
    scheme, netloc, query = parsed.scheme, parsed.netloc, parsed.query

    try:
        parsed_query = urllib.parse.parse_qsl(query)
    except ValueError as e:
        raise ValidationError(str(e))

    query_dict = dict(parsed_query)

    # we allow any kind of separator for a nicer UX. e.g. instead of "11487662456884849810705"
    # one can use "114 876 624 568 848 498 107 05" or "1,487,662,456,884,849,810,705". This also
    # allows copying out a value from e.g etherscan.
    score = remove_non_digits(query_dict.get('score', ''))

    parts = PurePosixPath(parsed.path).parts

    if len(parts) != 3 or scheme != 'eth' or netloc != 'block' or not score:
        raise ValidationError('checkpoint string must be of the form'
                              '"eth://block/byhash/<hash>?score=<score>"')

    block_hash = parts[2]

    if not is_block_hash(block_hash):
        raise ValidationError(
            f'Block hash must be valid hex string, got: {block_hash}')

    if not score.isdigit():
        raise ValidationError(
            f'Score (total difficulty) must be an integer, got: {score}')

    return Checkpoint(Hash32(decode_hex(block_hash)), int(score))
Example #3
0
def parse_byetherscan_uri(parsed: urllib.parse.ParseResult,
                          network_id: int) -> Checkpoint:

    try:
        network = Network(network_id)
    except ValueError:
        raise ValidationError(
            f"Can not resolve checkpoint through Etherscan API"
            f"for network {network_id}. Network not supported")

    try:
        etherscan_api_key = os.environ['TRINITY_ETHERSCAN_API_KEY']
    except KeyError:
        raise RuntimeError(
            "Etherscan API key missing. Assign your Etherscan API key "
            "to the TRINITY_ETHERSCAN_API_KEY environment variable.")

    etherscan_api = Etherscan(etherscan_api_key)

    latest_block_number = etherscan_api.get_latest_block(network)
    checkpoint_block_number = latest_block_number - BLOCKS_FROM_TIP
    checkpoint_block_response = etherscan_api.get_block_by_number(
        checkpoint_block_number, network)
    checkpoint_score = to_int(
        hexstr=checkpoint_block_response['totalDifficulty'])
    checkpoint_hash = checkpoint_block_response['hash']

    return Checkpoint(Hash32(decode_hex(checkpoint_hash)), checkpoint_score)
Example #4
0
def parse_byetherscan_uri(parsed: urllib.parse.ParseResult) -> Checkpoint:

    latest_block_number = get_latest_block()
    checkpoint_block_number = latest_block_number - BLOCKS_FROM_TIP
    checkpoint_block_response = get_block_by_number(checkpoint_block_number)
    checkpoint_score = to_int(
        hexstr=checkpoint_block_response['totalDifficulty'])
    checkpoint_hash = checkpoint_block_response['hash']

    return Checkpoint(Hash32(decode_hex(checkpoint_hash)), checkpoint_score)
Example #5
0
async def test_beam_syncer_with_checkpoint(request, event_loop, event_bus,
                                           chaindb_fresh, chaindb_churner):

    checkpoint = Checkpoint(
        block_hash=decode_hex(
            '0x5b8d32e4aebda3da7bdf2f0588cb42256e2ed0c268efec71b38278df8488a263'
        ),
        score=55,
    )

    await test_beam_syncer(
        request,
        event_loop,
        event_bus,
        chaindb_fresh,
        chaindb_churner,
        beam_to_block=66,
        checkpoint=checkpoint,
    )
Example #6
0
File: cli.py Project: veox/trinity
def parse_byetherscan_uri(parsed: urllib.parse.ParseResult,
                          network_id: int) -> Checkpoint:

    try:
        network = Network(network_id)
    except ValueError:
        raise ValidationError(
            f"Can not resolve checkpoint through Etherscan API"
            f"for network {network_id}. Network not supported")

    latest_block_number = get_latest_block(network)
    checkpoint_block_number = latest_block_number - BLOCKS_FROM_TIP
    checkpoint_block_response = get_block_by_number(checkpoint_block_number,
                                                    network)
    checkpoint_score = to_int(
        hexstr=checkpoint_block_response['totalDifficulty'])
    checkpoint_hash = checkpoint_block_response['hash']

    return Checkpoint(Hash32(decode_hex(checkpoint_hash)), checkpoint_score)