def _tester_services(deploy_key, private_keys, tester_blockgas_limit): # calling the fixture directly because we don't want to force all # blockchain_services to instantiate a state tester = tester_state( deploy_key, private_keys, tester_blockgas_limit, ) tester_registry_address = tester_deploy_contract( tester, deploy_key, contract_name='Registry', contract_file='Registry.sol', ) deploy_blockchain = BlockChainServiceTesterMock( deploy_key, tester, tester_registry_address, ) blockchain_services = list() for privkey in private_keys: blockchain = BlockChainServiceTesterMock( privkey, tester, tester_registry_address, ) blockchain_services.append(blockchain) return BlockchainServices(deploy_blockchain, blockchain_services)
def _tester_services(deploy_key, private_keys, tester_blockgas_limit): # calling the fixture directly because we don't want to force all # blockchain_services to instantiate a state tester = tester_state( deploy_key, private_keys, tester_blockgas_limit, ) tester_registry_address = tester_deploy_contract( tester, deploy_key, contract_name='Registry', contract_file='Registry.sol', ) deploy_blockchain = BlockChainServiceTesterMock( deploy_key, tester, tester_registry_address, ) blockchain_services = list() for privkey in private_keys: blockchain = BlockChainServiceTesterMock( privkey, tester, tester_registry_address, ) blockchain_services.append(blockchain) return BlockchainServices(deploy_blockchain, blockchain_services)
def setup_apps(amount, tokens, num_transfers, num_nodes, channels_per_node): assert len(tokens) <= num_nodes deposit = amount * num_transfers private_keys = [ sha3('mediated_transfer:{}'.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) verbosity = 3 apps = create_network( blockchain_services, tokens, channels_per_node, deposit, DEFAULT_SETTLE_TIMEOUT, UDPTransport, verbosity, ) return apps
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()
def transfer_speed(num_transfers=100, max_locked=100): # pylint: disable=too-many-locals channels_per_node = 1 num_nodes = 2 num_tokens = 1 private_keys = [ sha3('speed:{}'.format(position)) for position in range(num_nodes) ] tokens = [ sha3('token:{}'.format(number))[:20] for number in range(num_tokens) ] amounts = [a % 100 + 1 for a in range(1, num_transfers + 1)] deposit = sum(amounts) secrets = [str(i) for i in range(num_transfers)] 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) apps = create_network( private_keys, tokens, registry_address, channels_per_node, deposit, DEFAULT_SETTLE_TIMEOUT, DEFAULT_POLL_TIMEOUT, UDPTransport, BlockChainServiceTesterMock, ) app0, app1 = apps # pylint: disable=unbalanced-tuple-unpacking channel0 = app0.raiden.channelgraphs[tokens[0]].address_channel.values()[0] channel1 = app1.raiden.channelgraphs[tokens[0]].address_channel.values()[0] expiration = app0.raiden.chain.block_number() + DEFAULT_REVEAL_TIMEOUT + 3 start = time.time() for i, amount in enumerate(amounts): hashlock = sha3(secrets[i]) locked_transfer = channel0.create_lockedtransfer( app0.raiden.get_block_number(), amount=amount, identifier=1, # TODO: fill in identifier expiration=expiration, hashlock=hashlock, ) app0.raiden.sign(locked_transfer) channel0.register_transfer(locked_transfer) channel1.register_transfer(locked_transfer) if i > max_locked: idx = i - max_locked secret = secrets[idx] channel0.register_secret(secret) channel1.register_secret(secret) elapsed = time.time() - start print('%d transfers per second' % (num_transfers / elapsed))
def __init__(self): super(NettingChannelStateMachine, self).__init__() deploy_key = sha3('deploy_key') gas_limit = 10**10 self.private_keys = [ sha3('p1'), sha3('p2'), sha3('p3' ), # third key used to generate signed but invalid transfers ] self.addresses = map(privatekey_to_address, self.private_keys) self.log = list() self.tester_state = tester_state( deploy_key, self.private_keys, gas_limit, ) self.settle_timeout = 50 self.token_amount = 1000 self.tokens = [ new_token( deploy_key, self.tester_state, self.token_amount, self.log.append, ), new_token( deploy_key, self.tester_state, self.token_amount, self.log.append, ), ] self.token = self.tokens[0] self.token_addresses = [token.address for token in self.tokens] self.nettingchannel_library_address = deploy_nettingchannel_library( deploy_key, self.tester_state, ) self.channel_manager_library_address = deploy_channelmanager_library( deploy_key, self.tester_state, self.nettingchannel_library_address, ) self.registry = new_registry( deploy_key, self.tester_state, self.channel_manager_library_address, self.log.append, ) self.channelmanager = new_channelmanager( deploy_key, self.tester_state, self.log.append, self.registry, self.token.address, ) self.netting_channel = new_nettingcontract( self.private_keys[0], self.private_keys[1], self.tester_state, self.log.append, self.channelmanager, self.settle_timeout, ) address_and_balance = self.netting_channel.addressAndBalance( # pylint: disable=no-member sender=self.private_keys[0], ) self.closing_address = None self.update_transfer_called = False self.participant_addresses = { unhexlify(address_and_balance[0]), unhexlify(address_and_balance[2]), } self.channel_addresses = [ unhexlify(self.netting_channel.address), make_address(), # used to test invalid transfers ]