Example #1
0
def profile_transfer(num_nodes=10, channels_per_node=2):
    num_tokens = 1
    deposit = 10000

    tokens = [
        sha3('token:{}'.format(number))[:20] for number in range(num_tokens)
    ]

    private_keys = [
        sha3('speed:{}'.format(position)) for position in range(num_nodes)
    ]

    blockchain_services = list()
    tester = tester_state(
        private_keys[0],
        private_keys,
        tester_blockgas_limit(),
    )
    nettingchannel_library_address = tester_nettingchannel_library_address(
        tester_state, )
    channelmanager_library_address = tester_channelmanager_library_address(
        tester_state,
        nettingchannel_library_address,
    )
    registry_address = tester_registry_address(
        tester_state,
        channelmanager_library_address,
    )
    for privkey in private_keys:
        blockchain = BlockChainServiceTesterMock(
            privkey,
            tester,
            registry_address,
        )
        blockchain_services.append(blockchain)

    registry = blockchain_services[0].registry(registry_address)
    for token in tokens:
        registry.add_token(token)

    discovery_mock = Discovery()
    endpoint_discovery_services = [discovery_mock for _ in private_keys]

    verbosity = 3
    apps = create_apps(
        blockchain_services,
        endpoint_discovery_services,
        tokens,
        channels_per_node,
        deposit,
        DEFAULT_SETTLE_TIMEOUT,
        UDPTransport,
        verbosity,
    )

    main_app = apps[0]

    # channels
    main_graph = main_app.raiden.token_to_channelgraph[tokens[0]]

    # search for a path of length=2 A > B > C
    num_hops = 2
    source = main_app.raiden.address
    paths = main_graph.get_paths_of_length(source, num_hops)

    # sanity check
    assert paths

    path = paths[0]
    target = path[-1]

    # addresses
    token_address = main_graph.token_address

    amount = 10

    # measure the hot path
    with profiling.profile():
        result = main_app.raiden.mediated_transfer_async(
            token_address,
            amount,
            target,
            1,
        )
        result.wait()

    profiling.print_all_threads()
Example #2
0
def profile_transfer(num_nodes=10, channels_per_node=2):
    num_assets = 1
    deposit = 10000

    assets = [
        sha3('asset:{}'.format(number))[:20] for number in range(num_assets)
    ]

    private_keys = [
        sha3('speed:{}'.format(position)) for position in range(num_nodes)
    ]

    BlockChainServiceMock.reset()
    blockchain_services = list()
    for privkey in private_keys:
        blockchain = BlockChainServiceMock(
            privkey,
            MOCK_REGISTRY_ADDRESS,
        )
        blockchain_services.append(blockchain)

    registry = blockchain_services[0].registry(MOCK_REGISTRY_ADDRESS)
    for asset in assets:
        registry.add_asset(asset)

    verbosity = 3
    apps = create_network(
        blockchain_services,
        assets,
        channels_per_node,
        deposit,
        DEFAULT_SETTLE_TIMEOUT,
        UDPTransport,
        verbosity,
    )

    main_app = apps[0]
    main_api = main_app.raiden.api

    # channels
    main_assetmanager = main_app.raiden.get_manager_by_asset_address(assets[0])

    # search for a path of length=2 A > B > C
    num_hops = 2
    source = main_app.raiden.address
    paths = main_assetmanager.channelgraph.get_paths_of_length(
        source, num_hops)

    # sanity check
    assert len(paths)

    path = paths[0]
    target = path[-1]

    # addresses
    a, b, c = path
    asset_address = main_assetmanager.asset_address

    amount = 10

    # measure the hot path
    with profiling.profile():
        result = main_api.transfer_async(
            asset_address,
            amount,
            target,
            1  # TODO: fill in identifier
        )
        result.wait()

    profiling.print_all_threads()
def profile_transfer(num_nodes=10, channels_per_node=2):
    num_tokens = 1
    deposit = 10000

    tokens = [
        sha3('token:{}'.format(number).encode())[:20]
        for number in range(num_tokens)
    ]

    private_keys = [
        sha3('speed:{}'.format(position).encode())
        for position in range(num_nodes)
    ]

    blockchain_services = list()
    tester = tester_chain(
        private_keys[0],
        private_keys,
        tester_blockgas_limit(),
    )
    nettingchannel_library_address = tester_nettingchannel_library_address(
        tester_chain,
    )
    channelmanager_library_address = tester_channelmanager_library_address(
        tester_chain,
        nettingchannel_library_address,
    )
    registry_address = tester_registry_address(
        tester_chain,
        channelmanager_library_address,
    )
    for privkey in private_keys:
        blockchain = BlockChainServiceTesterMock(
            privkey,
            tester,
        )
        blockchain_services.append(blockchain)

    registry = blockchain_services[0].registry(registry_address)
    for token in tokens:
        registry.add_token(token)

    discovery_mock = Discovery()
    endpoint_discovery_services = [discovery_mock for _ in private_keys]

    apps = create_apps(
        blockchain_services,
        endpoint_discovery_services,
        registry_address,
        tokens,
        channels_per_node,
        deposit,
        DEFAULT_SETTLE_TIMEOUT,
        UDPTransport,
    )

    main_app = apps[0]

    # channels
    main_graph = main_app.raiden.token_to_channelgraph[tokens[0]]

    # search for a path of length=2 A > B > C
    num_hops = 2
    source = main_app.raiden.address
    paths = main_graph.get_paths_of_length(source, num_hops)

    # sanity check
    assert paths

    path = paths[0]
    target = path[-1]

    # addresses
    token_address = main_graph.token_address

    amount = 10

    # measure the hot path
    with profiling.profile():
        result = main_app.raiden.mediated_transfer_async(
            token_address,
            amount,
            target,
            1,
        )
        result.wait()

    profiling.print_all_threads()
def profile_transfer(num_nodes=10, channels_per_node=2):
    num_assets = 1
    deposit = 10000

    assets = [
        sha3('asset:{}'.format(number))[:20]
        for number in range(num_assets)
    ]

    private_keys = [
        sha3('speed:{}'.format(position))
        for position in range(num_nodes)
    ]

    BlockChainServiceMock.reset()
    blockchain_services = list()
    for privkey in private_keys:
        blockchain = BlockChainServiceMock(
            privkey,
            MOCK_REGISTRY_ADDRESS,
        )
        blockchain_services.append(blockchain)

    registry = blockchain_services[0].registry(MOCK_REGISTRY_ADDRESS)
    for asset in assets:
        registry.add_asset(asset)

    verbosity = 3
    apps = create_network(
        blockchain_services,
        assets,
        channels_per_node,
        deposit,
        DEFAULT_SETTLE_TIMEOUT,
        UDPTransport,
        verbosity,
    )

    main_app = apps[0]
    main_api = main_app.raiden.api

    # channels
    main_assetmanager = main_app.raiden.get_manager_by_asset_address(assets[0])

    # search for a path of length=2 A > B > C
    num_hops = 2
    source = main_app.raiden.address
    paths = main_assetmanager.channelgraph.get_paths_of_length(source, num_hops)

    # sanity check
    assert len(paths)

    path = paths[0]
    target = path[-1]

    # addresses
    a, b, c = path
    asset_address = main_assetmanager.asset_address

    amount = 10

    # measure the hot path
    with profiling.profile():
        result = main_api.transfer_async(
            asset_address,
            amount,
            target,
            1  # TODO: fill in identifier
        )
        result.wait()

    profiling.print_all_threads()