HomePhabricator

net: prevent peers.dat corruptions by only serializing once

Description

net: prevent peers.dat corruptions by only serializing once

Summary:
This fixes a potential corruption of the peers.dat file that could prevent a
node from restarting and force the user to manually delete the file.

hash: add HashedSourceWriter

This class is the counterpart to CHashVerifier, in that it
writes data to an underlying source stream,
while keeping a hash of the written data.

addrdb: Only call Serialize() once

The previous logic would call it once for serializing into the filestream,
and then again for serializing into the hasher. If AddrMan was changed
in between these calls by another thread, the resulting peers.dat would
be corrupt with non-matching checksum and data.
Fix this by using HashedSourceWriter, which writes the data
to the underlying stream and keeps track of the hash in one go.

This is a backport of core#26909

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D17200

Details

Provenance
Martin Zumsande <mzumsande@gmail.com>Authored on Jan 16 2023, 01:18
PiRKCommitted on Tue, Nov 26, 13:09
PiRKPushed on Tue, Nov 26, 13:09
Reviewer
Restricted Project
Differential Revision
D17200: net: prevent peers.dat corruptions by only serializing once
Parents
rABC7ade4257d9dc: [Chronik] Take lock when accessing ActiveTip in chronikbridge_tests
Branches
Unknown
Tags
Unknown