From 160c564e5f5815d7eea2ac68b160ba5240043f62 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 9 Sep 2020 13:28:45 +0200 Subject: [PATCH] fix: suppress duplicated channel_state_changed events --- lightningd/channel.c | 16 +++++++++------- tests/test_plugin.py | 8 -------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lightningd/channel.c b/lightningd/channel.c index 0d8fa436b..7f5c0d6d6 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -399,13 +399,15 @@ void channel_set_state(struct channel *channel, wallet_channel_save(channel->peer->ld->wallet, channel); /* plugin notification channel_state_changed */ - derive_channel_id(&cid, &channel->funding_txid, channel->funding_outnum); - notify_channel_state_changed(channel->peer->ld, - &channel->peer->id, - &cid, - channel->scid, - old_state, - state); + if (state != old_state) { /* see issue #4029 */ + derive_channel_id(&cid, &channel->funding_txid, channel->funding_outnum); + notify_channel_state_changed(channel->peer->ld, + &channel->peer->id, + &cid, + channel->scid, + old_state, + state); + } } void channel_fail_permanent(struct channel *channel, const char *fmt, ...) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 8d647e965..f12e67b3c 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -731,14 +731,6 @@ def test_channel_state_changed_unilateral(node_factory, bitcoind): bitcoind.generate_block(100) # so it gets settled - msg = l2.daemon.wait_for_log("channel_state_changed.*new_state.*") - event = ast.literal_eval(re.findall(".*({.*}).*", msg)[0]) - assert(event['peer_id'] == peer_id) - assert(event['channel_id'] == cid) - assert(event['short_channel_id'] == scid) - assert(event['old_state'] == "AWAITING_UNILATERAL") # this actually happens - assert(event['new_state'] == "AWAITING_UNILATERAL") # note: same states - msg = l2.daemon.wait_for_log("channel_state_changed.*new_state.*") event = ast.literal_eval(re.findall(".*({.*}).*", msg)[0]) assert(event['peer_id'] == peer_id)