Repository: bitcoin
Issue: CFilters reject and disconnect peers with a valid block hash
Labels: P2P

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

For quite some time now, I've noticed that neutrino clients connected to my Bitcoin Core instance would have issues connecting after a while. Today, I turned on debug logging for `[net]` and discovered these messages (see log section). Peers were being disconnected! But strangely, it seems like even though these peers are requesting valid block hashes, Bitcoin Core is rejecting the serving of CFilters to them. No other disconnect messages for CFilters have been observed. I checked validity two ways: by checking against bitcoin-cli getblock as well as using a block explorer (mempool.space).

### Expected behaviour

If a BIP-157 client requests a valid block hash as set forth by `BlockRequestAllowed`, it should receive a response from Bitcoin Core.

### Steps to reproduce

1. Setup Bitcoin Core node with `peerbloomfilters=1` and `peerblockfilters=1`, ensure port `8333` is open. Also set `debug=net` for debug level for networking logs.
2. Connect neutrino peer to Bitcoin Core node and wait.
3. Eventually, you will see the debug network message above.

### Relevant log output

```
2024-03-14T16:25:48Z [net] received: getcfheaders (37 bytes) peer=35
2024-03-14T16:25:48Z [net] peer 35 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:25:48Z [net] received: verack (0 bytes) peer=71
--
2024-03-14T16:25:48Z [net] received: getcfheaders (37 bytes) peer=12
2024-03-14T16:25:48Z [net] peer 12 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:25:49Z [net] received: getdata (37 bytes) peer=37
--
2024-03-14T16:25:49Z [net] received: getcfheaders (37 bytes) peer=13
2024-03-14T16:25:49Z [net] peer 13 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:25:49Z [net] disconnecting peer=13
--
2024-03-14T16:25:58Z [net] received: getcfilters (37 bytes) peer=75
2024-03-14T16:25:58Z [net] peer 75 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:25:58Z [net] received: getdata (73 bytes) peer=54
--
2024-03-14T16:25:58Z [net] received: getcfilters (37 bytes) peer=72
2024-03-14T16:25:58Z [net] peer 72 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:25:58Z [net] received: tx (372 bytes) peer=11
--
2024-03-14T16:26:14Z [net] received: getcfheaders (37 bytes) peer=50
2024-03-14T16:26:14Z [net] peer 50 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:14Z [net] sending inv (37 bytes) peer=54
--
2024-03-14T16:26:14Z [net] received: getcfheaders (37 bytes) peer=1
2024-03-14T16:26:14Z [net] peer 1 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:14Z [net] received: getcfheaders (37 bytes) peer=71
2024-03-14T16:26:14Z [net] peer 71 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:14Z [net] received: getcfheaders (37 bytes) peer=6
2024-03-14T16:26:14Z [net] peer 6 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:14Z [net] received: getcfheaders (37 bytes) peer=3
2024-03-14T16:26:14Z [net] peer 3 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:14Z [net] received: tx (327 bytes) peer=25
--
2024-03-14T16:26:15Z [net] Cleared nodestate for peer=71
2024-03-14T16:26:15Z [net] peer 26 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:15Z [net] sending inv (109 bytes) peer=54
--
2024-03-14T16:26:15Z [net] received: getcfheaders (37 bytes) peer=9
2024-03-14T16:26:15Z [net] peer 9 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:15Z [net] received: tx (345 bytes) peer=46
--
2024-03-14T16:26:15Z [net] received: getcfheaders (37 bytes) peer=67
2024-03-14T16:26:15Z [net] peer 67 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:15Z [net] received: getdata (37 bytes) peer=37
--
2024-03-14T16:26:24Z [net] received: getcfilters (37 bytes) peer=84
2024-03-14T16:26:24Z [net] peer 84 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:24Z [net] received: getdata (37 bytes) peer=37
--
2024-03-14T16:26:24Z [net] received: getcfilters (37 bytes) peer=87
2024-03-14T16:26:24Z [net] peer 87 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:24Z [net] sending inv (577 bytes) peer=57
--
2024-03-14T16:26:25Z [net] received: getcfilters (37 bytes) peer=85
2024-03-14T16:26:25Z [net] peer 85 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:25Z [net] Requesting tx c4d0491f6f1d12c2c2f7d3fef9501150b7a4e7f6346dd68308c41050567d5c64 peer=81
--
2024-03-14T16:26:26Z [net] received: getcfilters (37 bytes) peer=90
2024-03-14T16:26:26Z [net] peer 90 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:26Z [net] sending inv (109 bytes) peer=68
--
2024-03-14T16:26:53Z [net] received: getcfheaders (37 bytes) peer=98
2024-03-14T16:26:53Z [net] peer 98 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:26:53Z [net] received: ping (8 bytes) peer=28
--
2024-03-14T16:29:23Z [net] received: getcfheaders (37 bytes) peer=126
2024-03-14T16:29:23Z [net] peer 126 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:29:23Z [net] disconnecting peer=126
--
2024-03-14T16:29:51Z [net] received: getcfilters (37 bytes) peer=128
2024-03-14T16:29:51Z [net] peer 128 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:29:51Z [net] sending inv (541 bytes) peer=120
--
2024-03-14T16:30:44Z [net] received: getcfcheckpt (33 bytes) peer=139
2024-03-14T16:30:44Z [net] peer 139 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:30:44Z [net] disconnecting peer=139
--
2024-03-14T16:30:56Z [net] received: getcfheaders (37 bytes) peer=146
2024-03-14T16:30:56Z [net] peer 146 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:30:56Z [net] disconnecting peer=146
--
2024-03-14T16:31:11Z [net] received: getcfheaders (37 bytes) peer=151
2024-03-14T16:31:11Z [net] peer 151 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:31:11Z [net] disconnecting peer=151
--
2024-03-14T16:31:21Z [net] received: getcfilters (37 bytes) peer=154
2024-03-14T16:31:21Z [net] peer 154 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:31:21Z [net] disconnecting peer=154
--
2024-03-14T16:31:39Z [net] received: getcfheaders (37 bytes) peer=153
2024-03-14T16:31:39Z [net] peer 153 requested invalid block hash: 0000000000000000000132006d75c39161b70fd058da1b740ab02c3f1df4470d
2024-03-14T16:31:39Z [net] disconnecting peer=153
--
2024-03-14T16:40:31Z [net] received: getcfheaders (37 bytes) peer=74
2024-03-14T16:40:31Z [net] peer 74 requested invalid block hash: 000000000000000000017ff36e3f004964cdaea7d5e397965673ec5ef9ce9337
2024-03-14T16:40:31Z [net] disconnecting peer=74
--
2024-03-14T16:40:31Z [net] received: getcfheaders (37 bytes) peer=184
2024-03-14T16:40:31Z [net] peer 184 requested invalid block hash: 000000000000000000017ff36e3f004964cdaea7d5e397965673ec5ef9ce9337
2024-03-14T16:40:31Z [net] disconnecting peer=184
--
2024-03-14T16:40:31Z [net] received: getcfheaders (37 bytes) peer=73
2024-03-14T16:40:31Z [net] peer 73 requested invalid block hash: 000000000000000000017ff36e3f004964cdaea7d5e397965673ec5ef9ce9337
2024-03-14T16:40:31Z [net] disconnecting peer=73
--
2024-03-14T16:40:31Z [net] received: getcfheaders (37 bytes) peer=202
2024-03-14T16:40:31Z [net] peer 202 requested invalid block hash: 000000000000000000017ff36e3f004964cdaea7d5e397965673ec5ef9ce9337
2024-03-14T16:40:31Z [net] disconnecting peer=202
--
2024-03-14T16:40:32Z [net] received: getcfheaders (37 bytes) peer=78
2024-03-14T16:40:32Z [net] peer 78 requested invalid block hash: 000000000000000000017ff36e3f004964cdaea7d5e397965673ec5ef9ce9337
2024-03-14T16:40:32Z [net] received: getheaders (69 bytes) peer=222
--
2024-03-14T16:40:32Z [net] received: getcfheaders (37 bytes) peer=229
2024-03-14T16:40:32Z [net] peer 229 requested invalid block hash: 000000000000000000017ff36e3f004964cdaea7d5e397965673ec5ef9ce9337
2024-03-14T16:40:32Z [net] socket closed for peer=192
--
2024-03-14T16:40:32Z [net] received: getcfheaders (37 bytes) peer=77
2024-03-14T16:40:32Z [net] peer 77 requested invalid block hash: 000000000000000000017ff36e3f004964cdaea7d5e397965673ec5ef9ce9337
2024-03-14T16:40:32Z [net] disconnecting peer=77
--
2024-03-14T16:46:29Z [net] received: getcfheaders (37 bytes) peer=259
2024-03-14T16:46:29Z [net] peer 259 requested invalid block hash: 00000000000000000001a680cb297921d300dadaab79df9876303b6c0bd9dd69
2024-03-14T16:46:29Z [net] disconnecting peer=259
--
2024-03-14T16:46:29Z [net] received: getcfheaders (37 bytes) peer=241
2024-03-14T16:46:29Z [net] peer 241 requested invalid block hash: 00000000000000000001a680cb297921d300dadaab79df9876303b6c0bd9dd69
2024-03-14T16:46:29Z [net] sending inv (37 bytes) peer=265
--
2024-03-14T17:01:49Z [net] received: getcfheaders (37 bytes) peer=400
2024-03-14T17:01:49Z [net] peer 400 requested invalid block hash: 0000000000000000000026ebf8f613a1ce69849f12e2c5f8fd9867c2402e60fc
2024-03-14T17:01:49Z [net] disconnecting peer=400
--
2024-03-14T17:01:49Z [net] received: getcfheaders (37 bytes) peer=303
2024-03-14T17:01:49Z [net] peer 303 requested invalid block hash: 0000000000000000000026ebf8f613a1ce69849f12e2c5f8fd9867c2402e60fc
2024-03-14T17:01:50Z [net] disconnecting peer=303
--
2024-03-14T17:01:50Z [net] received: getcfheaders (37 bytes) peer=337
2024-03-14T17:01:50Z [net] peer 337 requested invalid block hash: 0000000000000000000026ebf8f613a1ce69849f12e2c5f8fd9867c2402e60fc
2024-03-14T17:01:50Z [net] disconnecting peer=337
--
2024-03-14T17:01:50Z [net] received: getcfheaders (37 bytes) peer=391
2024-03-14T17:01:50Z [net] peer 391 requested invalid block hash: 0000000000000000000026ebf8f613a1ce69849f12e2c5f8fd9867c2402e60fc
2024-03-14T17:01:50Z [net] disconnecting peer=391
--
2024-03-14T18:02:26Z [net] received: getcfheaders (37 bytes) peer=828
2024-03-14T18:02:26Z [net] peer 828 requested invalid block hash: 000000000000000000032b3666aa4da769d272e90a3b95819433ef1ad8cf0f91
2024-03-14T18:02:26Z [net] disconnecting peer=828
--
2024-03-14T18:02:26Z [net] received: getcfheaders (37 bytes) peer=500
2024-03-14T18:02:26Z [net] peer 500 requested invalid block hash: 000000000000000000032b3666aa4da769d272e90a3b95819433ef1ad8cf0f91
2024-03-14T18:02:26Z [net] disconnecting peer=500
--
2024-03-14T18:02:27Z [net] received: getcfheaders (37 bytes) peer=426
2024-03-14T18:02:27Z [net] peer 426 requested invalid block hash: 000000000000000000032b3666aa4da769d272e90a3b95819433ef1ad8cf0f91
2024-03-14T18:02:27Z [net] disconnecting peer=426
2024-03-14T18:02:27Z [net] received: getcfheaders (37 bytes) peer=606
2024-03-14T18:02:27Z [net] peer 606 requested invalid block hash: 000000000000000000032b3666aa4da769d272e90a3b95819433ef1ad8cf0f91
2024-03-14T18:02:27Z [net] disconnecting peer=606
--
2024-03-14T18:02:27Z [net] received: getcfheaders (37 bytes) peer=429
2024-03-14T18:02:27Z [net] peer 429 requested invalid block hash: 000000000000000000032b3666aa4da769d272e90a3b95819433ef1ad8cf0f91
2024-03-14T18:02:27Z [net] disconnecting peer=429
--
2024-03-14T18:02:27Z [net] received: getcfheaders (37 bytes) peer=425
2024-03-14T18:02:27Z [net] peer 425 requested invalid block hash: 000000000000000000032b3666aa4da769d272e90a3b95819433ef1ad8cf0f91
2024-03-14T18:02:27Z [net] disconnecting peer=425
--
2024-03-14T18:26:18Z [net] received: getcfheaders (37 bytes) peer=905
2024-03-14T18:26:18Z [net] peer 905 requested invalid block hash: 000000000000000000003b869494f4d6e7de0436d5ecd1b9e897728cdf5ca940
2024-03-14T18:26:18Z [net] disconnecting peer=905
--
2024-03-14T18:26:18Z [net] received: getcfheaders (37 bytes) peer=1003
2024-03-14T18:26:18Z [net] peer 1003 requested invalid block hash: 000000000000000000003b869494f4d6e7de0436d5ecd1b9e897728cdf5ca940
2024-03-14T18:26:18Z [net] disconnecting peer=1003
--
2024-03-14T19:08:54Z [net] received: getcfheaders (37 bytes) peer=1363
2024-03-14T19:08:54Z [net] peer 1363 requested invalid block hash: 000000000000000000014e6470d64f5f9e9c370325adaa8628841feb07a62ad0
2024-03-14T19:08:54Z [net] disconnecting peer=1363
--
2024-03-14T19:16:00Z [net] received: getcfheaders (37 bytes) peer=1244
2024-03-14T19:16:00Z [net] peer 1244 requested invalid block hash: 0000000000000000000262970ea32768668aba73aba631b9a17871fbe988b6c5
2024-03-14T19:16:00Z [net] disconnecting peer=1244
--
2024-03-14T19:47:31Z [net] received: getcfheaders (37 bytes) peer=942
2024-03-14T19:47:31Z [net] peer 942 requested invalid block hash: 0000000000000000000197ca35169bbd71bacab0258d773398720a23d0fb4a58
2024-03-14T19:47:31Z [net] disconnecting peer=942
--
2024-03-14T19:47:31Z [net] received: getcfheaders (37 bytes) peer=1066
2024-03-14T19:47:31Z [net] peer 1066 requested invalid block hash: 0000000000000000000197ca35169bbd71bacab0258d773398720a23d0fb4a58
2024-03-14T19:47:31Z [net] disconnecting peer=1066
--
2024-03-14T19:47:31Z [net] received: getcfheaders (37 bytes) peer=907
2024-03-14T19:47:31Z [net] peer 907 requested invalid block hash: 0000000000000000000197ca35169bbd71bacab0258d773398720a23d0fb4a58
2024-03-14T19:47:31Z [net] disconnecting peer=907
--
2024-03-14T19:47:31Z [net] received: getcfheaders (37 bytes) peer=906
2024-03-14T19:47:31Z [net] peer 906 requested invalid block hash: 0000000000000000000197ca35169bbd71bacab0258d773398720a23d0fb4a58
2024-03-14T19:47:31Z [net] sending inv (181 bytes) peer=114
--
2024-03-14T19:51:17Z [net] received: getcfheaders (37 bytes) peer=1822
2024-03-14T19:51:17Z [net] peer 1822 requested invalid block hash: 00000000000000000000c855dc4e0cc69918aed13ed048d38018b63e7b9b071c
2024-03-14T19:51:17Z [net] disconnecting peer=1822
--
2024-03-14T19:51:17Z [net] received: getcfheaders (37 bytes) peer=1798
2024-03-14T19:51:17Z [net] peer 1798 requested invalid block hash: 00000000000000000000c855dc4e0cc69918aed13ed048d38018b63e7b9b071c
2024-03-14T19:51:17Z [net] disconnecting peer=1798
--
2024-03-14T19:51:58Z [net] received: getcfheaders (37 bytes) peer=1836
2024-03-14T19:51:58Z [net] peer 1836 requested invalid block hash: 0000000000000000000170d2609f1b73735872a2242789f2190d846f585bddda
2024-03-14T19:51:58Z [net] disconnecting peer=1836
--
2024-03-14T20:03:34Z [net] received: getcfheaders (37 bytes) peer=1841
2024-03-14T20:03:34Z [net] peer 1841 requested invalid block hash: 0000000000000000000219dfc58b29fbf268e0d2c3b0bbf164e34527e3c03c3b
2024-03-14T20:03:34Z [net] sending inv (253 bytes) peer=25
--
2024-03-14T20:03:34Z [net] received: getcfheaders (37 bytes) peer=1875
2024-03-14T20:03:34Z [net] peer 1875 requested invalid block hash: 0000000000000000000219dfc58b29fbf268e0d2c3b0bbf164e34527e3c03c3b
2024-03-14T20:03:34Z [net] disconnecting peer=1875
--
2024-03-14T20:11:27Z [net] received: getcfheaders (37 bytes) peer=1837
2024-03-14T20:11:27Z [net] peer 1837 requested invalid block hash: 00000000000000000000292964b4b00d1d414583bd18d1ebea7a8041d4409c6d
2024-03-14T20:11:27Z [net] disconnecting peer=1837
--
2024-03-14T21:06:43Z [net] received: getcfheaders (37 bytes) peer=2002
2024-03-14T21:06:43Z [net] peer 2002 requested invalid block hash: 00000000000000000001b224ba634525a3263cda1f8cac13209f7c52b800a275
2024-03-14T21:06:43Z [net] disconnecting peer=2002
--
2024-03-14T22:51:15Z [net] received: getcfheaders (37 bytes) peer=1842
2024-03-14T22:51:15Z [net] peer 1842 requested invalid block hash: 0000000000000000000069998432cdfe3f87dda9bcd1d33c239fa775fbdfaed4
2024-03-14T22:51:15Z [net] disconnecting peer=1842
```

### How did you obtain Bitcoin Core

Pre-built binaries

### What version of Bitcoin Core are you using?

v26.0.0

### Operating system and version

Ubuntu 20.04 LTS

### Machine specifications

_No response_