Thursday, December 1, 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 should advertize that to its friends, by means of the wtxidrelay negotiations message. When these friends assist BIP339 as nicely, they might select to advertize transactions by means of their wtxid as an alternative of their txid.

Each transaction is barely 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 could request utilizing the txid, and a few could requests utilizing the wtxid (principally matching their BIP339 assist, 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 primarily based relay is healthier, however is just not out there 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 obtained A primary, will the consumer mark this transaction “fAlreadyHave” when receiving B later?

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

Earlier than the precise transaction is obtained, the node has no concept that ads for A and for B check with the identical transaction. To keep away from duplicate requests, Bitcoin Core introduces a 2s delay earlier than fetching transactions marketed utilizing txids, to present 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