mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge #18038: P2P: Mempool tracks locally submitted transactions to improve wallet privacy
50fc4df6c4[mempool] Persist unbroadcast set to mempool.dat (Amiti Uttarwar)297a178536[test] Integration tests for unbroadcast functionality (Amiti Uttarwar)6851502472[refactor/test] Extract P2PTxInvStore into test framework (Amiti Uttarwar)dc1da48dc5[wallet] Update the rebroadcast frequency to be ~1/day. (Amiti Uttarwar)e25e42f20a[p2p] Reattempt initial send of unbroadcast transactions (Amiti Uttarwar)7e93eecce3[util] Add method that returns random time in milliseconds (Amiti Uttarwar)89eeb4a333[mempool] Track "unbroadcast" transactions (Amiti Uttarwar) Pull request description: This PR introduces mempool tracking of unbroadcast transactions and periodic reattempts at initial broadcast. This is a part of the rebroadcast project, and a standalone privacy win. The current rebroadcast logic is terrible for privacy because 1. only the source wallet rebroadcasts transactions and 2. it does so quite frequently. In the current system, if a user submits a transaction that does not immediately get broadcast to the network (eg. they are offline), this "rebroadcast" behavior is the safety net that can actually serve as the initial broadcast. So, keeping the attempts frequent is important for initial delivery within a reasonable timespan. This PR aims to improve # 2 by reducing the wallet rebroadcast frequency to ~1/day from ~1/15 min. It achieves this by separating the notion of initial broadcast from rebroadcasts. With these changes, the mempool tracks locally submitted transactions & periodically reattempts initial broadcast. Transactions submitted via the wallet or RPC are added to an "unbroadcast" set & are removed when a peer sends a `getdata` request, or the transaction is removed from the mempool. Every 10-15 minutes, the node reattempts an initial broadcast. This enables reducing the wallet rebroadcast frequency while ensuring the transactions will be propagated to the network. For privacy improvements around # 1, please see #16698. Thank you to gmaxwell for the idea of how to break out this subset of functionality (https://github.com/bitcoin/bitcoin/pull/16698#issuecomment-571399346) ACKs for top commit: fjahr: Code review ACK50fc4df6c4MarcoFalke: ACK50fc4df6c4, I think this is ready for merge now 👻 amitiuttarwar: The current tip `50fc4df` currently has 6 ACKs on it, so I've opened #18807 to address the last bits. jnewbery: utACK50fc4df6c4. ariard: Code Review ACK50fc4df(minor points no need to invalid other ACKs) robot-visions: ACK50fc4df6c4sipa: utACK50fc4df6c4naumenkogs: utACK50fc4dfTree-SHA512: 2dd935d645d5e209f8abf87bfaa3ef0e4492705ce7e89ea64279cb27ffd37f4727fa94ad62d41be331177332f8edbebf3c7f4972f8cda10dd951b80a28ab3c0f
This commit is contained in:
@@ -12,7 +12,10 @@ found in the mini-node branch of http://github.com/jgarzik/pynode.
|
||||
P2PConnection: A low-level connection object to a node's P2P interface
|
||||
P2PInterface: A high-level interface object for communicating to a node over P2P
|
||||
P2PDataStore: A p2p interface class that keeps a store of transactions and blocks
|
||||
and can respond correctly to getdata and getheaders messages"""
|
||||
and can respond correctly to getdata and getheaders messages
|
||||
P2PTxInvStore: A p2p interface class that inherits from P2PDataStore, and keeps
|
||||
a count of how many times each txid has been announced."""
|
||||
|
||||
import asyncio
|
||||
from collections import defaultdict
|
||||
from io import BytesIO
|
||||
@@ -627,3 +630,20 @@ class P2PDataStore(P2PInterface):
|
||||
# Check that none of the txs are now in the mempool
|
||||
for tx in txs:
|
||||
assert tx.hash not in raw_mempool, "{} tx found in mempool".format(tx.hash)
|
||||
|
||||
class P2PTxInvStore(P2PInterface):
|
||||
"""A P2PInterface which stores a count of how many times each txid has been announced."""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.tx_invs_received = defaultdict(int)
|
||||
|
||||
def on_inv(self, message):
|
||||
# Store how many times invs have been received for each tx.
|
||||
for i in message.inv:
|
||||
if i.type == MSG_TX:
|
||||
# save txid
|
||||
self.tx_invs_received[i.hash] += 1
|
||||
|
||||
def get_invs(self):
|
||||
with mininode_lock:
|
||||
return list(self.tx_invs_received.keys())
|
||||
|
||||
Reference in New Issue
Block a user