Skip to content

Commit

Permalink
gossipd: truncate gossip_store.tmp for compaction.
Browse files Browse the repository at this point in the history
If something went wrong and there was an old one, we were
appending to it!

Reported-by: @SimonVrouwe
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jun 20, 2019
1 parent 92bd3a3 commit 47b5f2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gossipd/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ bool gossip_store_compact(struct gossip_store *gs)
"Compacting gossip_store with %zu entries, %zu of which are stale",
gs->count, gs->deleted);

fd = open(GOSSIP_STORE_TEMP_FILENAME, O_RDWR|O_APPEND|O_CREAT, 0600);
fd = open(GOSSIP_STORE_TEMP_FILENAME, O_RDWR|O_TRUNC|O_CREAT, 0600);

if (fd < 0) {
status_broken(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,20 @@ def setup_gossip_store_test(node_factory, bitcoind):
return l2


@unittest.skipIf(not DEVELOPER, "need dev-compact-gossip-store")
def test_gossip_store_compact_noappend(node_factory, bitcoind):
l2 = setup_gossip_store_test(node_factory, bitcoind)

# It should truncate this, not leave junk!
with open(os.path.join(l2.daemon.lightning_dir, 'gossip_store.tmp'), 'wb') as f:
f.write(bytearray.fromhex("07deadbeef"))

l2.rpc.call('dev-compact-gossip-store')
l2.restart()
wait_for(lambda: l2.daemon.is_in_log('gossip_store: Read '))
assert not l2.daemon.is_in_log('gossip_store:.*truncate')


def test_gossip_store_load_complex(node_factory, bitcoind):
l2 = setup_gossip_store_test(node_factory, bitcoind)

Expand Down

0 comments on commit 47b5f2e

Please sign in to comment.