diff --git a/CHANGELOG.md b/CHANGELOG.md index 829675f3d..08d8db27f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Protocol: `channel_update` sent to disable channel only if we reject an HTLC. +- Protocol: we don't send redundant `node_announcement` on every new channel. ### Deprecated diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index f40ff8467..7bc605854 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -339,13 +339,49 @@ static void send_node_announcement(struct daemon *daemon) tal_hex(tmpctx, err)); } +/* Return true if the only change would be the timestamp. */ +static bool node_announcement_redundant(struct daemon *daemon) +{ + struct node *n = get_node(daemon->rstate, &daemon->id); + if (!n) + return false; + + if (n->last_timestamp == -1) + return false; + + if (tal_count(n->addresses) != tal_count(daemon->announcable)) + return false; + + for (size_t i = 0; i < tal_count(n->addresses); i++) + if (!wireaddr_eq(&n->addresses[i], &daemon->announcable[i])) + return false; + + BUILD_ASSERT(ARRAY_SIZE(daemon->alias) == ARRAY_SIZE(n->alias)); + if (!memeq(daemon->alias, ARRAY_SIZE(daemon->alias), + n->alias, ARRAY_SIZE(n->alias))) + return false; + + BUILD_ASSERT(ARRAY_SIZE(daemon->rgb) == ARRAY_SIZE(n->rgb_color)); + if (!memeq(daemon->rgb, ARRAY_SIZE(daemon->rgb), + n->rgb_color, ARRAY_SIZE(n->rgb_color))) + return false; + + if (!memeq(daemon->globalfeatures, tal_count(daemon->globalfeatures), + n->gfeatures, tal_count(n->gfeatures))) + return false; + + return true; +} + /* Should we announce our own node? */ static void maybe_send_own_node_announce(struct daemon *daemon) { if (!daemon->rstate->local_channel_announced) return; - /* FIXME: We may not need to retransmit here, if previous still valid. */ + if (node_announcement_redundant(daemon)) + return; + send_node_announcement(daemon); daemon->rstate->local_channel_announced = false; } diff --git a/tests/test_gossip.py b/tests/test_gossip.py index 77bddaa46..1eac9a5df 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -4,7 +4,6 @@ from utils import wait_for, TIMEOUT, only_one import json import logging import os -import pytest import struct import subprocess import time @@ -843,7 +842,6 @@ def test_gossip_store_load(node_factory): assert not l1.daemon.is_in_log('gossip_store.*truncating') -@pytest.mark.xfail(strict=True) @unittest.skipIf(not DEVELOPER, "Needs fast gossip propagation") def test_node_reannounce(node_factory, bitcoind): "Test that we reannounce a node when parameters change"