Skip to content

Bip339: small corrections and update spec to match implementation#961

Closed
jnewbery wants to merge 3 commits intobitcoin:masterfrom
jnewbery:bip339-txid-relay
Closed

Bip339: small corrections and update spec to match implementation#961
jnewbery wants to merge 3 commits intobitcoin:masterfrom
jnewbery:bip339-txid-relay

Conversation

@jnewbery
Copy link
Copy Markdown
Contributor

@jnewbery jnewbery commented Aug 3, 2020

Updates text to match implementation, specifically that it's always permitted to request a transaction using the txid. Also includes some minor tidy-ups.

@jnewbery
Copy link
Copy Markdown
Contributor Author

jnewbery commented Aug 3, 2020

cc @sdaftuar @sipa

Copy link
Copy Markdown
Member

@sdaftuar sdaftuar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first commit seems unnecessary to me; I just took a quick look through the BIP repo and several other BIPs that introduce new p2p messages also use lower case (sendheaders BIP 130, feefilter BIP 133, compact blocks BIP 152) -- which is also what we send on the wire. It doesn't really matter but if it were up to me I'd just stick with lower case for consistency.

EDIT: Hah, you were making it consistent with the other p2p messages in this doc, not with other BIPs! Oops.

Comment thread bip-0339.mediawiki Outdated
Comment thread bip-0339.mediawiki Outdated
Comment thread bip-0339.mediawiki Outdated
Comment thread bip-0339.mediawiki Outdated
@jnewbery jnewbery force-pushed the bip339-txid-relay branch from 8da6903 to 1fca091 Compare August 3, 2020 18:15
@jnewbery
Copy link
Copy Markdown
Contributor Author

jnewbery commented Aug 3, 2020

Thanks for the review @sdaftuar . I've addressed all of your review comments.

Use lowercase for message types.
@jnewbery jnewbery force-pushed the bip339-txid-relay branch from 1fca091 to d1c237f Compare August 3, 2020 19:54
@jnewbery
Copy link
Copy Markdown
Contributor Author

jnewbery commented Aug 3, 2020

I just took a quick look through the BIP repo and several other BIPs that introduce new p2p messages also use lower case (sendheaders BIP 130, feefilter BIP 133, compact blocks BIP 152) -- which is also what we send on the wire

I mostly wanted these to be internally consistent within the document, so that it's clear that they're referring to the same concept. Most of the message types in this doc were uppercase which is why I standardized to that, but you're right that lowercase is better. I've updated the first commit to do that.

@jnewbery jnewbery force-pushed the bip339-txid-relay branch from d1c237f to 2f9649f Compare August 3, 2020 20:13
Copy link
Copy Markdown
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, some nits if you agree and retouch.

Comment thread bip-0339.mediawiki Outdated
Comment thread bip-0339.mediawiki Outdated
Comment thread bip-0339.mediawiki
A node may always fetch a transactions using the txid.
@jnewbery jnewbery force-pushed the bip339-txid-relay branch from 2f9649f to 1eee1b1 Compare August 4, 2020 13:43
@jonatack
Copy link
Copy Markdown
Member

jonatack commented Aug 4, 2020

ACK, looks like a net improvement (pun intended)

Comment thread bip-0339.mediawiki
# A new inv type MSG_WTX (0x00000005) is added, for use in both inv messages and getdata requests, indicating that the hash being referenced is a transaction's wtxid. In the case of getdata requests, MSG_WTX implies that the transaction being requested should be serialized with witness as well, as described in BIP 144.
# After a node has sent and received a wtxidrelay message to/from a given peer, the node is required to use the MSG_WTX inv-type when announcing transactions to that peer, or requesting announced transactions from that peer.
# After a node has received a wtxidrelay message from a peer, the node MUST use the MSG_WTX inv type when announcing transactions to that peer.
# After receiving an inv message containing a MSG_WTX object, a node SHOULD use a MSG_WTX getdata message to request any announced transactions. A node MAY still request transactions from that peer using MSG_TX getdata messages, such as for transactions not recently announced by that peer (like the parents of recently announced transactions).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On further thought -- would this last bullet be clearer if we wrote it like this:

After a node has received a wtxidrelay message from a peer, a node SHOULD use a MSG_WTX getdata message to request any announced transactions from that peer. A node MAY still request transactions from that peer using MSG_TX getdata messages, such as for transactions not recently announced by that peer (like the parents of recently announced transactions).

The way it's written here, it seems like if any peer sends us a MSG_WTX inv, that we should (a) respond with a MSG_WTX getdata (even if the peer hasn't negotiated wtxidrelay with us!) and (b) it's okay if we respond with a MSG_TX getdata (which is basically wrong, we're just trying to carve out reasons you might send one over the wire, we don't expect it to occur for a hash that appears as a MSG_WTX inv).

And should we add a new bullet saying that we (may? must?) ignore wtxidrelay messages unless the peer's version is >= 70016?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can keep the SHOULD as a MUST as you underscore well enough a INV(MSG_WTX) announcement must be paired with a GETDATA(MSG_WTX). But also fine with your current alternative, which sounds clearer IMO.

Yes, good to check peer's version and must ignore them, some bitcoin libraries are currently forgetting to export p2p versions to let upstream software announce p2p extensions they want to speak (like rust-bitcoin).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of this BIP (and I think the most reasonable reading of it) is that sending a peer a wtxidrelay message to a peer means "please send inventory to me using MSG_WTX objects in the INV message". I don't think it should also mean "you must request transactions using MSG_WTX objects in the GETDATA message". That would implicitly mean that wtxidrelay must be enabled in both directions (because for you to request MSG_WTX objects, I must be announcing MSG_WTX objects). If that's the intention, then I think the BIP needs to explicitly say that, and also specify what happens if one side sends a wtxidrelay but the other side doesn't.

I think the protocol is simpler if it's enabled separately in both directions and wtxidrelay simply means "send me MSG_WTX INVs".

Copy link
Copy Markdown
Member

@sdaftuar sdaftuar Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of this BIP (and I think the most reasonable reading of it) is that sending a peer a wtxidrelay message to a peer means "please send inventory to me using MSG_WTX objects in the INV message".

This is a misunderstanding of the BIP and the implementation. Note that the original BIP text was (essentially) correct here -- the intention is that wtxidrelay is either on in both directions on a link, or off in both directions. This is also how the implementation works:

  • for peers with a version >= 70016, we always send a wtxidrelay message, but we only enable it on a link if we also receive it
  • peers that haven't sent us a wtxidrelay message (or whose version is too low) will have any MSG_WTX inv's ignored (not a requirement of the BIP, but certainly permitted under the BIP)
  • if a peer has sent us a wtxidrelay message, they MUST announce transactions to us using MSG_WTX invs, so it would not make any sense for us to respond with MSG_TX getdata messages. There's no reason to think that requesting a hash and calling it a txid instead of a wtxid would allow our peer to successfully look it up.

The reason I'm ok with changing the MUST to a SHOULD here, regarding the getdata messages, is because sometimes you could imagine that a peer will announce a transaction via MSG_WTX, we'll hold off on fetching it for a while, and then orphan fetching will kick in and cause us to request that parent via txid -- which might be the same as the MSG_WTX wtxid (if it's a non-segwit transaction). So in that case, the traffic on the link might look like MSG_WTX inv followed by MSG_TX getdata. But that is a rare case, and we call it out explicitly in the new language, so the understanding should be that it's generally nonsensical to respond to a MSG_WTX inv with a MSG_TX getdata.

If you have more questions about the language, it's probably easiest to take it offline -- I'm happy to update the text with language that clarifies any confusion (and that seems easier than trying to hash it out here).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@sdaftuar sdaftuar mentioned this pull request Aug 7, 2020
@sdaftuar
Copy link
Copy Markdown
Member

sdaftuar commented Aug 7, 2020

FYI - I picked this up in #966.

@jnewbery jnewbery closed this Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants