(node_factory, bitcoind)
| 2113 | |
| 2114 | @pytest.mark.developer("needs DEVELOPER=1") |
| 2115 | def test_onchain_middleman_simple(node_factory, bitcoind): |
| 2116 | # We track channel balances, to verify that accounting is ok. |
| 2117 | coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py') |
| 2118 | |
| 2119 | # HTLC 1->2->3, 1->2 goes down after 2 gets preimage from 3. |
| 2120 | disconnects = ['-WIRE_UPDATE_FULFILL_HTLC', 'permfail'] |
| 2121 | l1, l2, l3 = node_factory.get_nodes(3, opts=[{'plugin': coin_mvt_plugin}, |
| 2122 | {'plugin': coin_mvt_plugin, |
| 2123 | 'disconnect': disconnects}, |
| 2124 | {}]) |
| 2125 | |
| 2126 | # l2 connects to both, so l1 can't reconnect and thus l2 drops to chain |
| 2127 | l2.rpc.connect(l1.info['id'], 'localhost', l1.port) |
| 2128 | l2.rpc.connect(l3.info['id'], 'localhost', l3.port) |
| 2129 | l2.fundchannel(l1, 10**6) |
| 2130 | c23, _ = l2.fundchannel(l3, 10**6) |
| 2131 | channel_id = first_channel_id(l1, l2) |
| 2132 | |
| 2133 | # Make sure routes finalized. |
| 2134 | mine_funding_to_announce(bitcoind, [l1, l2, l3]) |
| 2135 | l1.wait_channel_active(c23) |
| 2136 | |
| 2137 | # Give l1 some money to play with. |
| 2138 | l2.pay(l1, 2 * 10**8) |
| 2139 | |
| 2140 | # Must be bigger than dust! |
| 2141 | inv = l3.rpc.invoice(10**8, 'middleman', 'desc') |
| 2142 | rhash = inv['payment_hash'] |
| 2143 | |
| 2144 | route = l1.rpc.getroute(l3.info['id'], 10**8, 1)["route"] |
| 2145 | assert len(route) == 2 |
| 2146 | |
| 2147 | q = queue.Queue() |
| 2148 | |
| 2149 | def try_pay(): |
| 2150 | try: |
| 2151 | l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret']) |
| 2152 | l1.rpc.waitsendpay(rhash) |
| 2153 | q.put(None) |
| 2154 | except Exception as err: |
| 2155 | q.put(err) |
| 2156 | |
| 2157 | t = threading.Thread(target=try_pay) |
| 2158 | t.daemon = True |
| 2159 | t.start() |
| 2160 | |
| 2161 | # l2 will drop to chain. |
| 2162 | l2.daemon.wait_for_log('sendrawtx exit 0') |
| 2163 | l1.bitcoin.generate_block(1, wait_for_mempool=1) |
| 2164 | l2.daemon.wait_for_log(' to ONCHAIN') |
| 2165 | l1.daemon.wait_for_log(' to ONCHAIN') |
| 2166 | l2.daemon.wait_for_log('OUR_UNILATERAL/THEIR_HTLC') |
| 2167 | |
| 2168 | # l2 should fulfill HTLC onchain, and spend to-us (any order) |
| 2169 | l2.wait_for_onchaind_broadcast('OUR_HTLC_SUCCESS_TX', |
| 2170 | 'OUR_UNILATERAL/THEIR_HTLC') |
| 2171 | |
| 2172 | # Payment should succeed. |
nothing calls this directly
no test coverage detected