Repository navigation
Backport four Bitcoin Core 30.4/30.5 advisory fixes: TCP urgent data, 64-bit file positions, paused send timeout, duplicate INVs - #296
Merged
Conversation
The select() backend, which Windows and macOS use, put every socket into the exception set, whatever was asked of it. A peer whose receive side is paused is waited on for sending only, and TCP urgent data then showed as an error event; the socket handler reads on an error event, so the pause did not hold and what was read was kept without bound. poll(), which Linux uses, has no such case. The exception set is now filled only for a socket that is waited on for reading, and a socket nothing is asked of is left out of the call. Backport of Bitcoin Core 30.4 commit d4a065bf0fab, by Antoine Poinsot. Github-Pull: bitcoin/bitcoin#36665 Rebased-From: 1e0c407377034e9cbb4d52f1f534c06cdf202a36
After the change before this one a socket waited on for reading is still in the exception set of select(). With urgent data pending on it the wait returns at once, every time, with nothing for recv() to return: the socket handler spins for as long as the byte is there. Windows needs the exception set for one thing, a failed non-blocking connect(), which it reports nowhere else. So ERR becomes an event that can be asked for, ConnectToSocket() asks for it, and every other wait leaves the set empty. With select() a socket waited on without ERR no longer reports exceptional conditions; a closed or failed connection is seen by the read that follows, as before. No change with poll(). The Stratum v2 listener disconnects a client on ERR. On Windows and macOS it now finds a broken connection through recv(), like the P2P handler. A unit test sends an urgent byte and checks that a wait for reading does not report an error. Run on Linux with sock.cpp built for select(): it fails on the code as it was and on the change before this one, and passes here. Port of Bitcoin Core commit 97e3c9562, by Cory Fields, Vasil Dimov and Antoine Poinsot, to the event names of 30.x. Github-Pull: bitcoin/bitcoin#36716 Rebased-From: 97e3c9562291f5bbc2b03fef1c70e4975eb2a8c6
A position in a block or undo file was an unsigned int. Block files are capped at 128 MiB, undo files are not: the undo data of the blocks of one block file go into one undo file, and blocks that spend many large outputs have far more undo data than block data. Past 4 GiB the position wrapped, and on Windows fseek() takes a 32-bit long and failed from 2 GiB. The position, the sizes kept per file and the offsets in the block index are 64 bits wide, and seeking and truncating use the 64-bit calls on Windows. Positions are written as varints, so nothing on disk changes. Avian's own part: ReadRawBlock() computed the header position with a brace-initialized int64_t, which does not take a uint64_t; it casts now. Compiling the files that handle these positions with -Wshorten-64-to-32 before and after shows no place where a position is cut back to 32 bits. Backport of Bitcoin Core 30.4 commits adb363c753ee and a9e7b35d06af, by Antoine Poinsot. Github-Pull: bitcoin/bitcoin#36669 Rebased-From: 17556cb1f52fcbc807f65245101f72e8ec1573d8 Rebased-From: 48092a9042d8fcfd6bb7ae5911a1d53b8746d546
A peer that does not read leaves the send buffer over its limit, and the node stops queueing replies for it but goes on queueing announcements. The time the buffer went over the limit is now kept, and a peer that has not brought it back under within 20 minutes is disconnected. In Bitcoin Core the peer that could stay in that state was one too old to be asked for a pong. Avian refuses peers below protocol version 70033, all of which answer pings, so the ping timeout already ends such a connection here. The change is taken to keep the bound explicit and the code in step with 30.x. Backport of Bitcoin Core 30.4 commit 96b53721763e, by Antoine Poinsot. Github-Pull: bitcoin/bitcoin#36667 Rebased-From: cc2534cdf7b14d0f1a18928ebaab7f7fdd7e839e
An inv message may name the same transaction up to 50,000 times, and each entry was handled as if it were new. Entries are now passed over once their hash has been seen in the message, txids and wtxids apart. In Bitcoin Core the costly case is a wtxid announcement of an orphan, which looks at every missing parent each time. Avian does not negotiate wtxid relay and ignores wtxid announcements, so that path is not reached today; it would be once wtxid relay is turned on. The functional test of the upstream change is left out: it needs wtxid relay, and the functional suite is not localized. Its txid cases were run against a regtest node with the P2P layer of the framework set to Avian's magic and version: one announcement per transaction with this change, two on 5.0.6. Backport of Bitcoin Core 30.5 commit 1bb5289d48c1, by Gregory Sanders. Github-Pull: bitcoin/bitcoin#35878 Rebased-From: 1278a5970d5ada0979052a5bad899e896b8ab40b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four network and storage fixes from Bitcoin Core 30.4 and 30.5, each published there with a security advisory, and the follow-up to the first. Avian 5.x is based on 30.2 and had none of them. One commit per upstream change, with
Github-PullandRebased-Fromlines.Independent of #295: the two touch different files, and the release notes are added in different places.
What is taken, and what it means for Avian
select()backend put every socket in the exception set. TCP urgent data on a peer whose receive side was paused showed as an error event, the handler read on, and what it read was kept without bound.select(). Linux usespoll()and was not affected. This is the one that matters.fseek()failed from 2 GiB.invmessage is handled once per transaction it names, however often it names it.Differences from upstream
RECV,SEND,ERR). Without it, the first fix leaves a busy loop: a socket waited on for reading with urgent data pending wakes the handler every time with nothing to read. The Stratum v2 listener, which disconnects a client onERR, now finds a broken connection throughrecv()on Windows and macOS, as the P2P handler does.BlockManager::ReadRawBlock()computed the header position with a brace-initializedint64_t, which does not take auint64_t.How it was checked
Built and run in WSL (clang 18). Nothing was run on Windows or macOS.
script_assets_testsis skipped locally for want of its data directory. The newsock_tests/wait_ignores_urgent_datagoes throughselect()in the macOS CI job.select()path:sock.cppbuilt forselect()on Linux, with one more check added for the test run: a wait for sending only, as for a paused peer, must not report an error.-Wshorten-64-to-32before and after: no place where a position is cut back to 32 bits, and three such places gone._fseeki64,_ftelli64,_chsize_s, theselect()branch):-fsyntax-onlywith mingw-w64 passes forfs_helpers.cpp,streams.cpp,flatfile.cppandsock.cpp. CI has no Windows job, so the Guix build is the first full compile of them.Not tested: the send buffer timeout, and the attack of the first advisory against a running node.