Ejemplo n.º 1
0
def wait_for_settle(
    raiden: RaidenService,
    payment_network_id: typing.PaymentNetworkID,
    token_address: typing.TokenAddress,
    channel_ids: typing.List[typing.ChannelID],
    retry_timeout: float,
) -> None:
    """Wait until all channels are settled.

    Note:
        This does not time out, use gevent.Timeout.
    """
    if not isinstance(channel_ids, list):
        raise ValueError('channel_ids must be a list')

    channel_ids = list(channel_ids)

    while channel_ids:
        first_id = channel_ids[0]
        channel_state = views.get_channelstate_by_id(
            views.state_from_raiden(raiden),
            payment_network_id,
            token_address,
            first_id,
        )

        channel_is_settled = (channel_state is None
                              or channel.get_status(channel_state)
                              == CHANNEL_STATE_SETTLED)

        if channel_is_settled:
            channel_ids.pop()
        else:
            gevent.sleep(retry_timeout)
Ejemplo n.º 2
0
def wait_for_settle(raiden, payment_network_id, token_network_id, channel_ids,
                    poll_timeout):
    """Wait until all channels are settled.

    Note:
        This does not time out, use gevent.Timeout.
    """
    if not isinstance(channel_ids, list):
        raise ValueError('channel_ids must be a list')

    channel_ids = list(channel_ids)

    while channel_ids:
        first_id = channel_ids[0]
        channel_state = views.get_channelstate_by_id(
            views.state_from_raiden(raiden),
            payment_network_id,
            token_network_id,
            first_id,
        )

        channel_is_settled = (channel_state is None
                              or channel.get_status(channel_state)
                              == CHANNEL_STATE_SETTLED)

        if channel_is_settled:
            channel_ids.pop()
        else:
            gevent.sleep(poll_timeout)
Ejemplo n.º 3
0
def wait_for_close(
    raiden: RaidenService,
    payment_network_id: typing.PaymentNetworkID,
    token_address: typing.Address,
    channel_ids: typing.List[typing.ChannelID],
    retry_timeout: float,
) -> None:
    """Wait until all channels are closed.

    Note:
        This does not time out, use gevent.Timeout.
    """
    channel_ids = list(channel_ids)

    while channel_ids:
        first_id = channel_ids[0]
        channel_state = views.get_channelstate_by_id(
            views.state_from_raiden(raiden),
            payment_network_id,
            token_address,
            first_id,
        )

        channel_is_settled = (channel_state is None
                              or channel.get_status(channel_state)
                              in CHANNEL_AFTER_CLOSE_STATES)

        if channel_is_settled:
            channel_ids.pop()
        else:
            gevent.sleep(retry_timeout)
Ejemplo n.º 4
0
def wait_for_close(raiden, payment_network_id, token_network_id, channel_ids,
                   poll_timeout):
    """Wait until all channels are closed.

    Note:
        This does not time out, use gevent.Timeout.
    """
    channel_ids = list(channel_ids)

    while channel_ids:
        first_id = channel_ids[0]
        channel_state = views.get_channelstate_by_id(
            views.state_from_raiden(raiden),
            payment_network_id,
            token_network_id,
            first_id,
        )

        channel_is_settled = (channel_state is None
                              or channel.get_status(channel_state)
                              in CHANNEL_AFTER_CLOSE_STATES)

        if channel_is_settled:
            channel_ids.pop()
        else:
            gevent.sleep(poll_timeout)
Ejemplo n.º 5
0
def channel_state_until_state_change(
    raiden: 'RaidenService',
    payment_network_identifier: typing.PaymentNetworkID,
    token_address: typing.TokenAddress,
    channel_identifier: typing.ChannelID,
    state_change_identifier: int,
) -> typing.Optional[NettingChannelState]:
    """ Go through WAL state changes until a certain balance hash is found. """
    # Restore state from the latest snapshot
    wal = restore_to_state_change(
        node.state_transition,
        raiden.wal.storage,
        state_change_identifier,
    )

    channel_state = views.get_channelstate_by_id(
        chain_state=wal.state_manager.current_state,
        payment_network_id=payment_network_identifier,
        token_address=token_address,
        channel_id=channel_identifier,
    )

    if not channel_state:
        raise RaidenUnrecoverableError(
            f"Channel was not found before state_change {pex(state_change_identifier)}",
        )

    return channel_state
Ejemplo n.º 6
0
def wait_for_settle(
        raiden: RaidenService,
        payment_network_id: typing.PaymentNetworkID,
        token_address: typing.TokenAddress,
        channel_ids: typing.List[typing.ChannelID],
        retry_timeout: float,
) -> None:
    """Wait until all channels are settled.

    Note:
        This does not time out, use gevent.Timeout.
    """
    if not isinstance(channel_ids, list):
        raise ValueError('channel_ids must be a list')

    channel_ids = list(channel_ids)

    while channel_ids:
        last_id = channel_ids[-1]
        channel_state = views.get_channelstate_by_id(
            views.state_from_raiden(raiden),
            payment_network_id,
            token_address,
            last_id,
        )

        channel_is_settled = (
            channel_state is None or
            channel.get_status(channel_state) == CHANNEL_STATE_SETTLED
        )

        if channel_is_settled:
            channel_ids.pop()
        else:
            gevent.sleep(retry_timeout)
Ejemplo n.º 7
0
def wait_for_close(
        raiden: RaidenService,
        payment_network_id: typing.PaymentNetworkID,
        token_address: typing.TokenAddress,
        channel_ids: typing.List[typing.ChannelID],
        retry_timeout: float,
) -> None:
    """Wait until all channels are closed.

    Note:
        This does not time out, use gevent.Timeout.
    """
    channel_ids = list(channel_ids)

    while channel_ids:
        last_id = channel_ids[-1]
        channel_state = views.get_channelstate_by_id(
            views.state_from_raiden(raiden),
            payment_network_id,
            token_address,
            last_id,
        )

        channel_is_settled = (
            channel_state is None or
            channel.get_status(channel_state) in CHANNEL_AFTER_CLOSE_STATES
        )

        if channel_is_settled:
            channel_ids.pop()
        else:
            gevent.sleep(retry_timeout)
Ejemplo n.º 8
0
def channel_state_until_state_change(
        raiden,
        payment_network_identifier: typing.PaymentNetworkID,
        token_address: typing.TokenAddress,
        channel_identifier: typing.ChannelID,
        state_change_identifier: int,
) -> typing.Optional[NettingChannelState]:
    """ Go through WAL state changes until a certain balance hash is found. """
    wal = restore_to_state_change(
        transition_function=node.state_transition,
        storage=raiden.wal.storage,
        state_change_identifier=state_change_identifier,
    )

    msg = 'There is a state change, therefore the state must not be None'
    assert wal.state_manager.current_state is not None, msg

    channel_state = views.get_channelstate_by_id(
        chain_state=wal.state_manager.current_state,
        payment_network_id=payment_network_identifier,
        token_address=token_address,
        channel_id=channel_identifier,
    )

    if not channel_state:
        raise RaidenUnrecoverableError(
            f"Channel was not found before state_change {pex(state_change_identifier)}",
        )

    return channel_state