MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_generate_coinmoves

Function test_generate_coinmoves

tests/benchmark.py:137–215  ·  view source on GitHub ↗
(node_factory, bitcoind, executor, benchmark)

Source from the content-addressed store, hash-verified

135
136
137def test_generate_coinmoves(node_factory, bitcoind, executor, benchmark):
138 l1, l2, l3 = get_bench_line_graph(node_factory, 3, wait_for_announce=True)
139
140 # Route some payments
141 l1.rpc.xpay(l3.rpc.invoice(1, "test_generate_coinmoves", "test_generate_coinmoves")['bolt11'])
142 # Make some payments
143 l2.rpc.xpay(l3.rpc.invoice(1, "test_generate_coinmoves3", "test_generate_coinmoves3")['bolt11'])
144 # Receive some payments
145 l1.rpc.xpay(l2.rpc.invoice(1, "test_generate_coinmoves", "test_generate_coinmoves")['bolt11'])
146 wait_for(lambda: all([c['htlcs'] == [] for c in l1.rpc.listpeerchannels()['channels']]))
147
148 l2.stop()
149 entries = l2.db.query('SELECT * FROM channel_moves ORDER BY id;')
150 assert len(entries) == 4
151 next_id = entries[-1]['id'] + 1
152 next_timestamp = entries[-1]['timestamp'] + 1
153
154 batch = []
155 # Let's make 5 million entries.
156 for _ in range(5_000_000 // len(entries)):
157 # Random payment_hash
158 entries[0]['payment_hash'] = entries[1]['payment_hash'] = random.randbytes(32)
159 entries[2]['payment_hash'] = random.randbytes(32)
160 entries[3]['payment_hash'] = random.randbytes(32)
161 # Incrementing timestamps
162 for e in entries:
163 e['timestamp'] = next_timestamp
164 next_timestamp += 1
165
166 for e in entries:
167 batch.append((
168 next_id,
169 e['account_channel_id'],
170 e['account_nonchannel_id'],
171 e['tag_bitmap'],
172 e['credit_or_debit'],
173 e['timestamp'],
174 e['payment_hash'],
175 e['payment_part_id'],
176 e['payment_group_id'],
177 e['fees'],
178 ))
179 next_id += 1
180
181 l2.db.executemany("INSERT INTO channel_moves"
182 " (id, account_channel_id, account_nonchannel_id, tag_bitmap, credit_or_debit,"
183 " timestamp, payment_hash, payment_part_id, payment_group_id, fees)"
184 " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
185 batch)
186 l2.start()
187
188 def measure_latency(node, stop_event):
189 latencies = []
190
191 while not stop_event.is_set():
192 time.sleep(0.1)
193
194 start = time.time()

Callers

nothing calls this directly

Calls 9

wait_forFunction · 0.90
get_bench_line_graphFunction · 0.85
listpeerchannelsMethod · 0.80
xpayMethod · 0.45
invoiceMethod · 0.45
stopMethod · 0.45
queryMethod · 0.45
executemanyMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected