mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
net: always complete all initial private broadcast connections #36277
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36277
Loading…
Reference in a new issue
No description provided.
Delete branch "always_send"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Make sure we send out all three connections when initiating a private broadcast.
Use
MarkResolvedinstead ofRemoveto mark a tx as having been received back or mempool-conflicted. Prevent additional stale retry connections by tracking disconnects and explicitly granting new connections withTryGrantRetry.Intended as an alternative to #34707, addressing the theoretical timing attack described in https://github.com/bitcoin/bitcoin/pull/34707#issuecomment-5603256702. Also fixes theoretical timing attacks described in https://github.com/bitcoin/bitcoin/pull/29415#discussion_r2035693786. This is based on the idea described in https://github.com/bitcoin/bitcoin/pull/29415#discussion_r2037527330:
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Concept ACK, will review
Approach ACK
e4204baff7The code looks solid. It introduces a rigid number of times a transaction will be broadcast, regardless of whether it is received back or not. It starts at 3 and may be incremented if the transaction is stale in order to induce a new broadcast.
It also tracks when the connections are closed so that it does not remove a transaction from the list in the middle of a connection.
I did not review the tests yet. Will review them for a full ACK.
Thanks!
Show Signature
vasild's public key is on openpgp.org
DidNodeConfirmReception()is now unused, can be removed.I do not see a value in
NUM_PRIVATE_BROADCAST_PER_TXnow. Consider usingPrivateBroadcast::INITIAL_BROADCAST_COUNTall over the place and droppingNUM_PRIVATE_BROADCAST_PER_TX.Also the name
NUM_PRIVATE_BROADCAST_PER_TXis/was a bit misleading - we could send more times than that. Should beNUM_INITIAL_PRIVATE_BROADCAST_PER_TX.This increments the
send_limitcounter for a transaction that came fromGetStale()and is acceptable in the mempool. However such a transaction might still have unused "allowance". For example: broadcast 1 times, to be sent 2 more times (send_limitis3), not received back. Such transaction will have 2 more sends and does not needsend_limitto be incremented from3to4.Why replace
Remove()withMarkReceived()here? The transaction has not been actually received.Maybe elaborate this comment to something like:
After receiving the transaction (with this PR) we may send a few times more, so drop the last part:
What about removing transactions from the list only when the size of the list reaches
m_max_transactions? Then maybesend_status.disconnectedandPrivateBroadcast::NodeDisconnected()will not be needed?Add comments for the new functions before
class PrivateBroadcast.Naming nit: it is not a "limit" because we will always aim to send it this many times and will not settle for less. Maybe
planned_sends?Naming nit: I would find it more understandable if
receivedis calledreceived_by_us. Because nearbysend_statusescontains information whether the transaction has been received by the peers we send it to.If
ReattemptPrivateBroadcastgets scheduled before we complete all connections but the transaction now conflicts with our mempool, it will be removed and won't achieve the goal of this patch.Right but this is an easy way to make sure no more connections are scheduled for this transaction.
After some more thinking on this - we do not need the
NumToOpenAdd(1)call here at all. It is to compensate for a failed send. IIRC the origin of this was when the "retry stale" logic was running after 10 minutes. But it was changed to run every 2-3 minutes. I think that in the unlikely event that the send fails after opening the connection, the other 2 connections will suffice for the broadcast (just 1 suffices). In the even more unlikely event that they don't either, then the "retry stale" logic will pick it up in 2-3 minutes. Right?This was discussed in https://github.com/bitcoin/bitcoin/pull/29415#discussion_r2615178895. If we connect but fail the handshake (which is quite common) we do not reach
PickTxForSend, so we don't increasesend_statuses.size(). If we also implement your suggestion https://github.com/bitcoin/bitcoin/pull/36277#discussion_r4048983149, then we would never open a new connection and could leave a pending transaction stranded.I think this would also just make the broadcasting less reliable, since many of the first 3 initial txs would just fail handshakes.
I renamed this method to
MarkResolved, to handle both cases.Took the comment.
Done. Removed
NodeDisconnected. This simplifies it 👍.Added a second commit that removes it.
Renamed to
resolved.Renamed to
planned_sends.Right, we would grant an extra connection if
ReattemptPrivateBroadcastwas called before all 3 initial connections were made. Fixed by also checking that the tx is no longer pending.Thanks @vasild for your detailed review. I have taken most of your suggestions.
MarkReceived->MarkResolved.NodeDisconnectedand relateddisconnectedstate.DidNodeConfirmReception.github.com/bitcoin/[email protected]ACK
dad979bf01modulo weird situation for the userShow Signature
vasild's public key is on openpgp.org
This is fine, but I am just thinking - here we allow readd/reset only if the transaction has been sent 1000 times. I do not see this actually ever happening in realistic environments. Is it not more likely that somebody may want to readd/reset (and thus send again) a transaction which has reached its
planned_sendsand has been marked as resolved?What about changing this condition to:
super naming nit: since this variable is in the context of the
PrivateBroadcastclass, it does not need to contain the word "broadcast". There is some redundancy and unnecessary verbosity:PrivateBroadcast::INITIAL_BROADCAST_COUNTcould bePrivateBroadcast::INITIAL_COUNTfeel free to ignore.
This test had some value. It was removed because
txs[0]can no longer be used for it. Can we create another, unrelated transaction, put it in thetx_originator's mempool somehow (maybe get another peer toINVit totx_originatoredit: or directly sendTXmessage) and keep this test?This is a weird situation for the user:
getprivatebroadcastinfoRPC does not contain the transactionabortprivatebroadcastRPC errors with "Transaction not in private broadcast queue"I think would be resolved by the suggestion in https://github.com/bitcoin/bitcoin/pull/36277#discussion_r4060717644 because that would allow a forced resend (first point above will change).
This test establishes the 3 connections and then returns the transaction and then checks that the transaction gets delivered to the existent connections.
Would be nice if we can test that new connections are established/opened as well, after receiving the transaction. Could be achieved by:
Maybe not worth it if it is going to overcomplicate this test.
Concept ACK
(haven't looked at the test changes yet)
Should
Remove()returnplanned_sends - send_statuses.size()? Seems like it was wrong/brittle already before, but now a peer that completed the handshake (fDisconnect=true) but doesn't answer the pong would not get apeer_ack, but also wouldn't get a try back, so if we then callRemove()it could steal slots from other, unrelated transactions.in any case, the comment in line 20 should be made precise, because it is unclear what "exhausted" means, because it changed bahavior: Now the retry is basically dead code, since it will take a long time until 1000 resend attempts are reached - I think it might as well be removed. Before this change, it could be reached within minutes.
This would lead to a potential unexpected increase in resource usage - before, we'd only keep transactions while they were in flight, and the shared pointer would be released, typically when they were mined. Now, we'll keep them forever (well, until the next restart or until the maximum limit is reached) without a real necessity, which doesn't seem ideal, if someone would send a lot of large txns with private broadcast.
Indeed, but the tradeoff here is that we do not need to have a third new method
NodeDisconnectedand track the disconnected state for eachSendStatus. I'm not sure which way reviewers would prefer.master:PR:
Deleting the transactions eagerly is not a blocker for me. My preference, however, is to have a simpler interface (the public section of the
PrivateBroadcastclass) and simpler implementation (src/private_broadcast.cpp), which means to not track when a peer is disconnected. The queue is limited to 10k transactions. A full queue with 500bytes-sized transactions would occupy 5MB.Some historical data on transactions' sizes:
https://bitcoinvisuals.com/chain-tx-size
I've reverted to clear resolved/exhausted entries on
Add, so we reset as before. This makes this no longer relevant.I reverted the behavior back to using
NodeDisconnected, so this is also no longer changed.Reverted to using
NodeDisconnected, so this is no longer relevant.Added the test.
I reverted to deleting the entries at the start of
Add. This re-adds theNodeDisconnectedmethod anddisconnectedstate, but it resolves this concern. It was brought up as an objection to #34707 as well, so hopefully it makes this change less controversial.Done.
@mzumsande @vasild thank you for your reviews.
NodeDisconnectedand storing thedisconnectedstate. This makes cleanup at the beginning ofAddpossible, and gets rid of the concern in https://github.com/bitcoin/bitcoin/pull/36277#discussion_r4066000330.Removeto return the difference between planned sends and current sends.ACK
e2a6665e87Show Signature
vasild's public key is on openpgp.org
Logically,
planned_sendsorm_max_send_attemptsshould always be bigger thansend_statuses.size(). However they are updated in different places in the code and the>relationship depends on some higher level logic and not trivial to verify. It is correct now. But because we do not know how this code will be changed in the future, it would be more robust to guard against an underflow here:is this intended for backport?
@instagibbs ideally this can get merged and backported before release.
This PR should be merged and backported before a release or not at all imo. It's a pretty large behavioral delta which would compete for review time against a more complete fix for the issues a little further out.
Caveat: I will not be reviewing it further, just my two cents
I somewhat agree, but it's hard to say for sure until we have a consensus on what is meant by "a more complete fix". It is a fairly large change that is already past the release cutoff. However, we agreed on language that we are providing our users "best-effort" privacy. Our best-effort would be to try and backport this change.
IMO this should be included in 32.0 and in 31.x
Concept ACK
More streamlined change than #34707 (but it also achieves less).
Left few nits.
Nit: The expression could be moved to a separate method, e.g.
ReadyForCleanup(). Can be non-public.Second to that, as this form is also underflow-risk-free, while the current for can technically underflow.
Nit: The name could be a bit more telling, e.g.
INITIAL_CONNECTION_COUNTBase:
7988380da987c0b860885853ace8149b84ac2ee8Head:
00c1b52ee56b9a2f067befc56c171eef27efda41🟡 Minor
Resolved transactions with pending sends cannot be aborted (src/private_broadcast.cpp:163, head)
This filter hides resolved transactions from
GetBroadcastInfo, even thoughMarkResolvedretains them andIsPendingallows their remaining planned sends to proceed.AbortPrivateBroadcastsearches aGetBroadcastInfosnapshot, so an abort request after resolution cannot find or remove the transaction. The RPC reports that it is not in the queue while outstanding private-broadcast connections can still send it. Keep resolved entries available to the abort path, for example through a separate internal enumeration.Review coverage was incomplete. The adversarial review had incomplete evidence. The adversarial_glm review had incomplete evidence.
Full review report
Code Review ACK
e2a6665e87nit: maybe add a comment here that it deliberately ignores
resolved, so that the initially scheduled connections are always completed.would be nice if the fuzz test would also call
MarkResolved()andNodeDisconnected(), so it covers the actual way private broadcast works in the node. This would also require changing some assertion, as fas as I am concerned it could also be done in a follow-up.So that somebody does not "fix" it in the future :-D
Done.
Done.
Since this is would be the single callsite, I preferred not to move this into a helper. Hope that's ok.
Added the comment.
I added the two other methods to the fuzz test, which also required adding some more state to track. Some of the new state containers could be combined into structs, but that would be a bigger change so I would prefer to leave that cleanup to a follow-up.
Thanks @mzumsande @optout21 @vasild for your reviews. I have taken most of your suggestions.
Removehttps://github.com/bitcoin/bitcoin/pull/36277#discussion_r4083240831INITIAL_COUNT->INITIAL_CONNECTION_COUNThttps://github.com/bitcoin/bitcoin/pull/36277#discussion_r4120444347resolvedis deliberate inIsPendinghttps://github.com/bitcoin/bitcoin/pull/36277#discussion_r4123978823MarkResolvedandNodeDisconnectedto fuzz test https://github.com/bitcoin/bitcoin/pull/36277#discussion_r4124064031I ran the updated fuzz test overnight on 8 cores for ~10.5 hours, so ~84 hours of CPU time at a combined ~30k exec/s. No issues found.
git diff e2a6665e8719ecc5ccd9ed03d3880c5543a15797..00c1b52ee56b9a2f067befc56c171eef27efda41ACK
00c1b52ee5Show Signature
vasild's public key is on openpgp.org
Code Review ACK
00c1b52ee5I haven't reviewed the code yet, I plan to do this in the next few days, but please don't hold up merge waiting for my review, I'm ok reviewing post merge, especially since the release is coming up :)
Concept ACK
As far as I understand, currently on master there are two possible leaks, and this PR is solving them both:
inv leak
We have one transaction in the private broadcast queue, we open a connection to a peer. If the connection handshake finishes after we receive the transaction back from the network, we will disconnect without sending an INV.
A sybil attacker can use this to confirm a suspicion that a transaction is ours: it can delay the VERACK, feed us the tx over another connection, complete the handshake and observe that we don't INV over the first connection.
getdata leak
The flow of messages sent over a private broadcast connection is the following:
In private broadcast connections we only reply to getdata regarding the specific broadcast transaction that we INVed. In master we currently remove transactions after they are received back from the network, so if a peer sends getdata after we receive the transaction back from the network, we won't reply to it and instead disconnect.
A sybil attacker can use this to confirm a suspicion that a transaction is ours: it can delay the GETDATA, feed us the tx over another connection, send the GETDATA in the first connection and observe that we don't reply to it, and disconnect instead.
utACK
00c1b52ee5Post-Merge Code Review ACK
00c1b52ee5I've got rug-pulled, PR got merged while I was performing my review :)
(motto: nothing is final :P )
I share two concerns:
What happens when connections can't be opened due to some reason (e.g. Tor is down). The submitted TX will stay in the queue, but not show up in
getprivatebroadcastinfo, and can't be aborted viaabortprivatebroadcast. Maybe it would be more transparent if it considered in both of these RPCs.What happens when a transaction gets resolved for some reason (e.g. evicted from mempool or mempool check fails with a temporary fee issue), and the transaction get resubmitted? I think no retry will happen and no error is returned.
Nit: This could be pass-by-reference (mainly for consistency).