Ejemplo n.º 1
0
def setup_apps(amount, assets, num_transfers, num_nodes, channels_per_node):
    assert len(assets) <= num_nodes

    deposit = amount * num_transfers

    private_keys = [
        sha3('mediated_transfer:{}'.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,
    )

    return apps
Ejemplo n.º 2
0
def setup_apps(amount, assets, num_transfers, num_nodes, channels_per_node):
    assert len(assets) <= num_nodes

    deposit = amount * num_transfers

    private_keys = [
        sha3('mediated_transfer:{}'.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,
    )

    return apps
Ejemplo n.º 3
0
def _mock_services(private_keys, request):
    # make sure we are getting and leaving a clean state, just in case the
    # BlockChainServiceMock wasn't instantiate through the proper fixture.

    @request.addfinalizer
    def _cleanup():
        BlockChainServiceMock.reset()

    BlockChainServiceMock.reset()

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

    return blockchain_services
Ejemplo n.º 4
0
def _mock_services(deploy_key, private_keys, request):
    # make sure we are getting and leaving a clean state, just in case the
    # BlockChainServiceMock wasn't instantiate through the proper fixture.

    @request.addfinalizer
    def _cleanup():
        BlockChainServiceMock.reset()

    BlockChainServiceMock.reset()

    deploy_blockchain = BlockChainServiceMock(deploy_key, MOCK_REGISTRY_ADDRESS)

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

    return BlockchainServices(deploy_blockchain, blockchain_services)
Ejemplo n.º 5
0
def _mock_services(deploy_key, private_keys, request):
    # make sure we are getting and leaving a clean state, just in case the
    # BlockChainServiceMock wasn't instantiated through the proper fixture.

    @request.addfinalizer
    def _cleanup():  # pylint: disable=unused-variable
        BlockChainServiceMock.reset()

    BlockChainServiceMock.reset()

    deploy_blockchain = BlockChainServiceMock(deploy_key,
                                              MOCK_REGISTRY_ADDRESS)

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

    return BlockchainServices(deploy_blockchain, blockchain_services)
Ejemplo n.º 6
0
def test_webui():  # pylint: disable=too-many-locals
    num_assets = 3
    num_nodes = 10

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

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

    BlockChainServiceMock.reset()
    blockchain_service = BlockChainServiceMock(None, MOCK_REGISTRY_ADDRESS)
    registry = blockchain_service.registry(MOCK_REGISTRY_ADDRESS)

    for asset in assets_addresses:
        registry.add_asset(asset)

    channels_per_node = 2
    deposit = 100
    app_list = create_network(private_keys, assets_addresses,
                              MOCK_REGISTRY_ADDRESS, channels_per_node,
                              deposit, DEFAULT_SETTLE_TIMEOUT, UDPTransport,
                              BlockChainServiceMock)
    app0 = app_list[0]

    addresses = [
        app.raiden.address.encode('hex') for app in app_list
        if app != app_list[0]
    ]

    print '\nCreated nodes: \n',
    for node in addresses:
        print node

    setup_messages_cb()

    app0_assets = getattr(app0.raiden.api, 'assets')
    print '\nAvailable assets:'
    for asset in app0_assets:
        print asset.encode('hex')
    print '\n'

    wamp = WAMPRouter(app0.raiden, 8080, ['channel', 'test'])
    wamp.run()

    BlockChainServiceMock.reset()
Ejemplo n.º 7
0
 def _cleanup():  # pylint: disable=unused-variable
     BlockChainServiceMock.reset()
Ejemplo n.º 8
0
def test_webui():  # pylint: disable=too-many-locals
    num_assets = 3
    num_nodes = 10
    verbose = 0
    settle_timeout = DEFAULT_SETTLE_TIMEOUT

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

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

    BlockChainServiceMock.reset()
    blockchain_service = BlockChainServiceMock(None, MOCK_REGISTRY_ADDRESS)
    registry = blockchain_service.registry(MOCK_REGISTRY_ADDRESS)

    for asset in assets_addresses:
        registry.add_asset(asset)

    channels_per_node = 2
    deposit = 100

    blockchain_services = [
        BlockChainServiceMock(privkey, MOCK_REGISTRY_ADDRESS)
        for privkey in private_keys
    ]

    app_list = create_apps(
        blockchain_services,
        UDPTransport,
        verbose,
    )

    create_network_channels(
        app_list,
        assets_addresses,
        channels_per_node,
        deposit,
        settle_timeout,
    )

    app0 = app_list[0]

    addresses = [
        app.raiden.address.encode('hex')
        for app in app_list
        if app != app_list[0]
    ]

    print '\nCreated nodes: \n',
    for node in addresses:
        print node

    setup_messages_cb()

    app0_assets = getattr(app0.raiden.api, 'assets')
    print '\nAvailable assets:'
    for asset in app0_assets:
        print asset.encode('hex')
    print '\n'

    wamp = WAMPRouter(app0.raiden, 8080, ['channel', 'test'])
    wamp.run()

    BlockChainServiceMock.reset()
Ejemplo n.º 9
0
 def _cleanup():
     BlockChainServiceMock.reset()
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
def test_webui():  # pylint: disable=too-many-locals
    num_tokens = 3
    num_nodes = 10
    verbose = 0
    settle_timeout = DEFAULT_SETTLE_TIMEOUT

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

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

    BlockChainServiceMock.reset()
    blockchain_service = BlockChainServiceMock(None, MOCK_REGISTRY_ADDRESS)
    registry = blockchain_service.registry(MOCK_REGISTRY_ADDRESS)

    for token in tokens_addresses:
        registry.add_token(token)

    channels_per_node = 2
    deposit = 100

    blockchain_services = [
        BlockChainServiceMock(privkey, MOCK_REGISTRY_ADDRESS)
        for privkey in private_keys
    ]

    app_list = create_apps(
        blockchain_services,
        UDPTransport,
        verbose,
    )

    create_network_channels(
        app_list,
        tokens_addresses,
        channels_per_node,
        deposit,
        settle_timeout,
    )

    app0 = app_list[0]

    addresses = [
        app.raiden.address.encode('hex') for app in app_list
        if app != app_list[0]
    ]

    print '\nCreated nodes: \n',
    for node in addresses:
        print node

    setup_messages_cb()

    app0_tokens = getattr(app0.raiden.api, 'tokens')
    print '\nAvailable tokens:'
    for token in app0_tokens:
        print token.encode('hex')
    print '\n'

    wamp = WAMPRouter(app0.raiden, 8080, ['channel', 'test'])
    wamp.run()

    BlockChainServiceMock.reset()
Ejemplo n.º 12
0
 def _cleanup():
     BlockChainServiceMock.reset()
Ejemplo n.º 13
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()