Skip to content

Conversation

@jnewbery
Copy link
Contributor

@jnewbery jnewbery commented May 18, 2020

Support getcfheaders requests when -peerblockfilters is set.

Does not advertise compact filter support in version messages.

@jnewbery
Copy link
Contributor Author

This is the 3rd PR taken from #18876. Please see that PR for details of the full changes to support BIP 157.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Just a style question, feel free to ignore.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 18, 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.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CConnman* connman)
CConnman& connman)

Any reason why this is a pointer, but missing the nullptr check?

  • Either this should be a proper pointer with nullptr check, or
  • it should be a reference

Mixing the two combines the worst of each option.

(Same for pfrom)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This usage is the same as all the other Process*() functions in net_processing. Rather than introduce a new style for just this function, I think it makes sense to change it everywhere in net_processing in a refactor PR.

Copy link
Member

Choose a reason for hiding this comment

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

Generally new code should be style-conformant. See for example RelayTransaction, which properly passes connman. Obviously a non-blocking nit, so feel free to close this conversation.

Copy link
Contributor

@jkczyz jkczyz 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

For testing, what's the general approach been for testing bad requests? BIP 157 says to not respond, but we are disconnecting the peer in these cases.

Comment on lines +2020 to +2038
Copy link
Contributor

Choose a reason for hiding this comment

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

Given these checks aren't necessary for ProcessGetCFCheckPt, would they be more suitable in separate function? Then the caller wouldn't have to know which values to pass to make the checks succeed.

Downside is you might fetch the BlockFilterIndex even though these checks may later fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this makes more sense if you also look at the full changes in #18876, where this function is common logic for getcfheaders and getcfilters, and the max number of headers that can be requested is 2000, and the max number of filters that can be requested in 1000.

I agree that the getcfcheckpt logic passing in 0 and std::numeric_limits<uint32_t>::max() is a bit ugly. I could change it to pass in optionals, but that seems more aesthetic than anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option would be to simply use default parameters, i.e. if start_height and max_height diff are not passed, the whole range is allowed. That would need to change the order of the parameters though.

@theStack
Copy link
Contributor

Concept ACK

@jnewbery jnewbery force-pushed the 2020-05-cfheaders branch from befc63d to 4376797 Compare May 21, 2020 18:58
@jnewbery
Copy link
Contributor Author

Force pushed the branch to:

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.

ACK 4376797

Reviewed the code, played with the tests, and ran them locally.

FWIW, I have added the tests I suggested in the review club, feel free to copy them from there: fjahr@36d6854

* @param[in] filter_type The filter type the request is for. Must be basic filters.
* @param[in] start_height The start height for the request
* @param[in] stop_hash The stop_hash for the request
* @param[in] max_height_diff The maximum number of items permitted to request, as specified in BIP 157
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This threw me off initially (similar to what @jkczyz noted below). The BIP gives a specific number, why do we not just use the constant? I think this could help make it a little less confusing.

Suggested change
* @param[in] max_height_diff The maximum number of items permitted to request, as specified in BIP 157
* @param[in] max_height_diff The maximum number of headers or filters permitted to request, as specified in BIP 157

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @fjahr's comment and suggested change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add this in #19070 if I need to retouch that branch

@jnewbery
Copy link
Contributor Author

what's the general approach been for testing bad requests? BIP 157 says to not respond, but we are disconnecting the peer in these cases.

I don't have a strong opinion about whether to disconnect or drop bad requests. Generally I prefer simply dropping bad requests to prevent bugs becoming network partition possibilities, but in this case:

  • the message type is entirely new.
  • the peers sending us these requests are light clients, so the downside of disconnecting them is small.

I'm inclined to keep it as a disconnect since that's the only way we have to communicate to the client that there's a problem with the request, but I'm happy to change it if others disagree.

@maflcko
Copy link
Member

maflcko commented May 22, 2020

the peers sending us these requests are light clients, so the downside of disconnecting them is small.

I agree here. Generally the nicest thing you can do to misbehaving light clients is to disconnect them as early as possible. This way the misbehaviour bug will be hopefully caught early in the design and testing process of the light client. If not, at least in production it will be another indicator that something is wrong and users can file bugs. If the connection was kept alive, and without replying it might just time out on the light client and they'd think we are the ones misbehaving.

I was about to suggest to put a small comment in the source code to document this, but I wasn't exactly sure where to put it.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Some style nits that can be ignored

re-ACK 4376797, only change since my previous review #18876 (comment) is adding a spurious new line and a new commit with documentation 🐣

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

re-ACK 4376797f6c, only change since my previous review https://github.com/bitcoin/bitcoin/pull/18876#issuecomment-627322015 is adding a spurious new line and a new commit with documentation 🐣
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjc3gv+MB5VIjvGWjT85TlCzHERqu35XeRFo+DTLBUhkp1NGk1Uymar3cF68jOW
0W0Keide4ZEBCc1sz7mnhsXBBL6XhijSgGS7fTdjw9Iab8944dW11IzDmMFcHWwc
cglhfriS8Rpa3FUeq+FPrNI7zEA4UyHrXcIiUUzXkXBRK0yooTrpFzGMlS6HnB8+
MmzIuUaFTEKnIJA3exIAls8225TzmnIuPrSHtpNi+91RVpTnV1ZMAo++jBbcPE/p
riNswV/Yc/zG06xiO2YgleTyfip8FwjydEMaekkQUSL62IucTFQY0rHqeEWvysFr
L69g2vdnVDUgVLxiOrzLIUdhLjYxsjvyOUdXgC36UxpUERi2TuXzmMu0OWFSkChs
soAvIWL0hFt4oV/PTgBpxJPKrFtWgifwVy3l8iyZ07eVsGr0Z+YfNDwY6DWCJsM/
d+RG0asZEtOjdkwZF/PAc9tTWPsP/fLXiHO3z7928dASyT5+pKdaKOCSCeKH1+6p
lg1V3U+3
=0qw1
-----END PGP SIGNATURE-----

Timestamp of file with hash 40b1dadd7d8694410c23fb4d6f045b454bee5f2bf365f49994dc7f713b58f816 -

@jnewbery
Copy link
Contributor Author

Thanks for review @MarcoFalke and @theStack. I've addressed all of your review comments, and also removed some redundant wording from the comment for CFCHECKPOINT in protocol.h

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

re-ACK 5308c97 , only change is doc related 🗂

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

re-ACK 5308c97cca , only change is doc related 🗂
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUi5SgwAwz0FXCPt6ETbRNPe2chK9XeE0E40zYsq0hAJ/rw7G3/Rk2LyC9TG2GoW
OaJw75Eg80fAu7ImWcTHiUyhKSlIZKJR9QPKC02RImsFZ66UotzFZ0mefsgtkoh0
2bvUJXabSlrOkwt8y12oED2YS0Cgf3OG2DJCPtCGOq9kZUyK+4Ef5stvG6YiYF1/
GZ+WwyO1iL8G8nPZue3239QgMb3bvX6JxIB8q5oipmMzILg8ja7o/0Cxp1QYdxNF
8tK5nZn0kF4xlDaHrusuWIwgNcPGUYlHbCeCuZoXnompyHn/meyTp2yndmEAp72J
ILVkp9Nkzs7o7Q1vAZM7YCWOxHdw7ncDTq0tdcpr9BPtorlHvKWIsUJHvUBTd2el
mlJJaiM5WNq+yISCld8ItK+utub4g95zrfZWyzvs4pLZQTID9tQCtN8U/919zTn1
OUjYFoy+2AmssmJFtM+CkjJgcSAf6KHYcGXJyY4hhqLvhMsmv5SrW1EYJdy6AW5g
YbOfPwLk
=5MJF
-----END PGP SIGNATURE-----

Timestamp of file with hash eed11e440452664f3996d83b9c085e9a4c0ab77e69ea219b1fe7181017bc09a1 -

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

ACK 5308c97 🚀

@jkczyz
Copy link
Contributor

jkczyz commented May 25, 2020

ACK 5308c97

@maflcko maflcko merged commit 7d32cce into bitcoin:master May 26, 2020
@jnewbery jnewbery deleted the 2020-05-cfheaders branch May 26, 2020 13:50
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 27, 2020
5308c97 [test] Add test for cfheaders (Jim Posen)
f6b58c1 [net processing] Message handling for getcfheaders. (Jim Posen)
3bdc7c2 [doc] Add comment for m_headers_cache (John Newbery)

Pull request description:

  Support `getcfheaders` requests when `-peerblockfilters` is set.

  Does not advertise compact filter support in version messages.

ACKs for top commit:
  jkczyz:
    ACK 5308c97
  MarcoFalke:
    re-ACK 5308c97 , only change is doc related 🗂
  theStack:
    ACK 5308c97 🚀

Tree-SHA512: 240fc654f6f634c191d9f7628b6c4801f87ed514a1dd55c7de5d454d4012d1c09509a2d5a246bc7da445cd920252b4cd56a493c060cdb207b04af4ffe53b95f7
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 5308c97 with some optional style nits for follow-ups. @fjahr's tests at fjahr@36d6854 look worthwhile.

)
node0.send_and_ping(request)
response = node0.last_message['cfheaders']
assert_equal(len(response.hashes), 1000)
Copy link
Member

Choose a reason for hiding this comment

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

style nit: replace the multiple values of 1000 and of 16 in this file with well-named constants

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 16 is used to interpret a hex string into an int (RPC return values are strings), so we shouldn't have a constant for that. I tried replacing the 1000 with a constant, but I don't think it made things any clearer.

def on_addr(self, message): pass
def on_block(self, message): pass
def on_blocktxn(self, message): pass
def on_cfheaders(self, message): pass
Copy link
Member

Choose a reason for hiding this comment

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

nit: sort here and lines 34 and 72

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was fixed in the following PR.

* @param[in] filter_type The filter type the request is for. Must be basic filters.
* @param[in] start_height The start height for the request
* @param[in] stop_hash The stop_hash for the request
* @param[in] max_height_diff The maximum number of items permitted to request, as specified in BIP 157
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @fjahr's comment and suggested change.

maflcko pushed a commit that referenced this pull request Jun 4, 2020
…et_processing.{h,cpp}

8b3136b refactor: replace CNode pointers by references within net_processing.{h,cpp} (Sebastian Falbesoner)

Pull request description:

  This PR is inspired by a [recent code review comment](#19010 (comment)) on a PR that introduced new functions to the net_processing module. The point of the discussion was basically that whenever we pass something not by value (in the concrete example it was about `CNode*` and `CConnman*`) we should either use
  * a pointer (```CType*```) with null pointer check or
  * a reference (```CType&```)

  To keep things simple, this PR for a first approach
  * only tackles `CNode*` pointers
  * only within the net_processing module, i.e. no changes that would need adaption in other modules
  * keeps the names of the variables as they are

  I'm aware that PRs like this are kind of a PITA to review, but I think the code quality would increase if we get rid of pointers without nullptr check -- bloating up the code by adding all the missing checks would be the worse alternative, in my opinion.

  Possible follow-up PRs, in case this is received well:
  * replace CNode pointers by references for net module
  * replace CConnman pointers by references for net_processing module
  * ...

ACKs for top commit:
  MarcoFalke:
    ACK 8b3136b 🔻
  practicalswift:
    ACK 8b3136b

Tree-SHA512: 15b6a569ecdcb39341002b9f4e09b38ed4df077e3a3a50dfb1b72d98bdc9f9769c7c504f106456aa7748af8591af7bb836b72d46086df715ab116e4ac3224b3b
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 4, 2020
…ithin net_processing.{h,cpp}

8b3136b refactor: replace CNode pointers by references within net_processing.{h,cpp} (Sebastian Falbesoner)

Pull request description:

  This PR is inspired by a [recent code review comment](bitcoin#19010 (comment)) on a PR that introduced new functions to the net_processing module. The point of the discussion was basically that whenever we pass something not by value (in the concrete example it was about `CNode*` and `CConnman*`) we should either use
  * a pointer (```CType*```) with null pointer check or
  * a reference (```CType&```)

  To keep things simple, this PR for a first approach
  * only tackles `CNode*` pointers
  * only within the net_processing module, i.e. no changes that would need adaption in other modules
  * keeps the names of the variables as they are

  I'm aware that PRs like this are kind of a PITA to review, but I think the code quality would increase if we get rid of pointers without nullptr check -- bloating up the code by adding all the missing checks would be the worse alternative, in my opinion.

  Possible follow-up PRs, in case this is received well:
  * replace CNode pointers by references for net module
  * replace CConnman pointers by references for net_processing module
  * ...

ACKs for top commit:
  MarcoFalke:
    ACK 8b3136b 🔻
  practicalswift:
    ACK 8b3136b

Tree-SHA512: 15b6a569ecdcb39341002b9f4e09b38ed4df077e3a3a50dfb1b72d98bdc9f9769c7c504f106456aa7748af8591af7bb836b72d46086df715ab116e4ac3224b3b
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 19, 2020
Summary:
```
Support getcfheaders requests when -peerblockfilters is set.

Does not advertise compact filter support in version messages.
```

Backport of core [[bitcoin/bitcoin#19010 | PR19010]].

Depends on D8464.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D8465
kwvg added a commit to kwvg/dash that referenced this pull request Sep 19, 2021
@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.

8 participants