Thursday, November 24, 2022
HomeBitcoinp2p - Why does the bitcoin consumer ship transaction's txid and wtxid...

p2p – Why does the bitcoin consumer ship transaction’s txid and wtxid in ‘inv’ course of?


Wtxid relay was launched in BIP339, the place you may discover extra particulars on the rationale and design.

At any time when a node helps BIP339, it is going to advertize that to its friends, by means of the wtxidrelay negotiations message. When these friends help BIP339 as effectively, they could select to advertize transactions by means of their wtxid as an alternative of their txid.

Each transaction is simply advertized as soon as (utilizing the txid for regular friends, and utilizing the wtxid for BIP339 friends) on every connection. That is not the code you posted although; that code is for populating the relay pool: the set of latest transactions which is used to reply getdata requests despatched in response to transactions advertized by invs. As a result of some friends might request utilizing the txid, and a few might requests utilizing the wtxid (principally matching their BIP339 help, however even BIP339 friends will in some instances request utilizing txids), each are added to the relay pool.

  1. Why the node ship these two ids, what are the advantages?

Wtxid based mostly relay is healthier, however shouldn’t be accessible to pre-BIP339 friends, so each have to stay supported.

  1. Suppose a transaction’s txid is A, and its wtxid is B. Nodes will relay A and B inv to friends. After a consumer acquired A primary, will the consumer mark this transaction “fAlreadyHave” when receiving B later?

Usually the identical transaction is simply advertized as soon as per connection, however it’s potential {that a} node hears a txid A primary, and the wtxid B later from one other peer. If the precise transaction was acquired already (by fetching tx utilizing txid A), then each txid A and wtxid B can be thought-about “AlreadyHave”.

Earlier than the precise transaction is acquired, the node has no concept that ads for A and for B discuss with the identical transaction. To keep away from duplicate requests, Bitcoin Core introduces a 2s delay earlier than fetching transactions marketed utilizing txids, to offer wtxid friends an opportunity to advertize it first.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments