From 6195a878f71dc0f7423ea14123ce795c7c119dec Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 10 Aug 2019 20:17:49 +0930 Subject: [PATCH] lightningd: don't allow sending of HTLCs while still syncing. If we don't know block height, we shouldn't be sending HTLCs. This stops us forwarding HTLCs as well as new payments. Signed-off-by: Rusty Russell --- lightningd/peer_htlcs.c | 6 ++++++ tests/test_misc.py | 11 +++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index e52dc6d06..fac3cfeee 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -449,6 +449,12 @@ enum onion_type send_htlc_out(struct channel *out, return WIRE_TEMPORARY_CHANNEL_FAILURE; } + if (!topology_synced(out->peer->ld->topology)) { + log_info(out->log, "Attempt to send HTLC but still syncing" + " with bitcoin network"); + return WIRE_TEMPORARY_CHANNEL_FAILURE; + } + /* Make peer's daemon own it, catch if it dies. */ hout = new_htlc_out(out->owner, out, amount, cltv, payment_hash, onion_routing_packet, in == NULL, in); diff --git a/tests/test_misc.py b/tests/test_misc.py index cc4fb62de..e36c91fcd 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -152,10 +152,8 @@ def test_lightningd_still_loading(node_factory, bitcoind, executor): "id": r['id'] } - # Start it once, make sure it gets a second block (thus writes into db) - l1 = node_factory.get_node() - bitcoind.generate_block(1) - sync_blockheight(bitcoind, [l1]) + # Start it, establish channel. + l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True}) l1.stop() # Now make sure it's behind. @@ -171,9 +169,14 @@ def test_lightningd_still_loading(node_factory, bitcoind, executor): assert 'warning_bitcoind_sync' not in l1.rpc.getinfo() assert 'warning_lightningd_sync' in l1.rpc.getinfo() + # Payments will fail. FIXME: More informative msg? + with pytest.raises(RpcError, match=r'TEMPORARY_CHANNEL_FAILURE'): + l1.pay(l2, 1000) + # Release the mock, and it will recover. mock_release.set() wait_for(lambda: 'warning_lightningd_sync' not in l1.rpc.getinfo()) + l1.pay(l2, 1000) def test_ping(node_factory):