Exemplo n.º 1
0
async def _skip_complete_headers_iterator(
    headers: Iterable[BlockHeader], logger: ExtendedDebugLogger,
    completion_check: Callable[[BlockHeader], Awaitable[bool]]
) -> AsyncIterator[BlockHeader]:
    """
    We only want headers that are missing, so we iterate over the list
    until we find the first missing header, after which we return all of
    the remaining headers.
    """
    iter_headers = iter(headers)
    # for logging:
    first_discarded = None
    last_discarded = None
    num_discarded = 0
    for header in iter_headers:
        is_present = await completion_check(header)
        if is_present:
            if first_discarded is None:
                first_discarded = header
            else:
                last_discarded = header
            num_discarded += 1
        else:
            yield header
            break

    logger.debug(
        "Discarding %d headers that we already have: %s...%s",
        num_discarded,
        first_discarded,
        last_discarded,
    )

    for header in iter_headers:
        yield header
Exemplo n.º 2
0
async def _skip_complete_headers_iterator(
    headers: Iterable[BlockHeader], logger: ExtendedDebugLogger,
    completion_check: Callable[[BlockHeader], Awaitable[bool]]
) -> AsyncIterator[BlockHeader]:
    """
    We only want headers that are missing, so we iterate over the list
    until we find the first missing header, after which we return all of
    the remaining headers.
    """
    iter_headers = iter(headers)
    for header in iter_headers:
        is_present = await completion_check(header)
        if is_present:
            logger.debug("Discarding header that we already have: %s", header)
        else:
            yield header
            break

    for header in iter_headers:
        yield header