From 1df1300cc941a23b1a63c46ca4dfdaead48f0058 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 10 Feb 2025 16:37:52 +1030 Subject: [PATCH] gossip_store: don't need to check for truncated amounts. That's actually caught by the gossmap load now. Signed-off-by: Rusty Russell --- common/gossmap.c | 2 +- gossipd/gossip_store.c | 22 +--------------------- tests/test_gossip.py | 4 ++-- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/common/gossmap.c b/common/gossmap.c index 4f3f3e1fa..524cf1b4f 100644 --- a/common/gossmap.c +++ b/common/gossmap.c @@ -1275,7 +1275,7 @@ struct gossmap *gossmap_load_(const tal_t *ctx, logcb(cbarg, LOG_BROKEN, "gossip_store only processed %"PRIu64 " bytes of %"PRIu64" (expected %"PRIu64")", - map->map_size, map->map_end, expected_len); + map->map_end, map->map_size, expected_len); return tal_free(map); } return map; diff --git a/gossipd/gossip_store.c b/gossipd/gossip_store.c index 74d859692..4dabe4eeb 100644 --- a/gossipd/gossip_store.c +++ b/gossipd/gossip_store.c @@ -204,7 +204,6 @@ static int gossip_store_compact(struct daemon *daemon, struct gossip_hdr hdr; u8 oldversion, version = GOSSIP_STORE_VER; struct stat st; - bool prev_chan_ann = false; struct timeabs start = time_now(); const char *bad; @@ -313,18 +312,8 @@ static int gossip_store_compact(struct daemon *daemon, } switch (fromwire_peektype(msg)) { - case WIRE_GOSSIP_STORE_CHANNEL_AMOUNT: - /* Previous channel_announcement may have been deleted */ - if (prev_chan_ann) - cannounces++; - prev_chan_ann = false; - break; case WIRE_CHANNEL_ANNOUNCEMENT: - if (prev_chan_ann) { - bad = "channel_announcement without amount"; - goto badmsg; - } - prev_chan_ann = true; + cannounces++; break; case WIRE_GOSSIP_STORE_CHAN_DYING: { struct chan_dying cd; @@ -346,9 +335,6 @@ static int gossip_store_compact(struct daemon *daemon, case WIRE_NODE_ANNOUNCEMENT: nannounces++; break; - default: - bad = "Unknown message"; - goto badmsg; } if (!write_all(new_fd, &hdr, sizeof(hdr)) @@ -363,12 +349,6 @@ static int gossip_store_compact(struct daemon *daemon, assert(*total_len == lseek(new_fd, 0, SEEK_END)); - /* Unlikely, but a channel_announcement without an amount: we just truncate. */ - if (prev_chan_ann) { - bad = "channel_announcement without amount"; - goto badmsg; - } - /* If we have any contents, and the file is less than 1 hour * old, say "seems good" */ if (st.st_mtime > time_now().ts.tv_sec - 3600 && *total_len > 1) { diff --git a/tests/test_gossip.py b/tests/test_gossip.py index a35c578c0..8a5814055 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -1283,7 +1283,7 @@ def test_gossip_store_load_announce_before_update(node_factory): def test_gossip_store_load_amount_truncated(node_factory): """Make sure we can read canned gossip store with truncated amount""" - l1 = node_factory.get_node(start=False, broken_log=r'gossip_store: channel_announcement without amount \(offset 1\)|Moving to gossip_store.corrupt|plugin-cln-renepay:.*unable to fetch channel capacity') + l1 = node_factory.get_node(start=False, broken_log=r'gossip_store only processed 1 bytes of 445 \(expected 445\)|Moving to gossip_store.corrupt|plugin-cln-renepay:.*unable to fetch channel capacity') with open(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, 'gossip_store'), 'wb') as f: f.write(bytearray.fromhex("0c" # GOSSIP_STORE_VERSION "000001b0" # len @@ -1294,7 +1294,7 @@ def test_gossip_store_load_amount_truncated(node_factory): l1.start() # May preceed the Started msg waited for in 'start'. - wait_for(lambda: l1.daemon.is_in_log(r'\*\*BROKEN\*\* gossipd: gossip_store: channel_announcement without amount \(offset 1\)\.')) + wait_for(lambda: l1.daemon.is_in_log(r'\*\*BROKEN\*\* gossipd: gossip_store only processed 1 bytes of 445 \(expected 445\)')) wait_for(lambda: l1.daemon.is_in_log(r'\*\*BROKEN\*\* gossipd: gossip_store: Moving to gossip_store.corrupt')) wait_for(lambda: l1.daemon.is_in_log(r'gossip_store: Read 0/0/0/0 cannounce/cupdate/nannounce/delete from store in 0 bytes, now 1 bytes \(populated=false\)')) assert os.path.exists(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, 'gossip_store.corrupt'))