Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p: refactor AlreadyHave(), CInv::type, INV/TX processing #19610

Merged
merged 10 commits into from
Sep 2, 2020

Conversation

jonatack
Copy link
Member

@jonatack jonatack commented Jul 28, 2020

Building on #19590 and the recent wtxid and GenTxid changes, this is a refactoring and cleanup PR to simplify and improve some of the net processing code.

Some of the diffs are best reviewed with -w to ignore spacing.

Co-authored by John Newbery.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 28, 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.

laanwj added a commit that referenced this pull request Jul 30, 2020
…use in net processing

c251d71 p2p, refactoring: use CInv helpers in net_processing.cpp (Jon Atack)
4254cd9 p2p: add CInv transaction message helper methods (Jon Atack)

Pull request description:

  Following the merge of wtxid relay in #18044, this is the first of three refactoring PRs (this one, #19610, and #19611) with no change in behavior, tightly scoped to ease review, to simplify the net processing code and improve encapsulation:

  - add `CInv` transaction message helper methods, defined in the class

  - use the new helpers in `net_processing.cpp` to simplify the code and improve encapsulation

  Test coverage is provided by the functional p2p tests, notably (from seeing which tests failed when breaking things to test coverage) `p2p_segwit`, `p2p_tx_download`, `p2p_feefilter`, and `p2p_permissions`.

ACKs for top commit:
  fjahr:
    Code review ACK c251d71
  laanwj:
    Code review ACK c251d71
  vasild:
    ACK c251d71
  theStack:
    Code-Review ACK c251d71
  hebasto:
    ACK c251d71, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: ead034b3c9e438909b4c5010c570d7930e69063c114290b051b7cebfd9bd5b19f573218bebe8a521256d32e830797f997adad3d85b4539c64ac5762b698e656d
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 31, 2020
…lpers; use in net processing

c251d71 p2p, refactoring: use CInv helpers in net_processing.cpp (Jon Atack)
4254cd9 p2p: add CInv transaction message helper methods (Jon Atack)

Pull request description:

  Following the merge of wtxid relay in bitcoin#18044, this is the first of three refactoring PRs (this one, bitcoin#19610, and bitcoin#19611) with no change in behavior, tightly scoped to ease review, to simplify the net processing code and improve encapsulation:

  - add `CInv` transaction message helper methods, defined in the class

  - use the new helpers in `net_processing.cpp` to simplify the code and improve encapsulation

  Test coverage is provided by the functional p2p tests, notably (from seeing which tests failed when breaking things to test coverage) `p2p_segwit`, `p2p_tx_download`, `p2p_feefilter`, and `p2p_permissions`.

ACKs for top commit:
  fjahr:
    Code review ACK c251d71
  laanwj:
    Code review ACK c251d71
  vasild:
    ACK c251d71
  theStack:
    Code-Review ACK c251d71
  hebasto:
    ACK c251d71, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: ead034b3c9e438909b4c5010c570d7930e69063c114290b051b7cebfd9bd5b19f573218bebe8a521256d32e830797f997adad3d85b4539c64ac5762b698e656d
Copy link
Contributor

@fjahr fjahr 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 82c9297

src/protocol.h Outdated Show resolved Hide resolved
@jnewbery
Copy link
Contributor

jnewbery commented Aug 3, 2020

I think a better approach than the changes within AlreadyHave() is to split that function up into AlreadyHaveTx() and AlreadyHaveBlock() since those are two totally separate concepts. @jonatack would you be interested in taking the commits from here: https://github.com/jnewbery/bitcoin/commits/2020-07-split-already-have? (see also #19569 (comment))

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.

Concept ACK. Needs rebase.

src/protocol.h Outdated Show resolved Hide resolved
@jonatack jonatack changed the title p2p, refactor: add CInv block message helpers; use in net processing p2p: refactor AlreadyHave(), CInv::type and inv/tx processing Aug 8, 2020
@jonatack jonatack changed the title p2p: refactor AlreadyHave(), CInv::type and inv/tx processing p2p: refactor AlreadyHave(), CInv::type, INV/TX processing Aug 8, 2020
@jonatack jonatack force-pushed the CInv-block-message-helpers branch 2 times, most recently from bbd5638 to 4789cff Compare August 8, 2020 14:06
@jonatack
Copy link
Member Author

jonatack commented Aug 8, 2020

Rebased with four commits pulled in from @jnewbery's master...jnewbery:2020-07-split-already-have branch as well as the changes in #19611.

@laanwj
Copy link
Member

laanwj commented Aug 9, 2020

I think a better approach than the changes within AlreadyHave() is to split that function up into AlreadyHaveTx() and AlreadyHaveBlock() since those are two totally separate concepts.

Great idea. The block and transaction paths have drifted apart so much that it no longer makes sense to have a common function there.

src/protocol.h Outdated Show resolved Hide resolved
jonatack and others added 3 commits August 26, 2020 11:57
and otherwise log that an unknown INV type was received.

In INV processing, when handling transaction type inv messages,
ToGenTxid() expects that we constructed the CInv ourselves or
that we verified that it is for a transaction type CInv.

Therefore, change this `else` branch into an `else if (inv.GenMsgTx())`
to make this safer and log any INVs that fall through.
@jonatack
Copy link
Member Author

jonatack commented Aug 26, 2020

Removed the unused helper methods from the first commit per git diff 533a9a0 125468a

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 125468a

@jnewbery
Copy link
Contributor

I think the CInv::type change from int to uint32_t change should be added back (not necessarily the private qualifier). While fuzzing it brings up the following complaint #19678

Why? This seems unrelated to this PR (the UBSan warning happens before this PR). Changing the type of CInv.type (which is serialized/deserialized for network messages) is a very different change from the internal refactors in this PR. Can you save it for a different PR?

@Crypt-iQ
Copy link
Contributor

@jnewbery I thought since it was already added previously, it would fit into the scope of the PR. No problem to be added into another PR, either I or somebody else could do that.

@jonatack
Copy link
Member Author

Dropped the CInv::type type change commit in favor of #19818. Thanks everyone.

@laanwj
Copy link
Member

laanwj commented Aug 27, 2020

Code review ACK fb56d37
Agree it's better to split out the P2P change.

@jnewbery
Copy link
Contributor

jnewbery commented Sep 1, 2020

utACK fb56d37

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK fb56d37

@laanwj laanwj merged commit 505b39e into bitcoin:master Sep 2, 2020
@jonatack jonatack deleted the CInv-block-message-helpers branch September 2, 2020 12:51
laanwj added a commit that referenced this pull request Sep 3, 2020
…UBSan warning

7984c39 test framework: serialize/deserialize inv type as unsigned int (Jon Atack)
407175e p2p: change CInv::type from int to uint32_t (Jon Atack)

Pull request description:

  Fixes UBSan implicit-integer-sign-change issue per #19610 (comment).

  Credit to Crypt-iQ for finding and reporting the issue and to vasild for the original review suggestion in #19590 (review).

  Closes #19678.

ACKs for top commit:
  laanwj:
    ACK 7984c39
  MarcoFalke:
    ACK 7984c39 🌻
  vasild:
    ACK 7984c39

Tree-SHA512: 59f3a75f40ce066ca6f0bb1927197254238302b4073af1574bdbfe6ed580876437be804be4e47d51467d604f0d9e3a5875159f7f2edbb2351fdb2bb9465100b5
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 3, 2020
…processing

fb56d37 p2p: ensure inv is GenMsgTx before ToGenTxid in inv processing (John Newbery)
aa36213 test: use CInv::MSG_WITNESS_TX flag in p2p_segwit (Jon Atack)
24ee4f0 p2p: make gtxid(.hash) and fAlreadyHave localvars const (Jon Atack)
b1c8554 p2p: use CInv block message helpers in net_processing.cpp (Jon Atack)
acd6642 [net processing] Change AlreadyHaveTx() to take a GenTxid (John Newbery)
5fdfb80 [net processing] Change AlreadyHaveBlock() to take block_hash argument (John Newbery)
430e183 [net processing] Remove mempool argument from AlreadyHaveBlock() (John Newbery)
42ca561 [net processing] Split AlreadyHave() into separate block and tx functions (John Newbery)
39f1dc9 p2p: remove nFetchFlags from NetMsgType TX and INV processing (Jon Atack)
471714e p2p: add CInv block message helper methods (Jon Atack)

Pull request description:

  Building on bitcoin#19590 and the recent `wtxid` and `GenTxid` changes, this is a refactoring and cleanup PR to simplify and improve some of the net processing code.

  Some of the diffs are best reviewed with `-w` to ignore spacing.

  Co-authored by John Newbery.

ACKs for top commit:
  laanwj:
    Code review ACK fb56d37
  jnewbery:
    utACK fb56d37
  vasild:
    ACK fb56d37

Tree-SHA512: ba39b58e6aaf850880a842fe5f6295e9f1870906ef690206acfc17140aae2ac854981e1066dbcd4238062478762fbd040ef772fdc2c50eea6869997c583e6a6d
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 3, 2020
…`, fix UBSan warning

7984c39 test framework: serialize/deserialize inv type as unsigned int (Jon Atack)
407175e p2p: change CInv::type from int to uint32_t (Jon Atack)

Pull request description:

  Fixes UBSan implicit-integer-sign-change issue per bitcoin#19610 (comment).

  Credit to Crypt-iQ for finding and reporting the issue and to vasild for the original review suggestion in bitcoin#19590 (review).

  Closes bitcoin#19678.

ACKs for top commit:
  laanwj:
    ACK 7984c39
  MarcoFalke:
    ACK 7984c39 🌻
  vasild:
    ACK 7984c39

Tree-SHA512: 59f3a75f40ce066ca6f0bb1927197254238302b4073af1574bdbfe6ed580876437be804be4e47d51467d604f0d9e3a5875159f7f2edbb2351fdb2bb9465100b5
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 12, 2021
Summary:
Partial backport of [[bitcoin/bitcoin#19610 | core#19610]]:
bitcoin/bitcoin@471714e

Depends on D9500.

Test Plan:
  ninja all check
  ninja bitcoin-fuzzers

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9501
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 12, 2021
…ions

Summary:
Partial backport of [[bitcoin/bitcoin#19610 | core#19610]]:
bitcoin/bitcoin@42ca561?diff=split&w=1

This will help narrowing the cs_main scope when introducing the proofs.
There are more simplifications and de-duplication to come in follow-up
backports.

Depends on D9501.

Note that the commit
bitcoin/bitcoin@39f1dc9
is skipped because it is a segwit only commit.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9502
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 12, 2021
Summary:
Partial backport of [[bitcoin/bitcoin#19610 | core#19610]]:
bitcoin/bitcoin@430e183

Depends on D9502.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9503
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 12, 2021
Summary:
Partial backport of [[bitcoin/bitcoin#19610 | core#19610]]:
bitcoin/bitcoin@5fdfb80

Depends on D9503.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9504
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 12, 2021
Summary:
Partial backport if [[bitcoin/bitcoin#19610 | core#19610]]:
bitcoin/bitcoin@acd6642

Depends on D9504.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9505
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 12, 2021
Summary:
Partial backport of [[bitcoin/bitcoin#19610 | core#19610]]:
bitcoin/bitcoin@b1c8554

Depends on D9505.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9506
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 12, 2021
Summary:
Partial backport of [[bitcoin/bitcoin#19610 | core#19610]]:
bitcoin/bitcoin@24ee4f0

There is very few remaining when removed the segwit content.

Depends on D9506.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9507
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 12, 2021
Summary:
```
and otherwise log that an unknown INV type was received.

In INV processing, when handling transaction type inv messages,
ToGenTxid() expects that we constructed the CInv ourselves or
that we verified that it is for a transaction type CInv.

Therefore, change this `else` branch into an `else if (inv.GenMsgTx())`
to make this safer and log any INVs that fall through.
```

Completes backport of [[bitcoin/bitcoin#19610 | core#19610]]:
bitcoin/bitcoin@fb56d37

Depends on D9507.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9508
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 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.

None yet

7 participants