I'm trying to request tx messages from known peers but it doesn't appear as though this is supported with bitcoin-cli. Is there a way to do this?
2 Answers
See https://en.bitcoin.it/wiki/Protocol_documentation#getdata for the original reason why this is not possible:
arbitrary access to transactions in the chain is not allowed to avoid having clients start to depend on nodes having full transaction indexes (which modern nodes do not).
Update
As Murch and Pieter Wuille explained, there are also privacy-related safeguards against obtaining arbitrary transaction data from peers:
Some of these are described in https://github.com/bitcoin/bitcoin/pull/18861 (May 2020):
In general, we should try to not leak information about what transactions we have (recently) learned about before deciding to announce them to our peers. There is a controlled transaction dissemination process that reveals our transactions to peers that has various safeguards for privacy (it's rate-limited, delayed & batched, deterministically sorted, ...), and ideally there is no way to test which transactions we have before that controlled process reveals them.
I think it is worth reading that web-page in full to see the full rationale and some further comments there.
-
Historically that was the reason why arbitrary transaction fetching was not allowed, but in more recent times that rationale on the wiki is actually outdated. You can't even request arbitrary mempool transactions anymore if they haven't been announced to you yet (because of privacy reasons, see @Murch's answer). Mar 10 at 16:09
-
-
1OK, I've added something to my answer to point that out (I considered just deleting mine in favour of Murch's answer but can't yet). Mar 10 at 22:00
No, such a function does not exist. A node will not provide a transaction that it has not previously offered to the requesting peer—that would make nodes trivially fingerprintable. Also, it would be expensive for nodes to look up arbitrary transactions, as RedGrittyBrick pointed out in the other answer.
Bitcoin Core will only relay each transaction when it first learns about it. It will at that point announce its new inventory to all its peers, which may request the newly offered transaction after the announcement. If a transaction does not propagate to every node at that time, that’s fine—if the transaction is included in a block, it’s guaranteed to reach everyone.