Skip to content

Conversation

sipa
Copy link
Member

@sipa sipa commented Jul 23, 2020

This is based on #18044 (comment).

A new type GenTxid is added to protocol.h, which represents a tagged txid-or-wtxid. The tx request logic is updated to use these instead of uint256s, permitting per-announcement distinguishing of txid/wtxid (instead of assuming that everything we want to request from a wtxid peer is wtx). Then the restriction of orphan-parent requesting to non-wtxid peers is lifted.

Also document BIP339 in doc/bips.md.

@fanquake fanquake added the P2P label Jul 23, 2020
@fanquake fanquake requested review from sdaftuar and ajtowns July 23, 2020 01:01
@sipa
Copy link
Member Author

sipa commented Jul 23, 2020

@ajtowns I made a few changes compared to your branch:

  • The pair type is a bit richer, and in primitives/transaction.h (so that it's available from txrequest in Overhaul transaction request logic #19184).
  • All of the txrequest data structures use it, not just m_tx_process_time - this feels more obviously correct.
  • The restriction that wtxidrelay peers can only announce using MSG_WTX invs remains - this isn't violated by txid-based orphan parent requests (which are get GETDATAs, not INVs).

Let me know what you think.

@sipa sipa force-pushed the 202007_wtxid_followup branch from 7189ef5 to 154778d Compare July 23, 2020 02:50
Copy link
Contributor

@ajtowns ajtowns left a comment

Choose a reason for hiding this comment

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

All of the txrequest data structures use it, not just m_tx_process_time - this feels more obviously correct.

👍

The restriction that wtxidrelay peers can only announce using MSG_WTX invs remains - this isn't violated by txid-based orphan parent requests (which are get GETDATAs, not INVs).

Ha. I thought when I was writing that patch that removing that restriction wasn't supposed to be necessary.

Code review ACK 154778d

@naumenkogs
Copy link
Member

utACK 154778d

Copy link
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 154778d code review, debug build/tests/ran node, checked test here fails on master and reverted test fails on the branch.

Reviewers: suggest reviewing 54a0936 with -w.

@sipa sipa force-pushed the 202007_wtxid_followup branch 2 times, most recently from 968edda to 338f80e Compare July 23, 2020 23:35
@jonatack
Copy link
Member

ACK 338f80e per git range-diff 007e15dc 154778d 338f80e and re-code review. Re-debug build with Clang 12, ran tests and node.

}
for (const CTxIn& txin : tx.vin) {
// Here, we only have the txid (and not wtxid) of the
// inputs, so we only request in txid mode, even for
Copy link

Choose a reason for hiding this comment

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

Strictly interpreting the BIP, the requirement for wtxid-relay on fetching is scoped to "announced transactions from that peer", and orphan parents have not been announced so we don't violate wtxid-relay policy here. Concern is on future BIP implementers on how they interpret "is required" and severing the connection for violations. Lightweight clients broadcasting a parent + CPFP tx may know issues due to this.

In the meanwhile, I share Suhas point to not commit a given handling of this behavior. Maybe we should amend the BIP to invite liberal enforcement of violations, just dropping non-complying invs/getdatas ?

Copy link
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.

Just did a code review and spotted one potential issue, but otherwise looks good. Will test.

@sipa sipa force-pushed the 202007_wtxid_followup branch from 338f80e to 707d0f4 Compare July 25, 2020 21:29
@sipa
Copy link
Member Author

sipa commented Jul 25, 2020

Changed the code to treat tx announcements as keyed by hash (rather than hash+wtxidness), so that txid requests for parents of unconfirmed transactions won't result in a duplicate query if a wtxid with the same hash is already in flight. This reduces the diff a bit as well, and removed the need for ToString().

@jnewbery
Copy link
Contributor

I have a hard time reasoning about the consistency of the various data structures around tx requesting if we don't.

I 100% agree with this. Net processing is complicated enough as it is without having data structures hold a mixture of different types. txids and wtxids are different types that just happen to both be encoded in a uint256, which means the compiler can't protect us from bugs where we mistake one for the other.

If we're going to do this, we should at least make it very clear to the programmer by adding comments to the data structures and functions that are doing this. For example, EraseTxRequest(), GetTxRequestTime()and UpdateTxRequestTime() all have a parameter named txid. Anyone reading/reviewing that code would therefore expect those parameters to be txids (and by extension, g_already_asked_for to be keyed by txid).

Copy link
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 707d0f4

I added a few CInv tx msg type boolean helpers on this branch to simplify ToGenTxid() and the net processing code, if you're inclined to use any of it: https://github.com/jonatack/bitcoin/commits/add-inv-msg-booleans (EDIT: opened #19590 for the parts non-specific to this branch).

@sipa
Copy link
Member Author

sipa commented Jul 26, 2020

@jnewbery Would it help if the various txrequest-related functions take a GenTxid argument, but where appropriate, call GetHash() on it when they really just need a txid-or-wtxid key, instead of passing those keys around as uint256s?

@sdaftuar
Copy link
Member

Code review ACK, apart from the test change which I haven't reviewed. Will test.

@sdaftuar
Copy link
Member

ACK 707d0f4

@naumenkogs
Copy link
Member

utACK 707d0f4

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 27, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@sipa
Copy link
Member Author

sipa commented Jul 27, 2020

I added 3 extra commits that introduce more GenTxid uses, without changing behavior.

@sdaftuar
Copy link
Member

utACK c048357

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Code review ACK c048357. A few comments inline.

Thanks for updating the functions to take GenTxids. I think that's clearer. I still think that the original version of this PR was better still, and that storing GenTxids in the various tx download data structures is easier to reason about and worth the marginal loss in efficiency, but I guess that all this is going away with #19184 so it doesn't matter too much.

@jonatack
Copy link
Member

Light ACK c048357 modulo Gleb's and John's feedback above.

@sipa sipa force-pushed the 202007_wtxid_followup branch from c048357 to 10b7a6d Compare July 30, 2020 20:46
@sipa
Copy link
Member Author

sipa commented Jul 30, 2020

Rebased and addressed comments.

@ajtowns
Copy link
Contributor

ajtowns commented Jul 31, 2020

ACK 10b7a6d -- code review. Using gtxid to replace the is_txid_or_wtxid flag for the mempool functions is nice.

@naumenkogs
Copy link
Member

utACK 10b7a6d

@jonatack
Copy link
Member

ACK 10b7a6d

@jnewbery
Copy link
Contributor

Code review ACK 10b7a6d

@fanquake fanquake merged commit f7c73b0 into bitcoin:master Jul 31, 2020
@jnewbery
Copy link
Contributor

I have a backport of (the first 4 commits of) this to v0.20 here: https://github.com/jnewbery/bitcoin/tree/2020-07-v20-wtxid-orphan. It can be added to #19606 or PR'ed separately. Whatever is easiest for reviewers.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 31, 2020
10b7a6d refactor: make txmempool interface use GenTxid (Pieter Wuille)
5c124e1 refactor: make FindTxForGetData use GenTxid (Pieter Wuille)
a2bfac8 refactor: use GenTxid in tx request functions (Pieter Wuille)
e65d115 test: request parents of orphan from wtxid relay peer (Anthony Towns)
900d7f6 p2p: enable fetching of orphans from wtxid peers (Pieter Wuille)
9efd86a refactor: add GenTxid (=txid or wtxid) type and use it for tx request logic (Pieter Wuille)
d362f19 doc: list support for BIP 339 in doc/bips.md (Pieter Wuille)

Pull request description:

  This is based on bitcoin#18044 (comment).

  A new type `GenTxid` is added to protocol.h, which represents a tagged txid-or-wtxid. The tx request logic is updated to use these instead of uint256s, permitting per-announcement distinguishing of txid/wtxid (instead of assuming that everything we want to request from a wtxid peer is wtx). Then the restriction of orphan-parent requesting to non-wtxid peers is lifted.

  Also document BIP339 in doc/bips.md.

ACKs for top commit:
  jnewbery:
    Code review ACK 10b7a6d
  jonatack:
    ACK 10b7a6d
  ajtowns:
    ACK 10b7a6d -- code review. Using gtxid to replace the is_txid_or_wtxid flag for the mempool functions is nice.
  naumenkogs:
    utACK 10b7a6d

Tree-SHA512: d518d13ffd71f8d2b3c175dc905362a7259689e6022a97a0b4f14f1f9fdd87475cf5af70cb12338d1e5d31b52c12e4faaea436114056a2ae9669cb506240758b
laanwj added a commit that referenced this pull request Nov 5, 2020
d4a1ee8 Further improve comments around recentRejects (Suhas Daftuar)
f082a13 Disconnect peers sending wtxidrelay message after VERACK (Suhas Daftuar)
22effa5 test: Use wtxid relay generally in functional tests (Fabian Jahr)
e481681 test: Add tests for wtxid tx relay in segwit test (Fabian Jahr)
6be398b test: Update test framework p2p protocol version to 70016 (Fabian Jahr)
e364b2a Rename AddInventoryKnown() to AddKnownTx() (Suhas Daftuar)
879a3cf Make TX_WITNESS_STRIPPED its own rejection reason (Suhas Daftuar)
c1d6a10 Delay getdata requests from peers using txid-based relay (Suhas Daftuar)
181ffad Add p2p message "wtxidrelay" (Suhas Daftuar)
9382672 ignore non-wtxidrelay compliant invs (Anthony Towns)
2599277 Add support for tx-relay via wtxid (Suhas Daftuar)
be1b7a8 Add wtxids to recentRejects (Suhas Daftuar)
7384521 Add wtxids of confirmed transactions to bloom filter (Suhas Daftuar)
606755b Add wtxid-index to orphan map (Suhas Daftuar)
3654937 Add a wtxid-index to mapRelay (Suhas Daftuar)
f7833b5 Just pass a hash to AddInventoryKnown (Suhas Daftuar)
4df3d13 Add a wtxid-index to the mempool (Suhas Daftuar)

Pull request description:

  We want wtxid relay to be widely deployed before taproot activation, so it should be backported to v0.20.

  The main difference from #18044 is removing the changes to the unbroadcast set (which was only added post-v0.20). The rest is mostly minor rebase conflicts (eg connman changed from a pointer to a reference in master, etc).

  We'll also want to backport #19569 after that's merged.

ACKs for top commit:
  fjahr:
    re-ACK d4a1ee8
  instagibbs:
    reACK d4a1ee8
  laanwj:
    re-ACK d4a1ee8
  hebasto:
    re-ACK d4a1ee8, only rebased since my [previous](#19606 (review)) review:

Tree-SHA512: 1bb8725dd2313a9a03cacf8fb7317986eed3d8d1648fa627528441256c37c793bb0fae6c8c139d05ac45d0c7a86265792834e8e09cbf45286426ca6544c10cd5
@jnewbery
Copy link
Contributor

jnewbery commented Nov 5, 2020

Backported to 0.20 in #20317

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants