2018-08-04 12:35:03 +02:00
|
|
|
from concurrent import futures
|
|
|
|
from fixtures import * # noqa: F401,F403
|
|
|
|
from time import time
|
|
|
|
from tqdm import tqdm
|
|
|
|
|
|
|
|
|
2017-11-20 16:16:17 +01:00
|
|
|
import pytest
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
|
|
num_workers = 480
|
|
|
|
num_payments = 10000
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def executor():
|
|
|
|
ex = futures.ThreadPoolExecutor(max_workers=num_workers)
|
|
|
|
yield ex
|
|
|
|
ex.shutdown(wait=False)
|
|
|
|
|
2018-02-21 19:46:04 +01:00
|
|
|
|
2017-11-20 16:16:17 +01:00
|
|
|
def test_single_hop(node_factory, executor):
|
|
|
|
l1 = node_factory.get_node()
|
|
|
|
l2 = node_factory.get_node()
|
|
|
|
|
2018-05-17 22:03:57 +02:00
|
|
|
l1.rpc.connect(l2.rpc.getinfo()['id'], 'localhost:%d' % l2.port)
|
2017-11-20 16:16:17 +01:00
|
|
|
l1.openchannel(l2, 4000000)
|
|
|
|
|
|
|
|
print("Collecting invoices")
|
|
|
|
fs = []
|
|
|
|
invoices = []
|
|
|
|
for i in tqdm(range(num_payments)):
|
2021-07-12 08:49:19 +02:00
|
|
|
inv = l2.rpc.invoice(1000, 'invoice-%d' % (i), 'desc')
|
|
|
|
invoices.append((inv['payment_hash'], inv['payment_secret']))
|
2017-11-20 16:16:17 +01:00
|
|
|
|
|
|
|
route = l1.rpc.getroute(l2.rpc.getinfo()['id'], 1000, 1)['route']
|
|
|
|
print("Sending payments")
|
|
|
|
start_time = time()
|
|
|
|
|
2021-07-12 08:49:19 +02:00
|
|
|
def do_pay(i, s):
|
|
|
|
p = l1.rpc.sendpay(route, i, payment_secret=s)
|
2018-05-18 15:08:58 +02:00
|
|
|
r = l1.rpc.waitsendpay(p['payment_hash'])
|
|
|
|
return r
|
|
|
|
|
2021-07-12 08:49:19 +02:00
|
|
|
for i, s in invoices:
|
|
|
|
fs.append(executor.submit(do_pay, i, s))
|
2017-11-20 16:16:17 +01:00
|
|
|
|
2018-05-18 15:08:58 +02:00
|
|
|
for f in tqdm(futures.as_completed(fs), total=len(fs)):
|
2017-11-20 16:16:17 +01:00
|
|
|
f.result()
|
|
|
|
|
|
|
|
diff = time() - start_time
|
|
|
|
print("Done. %d payments performed in %f seconds (%f payments per second)" % (num_payments, diff, num_payments / diff))
|
|
|
|
|
2018-02-21 19:46:04 +01:00
|
|
|
|
2017-11-20 16:16:17 +01:00
|
|
|
def test_single_payment(node_factory, benchmark):
|
2018-09-27 02:18:24 +02:00
|
|
|
l1, l2 = node_factory.line_graph(2)
|
2017-11-20 16:16:17 +01:00
|
|
|
|
|
|
|
def do_pay(l1, l2):
|
|
|
|
invoice = l2.rpc.invoice(1000, 'invoice-{}'.format(random.random()), 'desc')['bolt11']
|
|
|
|
l1.rpc.pay(invoice)
|
|
|
|
|
|
|
|
benchmark(do_pay, l1, l2)
|
2018-05-18 00:14:01 +02:00
|
|
|
|
|
|
|
|
2018-10-12 15:02:58 +02:00
|
|
|
def test_forward_payment(node_factory, benchmark):
|
2018-12-08 00:27:14 +01:00
|
|
|
l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True)
|
2018-10-12 15:02:58 +02:00
|
|
|
|
|
|
|
def do_pay(src, dest):
|
|
|
|
invoice = dest.rpc.invoice(1000, 'invoice-{}'.format(random.random()), 'desc')['bolt11']
|
|
|
|
src.rpc.pay(invoice)
|
|
|
|
|
|
|
|
benchmark(do_pay, l1, l3)
|
|
|
|
|
|
|
|
|
|
|
|
def test_long_forward_payment(node_factory, benchmark):
|
2018-12-08 00:27:14 +01:00
|
|
|
nodes = node_factory.line_graph(21, wait_for_announce=True)
|
2018-10-12 15:02:58 +02:00
|
|
|
|
|
|
|
def do_pay(src, dest):
|
|
|
|
invoice = dest.rpc.invoice(1000, 'invoice-{}'.format(random.random()), 'desc')['bolt11']
|
|
|
|
src.rpc.pay(invoice)
|
|
|
|
|
|
|
|
benchmark(do_pay, nodes[0], nodes[-1])
|
|
|
|
|
|
|
|
|
2018-05-18 00:14:01 +02:00
|
|
|
def test_invoice(node_factory, benchmark):
|
|
|
|
l1 = node_factory.get_node()
|
|
|
|
|
|
|
|
def bench_invoice():
|
|
|
|
l1.rpc.invoice(1000, 'invoice-{}'.format(time()), 'desc')
|
|
|
|
|
|
|
|
benchmark(bench_invoice)
|
|
|
|
|
|
|
|
|
|
|
|
def test_pay(node_factory, benchmark):
|
2018-09-27 02:18:24 +02:00
|
|
|
l1, l2 = node_factory.line_graph(2)
|
2018-05-18 00:14:01 +02:00
|
|
|
|
|
|
|
invoices = []
|
|
|
|
for _ in range(1, 100):
|
|
|
|
invoice = l2.rpc.invoice(1000, 'invoice-{}'.format(random.random()), 'desc')['bolt11']
|
|
|
|
invoices.append(invoice)
|
|
|
|
|
|
|
|
def do_pay(l1, l2):
|
|
|
|
l1.rpc.pay(invoices.pop())
|
|
|
|
|
|
|
|
benchmark(do_pay, l1, l2)
|
|
|
|
|
|
|
|
|
|
|
|
def test_start(node_factory, benchmark):
|
|
|
|
benchmark(node_factory.get_node)
|