示例#1
0
def _get_required_gas_estimate_for_state(raiden) -> int:
    chain_state = views.state_from_raiden(raiden)
    registry_address = raiden.default_registry.address
    token_addresses = views.get_token_identifiers(chain_state,
                                                  registry_address)

    gas_estimate = 0

    for token_address in token_addresses:
        token_network_address = views.get_token_network_identifier_by_token_address(
            chain_state=chain_state,
            payment_network_id=registry_address,
            token_address=token_address,
        )
        num_opening_channels = len(
            raiden.chain.token_network(
                token_network_address).open_channel_transactions, )
        num_opened_channels = len(
            views.get_channelstate_open(
                chain_state,
                registry_address,
                token_address,
            ))
        num_closing_channels = len(
            views.get_channelstate_closing(
                chain_state,
                registry_address,
                token_address,
            ))
        num_closed_channels = len(
            views.get_channelstate_closed(
                chain_state,
                registry_address,
                token_address,
            ))
        num_settling_channels = len(
            views.get_channelstate_settling(
                chain_state,
                registry_address,
                token_address,
            ))
        num_settled_channels = len(
            views.get_channelstate_settled(
                chain_state,
                registry_address,
                token_address,
            ))

        gas_estimate += _get_required_gas_estimate(
            opening_channels=num_opening_channels,
            opened_channels=num_opened_channels,
            closing_channels=num_closing_channels,
            closed_channels=num_closed_channels,
            settling_channels=num_settling_channels,
            settled_channels=num_settled_channels,
        )

    return gas_estimate
示例#2
0
def get_required_gas_estimate(raiden: "RaidenService",
                              channels_to_open: int = 0) -> int:
    num_opening_channels = 0
    num_opened_channels = 0
    num_closing_channels = 0
    num_closed_channels = 0
    num_settling_channels = 0
    num_settled_channels = 0

    # Only use the token networks that have been instantiated. Instantiating
    # the token networks here has a very high performance impact for a registry
    # with lots of tokens.
    #
    # The lock is being acquired to prevent chnages to the dictionary while
    # iterating over it.
    with raiden.proxy_manager.token_network_creation_lock:
        num_opening_channels = sum(
            token_network.opening_channels_count for token_network in
            raiden.proxy_manager.address_to_token_network.values())

    chain_state = views.state_from_raiden(raiden)
    registry_address = raiden.default_registry.address
    token_addresses = views.get_token_identifiers(chain_state,
                                                  registry_address)

    for token_address in token_addresses:
        num_opened_channels += len(
            views.get_channelstate_open(chain_state, registry_address,
                                        token_address))
        num_closing_channels += len(
            views.get_channelstate_closing(chain_state, registry_address,
                                           token_address))
        num_closed_channels += len(
            views.get_channelstate_closed(chain_state, registry_address,
                                          token_address))
        num_settling_channels += len(
            views.get_channelstate_settling(chain_state, registry_address,
                                            token_address))
        num_settled_channels += len(
            views.get_channelstate_settled(chain_state, registry_address,
                                           token_address))

    return _get_required_gas_estimate(
        gas_measurements=gas_measurements(
            raiden.contract_manager.contracts_version),
        opening_channels=num_opening_channels + channels_to_open,
        opened_channels=num_opened_channels,
        closing_channels=num_closing_channels,
        closed_channels=num_closed_channels,
        settling_channels=num_settling_channels,
        settled_channels=num_settled_channels,
    )
示例#3
0
def _get_required_gas_estimate_for_state(raiden: "RaidenService") -> int:
    num_opening_channels = 0
    num_opened_channels = 0
    num_closing_channels = 0
    num_closed_channels = 0
    num_settling_channels = 0
    num_settled_channels = 0

    # Only use the token networks that have been instantiated. Instantiating
    # the token networks here can have a high performance impacet for a token
    # network registry with lots of registeres tokens.
    with raiden.proxy_manager.token_network_creation_lock:
        num_opening_channels = sum(
            token_network.opening_channels_count for token_network in
            raiden.proxy_manager.address_to_token_network.values())

    chain_state = views.state_from_raiden(raiden)
    registry_address = raiden.default_registry.address
    token_addresses = views.get_token_identifiers(chain_state,
                                                  registry_address)

    for token_address in token_addresses:
        num_opened_channels += len(
            views.get_channelstate_open(chain_state, registry_address,
                                        token_address))
        num_closing_channels += len(
            views.get_channelstate_closing(chain_state, registry_address,
                                           token_address))
        num_closed_channels += len(
            views.get_channelstate_closed(chain_state, registry_address,
                                          token_address))
        num_settling_channels += len(
            views.get_channelstate_settling(chain_state, registry_address,
                                            token_address))
        num_settled_channels += len(
            views.get_channelstate_settled(chain_state, registry_address,
                                           token_address))

    return _get_required_gas_estimate(
        gas_measurements=gas_measurements(
            raiden.contract_manager.contracts_version),
        opening_channels=num_opening_channels,
        opened_channels=num_opened_channels,
        closing_channels=num_closing_channels,
        closed_channels=num_closed_channels,
        settling_channels=num_settling_channels,
        settled_channels=num_settled_channels,
    )
示例#4
0
def _get_required_gas_estimate_for_state(raiden) -> int:
    chain_state = views.state_from_raiden(raiden)
    token_addresses = views.get_token_identifiers(
        chain_state, raiden.default_registry.address)

    gas_estimate = 0

    for token_address in token_addresses:
        num_opened_channels = len(
            views.get_channelstate_open(
                chain_state,
                raiden.default_registry.address,
                token_address,
            ))
        num_closing_channels = len(
            views.get_channelstate_closing(
                chain_state,
                raiden.default_registry.address,
                token_address,
            ))
        num_closed_channels = len(
            views.get_channelstate_closed(
                chain_state,
                raiden.default_registry.address,
                token_address,
            ))
        num_settling_channels = len(
            views.get_channelstate_settling(
                chain_state,
                raiden.default_registry.address,
                token_address,
            ))
        num_settled_channels = len(
            views.get_channelstate_settled(
                chain_state,
                raiden.default_registry.address,
                token_address,
            ))

        gas_estimate += _get_required_gas_estimate(
            opened_channels=num_opened_channels,
            closing_channels=num_closing_channels,
            closed_channels=num_closed_channels,
            settling_channels=num_settling_channels,
            settled_channels=num_settled_channels,
        )

    return gas_estimate
示例#5
0
def _get_required_gas_estimate_for_state(raiden: "RaidenService") -> int:
    chain_state = views.state_from_raiden(raiden)
    registry_address = raiden.default_registry.address
    token_addresses = views.get_token_identifiers(chain_state,
                                                  registry_address)
    measurements = gas_measurements(raiden.contract_manager.contracts_version)

    gas_estimate = 0

    for token_address in token_addresses:
        token_network_address = views.get_token_network_address_by_token_address(
            chain_state=chain_state,
            token_network_registry_address=registry_address,
            token_address=token_address,
        )
        if token_network_address is None:
            continue

        num_opening_channels = raiden.proxy_manager.token_network(
            token_network_address).opening_channels_count
        num_opened_channels = len(
            views.get_channelstate_open(chain_state, registry_address,
                                        token_address))
        num_closing_channels = len(
            views.get_channelstate_closing(chain_state, registry_address,
                                           token_address))
        num_closed_channels = len(
            views.get_channelstate_closed(chain_state, registry_address,
                                          token_address))
        num_settling_channels = len(
            views.get_channelstate_settling(chain_state, registry_address,
                                            token_address))
        num_settled_channels = len(
            views.get_channelstate_settled(chain_state, registry_address,
                                           token_address))

        gas_estimate += _get_required_gas_estimate(
            gas_measurements=measurements,
            opening_channels=num_opening_channels,
            opened_channels=num_opened_channels,
            closing_channels=num_closing_channels,
            closed_channels=num_closed_channels,
            settling_channels=num_settling_channels,
            settled_channels=num_settled_channels,
        )

    return gas_estimate
示例#6
0
def test_channelstate_filters():
    test_state = factories.make_chain_state(number_of_channels=5)
    chain_state = test_state.chain_state
    token_network_registry_address = test_state.token_network_registry_address
    token_address = test_state.token_address

    channel_open, channel_closing, channel_closed, channel_settling, channel_settled = (
        test_state.channels
    )
    in_progress = TransactionExecutionStatus(started_block_number=chain_state.block_number)
    done = TransactionExecutionStatus(
        started_block_number=chain_state.block_number,
        finished_block_number=chain_state.block_number,
        result=TransactionExecutionStatus.SUCCESS,
    )
    channel_closing.close_transaction = in_progress
    channel_closed.close_transaction = done
    channel_settling.close_transaction = done
    channel_settling.settle_transaction = in_progress
    channel_settled.close_transaction = done
    channel_settled.settle_transaction = done

    unknown_token = factories.make_address()
    assert (
        views.get_channelstate_open(
            chain_state=chain_state,
            token_network_registry_address=token_network_registry_address,
            token_address=unknown_token,
        )
        == []
    )

    opened = views.get_channelstate_open(
        chain_state=chain_state,
        token_network_registry_address=token_network_registry_address,
        token_address=token_address,
    )
    assert opened == [channel_open]

    closing = views.get_channelstate_closing(
        chain_state=chain_state,
        token_network_registry_address=token_network_registry_address,
        token_address=token_address,
    )
    assert closing == [channel_closing]

    closed = views.get_channelstate_closed(
        chain_state=chain_state,
        token_network_registry_address=token_network_registry_address,
        token_address=token_address,
    )
    assert closed == [channel_closed]

    settling = views.get_channelstate_settling(
        chain_state=chain_state,
        token_network_registry_address=token_network_registry_address,
        token_address=token_address,
    )
    assert settling == [channel_settling]

    settled = views.get_channelstate_settled(
        chain_state=chain_state,
        token_network_registry_address=token_network_registry_address,
        token_address=token_address,
    )
    assert settled == [channel_settled]