gossipd: don't create redundant node_announcements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-09-24 11:12:00 +09:30 committed by Christian Decker
parent afc92dd757
commit bb5e2ffafb
3 changed files with 38 additions and 3 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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"