| 341 | @pytest.mark.openchannel('v2') |
| 342 | @pytest.mark.parametrize("anchors", [False, True]) |
| 343 | def test_opening_tiny_channel(node_factory, anchors): |
| 344 | # Test custom min-capacity-sat parameters |
| 345 | # |
| 346 | # [l1]-----> [l2] (~6000) - technical minimal value that wont be rejected |
| 347 | # \ |
| 348 | # o---> [l3] (10000) - the current default |
| 349 | # \ |
| 350 | # o-> [l4] (20000) - a node with a higher minimal value |
| 351 | # |
| 352 | # For each: |
| 353 | # 1. Try to establish channel with capacity 1sat smaller than min_capacity_sat |
| 354 | # 2. Try to establish channel with capacity exact min_capacity_sat |
| 355 | # |
| 356 | # BOLT #2: |
| 357 | # The receiving node MAY fail the channel if: |
| 358 | # ... |
| 359 | # - `funding_satoshis` is too small. |
| 360 | # ... |
| 361 | # The receiving node MUST fail the channel if: |
| 362 | # ... |
| 363 | # - it considers `feerate_per_kw` too small for timely processing or unreasonably large. |
| 364 | # |
| 365 | dustlimit = 546 |
| 366 | reserves = 2 * dustlimit |
| 367 | if anchors: |
| 368 | min_commit_tx_fees = basic_fee(3750, True) |
| 369 | else: |
| 370 | min_commit_tx_fees = basic_fee(7500, False) |
| 371 | overhead = reserves + min_commit_tx_fees |
| 372 | if anchors: |
| 373 | # Gotta fund those anchors too! |
| 374 | overhead += 660 |
| 375 | |
| 376 | l2_min_capacity = 1 # just enough to get past capacity filter |
| 377 | l3_min_capacity = 10000 # the current default |
| 378 | l4_min_capacity = 20000 # a server with more than default minimum |
| 379 | |
| 380 | opts = [{'min-capacity-sat': 0, 'dev-no-reconnect': None}, |
| 381 | {'min-capacity-sat': l2_min_capacity, 'dev-no-reconnect': None}, |
| 382 | {'min-capacity-sat': l3_min_capacity, 'dev-no-reconnect': None}, |
| 383 | {'min-capacity-sat': l4_min_capacity, 'dev-no-reconnect': None}] |
| 384 | if anchors is False: |
| 385 | for opt in opts: |
| 386 | opt['dev-force-features'] = "-23" |
| 387 | l1, l2, l3, l4 = node_factory.get_nodes(4, opts=opts) |
| 388 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 389 | l1.rpc.connect(l3.info['id'], 'localhost', l3.port) |
| 390 | l1.rpc.connect(l4.info['id'], 'localhost', l4.port) |
| 391 | |
| 392 | with pytest.raises(RpcError, match=r'They sent (ERROR|WARNING|ABORT).*channel capacity is .*, which is below .*sat'): |
| 393 | l1.fundchannel(l2, l2_min_capacity + overhead - 1) |
| 394 | assert only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['connected'] |
| 395 | |
| 396 | l1.fundchannel(l2, l2_min_capacity + overhead) |
| 397 | |
| 398 | with pytest.raises(RpcError, match=r'They sent (ERROR|WARNING|ABORT).*channel capacity is .*, which is below .*sat'): |
| 399 | l1.fundchannel(l3, l3_min_capacity + overhead - 1) |
| 400 | assert only_one(l1.rpc.listpeers(l3.info['id'])['peers'])['connected'] |