Page MenuHomePhabricator

net: prevent peers.dat corruptions by only serializing once
ClosedPublic

Authored by PiRK on Mon, Nov 25, 15:44.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK published this revision for review.Mon, Nov 25, 16:38
PiRK edited the summary of this revision. (Show Details)
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/hash.h
200 ↗(On Diff #51092)

layout

This revision is now accepted and ready to land.Tue, Nov 26, 08:34