Commit graph

968 commits

Author SHA1 Message Date
Gleb Naumenko
77ccb7fce1
Use std::chrono for salting when randomizing ADDR destination 2022-03-13 16:40:36 +01:00
MarcoFalke
384866e870
Merge bitcoin/bitcoin#24427: refactor: Release cs_main before MaybeSendFeefilter
faa329fd46 refactor: Release cs_main before MaybeSendFeefilter (MarcoFalke)

Pull request description:

  There is no need for any lock to be held, because net processing is single threaded. So holding the validation lock cs_main for sending a feefilter is confusing and might even degrade blockchain-related RPC performance minimally.

ACKs for top commit:
  ajtowns:
    ACK faa329fd46 ; code review only
  vasild:
    ACK faa329fd46

Tree-SHA512: 3e7f9faff1631cc64c86fc1a354ada67617ad1e7a046625cc741f4711854eb41ca8aad5a51ef0d94ff65947b68dba8345c9f786b20ee0a8b7a2e8741cfced21f
2022-03-07 08:47:05 +01:00
Vasil Dimov
0cfc0cd322
net: fix GetListenPort() to derive the proper port
`GetListenPort()` uses a simple logic: "if `-port=P` is given, then we
must be listening on `P`, otherwise we must be listening on `8333`".
This is however not true if `-bind=` has been provided with `:port` part
or if `-whitebind=` has been provided. Thus, extend `GetListenPort()` to
return the port from `-bind=` or `-whitebind=`, if any.

Fixes https://github.com/bitcoin/bitcoin/issues/20184 (cases 1. 2. 3. 5.)
2022-03-02 15:42:37 +01:00
MarcoFalke
faa329fd46
refactor: Release cs_main before MaybeSendFeefilter 2022-02-23 10:26:54 +01:00
Suhas Daftuar
ef6dbe6863 Respond to getheaders if we have sufficient chainwork
Previously, we would check to see if we were in IBD and ignore getheaders
requests accordingly. However, the IBD criteria -- an optimization mostly
targeted at behavior when we have peers serving us many blocks we need to
download -- is difficult to reason about in edge-case scenarios, such as if the
network were to go a long time without any blocks found and nodes getting
restarted during that time.

To make things simpler to reason about, just use nMinimumChainWork as our
anti-DoS threshold; as long as our chain has that much work, it should be fine
to respond to a peer asking for our headers (and this should allow such a peer
to request blocks from us if needed).
2022-02-22 11:34:05 -05:00
Vasil Dimov
d0abce9a50
net: include the port when deciding a relay destination
In `PeerManagerImpl::RelayAddress()` we used just the hash of the
address that is being relayed to decide where to relay it to. Include
the port in that hash, so that e.g. `1.1.1.1:5555` and `1.1.1.1:6666`
get relayed to different peers. Those are two different, distinct
services after all.
2022-02-11 15:21:51 +01:00
MarcoFalke
fa61dd44f9
p2p: Serialize cmpctblock at most once in NewPoWValidBlock 2022-01-26 09:10:26 +01:00
Hennadii Stepanov
5d59ae0ba8
Remove/inline ReadRawBlockFromDisk(block_data, pindex, message_start) 2022-01-25 20:43:37 +01:00
MarcoFalke
39d9bbe4ac
Merge bitcoin/bitcoin#23706: rpc: getblockfrompeer followups
923312fbf6 rpc: use peer_id, block_hash for FetchBlock (Sjors Provoost)
34d5399211 rpc: more detailed errors for getblockfrompeer (Sjors Provoost)
60243cac72 rpc: turn already downloaded into error in getblockfrompeer (Sjors Provoost)
809d66bb65 rpc: clarify getblockfrompeer behavior when called multiple times (Sjors Provoost)
0e3d7c5ee1 refactor: drop redundant hash argument from FetchBlock (Sjors Provoost)
8d1a3e6498 rpc: allow empty JSON object result (Sjors Provoost)
bfbf91d0b2 test: fancier Python for getblockfrompeer (Sjors Provoost)

Pull request description:

  Followups from #20295.

ACKs for top commit:
  jonatack:
    ACK 923312fbf6 📦
  fjahr:
    tested ACK 923312fbf6

Tree-SHA512: da9eca76e302e249409c9d7f0d16cca668ed981e2ab6ca2d1743dad0d830b94b1bc5ffb9028a00764b863201945c273cc8f4409a4c9ca3817830007dffa2bc20
2022-01-25 18:48:41 +01:00
MarcoFalke
973c390298
Merge bitcoin/bitcoin#24078: net, refactor: Rename CNetMessage::m_command with CNetMessage::m_type
224d87855e net, refactor: Drop tautological local variables (Hennadii Stepanov)
3073a9917b scripted-diff: Rename CNetMessage::m_command with CNetMessage::m_type (Hennadii Stepanov)

Pull request description:

  https://github.com/bitcoin/bitcoin/pull/18533#issue-594592488:
  > a message is not a command, but simply a message of some type

  Continuation of bitcoin/bitcoin#18533 and bitcoin/bitcoin#18937.

ACKs for top commit:
  theStack:
    Concept and code-review ACK 224d87855e
  shaavan:
    Code Review ACK 224d87855e
  w0xlt:
    crACK 224d878

Tree-SHA512: 898cafb44708dae1413fcc1533d809d75878891354f1b5edaaec1287f4921c31adc9330f4d42d82544a39689886bc17fee71ea587f9199fd5cc849d376f82176
2022-01-24 08:49:17 +01:00
fanquake
6d859cbd79
Merge bitcoin/bitcoin#24021: Rename and move PoissonNextSend functions
9b8dcb25b5 [net processing] Rename PoissonNextSendInbound to NextInvToInbounds (John Newbery)
ea99f5d01e [net processing] Move PoissonNextSendInbound to PeerManager (John Newbery)
bb060746df scripted-diff: replace PoissonNextSend with GetExponentialRand (John Newbery)
03cfa1b603 [refactor] Use uint64_t and std namespace in PoissonNextSend (John Newbery)
9e64d69bf7 [move] Move PoissonNextSend to src/random and update comment (John Newbery)

Pull request description:

  `PoissonNextSend` and `PoissonNextSendInbound` are used in the p2p code to obfuscate various regularly occurring processes, in order to make it harder for others to get timing-based information deterministically.

  The naming of these functions has been confusing to several people (including myself, see also #23347) because the resulting random timestamps don't follow a Poisson distribution but an exponential distribution (related to events in a Poisson process, hence the name). This PR
  - moves `PoissonNextSend()` out of `net` to `random` and renames it to `GetExponentialRand()`
  - moves `PoissonNextSendInbound()` out of `CConnman` to `PeerManager` and renames it to `NextInvToInbounds()`
  - adds documentation for these functions

  This is work by jnewbery - due to him being less active currently, I opened the PR and will address feedback.

ACKs for top commit:
  jnewbery:
    ACK 9b8dcb25b5
  hebasto:
    ACK 9b8dcb25b5, I have reviewed the code and it looks OK, I agree it can be merged.
  theStack:
    ACK 9b8dcb25b5 📊

Tree-SHA512: 85c366c994e7147f9981fe863fb9838502643fa61ffd32d55a43feef96a38b79a5daa2c4d38ce01074897cc95fa40c76779816edad53f5265b81b05c3a1f4f50
2022-01-23 11:44:02 +08:00
Sebastian Falbesoner
0639aba42a scripted-diff: rename cs_SubVer -> m_subver_mutex
-BEGIN VERIFY SCRIPT-
sed -i 's/cs_SubVer/m_subver_mutex/g' ./src/net.h ./src/net.cpp ./src/net_processing.cpp
-END VERIFY SCRIPT-
2022-01-16 16:47:11 +01:00
Hennadii Stepanov
224d87855e
net, refactor: Drop tautological local variables 2022-01-15 21:03:00 +02:00
Hennadii Stepanov
3073a9917b
scripted-diff: Rename CNetMessage::m_command with CNetMessage::m_type
-BEGIN VERIFY SCRIPT-
sed -i 's/std::string m_command;/std::string m_type;/g' ./src/net.h
sed -i 's/* command and size./* type and size./g' ./src/net.h
sed -i 's/msg.m_command/msg.m_type/g' ./src/net.cpp ./src/net_processing.cpp ./src/test/fuzz/p2p_transport_serialization.cpp
-END VERIFY SCRIPT-
2022-01-15 20:59:19 +02:00
John Newbery
9b8dcb25b5 [net processing] Rename PoissonNextSendInbound to NextInvToInbounds 2022-01-13 15:55:01 +01:00
John Newbery
ea99f5d01e [net processing] Move PoissonNextSendInbound to PeerManager 2022-01-13 15:55:01 +01:00
John Newbery
bb060746df scripted-diff: replace PoissonNextSend with GetExponentialRand
This distribution is used for more than just the next inv send, so make
the name more generic.

Also rename to "exponential" to avoid the confusion that this is a
poisson distribution.

-BEGIN VERIFY SCRIPT-
ren() { sed -i "s/\<$1\>/$2/g" $(git grep -l "$1" ./src) ; }

ren  PoissonNextSend   GetExponentialRand
ren  "a poisson timer" "an exponential timer"
-END VERIFY SCRIPT-
2022-01-13 15:55:01 +01:00
Russell Yanofsky
90fc8b089d Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
MarcoFalke
06209574da
Merge bitcoin/bitcoin#23832: Refactor: Changes time variables from int to chrono
fe86eb50c9 Refactor: Uses c++ init convention for time variables (Shashwat)
6111b0d7fa Refactor: Changes remaining time variable type from int to chrono (Shashwat)

Pull request description:

  This PR is a follow-up to #23801.
  This PR aims to make the following changes to all the time variables in **net_processing.cpp** wherever possible.

  - Convert all time variables to `std::chrono.`
  - Use `chorno::literals` wherever possible.
  - Use `auto` keywords wherever possible.
  - Use `var{val}` convention of initialization.

  This PR also minimizes the number of times, serialization of time `count_seconds(..)` occurs.

ACKs for top commit:
  MarcoFalke:
    re-ACK fe86eb50c9  🏕

Tree-SHA512: c8684c0c60a11140027e36b6e9706a45ecdeae6b5ba0bf267e50655835daee5e5410e34096a8c4eca005f327caae1ac258cc7b8ba663eab58abf131f6d2f4d42
2022-01-06 13:37:26 +01:00
MarcoFalke
fa9f4554ca
refactor: Remove pointless and confusing shift in RelayAddress 2022-01-04 17:07:29 +01:00
Shashwat
fe86eb50c9 Refactor: Uses c++ init convention for time variables
This commit does following changes to time variables in net_processing.h:
- Used {} initialization.
- Uses universal initializer auto.
- Uses chrono::literals

The reason for these changes is to make code simpler, and easier to
understand and rationalize.
2022-01-04 11:17:22 +05:30
Shashwat
6111b0d7fa Refactor: Changes remaining time variable type from int to chrono 2022-01-04 11:17:22 +05:30
Hennadii Stepanov
f47dda2c58
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
* 2020: fa0074e2d8
* 2019: aaaaad6ac9
2021-12-30 19:36:57 +02:00
Sjors Provoost
923312fbf6
rpc: use peer_id, block_hash for FetchBlock 2021-12-24 16:29:04 +01:00
Sjors Provoost
34d5399211
rpc: more detailed errors for getblockfrompeer 2021-12-24 16:29:03 +01:00
Sjors Provoost
809d66bb65
rpc: clarify getblockfrompeer behavior when called multiple times 2021-12-24 16:28:54 +01:00
Sjors Provoost
0e3d7c5ee1
refactor: drop redundant hash argument from FetchBlock 2021-12-24 16:28:53 +01:00
MarcoFalke
3ec8f9f123
Merge bitcoin/bitcoin#23801: Refactor: Change time variable type from int64_t to std::chrono::seconds in net_processing.cpp
92082ea0bb Change time variable type to std::chrono::seconds in src/net_processing.cpp (Shashwat)

Pull request description:

  - This is a follow-up to PR #23758
  - This changes the remaining time variable in `net_processing.cpp` from **int64_t** to **std::chrono::seconds**

ACKs for top commit:
  naumenkogs:
    ACK 92082ea0bb
  hebasto:
    re-ACK 92082ea0bb

Tree-SHA512: 559e351d9046d4ba2b842ae38da13b4befc7feee71f0762f97907812471e2840b0d43c90c92222d15619fe40cc21f11d40900500ca07b470f7ac8b0046cc1d68
2021-12-20 11:48:54 +01:00
Shashwat
92082ea0bb Change time variable type to std::chrono::seconds in src/net_processing.cpp
- This commit is a followup to commit: 60b579
- This changes the remaining time variable in net_processing.cpp from
int64_t to std::chrono
2021-12-20 11:32:37 +05:30
W. J. van der Laan
14ba286556
Merge bitcoin/bitcoin#23695: p2p: Always serialize local timestamp for version msg
fa1dc9b36a p2p: Always serialize local timestamp for version msg (MarcoFalke)

Pull request description:

  Currently we serialize the local time when connecting to outbound connections and the "adjusted network" time when someone connects to us.

  I presume the reason is to avoid a fingerprint in case the local time is misconfigured. However, the fingerprint still exits when:
  * The local time goes out-of-sync after timedata is filled up, in which case the adjusted time is *not* adjusted. See comment in `src/timedata.cpp`. (In practise I expect no adjustment to happen after timedata is filled up by one entry more than half its size).
  * The local time is off by more than 70 minutes. See `DEFAULT_MAX_TIME_ADJUSTMENT`. While there is a warning in this case, the warning might be missed by the node operator.
  * The adjusted time is poisoned by an attacker. This is only a theoretical concern after commit e457513eb1.

  Using the adjusted time does help in a the case where the local time is off by a constant less than 70 minutes and the node quickly connects to 5 outbound peers to retrieve the adjusted time.

  Still, I think using `GetAdjustedTime` here gives a false sense of security. It will be better for node operators to instead set the correct time.

ACKs for top commit:
  naumenkogs:
    ACK fa1dc9b36a
  laanwj:
    Code review ACK fa1dc9b36a
  w0xlt:
    crACK fa1dc9b

Tree-SHA512: 70a0f4ab3500e6ddcde291620e35273018cefd1d9e94b91ad333e360139ed18862718bb1a9854af2bf79990bf74b05d95492f77d0747c7b9bdd276c020116dcb
2021-12-17 21:44:59 +01:00
MarcoFalke
fa3d62cf7b
Move FindForkInGlobalIndex from BlockManager to CChainState
The helper was moved in commit b026e318c3,
which also mentioned that it could be moved to CChainState. So do that,
as the functionality is not block-storage related.

This also allows to drop one function argument.
2021-12-15 17:45:48 +01:00
MarcoFalke
60b5795133
Merge bitcoin/bitcoin#23758: net: Use type-safe mockable time for peer connection time
fad943821e scripted-diff: Rename touched member variables (MarcoFalke)
fa663a4c0d Use mockable time for peer connection time (MarcoFalke)
fad7ead146 refactor: Use type-safe std::chrono in net (MarcoFalke)

Pull request description:

  Benefits:
  * Type-safe
  * Mockable
  * Allows to revert a temporary test workaround

ACKs for top commit:
  naumenkogs:
    ACK fad943821e
  shaavan:
    ACK fad943821e

Tree-SHA512: af9bdfc695ab727b100c6810a7289d29b02b0ea9fa4fee9cc1f3eeefb52c8c465ea2734bae0c1c63b3b0d6264ba2c493268bc970ef6916570eb166de77829d82
2021-12-15 13:07:34 +01:00
MarcoFalke
fa1dc9b36a
p2p: Always serialize local timestamp for version msg 2021-12-14 18:04:48 +01:00
MarcoFalke
9635760ce8
Merge bitcoin/bitcoin#22777: net processing: don't request tx relay on feeler connections
eaf6be0114 [net processing] Do not request transaction relay from feeler connections (John Newbery)
0220b834b1 [test] Add testing for outbound feeler connections (John Newbery)

Pull request description:

  Feelers are short-lived connections used to test the viability of peers. The bitcoind node will periodically open feeler connections to addresses in its addrman, wait for a `version` message from the peer, and then close the connection.

  Currently, we set `fRelay` to `1` in the `version` message for feeler connections, indicating that we want the peer to relay transactions to us. However, we close the connection immediately on receipt of the `version` message, and so never process any incoming transaction announcements. This PR changes that behaviour to instead set `fRelay` to `0` indicating that we do not wish to receive transaction announcements from the peer.

  This PR also extends the `addconnection` RPC to allow creating outbound feeler connections from the node to the test framework, and a test to verify that the node sets `fRelay` to `0` in the `version` message to feeler connections.

ACKs for top commit:
  naumenkogs:
    ACK eaf6be0114
  MarcoFalke:
    review ACK eaf6be0114 🏃

Tree-SHA512: 1c56837dbd0a396fe404a5e39f7459864d15f666664d6b35ad109628b13158e077e417e586bf48946a23bd5cbe63716cb4bf22cdf8781b74dfce6047b87b465a
2021-12-14 17:57:10 +01:00
MarcoFalke
fad943821e
scripted-diff: Rename touched member variables
-BEGIN VERIFY SCRIPT-

 ren() { sed -i "s/\<$1\>/$2/g" $( git grep -l "$1" ./src/ ) ; }

 ren nLastBlockTime m_last_block_time
 ren nLastTXTime    m_last_tx_time
 ren nTimeConnected m_connected

-END VERIFY SCRIPT-
2021-12-13 13:32:08 +01:00
MarcoFalke
fad7ead146
refactor: Use type-safe std::chrono in net 2021-12-13 12:32:09 +01:00
MarcoFalke
9f7661c0c4
Merge bitcoin/bitcoin#19499: p2p: Make timeout mockable and type safe, speed up test
fadc0c80ae p2p: Make timeout mockable and type safe, speed up test (MarcoFalke)
fa6d5a238d scripted-diff: Rename m_last_send and m_last_recv (MarcoFalke)

Pull request description:

  Use type-safe time for better code readability/maintainability and mockable time for better testability. This speeds up the p2p_timeout test.

  This is also a bugfix for intermittent test issues like: https://cirrus-ci.com/task/4769904156999680?command=ci#L2836

  Fixes #20654

ACKs for top commit:
  laanwj:
    Code review ACK fadc0c80ae
  naumenkogs:
    ACK fadc0c80ae

Tree-SHA512: 28c6544c97f188c8a0fbc80411c74ab74ffd055885322c325aa3d1c404b29c3fd70a737e86083eecae58ef394db1cb56bc122d06cff63742aa89a8e868730c64
2021-12-10 10:02:12 +01:00
MarcoFalke
f6013265b7
Merge bitcoin/bitcoin#20295: rpc: getblockfrompeer
dce8c4c381 rpc: getblockfrompeer (Sjors Provoost)
b884ababc2 rpc: move Ensure* helpers to server_util.h (Sjors Provoost)

Pull request description:

  This adds an RPC method to fetch a block directly from a peer. This can used to fetch stale blocks with lower proof of work that are normally ignored by the node (`headers-only` in `getchaintips`).

  Usage:
  ```
  bitcoin-cli getblockfrompeer HASH peer_n
  ```

  Closes #20155

  Limitations:
  * you have to specify which peer to fetch the block from
  * the node must already have the header

ACKs for top commit:
  jnewbery:
    ACK dce8c4c381
  fjahr:
     re-ACK dce8c4c381

Tree-SHA512: 843ba2b7a308f640770d624d0aa3265fdc5c6ea48e8db32269b96a082b7420f7953d1d8d1ef2e6529392c7172dded9d15639fbc9c24e7bfa5cfb79e13a5498c8
2021-12-08 10:39:37 +01:00
fanquake
e457513eb1
Merge bitcoin/bitcoin#23631: p2p: Don't use timestamps from inbound peers for Adjusted Time
0c85dc30e6 p2p: Don't use timestamps from inbound peers (Martin Zumsande)

Pull request description:

  `GetAdjustedTime()` (used e.g. in validation and addrman) returns a time with an offset that is influenced by timestamps that our peers have sent us in their version message.

  Currently, timestamps from all peers are used for this.
  However, I think that it would make sense to ignore the timedata samples from inbound peers, making it much harder for others to influence the Adjusted Time in a targeted way.
  With the extra feeler connections (every 2 minutes on average) and extra block-relay-only connections (every 5 minutes on average) there are also now plenty of opportunities to gather a meaningful number of timedata samples from outbound peers.

  There are some measures in place to prevent abuse: the `-maxtimeadjustment` parameter with a default of 70 minutes, warnings in cases of large deviations, only using the first 200 samples ([explanation](383d350bd5/src/timedata.cpp (L57-L72))), but I think that only using samples from outbound connections in the first place would be an additional safety measure that would make sense.

  See also issue #4521 for further context and links: There have been several discussions in the past about replacing or abolishing the existing timedata system.

ACKs for top commit:
  jnewbery:
    Concept and code review ACK 0c85dc30e6
  naumenkogs:
    ACK 0c85dc30e6
  vasild:
    ACK 0c85dc30e6

Tree-SHA512: 2d6375305bcae034d68b58b7a07777b40ac430dfed554c88e681a048c527536691e1b7d08c0ef995247d356f8e81aa0a4b983bf2674faf6a416264e5f1af0a96
2021-12-07 17:36:53 +08:00
MarcoFalke
fadc0c80ae
p2p: Make timeout mockable and type safe, speed up test 2021-12-06 10:47:52 +01:00
MarcoFalke
8b1de78577
Merge bitcoin/bitcoin#23413: Replace MakeSpan helper with Span deduction guide
11daf6ceb1 More Span simplifications (Pieter Wuille)
568dd2f839 Replace MakeSpan helper with Span deduction guide (Pieter Wuille)

Pull request description:

  C++17 supports [user-defined deduction guides](https://en.cppreference.com/w/cpp/language/class_template_argument_deduction), allowing class constructors to be invoked without specifying class template arguments. Instead, the code can contain rules to infer the template arguments from the constructor argument types.

  This alleviates the need for the `MakeSpan` helper. Convert the existing MakeSpan rules into deduction rules for `Span` itself, and replace all invocations of `MakeSpan` with just `Span` ones.

ACKs for top commit:
  MarcoFalke:
    re-ACK 11daf6ceb1 Only change is removing a hunk in the tests 🌕

Tree-SHA512: 10f3e82e4338f39d9b7b407cd11aac7ebe1e9191b58e3d7f4e5e338a4636c0e126b4a1d912127c7446f57ba356c8d6544482e47f97901efea6a54fffbfd7895f
2021-12-03 10:44:37 +01:00
Sjors Provoost
dce8c4c381
rpc: getblockfrompeer
Co-authored-by: John Newbery <john@johnnewbery.com>
2021-12-02 13:16:18 +07:00
W. J. van der Laan
63c0d0e937
Merge bitcoin/bitcoin#21327: net_processing: ignore transactions while in IBD
6aed8b7e9b [test] tx processing before and after ibd (glozow)
b9e105b664 [net_processing] ignore all transactions during ibd (glozow)

Pull request description:

  This is basically a mini, IBD-only version of #21224

  Incoming transactions aren't really relevant until we're caught up. That's why we send a giant feefilter and don't send tx getdatas, but we also shouldn't process them if peers send them anyway. Simply ignore them.

ACKs for top commit:
  jnewbery:
    reACK 6aed8b7e9b
  laanwj:
    Code review ACK 6aed8b7e9b

Tree-SHA512: 8e1616bf355f9d0b180bdbc5461f24c757dc5d7bc7bf651470f3b0bffcca5d5e68287106255b5cede2d96b42bce448a0f8c0649de35a530c5e079f7c89c70a35
2021-11-30 19:09:15 +01:00
Pieter Wuille
568dd2f839 Replace MakeSpan helper with Span deduction guide 2021-11-29 17:58:53 -05:00
Martin Zumsande
0c85dc30e6 p2p: Don't use timestamps from inbound peers
This makes it harder for others to tamper with
our adjusted time.
2021-11-29 16:46:41 +01:00
MarcoFalke
fac49470ca
doc: Fix incorrect C++ named args 2021-11-17 09:25:14 +01:00
John Newbery
0fdb619aaf [validation] Always call mempool.check() after processing a new transaction
CTxMemPool::check() will carry out internal consistency checks 1/n times,
where n is set by the `-checkmempool` configuration option. By default,
mempool consistency checks are disabled entirely on mainnet.

Therefore, this change has no effect on mainnet nodes running with
default configuration. It simply removes the responsibility to trigger
mempool consistency checks from net_processing.
2021-11-03 14:37:45 +00:00
John Newbery
2c64270bbe [refactor] Don't call AcceptToMemoryPool() from outside validation.cpp 2021-11-03 14:34:41 +00:00
John Newbery
92a3aeecf6 [validation] Add CChainState::ProcessTransaction()
This just calls through to AcceptToMemoryPool() internally, and is currently unused.

Also add a new transaction validation failure reason TX_NO_MEMPOOL to
indicate that there is no mempool.
2021-11-03 14:34:38 +00:00
glozow
b9e105b664 [net_processing] ignore all transactions during ibd
Co-authored-by: Amiti Uttarwar <amiti@uttarwar.org>
2021-10-28 16:31:22 +01:00
MarcoFalke
1847ce2d49
Merge bitcoin/bitcoin#23157: txmempool -/-> validation 1/2: improve performance of check() and remove dependency on validation
082c5bf099 [refactor] pass coinsview and height to check() (glozow)
ed6115f1ea [mempool] simplify some check() logic (glozow)
9e8d7ad5d9 [validation/mempool] use Spend/AddCoin instead of UpdateCoins (glozow)
09d18916af MOVEONLY: remove single-use helper func CheckInputsAndUpdateCoins (glozow)
e8639ec26a [mempool] remove now-unnecessary code (glozow)
54c6f3c1da [mempool] speed up check() by using coins cache and iterating in topo order (glozow)
30e240f65e [bench] Benchmark CTxMemPool::check() (glozow)
cb1407196f [refactor/bench] make mempool_stress bench reusable and parameterizable (glozow)

Pull request description:

  Remove the txmempool <-> validation circular dependency by removing txmempool's dependency on validation. There are two functions in txmempool that need validation right now: `check()` and `removeForReorg()`. This PR removes the dependencies in `check()`.

  This PR also improves the performance of `CTxMemPool::check()` by walking through the entries exactly once, in ascending ancestorcount order, which guarantees that we see parents before children.

ACKs for top commit:
  jnewbery:
    reACK 082c5bf099
  GeneFerneau:
    tACK [082c5bf](082c5bf099)
  rajarshimaitra:
    tACK 082c5bf099
  theStack:
    Code-review ACK 082c5bf099

Tree-SHA512: 40ac622af1627b5c3e6abb4f0f035d833265a8c5e8dc88faf5354875dfb5137f137825e54bbd2a2668ed37b145c5d02285f776402629f58596e51853a9a79d29
2021-10-25 15:21:27 +02:00
MarcoFalke
224e90d9fd
Merge bitcoin/bitcoin#23336: refactor: Make GenTxid boolean constructor private
fa4ec1c0bd Make GenTxid boolean constructor private (MarcoFalke)
faeb9a5753 remove unused CTxMemPool::info(const uint256& txid) (MarcoFalke)

Pull request description:

  This boolean argument is either verbose (when used with a named arg) or unintuitive and dangerous (when used as a plain bool).

  Fix that by making the constructor private.

ACKs for top commit:
  laanwj:
    Code review ACK fa4ec1c0bd
  jnewbery:
    Code review ACK fa4ec1c0bd
  glozow:
    code review ACK fa4ec1c0bd

Tree-SHA512: bf08ee09168885cfda71e5a01ec412b93964662a90dd9d91e75f7fdf2eaff7c21a95204d0e90b00438bfeab564d0aea66bdb9c0394ee7a05743e65a817159446
2021-10-22 17:16:58 +02:00
fanquake
788909f3c7
Merge bitcoin/bitcoin#23042: net: Avoid logging AlreadyHaveTx when disconnecting misbehaving peer
fa2662c293 net: Avoid logging AlreadyHaveTx when disconnecting misbehaving peer (MarcoFalke)

Pull request description:

  There is no need to log `AlreadyHaveTx` for an inv when a peer is marked for disconnection due to sending that inv. In fact, I find it confusing that a `block-relay-only` connection calls `AlreadyHaveTx` at all. Also there is no need to call `AddKnownTx` when the peer is marked for disconnection.

ACKs for top commit:
  naumenkogs:
    ACK fa2662c293
  jnewbery:
    Code review ACK fa2662c293
  dunxen:
    Concept and code review ACK fa2662c293

Tree-SHA512: 9996b807a824021f992b5281d82ff0cbbe6a442c2fedf7dfd6adda64ccc5e0ef4fb0ff91ab75086f975837bbbb7a5934ac7e671a80dcababa7203c92fc0c7f84
2021-10-22 19:22:44 +08:00
MarcoFalke
fa4ec1c0bd
Make GenTxid boolean constructor private 2021-10-22 12:32:16 +02:00
MarcoFalke
c001da306b
Merge bitcoin/bitcoin#23325: mempool: delete exists(uint256) function
4307849256 [mempool] delete exists(uint256) function (glozow)
d50fbd4c5b create explicit GenTxid::{Txid, Wtxid} ctors (glozow)

Pull request description:

  We use the same type for txids and wtxids, `uint256`. In places where we want the ability to pass either one, we distinguish them using `GenTxid`.

  The (overloaded) `CTxMemPool::exists()` function is defined as follows:
  ```c
  bool exists(const uint256& txid) const { return exists(GenTxid{false, txid}); }
  ```
  It always assumes that a uint256 is a txid, which is a footgunny interface.
  Querying by wtxid returns a false negative if the transaction has a witness. 🐛

  Another approach would be to try both:
  ```c
  bool exists(const uint256& txid) const { return exists(GenTxid{false, txid}) || exists(GenTxid{false, txid}); }
  ```
  But that's slower and wrongfully placing the burden on the callee; the caller always knows whether the hash is a txid or a wtxid.

ACKs for top commit:
  laanwj:
    Code review ACK 4307849256
  jnewbery:
    Tested and code review ACK 4307849256
  MarcoFalke:
    review ACK 4307849256 👘

Tree-SHA512: 8ed167a96f3124b6c14e41073c8358658114ce121a15a4cca2db7a5ac565903a6236e34e88ac03382b8bb8b68e3999abbfc5718bc8c22476554d6b49a5298eec
2021-10-22 12:29:28 +02:00
glozow
4307849256 [mempool] delete exists(uint256) function
Allowing callers to pass in a uint256 (which could be txid or wtxid)
but then always assuming that it's a txid is a footgunny interface.
2021-10-21 16:26:59 +01:00
MarcoFalke
fadf1186c8
p2p: Use mocktime for ping timeout 2021-10-07 13:22:02 +02:00
MarcoFalke
c4fc899442
Merge bitcoin/bitcoin#22950: [p2p] Pimpl AddrMan to abstract implementation details
021f86953e [style] Run changed files through clang formatter. (Amiti Uttarwar)
375750387e scripted-diff: Rename CAddrInfo to AddrInfo (Amiti Uttarwar)
dd8f7f2500 scripted-diff: Rename CAddrMan to AddrMan (Amiti Uttarwar)
3c263d3f63 [includes] Fix up included files (Amiti Uttarwar)
29727c2aa1 [doc] Update comments (Amiti Uttarwar)
14f9e000d0 [refactor] Update GetAddr_() function signature (Amiti Uttarwar)
40acd6fc9a [move-only] Move constants to test-only header (Amiti Uttarwar)
7cf41bbb38 [addrman] Change CAddrInfo access (Amiti Uttarwar)
e3f1ea659c [move-only] Move CAddrInfo to test-only header file (Amiti Uttarwar)
7cba9d5618 [net, addrman] Remove external dependencies on CAddrInfo objects (Amiti Uttarwar)
8af5b54f97 [addrman] Introduce CAddrMan::Impl to encapsulate addrman implementation. (Amiti Uttarwar)
f2e5f38f09 [move-only] Match ordering of CAddrMan declarations and definitions (Amiti Uttarwar)
5faa7dd6d8 [move-only] Move CAddrMan function definitions to cpp (Amiti Uttarwar)

Pull request description:

  Introduce the pimpl pattern for AddrMan to separate the implementation details from the externally used object representation. This reduces compile-time dependencies and conceptually clarifies AddrMan's interface from the implementation specifics.

  Since the unit & fuzz tests currently rely on accessing AddrMan internals, this PR introduces addrman_impl.h, which is exclusively imported by addrman.cpp and test files.

ACKs for top commit:
  jnewbery:
    ACK 021f86953e
  GeneFerneau:
    utACK [021f869](021f86953e)
  mzumsande:
    ACK 021f86953e
  rajarshimaitra:
    Concept + Code Review ACK 021f86953e
  theuni:
    ACK 021f86953e

Tree-SHA512: aa70cb77927a35c85230163c0cf6d3872382d79048b0fb79341493caa46f8e91498cb787d8b06aba4da17b2f921f2230e73f3d66385519794fff86a831b3a71d
2021-10-05 16:48:33 +02:00
MarcoFalke
816e15ee81
Merge bitcoin/bitcoin#22951: consensus: move amount.h into consensus
9d0379cea6 consensus: use <cstdint> over <stdint.h> in amount.h (fanquake)
863e52fe63 consensus: make COIN & MAX_MONEY constexpr (fanquake)
d09071da5b [MOVEONLY] consensus: move amount.h into consensus (fanquake)

Pull request description:

  A first step (of a few) towards some source code reorganization, as well as making libbitcoinconsensus slightly more self contained.

  Related to #15732.

ACKs for top commit:
  MarcoFalke:
    concept ACK 9d0379cea6 🏝

Tree-SHA512: 97fc79262dcb8c00996852a288fee69ddf8398ae2c95700bba5b326f1f38ffcfaf8fa66e29d0cb446d9b3f4e608a96525fae0c2ad9cd531ad98ad2a4a687cd6a
2021-10-05 09:43:23 +02:00
glozow
082c5bf099 [refactor] pass coinsview and height to check()
Removes check's dependency on validation.h
2021-10-04 15:00:28 +01:00
fanquake
d09071da5b
[MOVEONLY] consensus: move amount.h into consensus
Move amount.h to consensus/amount.h.
Renames, adds missing and removes uneeded includes.
2021-09-30 07:41:57 +08:00
Amiti Uttarwar
dd8f7f2500 scripted-diff: Rename CAddrMan to AddrMan
-BEGIN VERIFY SCRIPT-
git grep -l CAddrMan src/ test/ | xargs sed -i 's/CAddrMan/AddrMan/g'
-END VERIFY SCRIPT-
2021-09-28 22:21:10 -04:00
Niklas Gögge
0dc8bf5b92 [net processing] Dont request compact blocks in blocks-only mode 2021-09-28 22:11:30 +02:00
John Newbery
eaf6be0114 [net processing] Do not request transaction relay from feeler connections
Add a test to verify that feeler connections do not request transaction relay.
2021-09-22 16:12:16 +01:00
MarcoFalke
fa2662c293
net: Avoid logging AlreadyHaveTx when disconnecting misbehaving peer
Can be reviewed with --color-moved=dimmed-zebra
2021-09-20 09:25:02 +02:00
MarcoFalke
fa66a7d732
p2p: Rename fBlocksOnly, Add test
The new name describes better what the bool does and also limits the confusion of the three different concepts:
* fBlocksOnly (This bool to skip tx invs)
* -blocksonly (A setting to ignore incoming txs)
* block-relay-only (A connection type in the block-relay-only P2P graph)
2021-09-12 12:53:50 +02:00
Russell Yanofsky
93b9800fec scripted-diff: Rename overloaded int GetArg to GetIntArg
Improve readability of code, simplify future scripted diff cleanup PRs, and be
more consistent with naming for GetBoolArg.

This will also be useful for replacing runtime settings type checking
with compile time checking.

-BEGIN VERIFY SCRIPT-
git grep -l GetArg | xargs sed -i 's/GetArg(\([^)]*\( [0-9]\+\|-1\|port\|BaseParams().RPCPort()\|Params().GetDefaultPort()\|_TIMEOUT\|Height\|_WORKQUEUE\|_THREADS\|_CONNECTIONS\|LIMIT\|SigOp\|Bytes\|_VERSION\|_AGE\|_CHECKS\|Checks() ? 1 : 0\|_BANTIME\|Cache\|BLOCKS\|LEVEL\|Weight\|Version\|BUFFER\|TARGET\|WEIGHT\|TXN\|TRANSACTIONS\|ADJUSTMENT\|i64\|Size\|nDefault\|_EXPIRY\|HEIGHT\|SIZE\|SNDHWM\|_TIME_MS\)\))/GetIntArg(\1)/g'
-END VERIFY SCRIPT-

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2021-09-27 06:57:20 -04:00
MarcoFalke
fa9eade142
Remove GetAddrName
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.html#c131-avoid-trivial-getters-and-setters
2021-08-26 10:44:26 +02:00
Pieter Wuille
75290ae61e Drop us=... message in net debug for sending version message
The us=... message in the debug log when sending a version message is
always [::]:0, because we no longer send our own address there.
Therefore, this information is entirely redundant. Remove it.
2021-08-21 19:16:47 -04:00
Pieter Wuille
5d47860334 refactor: move CAddress-without-nTime logic to net_processing
Historically, the VERSION message contains an "addrMe" and an "addrYou". As
these are sent before version negotiation is complete, the protocol version is
INIT_PROTO_VERSION (209), and in that protocol, CAddress is serialized without
nTime.

This is in fact the only situation left where a CAddress is (de)serialized
without nTime. As it's such a simple structure (CService for ip/port + uint64_t
for nServices), just inline that structure in the few places where it occurs,
and remove the logic for dealing with missing nTime from CAddress.
2021-08-21 19:16:47 -04:00
fanquake
4c87665707
Merge bitcoin/bitcoin#22604: p2p, rpc, test: address rate-limiting follow-ups
d930c7f5b0 p2p, rpc, test: address rate-limiting follow-ups (Jon Atack)

Pull request description:

  Incorporates review feedback in #22387.

  Edit, could be considered separately: should a release note (or two) be added for 22.0? e.g. the new getpeerinfo fields in `Updated RPCs` and the rate-limiting itself in `P2P and network changes`.

ACKs for top commit:
  MarcoFalke:
    review ACK d930c7f5b0
  theStack:
    re-ACK d930c7f5b0 🌮
  Zero-1729:
    crACK d930c7f

Tree-SHA512: b2101cad87f59c238603f38bd8e8df7a4d48929794e4de9e0e0ff2afa935a68475c2d369aa669d124a0bec2f50280fb47e8b980bde6ad812db08cf67b71c066a
2021-08-14 13:33:47 +08:00
MarcoFalke
dd981b5e84
Merge bitcoin/bitcoin#22618: [p2p] Small follow-ups to 21528
9778b0fec1 [net_processing] Provide debug error if code assumptions change. (Amiti Uttarwar)
aa79c91260 [docs] Add release notes for #21528 (Amiti Uttarwar)

Pull request description:

  Adds a release note & addresses [this](https://github.com/bitcoin/bitcoin/pull/21528#discussion_r680963101) review comment to make expectations more explicit.

ACKs for top commit:
  Zero-1729:
    re-ACK 9778b0fec1
  jonatack:
    ACK 9778b0fec1

Tree-SHA512: 9507df5f2746d05c6df8c86b7a19364610ebfafc81af7650be7e68d7536a0685cce9fd2e5f287ef92b6245c584f8875b24a958109ba5bd8acf3c8fc9fd19eef2
2021-08-05 09:29:54 +02:00
Amiti Uttarwar
9778b0fec1 [net_processing] Provide debug error if code assumptions change.
Currently, this call to SetupAddressRelay will never return false because of
the previous guard that returns early if the peer is not an inbound connection.
Rather than implicitly relying on this guarantee, throw an error in the debug
build if it ever changes.
2021-08-04 12:36:22 -07:00
Jon Atack
d930c7f5b0
p2p, rpc, test: address rate-limiting follow-ups 2021-08-04 19:03:51 +02:00
MarcoFalke
513e1071a1
Merge bitcoin/bitcoin#22616: p2p, rpc: address relay fixups
5e33f762d4 p2p, rpc: address relay fixups (Jon Atack)

Pull request description:

  Following review of new changes merged today, move a use of `statestats` in getpeerinfo to within the section guarded by `if (fStateStats)`, e.g. `PeerManagerImpl::GetNodeStateStats` true, and pass an in-param by reference to const.

ACKs for top commit:
  amitiuttarwar:
    ACK 5e33f762d4
  jnewbery:
    ACK 5e33f762d4

Tree-SHA512: b42f33c615b14079e2c4e6060209de8707d71b351dd1e11e04a2a6fc12d15747d0c5d9b24850217080fd1ef92e63f96d6925c4badf280b781edd696c349be7d6
2021-08-04 17:17:55 +02:00
MarcoFalke
5b2d8661c9
Merge bitcoin/bitcoin#22577: Close minor startup race between main and scheduler threads
703b1e612a Close minor startup race between main and scheduler threads (Larry Ruane)

Pull request description:

  This is a low-priority bug fix. The scheduler thread runs `CheckForStaleTipAndEvictPeers()` every 45 seconds (EXTRA_PEER_CHECK_INTERVAL). If its first run happens before the active chain is set up (`CChain::SetTip()`), `bitcoind` will assert:
  ```
  (...)
  2021-07-28T22:16:49Z init message: Loading block index…
  bitcoind: validation.cpp:4968: CChainState& ChainstateManager::ActiveChainstate() const: Assertion `m_active_chainstate' failed.
  Aborted (core dumped)
  ```
  I ran into this while using the debugger to investigate an unrelated problem. Single-stepping through threads with a debugger can cause the relative thread execution timing to be very different than usual. I don't think any automated tests are needed for this PR. I'll give reproduction steps in the next PR comment.

ACKs for top commit:
  MarcoFalke:
    cr ACK 703b1e612a
  tryphe:
    tested ACK 703b1e612a
  0xB10C:
    ACK 703b1e612a
  glozow:
    code review ACK 703b1e612a - it makes sense to me to start peerman's background tasks here, after `chainstate->LoadChainTip()` and `node.connman->Start()` have been called.

Tree-SHA512: 9316ad768cba3b171f62e2eb400e3790af66c47d1886d7965edb38d9710fc8c8f8e4fb38232811c9346732ce311d39f740c5c2aaf5f6ca390ddc48c51a8d633b
2021-08-04 16:37:12 +02:00
Jon Atack
5e33f762d4
p2p, rpc: address relay fixups 2021-08-03 13:09:19 +02:00
fanquake
06788c6705
Merge bitcoin/bitcoin#21528: [p2p] Reduce addr blackholes
3f7250b328 [test] Use the new endpoint to improve tests (Amiti Uttarwar)
3893da06db [RPC] Add field to getpeerinfo to indicate if addr relay is enabled (Amiti Uttarwar)
0980ca78cd [test] Test that we intentionally select addr relay peers. (Amiti Uttarwar)
c061599e40 [net_processing] Remove RelayAddrsWithPeer function (Amiti Uttarwar)
201e496481 [net_processing] Introduce new field to indicate if addr relay is enabled (Amiti Uttarwar)
1d1ef2db7e [net_processing] Defer initializing m_addr_known (Amiti Uttarwar)
6653fa3328 [test] Update p2p_addr_relay test to prepare (Amiti Uttarwar)
2fcaec7bbb [net_processing] Introduce SetupAddressRelay (Amiti Uttarwar)

Pull request description:

  This PR builds on the test refactors extracted into #22306 (first 5 commits).

  This PR aims to reduce addr blackholes. When we receive an `addr` message that contains 10 or less addresses, we forward them to 1-2 peers. This is the main technique we use for self advertisements, so sending to peers that wouldn't relay would effectively "blackhole" the trickle. Although we cannot prevent this in a malicious case, we can improve it for the normal, honest cases, and reduce the overall likelihood of occurrence. Two known cases where peers would not participate in addr relay are if they have connected to you as a block-relay-only connection, or if they are a light client.

  This implementation defers initialization of `m_addr_known` until it is needed, then uses its presence to decide if the peer is participating in addr relay. For outbound (not block-relay-only) peers, we initialize the filter before sending the initial self announcement when processing their `version` message. For inbound peers, we initialize the filter if/when we get an addr related message (`ADDR`, `ADDRV2`, `GETADDR`). We do NOT initialize the filter based on a `SENDADDRV2` message.

  To communicate about these changes beyond bitcoin core & to (try to) ensure that no other software would be disrupted, I have:
  - Posted to the [mailing list](https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-April/018784.html)
  - Researched other open source clients to confirm compatibility, opened issues in all the projects & documented in https://github.com/bitcoin/bitcoin/pull/21528#issuecomment-809906430. Many have confirmed that this change would not be problematic.
  - Raised as topic during [bitcoin-core-dev meeting](https://www.erisian.com.au/bitcoin-core-dev/log-2021-03-25.html#l-954)
  - Raised as topic during [bitcoin p2p meeting](https://www.erisian.com.au/bitcoin-core-dev/log-2021-04-20.html#l-439)

ACKs for top commit:
  jnewbery:
    reACK 3f7250b328
  glozow:
    ACK 3f7250b328
  ajtowns:
    utACK 3f7250b328

Tree-SHA512: 29069282af684c1cd37d107c395fdd432dcccb11626f3c2dabfe92fdc4c85e74c7c4056fbdfa88017fec240506639b72ac6c311f8ce7c583112eb15f47e421af
2021-08-03 09:47:51 +08:00
Larry Ruane
703b1e612a Close minor startup race between main and scheduler threads
Don't schedule class PeerManagerImpl's background tasks from its
constructor, but instead do that from a separate method,
StartScheduledTasks(), that can be called later at the end of startup,
after other things, such as the active chain, are initialzed.
2021-07-30 16:34:09 -06:00
Amiti Uttarwar
3893da06db [RPC] Add field to getpeerinfo to indicate if addr relay is enabled 2021-07-29 17:43:01 -07:00
Amiti Uttarwar
c061599e40 [net_processing] Remove RelayAddrsWithPeer function
Now that we have a simple boolean stored on the field, the wrapper function is
no longer necessary.
2021-07-29 17:43:00 -07:00
Amiti Uttarwar
201e496481 [net_processing] Introduce new field to indicate if addr relay is enabled 2021-07-29 17:41:19 -07:00
Amiti Uttarwar
1d1ef2db7e [net_processing] Defer initializing m_addr_known
Use SetupAddressRelay to only initialize `m_addr_known` as needed. For outbound
peers, we initialize the filter before sending our self announcement (not
applicable for block-relay-only connections). For inbound peers, we initialize
the filter when we get an addr related message (ADDR, ADDRV2, GETADDR).

These changes intend to mitigate address blackholes. Since an inbound peer has
to send us an addr related message to become eligible as a candidate for addr
relay, this should reduce our likelihood of sending them self-announcements.
2021-07-29 17:40:21 -07:00
Amiti Uttarwar
2fcaec7bbb [net_processing] Introduce SetupAddressRelay
Idempotent function that initializes m_addr_known for connections that support
address relay (anything other than block-relay-only). Unused until the next
commit.
2021-07-29 17:40:17 -07:00
MarcoFalke
67b9416540
Merge bitcoin/bitcoin#21562: [net processing] Various tidying up of PeerManagerImpl ctor
fde1bf4f61 [net processing] Default initialize m_recent_confirmed_transactions (John Newbery)
37dcd12d53 scripted-diff: Rename recentRejects (John Newbery)
cd9902ac50 [net processing] Default initialize recentRejects (John Newbery)
a28bfd1d4c [net processing] Default initialize m_stale_tip_check_time (John Newbery)
9190b01d8d [net processing] Add Orphanage empty consistency check (John Newbery)

Pull request description:

  - Use default initialization of PeerManagerImpl members where possible
  - Remove unique_ptr indirection where it's not needed

ACKs for top commit:
  MarcoFalke:
    ACK fde1bf4f61 👞
  theStack:
    re-ACK fde1bf4f61

Tree-SHA512: 7ddedcc972df8e933e1fbe5c88b8ea17df89e1e58fc769518512c5540e49dc8eddb3f47e78d1329a6fc5644d2c1d11c981f681fd633f5218bfa4b3e6a86f3d7b
2021-07-28 16:31:41 +02:00
0xb10c
4224dec22b
tracing: Tracepoints for in- and outbound P2P msgs
Can be used to monitor in- and outbound node traffic.

Based on ealier work by jb55.

Co-authored-by: William Casarin <jb55@jb55.com>
2021-07-27 17:12:16 +02:00
MarcoFalke
f372623807
Merge bitcoin/bitcoin#22495: p2p: refactor: tidy up PeerManagerImpl::Misbehaving(...)
8858e88c84 p2p: refactor: tidy up `PeerManagerImpl::Misbehaving(...)` (Sebastian Falbesoner)

Pull request description:

  This simple refactoring PR has the goal to improve the readability of the `Misbehaving` method by

  - introducing constant variables `score_before` and  `score_now` (to avoid repeatedly calculating the former)
  - deduplicating calls to LogPrint(), eliminates else-branch

ACKs for top commit:
  jnewbery:
    utACK 8858e88c84
  rajarshimaitra:
    tACK 8858e88c84

Tree-SHA512: 1d4dd5ac1d16ee9595edf4fa46e4960915a203641d74e6c33cffaba62ea71328834309a4451256fb45daf759f0cf6f4f199c46815afff6c89c0746e2ad4d4092
2021-07-27 11:26:39 +02:00
Sebastian Falbesoner
8858e88c84 p2p: refactor: tidy up PeerManagerImpl::Misbehaving(...)
- introduce constant variables `score_before` and
  `score_after` in order to improve readability
- deduplicate calls to LogPrint(), eliminates else-branch
2021-07-26 15:51:14 +02:00
W. J. van der Laan
5d83e7d714
Merge bitcoin/bitcoin#21090: Default to NODE_WITNESS in nLocalServices
a806647d26 [validation] Always include merkle root in coinbase commitment (Dhruv Mehta)
189128c220 [validation] Set witness script flag with p2sh for blocks (Dhruv Mehta)
ac82b99db7 [p2p] remove redundant NODE_WITNESS checks (Dhruv Mehta)
6f8b198b82 [p2p] remove unused segwitheight=-1 option (Dhruv Mehta)
eba5b1cd64 [test] remove or move tests using `-segwitheight=-1` (Dhruv Mehta)

Pull request description:

  Builds on #21009 and makes progress on remaining items in #17862

  Removing `RewindBlockIndex()` in #21009 allows the following:

  - removal of tests using `segwitheight=-1` in `p2p_segwit.py`.
  - move `test_upgrade_after_activation()` out of `p2p_segwit.py` reducing runtime
  - in turn, that allows us to drop support for `-segwitheight=-1`, which is only supported for that test.
  - that allows us to always set `NODE_WITNESS` in our local services. The only reason we don't do that is to support `-segwitheight=-1`.
  - that in turn allows us to drop all of the `GetLocalServices() & NODE_WITNESS` checks inside `net_processing.cpp`, since our local services would always include `NODE_WITNESS`

ACKs for top commit:
  mzumsande:
    Code-Review ACK a806647d26
  laanwj:
    Code review ACK a806647d26, nice cleanup
  jnewbery:
    utACK a806647d26
  theStack:
    ACK a806647d26

Tree-SHA512: 73e1a69d1d7eca1f5c38558ec6672decd0b60b16c2ef6134df6f6af71bb159e6eea160f9bb5ab0eb6723c6632d29509811e29469d0d87abbe9b69a2890fbc73e
2021-07-22 17:36:38 +02:00
fanquake
e4487fd5bb
Merge bitcoin/bitcoin#22096: p2p: AddrFetch - don't disconnect on self-announcements
5730a43703 test: Add functional test for AddrFetch connections (Martin Zumsande)
c34ad3309f net, rpc: Enable AddrFetch connections for functional testing (Martin Zumsande)
533500d907 p2p: Add timeout for AddrFetch peers (Martin Zumsande)
b6c5d1e450 p2p: AddrFetch - don't disconnect on self-announcements (Martin Zumsande)

Pull request description:

  AddrFetch connections (old name: oneshots) are intended to be short-lived connections on which we ask a peer for addresses via `getaddr` and disconnect after receiving them.

  This is done by disconnecting after receiving the first `addr`. However, it is no longer working as intended, because nowadays, the first `addr` a typical bitcoin core node sends is its self-announcement.
  So we'll disconnect before the peer gets a chance to answer our `getaddr`.

  I checked that this affects both `-seednode` peers specified manually, and DNS seeds when AddrFetch is used as a fallback if DNS doesn't work for us.

  The current behavior of getting peers via AddrFetch when starting with an empty addrman would be to connect to the peer, receive its self-announcement and add it to addrman, disconnect, reconnect to the same peer again as a full outbound (no other addresses in addrman) and then receive more `addr`. This is silly and not in line with AddrFetch peer being intended to be short-lived peers. 

  Fix this by only disconnecting after receiving an `addr` message of size > 1.

  [Edit] As per review discussion, this PR now also adds a timeout after which we disconnect if we haven't received any suitable `addr`, and a functional test.

ACKs for top commit:
  amitiuttarwar:
    reACK 5730a43703
  naumenkogs:
    ACK 5730a43703
  jnewbery:
    ACK 5730a43703

Tree-SHA512: 8a81234f37e827705138eb254223f7f3b3bf44a06cb02126fc7990b0d231b9bd8f07d38d185cc30d55bf35548a6fdc286b69602498d875b937e7c58332158bf9
2021-07-20 20:27:21 +08:00
John Newbery
fde1bf4f61 [net processing] Default initialize m_recent_confirmed_transactions
Now that m_recent_confirmed_transactions is owned by PeerManagerImpl,
and PeerManagerImpl's lifetime is managed by the node context, we can
just default initialize m_recent_confirmed_transactions during object
initialization. We can also remove the unique_ptr indirection.
2021-07-20 13:15:26 +01:00
John Newbery
37dcd12d53 scripted-diff: Rename recentRejects
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren recentRejects m_recent_rejects
-END VERIFY SCRIPT-
2021-07-20 13:14:32 +01:00
John Newbery
cd9902ac50 [net processing] Default initialize recentRejects
Now that recentRejects is owned by PeerManagerImpl, and
PeerManagerImpl's lifetime is managed by the node context, we can just
default initialize recentRejects during object initialization. We can
also remove the unique_ptr indirection.
2021-07-20 13:13:59 +01:00
John Newbery
a28bfd1d4c [net processing] Default initialize m_stale_tip_check_time 2021-07-20 13:12:42 +01:00
John Newbery
9190b01d8d [net processing] Add Orphanage empty consistency check
When removing the final peer, assert that m_tx_orphanage is empty.
2021-07-20 13:12:42 +01:00
Pieter Wuille
f424d601e1 Add logging and addr rate limiting statistics
Includes logging improvements by Vasil Dimov and John Newbery.
2021-07-15 13:03:20 -07:00
Pieter Wuille
5648138f59 Randomize the order of addr processing 2021-07-15 12:59:23 -07:00
Pieter Wuille
0d64b8f709 Rate limit the processing of incoming addr messages
While limitations on the influence of attackers on addrman already
exist (affected buckets are restricted to a subset based on incoming
IP / network group), there is no reason to permit them to let them
feed us addresses at more than a multiple of the normal network
rate.

This commit introduces a "token bucket" rate limiter for the
processing of addresses in incoming ADDR and ADDRV2 messages.
Every connection gets an associated token bucket. Processing an
address in an ADDR or ADDRV2 message from non-whitelisted peers
consumes a token from the bucket. If the bucket is empty, the
address is ignored (it is not forwarded or processed). The token
counter increases at a rate of 0.1 tokens per second, and will
accrue up to a maximum of 1000 tokens (the maximum we accept in a
single ADDR or ADDRV2). When a GETADDR is sent to a peer, it
immediately gets 1000 additional tokens, as we actively desire many
addresses from such peers (this may temporarily cause the token
count to exceed 1000).

The rate limit of 0.1 addr/s was chosen based on observation of
honest nodes on the network. Activity in general from most nodes
is either 0, or up to a maximum around 0.025 addr/s for recent
Bitcoin Core nodes. A few (self-identified, through subver) crawler
nodes occasionally exceed 0.1 addr/s.
2021-07-15 12:52:38 -07:00
Dhruv Mehta
ac82b99db7 [p2p] remove redundant NODE_WITNESS checks
nLocalServices defaults to NODE_WITNESS and these checks are obsolete
2021-07-07 22:13:01 -07:00
Anthony Towns
2b0d291da8 [refactor] Add deploymentstatus.h
Provides DeploymentEnabled, DeploymentActiveAt, and DeploymentActiveAfter
helpers for checking the status of buried deployments. Can be overloaded
so the same syntax works for non-buried deployments, allowing future
soft forks to be changed from signalled to buried deployments without
having to touch the implementation code.

Replaces IsWitnessEnabled and IsScriptWitnessEnabled.
2021-06-29 17:11:12 +10:00
fanquake
8071ec179d
Merge bitcoin/bitcoin#21789: refactor: Remove ::Params() global from CChainState
fa0d9211ef refactor: Remove chainparams arg from CChainState member functions (MarcoFalke)
fa38947125 refactor: Remove ::Params() global from inside CChainState member functions (MarcoFalke)

Pull request description:

  The `::Params()` global is verbose and confusing. Also it makes tests a bit harder to write because they'd have to mock a global.

  Fix all issues by simply using a member variable that points to the right params.

  (Can be reviewed with `--word-diff-regex=.`)

ACKs for top commit:
  jnewbery:
    ACK fa0d9211ef
  kiminuo:
    utACK fa0d9211
  theStack:
    ACK fa0d9211ef 🍉

Tree-SHA512: 44676b19c9ed471ccb536331d3029bad192d7d50f394fd7b8527ec431452aeec8c4494164b9cf8e16e0123c4463b16be864366c6b599370032c17262625a0356
2021-06-29 11:22:57 +08:00
Jon Atack
184d4534f6
script, doc: spelling update 2021-06-23 13:33:18 +02:00
W. J. van der Laan
f6a25bea82
Merge bitcoin/bitcoin#22147: p2p: Protect last outbound HB compact block peer
30aee2dfe6 tests: Add test for compact block HB selection (Pieter Wuille)
6efbcec4de Protect last outbound HB compact block peer (Suhas Daftuar)

Pull request description:

  If all our high-bandwidth compact block serving peers (BIP 152) stall block
  download, then we can be denied a block for (potentially) a long time. As
  inbound connections are much more likely to be adversarial than outbound
  connections, mitigate this risk by never removing our last outbound HB peer if
  it would be replaced by an inbound.

ACKs for top commit:
  achow101:
    ACK 30aee2dfe6
  ariard:
    Code ACK 30aee2dfe
  jonatack:
    ACK 30aee2dfe6

Tree-SHA512: 5c6c9326e3667b97e0864c371ae2174d2be9054dad479f4366127b9cd3ac60ffa01ec9707b16ef29cac122db6916cf56fd9985733390017134ace483278921d5
2021-06-21 08:18:55 +02:00
Martin Zumsande
533500d907 p2p: Add timeout for AddrFetch peers
If AddrFetch peers don't send us addresses, disconnect them after
a while.
2021-06-17 22:00:07 +02:00
MarcoFalke
fa0d9211ef
refactor: Remove chainparams arg from CChainState member functions
Passing this is confusing and redundant with the m_params member.
2021-06-13 09:43:54 +02:00
fanquake
96f828ba4d
Merge bitcoin/bitcoin#22221: refactor: Pass block reference instead of pointer to PeerManagerImpl::BlockRequested
fa334b4054 refactor: Pass block reference instead of pointer to PeerManagerImpl::BlockRequested (MarcoFalke)

Pull request description:

  This allows to remove an assert and at the same time make it more obvious that the block is never nullptr.

  Also, add missing `{}` while touching the function.

ACKs for top commit:
  jnewbery:
    Code review ACK fa334b4054
  mjdietzx:
    crACK fa334b4054
  theStack:
    Code review ACK fa334b4054

Tree-SHA512: 9733d3e20e048fcb2ac7510eae3539ce8aaa7397bd944a265123f1ffd90e15637cdaad19dba16f76d83f3f0d1888f1b7014c191bb430e410a106c49ca61a725c
2021-06-12 15:54:38 +08:00
MarcoFalke
fa334b4054
refactor: Pass block reference instead of pointer to PeerManagerImpl::BlockRequested 2021-06-11 09:56:16 +02:00
Carl Dong
6c3b5dc0c1 scripted-diff: tree-wide: Remove all review-only assertions
-BEGIN VERIFY SCRIPT-
find_regex='((assert|CHECK_NONFATAL)\(std::addressof|TODO: REVIEW-ONLY)' \
    && git grep -l -E "$find_regex" -- . \
        | xargs sed -i -E "/${find_regex}/d"
-END VERIFY SCRIPT-
2021-06-10 15:05:24 -04:00
Suhas Daftuar
6efbcec4de Protect last outbound HB compact block peer
If all our high-bandwidth compact block serving peers (BIP 152) stall block
download, then we can be denied a block for (potentially) a long time. As
inbound connections are much more likely to be adversarial than outbound
connections, mitigate this risk by never removing our last outbound HB peer if
it would be replaced by an inbound.
2021-06-03 17:15:25 -04:00
John Newbery
2f4ad6b7ef scripted-diff: rename MarkBlockAs functions
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren  MarkBlockAsInFlight BlockRequested
ren  MarkBlockAsReceived RemoveBlockRequest
-END VERIFY SCRIPT-
2021-06-03 14:57:37 +01:00
John Newbery
2c45f832e8 [net processing] Tidy up MarkBlockAsReceived() 2021-06-03 14:57:37 +01:00
John Newbery
6299350733 [net processing] Add IsBlockRequested() function
MarkBlockAsReceived() should not be used for both removing the block
from mapBlocksInFlight and checking whether it was in the map.
2021-06-03 14:57:26 +01:00
John Newbery
4e90d2dd0e [net processing] Remove QueuedBlock.hash
It's redundant with CBlockIndex::GetBlockHash()
2021-06-03 12:57:43 +01:00
John Newbery
156a19ee6a scripted-diff: rename nPeersWithValidatedDownloads
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren nPeersWithValidatedDownloads  m_peers_downloading_from
-END VERIFY SCRIPT-
2021-06-03 12:49:27 +01:00
John Newbery
b03de9c753 [net processing] Remove CNodeState.nBlocksInFlightValidHeaders
nBlocksInFlightValidHeaders always has the same value as nBlocksInFlight, since we only download
blocks with valid headers.
2021-06-03 12:45:15 +01:00
John Newbery
b4e29f2436 [net processing] Remove QueuedBlock.fValidatedHeaders
Since headers-first syncing, we only ever request a block if we've already validated its headers.
Therefore QueuedBlock.fValidatedHeaders is always set to true. Remove it.
2021-06-03 12:39:56 +01:00
John Newbery
85e058b191 [net processing] Remove unnecessary hash arg from MarkBlockAsInFlight()
MarkBlockAsInFlight is always called with a non-null pindex. Just get the block hash
from that pindex inside the function.
2021-06-03 12:39:55 +01:00
fanquake
e12f287498
net: cleanup newly added PeerManagerImpl::ProcessNewBlock
Addresses some post-merge comments.
2021-05-31 14:36:46 +08:00
Martin Zumsande
b6c5d1e450 p2p: AddrFetch - don't disconnect on self-announcements
Disconnecting an AddrFetch peer only after receiving an addr
message of size >1 prevents dropping them before
they had a chance to answer the getaddr request.
2021-05-28 18:29:05 +02:00
MarcoFalke
aeecb1c2eb
Merge bitcoin/bitcoin#21992: p2p: Remove -feefilter option
a7a43e8fe8 Factor feefilter logic out (amadeuszpawlik)
c0385f10a1 Remove -feefilter option (amadeuszpawlik)

Pull request description:

  net: Remove -feefilter option, as it is debug only and isn't used in any tests. Checking this option for every peer on every iteration of the message handler is unnecessary, as described in #21545.
  refactor: Move feefilter logic out into a separate `MaybeSendFeefilter(...)` function to improve readability of the already long `SendMessages(...)`. fixes  #21545

  The configuration option `-feefilter` has been added in 9e072a6e66: _"Implement "feefilter" P2P message"_
  According to the [BIP133](https://github.com/bitcoin/bips/blob/master/bip-0133.mediawiki), turning the fee filter off was ment for:
  > [...] a node [...] using prioritisetransaction to accept transactions whose actual fee rates might fall below the node's mempool min fee [in order to] disable the fee filter to make sure it is exposed to all possible txid's

  `-feefilter` was subsequently set as debug only in #8150, with the motivation that the help message was too difficult to translate.

ACKs for top commit:
  jnewbery:
    Code review ACK a7a43e8fe8
  promag:
    Code review ACK a7a43e8fe8.
  MarcoFalke:
    review ACK a7a43e8fe8 🦁

Tree-SHA512: 8ef9a2f255597c0279d3047dcc968fd30fb7402e981b69206d08eed452c705ed568c24e646e98d06eac118eddd09205b584f45611d1c874abf38f48b08b67630
2021-05-25 08:42:30 +02:00
amadeuszpawlik
a7a43e8fe8 Factor feefilter logic out
Break SendMessages() function into smaller units to improve readability.
Adds lock assert, as `round()` isn't thread safe.
closes #21545
2021-05-24 14:59:39 +02:00
fanquake
d3fa42c795
Merge bitcoin/bitcoin#21186: net/net processing: Move addr data into net_processing
0829516d1f [refactor] Remove unused ForEachNodeThen() template (John Newbery)
09cc66c00e scripted-diff: rename address relay fields (John Newbery)
76568a3351 [net processing] Move addr relay data and logic into net processing (John Newbery)
caba7ae8a5 [net processing] Make RelayAddress() a member function of PeerManagerImpl (John Newbery)
86acc96469 [net processing] Take NodeId instead of CNode* as originator for RelayAddress() (John Newbery)

Pull request description:

  This continues the work of moving application layer data into net_processing, by moving all addr data into the new Peer object added in #19607.

  For motivation, see #19398.

ACKs for top commit:
  laanwj:
    Code review ACK 0829516d1f
  mzumsande:
    ACK 0829516d1f, reviewed the code and ran tests.
  sipa:
    utACK 0829516d1f
  hebasto:
    re-ACK 0829516d1f

Tree-SHA512: efe0410fac288637f203eb37d1999910791e345872d37e1bd5cde50e25bb3cb1c369ab86b3a166ffd5e06ee72e4508aa2c46d658be6a54e20b4f220d2f57d0a6
2021-05-24 20:28:31 +08:00
amadeuszpawlik
c0385f10a1 Remove -feefilter option
Feefilter option is debug only and it isn't used in any tests, it's wasteful
to check this option for every peer on every iteration of the message handler
loop. refs #21545
2021-05-19 16:55:03 +02:00
Jon Atack
80ba294854
p2p: allow CConnman::GetAddresses() by network, add doxygen 2021-05-19 13:05:54 +02:00
Jon Atack
7075f604e8
scripted-diff: update noban documentation in net_processing.cpp
-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src/net_processing.cpp | xargs sed -i "s/$1/$2/g"; }
s 'the noban permission'      'NetPermissionFlags::NoBan permission'
s 'the NOBAN permission flag' 'NetPermissionFlags::NoBan permission'
s 'noban permission'          'NetPermissionFlags::NoBan permission'
-END VERIFY SCRIPT-
2021-05-12 16:13:32 +02:00
Jon Atack
a95540cf43
scripted-diff: rename NetPermissionFlags enumerators
- drop redundant PF_ permission flags prefixes
- drop ALL_CAPS naming per https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-caps
- rename IsImplicit to Implicit

-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; }

s 'PF_NONE'        'None'
s 'PF_BLOOMFILTER' 'BloomFilter'
s 'PF_RELAY'       'Relay'
s 'PF_FORCERELAY'  'ForceRelay'
s 'PF_DOWNLOAD'    'Download'
s 'PF_NOBAN'       'NoBan'
s 'PF_MEMPOOL'     'Mempool'
s 'PF_ADDR'        'Addr'
s 'PF_ISIMPLICIT'  'Implicit'
s 'PF_ALL'         'All'
-END VERIFY SCRIPT-
2021-05-12 16:13:30 +02:00
Jon Atack
91f6e6e6d1
scripted-diff: add NetPermissionFlags scopes where not already present
-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" -- 'src' ':!src/net_permissions.h' | xargs sed -i -E "s/([^:])$1/\1NetPermissionFlags::$1/"; }

s 'PF_NONE'
s 'PF_BLOOMFILTER'
s 'PF_RELAY'
s 'PF_FORCERELAY'
s 'PF_DOWNLOAD'
s 'PF_NOBAN'
s 'PF_MEMPOOL'
s 'PF_ADDR'
s 'PF_ISIMPLICIT'
s 'PF_ALL'
-END VERIFY SCRIPT-

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2021-05-12 10:50:58 +02:00
John Newbery
39e19713cd [net processing] Add internal _RelayTransactions()
Callers of the external RelayTransactions() no longer need to lock cs_main.
2021-05-04 09:31:03 +01:00
John Newbery
09cc66c00e scripted-diff: rename address relay fields
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren fGetAddr     m_getaddr_sent
ren fSentAddr    m_getaddr_recvd
ren vAddrToSend  m_addrs_to_send
-END VERIFY SCRIPT-
2021-04-30 11:29:16 +01:00
John Newbery
76568a3351 [net processing] Move addr relay data and logic into net processing 2021-04-30 11:29:14 +01:00
MarcoFalke
fac96d0265
p2p: Limit m_block_inv_mutex 2021-04-25 20:39:59 +02:00
MarcoFalke
2bce9329e8
Merge bitcoin/bitcoin#21719: refactor: Add and use EnsureConnman in rpc code
fafb68add5 refactor: Add and use EnsureConnman in rpc code (MarcoFalke)
faabeb854a refactor: Mark member functions const (MarcoFalke)

Pull request description:

  This removes the 10 occurrences of `throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");` and replaces them with `EnsureConnman`.

ACKs for top commit:
  jarolrod:
    re-ACK fafb68add5
  theStack:
    ACK fafb68add5
  ryanofsky:
    Code review ACK fafb68add5

Tree-SHA512: 84c63cfe31e548645d906f7191a3526c7bea99ed0d54c2a75c2041452a44fe149ede343d8e1943b0e7770816c828bb047dfec8bc541a1f2b89920a126ee54d68
2021-04-21 07:23:34 +02:00
Sebastian Falbesoner
f2f2541ee7 remove executable flag for src/net_processing.cpp 2021-04-19 09:47:34 +02:00
MarcoFalke
faabeb854a
refactor: Mark member functions const 2021-04-17 20:13:34 +02:00
R E Broadley
9a0653553a Refactor ProcessNewBlock to reduce code duplication 2021-04-17 09:55:19 +01:00
fanquake
1f14130cb0
Merge #21575: refactor: Create blockstorage module
fadcd3f78e doc: Remove irrelevant link to GitHub (MarcoFalke)
fa121b628d blockstorage: [refactor] Use chainman reference where possible (MarcoFalke)
fa0c7d9ad2 move-only: Move *Disk functions to blockstorage (MarcoFalke)
fa91b2b2b3 move-only: Move AbortNode to shutdown (MarcoFalke)
fa413f07a1 move-only: Move ThreadImport to blockstorage (MarcoFalke)
faf843c07f refactor: Move load block thread into ChainstateManager (MarcoFalke)

Pull request description:

  This picks up the closed pull request #21030 and is the first step toward fixing #21220.

  The basic idea is to move all disk access into a separate module with benefits:
  * Breaking down the massive files init.cpp and validation.cpp into logical units
  * Creating a standalone-module to reduce the mental complexity
  * Pave the way to fix validation related circular dependencies
  * Pave the way to mock disk access for testing, especially where it is performance critical (like fuzzing)

ACKs for top commit:
  promag:
    Code review ACK fadcd3f78e, checked (almost) moved only changes. This is a nice tidy up change and doesn't change behavior. Easily reviewed commit by commit.
  jamesob:
    ACK fadcd3f78e ([`jamesob/ackr/21575.1.MarcoFalke.refactor_create_blocksto`](https://github.com/jamesob/bitcoin/tree/ackr/21575.1.MarcoFalke.refactor_create_blocksto))
  ryanofsky:
    Code review ACK fadcd3f78e. New organization makes sense, moves extraneous things outside of validation.cpp. PR is also easy to review with helpfully split up moveonly commits.

Tree-SHA512: 917996592b6d8f9998289d8cb2b1b78b23d1fdb3b07216c9caec1380df33baa09dc2c1e706da669d440b497e79c9c62a01ca20dc202df5ad974a75f3ef7a143b
2021-04-13 22:00:28 +08:00
fanquake
3b0078f958
doc: fixup -Wdocumentation issues 2021-04-06 14:50:17 +08:00
MarcoFalke
fa0c7d9ad2
move-only: Move *Disk functions to blockstorage
Can be reviewed with the git options
--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
2021-04-05 20:26:14 +02:00
MarcoFalke
fa5eabe721
refactor: Remove negative lock annotations from globals 2021-04-05 08:42:15 +02:00
W. J. van der Laan
086226d98a
Merge #21198: net: Address outstanding review comments from PR20721
5ed535a02f [net] Changes to RunInactivityChecks (John Newbery)

Pull request description:

  Updates the RunInactivityChecks() function:

  - rename to ShouldRunInactivityChecks (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r576394790)
  - take optional time now (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575895661)
  - call from within InactivityChecks (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575894665)
  - update comment (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575894343)
  - change ordering of inequality (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r574925129)
  - ~make inline (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r574903578)~

ACKs for top commit:
  laanwj:
    Code review ACK 5ed535a02f

Tree-SHA512: e6ac8e8cce5cddc84a52a40c908634c25f58be74512d642840d7bd7fa65c3d90a0f46cc19e4865b3fae7c933138247f58356167a60a5c519305cfd6d05e51f51
2021-04-01 16:36:22 +02:00
John Newbery
5ed535a02f [net] Changes to RunInactivityChecks
- rename to ShouldRunInactivityChecks (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r576394790)
- take optional time now (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575895661)
- call from within InactivityChecks (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575894665)
- update comment (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r575894343)
- change ordering of inequality (https://github.com/bitcoin/bitcoin/pull/20721#discussion_r574925129)
2021-04-01 11:35:27 +01:00
MarcoFalke
80a699fda9
Merge #21525: [Bundle 4.5/n] Followup fixups to bundle 4
693414d271 node/ifaces: ChainImpl: Use an accessor for ChainMan (Carl Dong)
98c4e252f0 node/ifaces: NodeImpl: Use an accessor for ChainMan (Carl Dong)
7e8b5ee814 validation: Make BlockManager::LookupBlockIndex const (Carl Dong)
88aead263c node: Avoid potential UB by asserting assumptions (Carl Dong)
1dd8ed7a84 net_processing: Move comments to declarations (Carl Dong)
07156eb387 node/coinstats: Replace #include with fwd-declaration (Carl Dong)
7b8e976cd5 miner: Add chainstate member to BlockAssembler (Carl Dong)
e62067e7bc Revert "miner: Pass in chainstate to BlockAssembler::CreateNewBlock" (Carl Dong)
eede0647b0 Revert "scripted-diff: Invoke CreateNewBlock with chainstate" (Carl Dong)
0c1b2bc549 Revert "miner: Remove old CreateNewBlock w/o chainstate param" (Carl Dong)

Pull request description:

  Chronological history of this changeset:
  1. Bundle 4 (#21270) got merged
  2. Posthumous reviews were posted
  3. These changes were prepended in bundle 5
  4. More reviews were added in bundle 5
  5. Someone suggested that we split the prepended changes up to another PR
  6. This is that PR

  In the future, I will just do posthumous review changes in another PR instead. I apologize for the confusion.

  Addresses posthumous reviews on bundle 4:
    - From jnewbery:
      - https://github.com/bitcoin/bitcoin/pull/21270#issuecomment-796738048
        - I didn't fix this one, but I added a `TODO` comment so that we don't lost track of it
      - https://github.com/bitcoin/bitcoin/pull/21270#discussion_r592291225
      - https://github.com/bitcoin/bitcoin/pull/21270#discussion_r592296942
      - https://github.com/bitcoin/bitcoin/pull/21270#discussion_r592299738
      - https://github.com/bitcoin/bitcoin/pull/21270#discussion_r592301704
    - From MarcoFalke:
      - https://github.com/bitcoin/bitcoin/pull/21270#discussion_r593096212
      - https://github.com/bitcoin/bitcoin/pull/21270#discussion_r593097032
      - https://github.com/bitcoin/bitcoin/pull/21270#discussion_r593097867
      - https://github.com/bitcoin/bitcoin/pull/21270#discussion_r593100570

  Addresses reviews on bundle 5:
  - Checking chainman existence before locking cs_main
    - MarcoFalke
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r596601776
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r596601876
  - Appropriate locking, usage of chainman, and control flow in `src/node/interfaces.cpp`
    - MarcoFalke
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r596601383
    - jnewbery
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r597029360
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r597029921
    - ryanofsky
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r597163828
  - Style/comment formatting changes
    - jnewbery
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r597026552
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r597027186
  - Making LookupBlockIndex const
    - jnewbery
      - https://github.com/bitcoin/bitcoin/pull/21391#discussion_r597035062

ACKs for top commit:
  MarcoFalke:
    review ACK 693414d271 🛐
  ryanofsky:
    Code review ACK 693414d271. I reviewed this previously as part of #21391. I am a fan of the increasingly complicated bundle numbering, and kind of hope there in the next round there is some way we can get bundles 5.333333 and 5.666667!
  jamesob:
    ACK 693414d271 ([`jamesob/ackr/21525.1.dongcarl.bundle_4_5_n_followup_f`](https://github.com/jamesob/bitcoin/tree/ackr/21525.1.dongcarl.bundle_4_5_n_followup_f))

Tree-SHA512: 9bdc199f70400d01764e1bd03c25bdb6cff26dcef60e4ca3b649baf8d017a2dfc1f058099067962b4b6ccd32d078002b1389d733039f4c337558cb70324c0ee3
2021-04-01 10:58:53 +02:00
John Newbery
caba7ae8a5 [net processing] Make RelayAddress() a member function of PeerManagerImpl 2021-04-01 08:08:11 +01:00
John Newbery
86acc96469 [net processing] Take NodeId instead of CNode* as originator for RelayAddress()
This makes the following commit easier.
2021-04-01 08:08:11 +01:00
MarcoFalke
539e4eec63
Merge #21236: net processing: Extract addr send functionality into MaybeSendAddr()
935d488922 [net processing] Refactor MaybeSendAddr() (John Newbery)
01a79ff924 [net processing] Fix overindentation in MaybeSendAddr() (John Newbery)
38c0be5da3 [net processing] Refactor MaybeSendAddr() - early exits (John Newbery)
c87423c58b [net processing] Change MaybeSendAddr() to take a reference (John Newbery)
ad719297f2 [net processing] Extract `addr` send functionality into MaybeSendAddr() (John Newbery)
4ad4abcf07 [net] Change addr send times fields to be guarded by new mutex (John Newbery)
c02fa47baa [net processing] Only call GetTime() once in SendMessages() (John Newbery)

Pull request description:

  This continues the work of moving application layer data into net_processing. It refactors `addr` send functionality into its own function `MaybeSendAddr()` and flattens/simplifies the code. Isolating and simplifying the addr handling code makes subsequent changes (which will move addr data and logic into net processing) easier to review.

  This is a pure refactor. There are no functional changes.

  For motivation of the project, see #19398.

ACKs for top commit:
  sipa:
    utACK 935d488922
  hebasto:
    ACK 935d488922, I have reviewed the code and it looks OK, I agree it can be merged.
  MarcoFalke:
    review ACK 935d488922 🐑

Tree-SHA512: 4e9dc84603147e74f479a211b42bcf315bdf5d14c21c08cf0b17d6c252775b90b012f0e0d834f1a607ed63c7ed5c63d5cf49b134344e7b64a1695bfcff111c92
2021-04-01 08:29:53 +02:00
John Newbery
935d488922 [net processing] Refactor MaybeSendAddr()
Changes to make MaybeSendAddr simpler and easier to maintain/update:

- assert invariant that node.vAddrToSend.size() can never exceed
  MAX_ADDR_TO_SEND
- erase known addresses from vAddrToSend in one pass
- no check for (vAddr.size() >= MAX_ADDR_TO_SEND) during iteration,
  since vAddr can never exceed MAX_ADDR_TO_SEND.
2021-03-31 18:06:51 +01:00
Carl Dong
1dd8ed7a84 net_processing: Move comments to declarations
Also:
- Remove extraneous blank line
2021-03-30 13:52:22 -04:00
MarcoFalke
1999baac30
Merge #20228: addrman: Make addrman a top-level component
3fc06d3d7b [net] remove fUpdateConnectionTime from FinalizeNode (John Newbery)
7c4cc67c0c [net] remove CConnman::AddNewAddresses (John Newbery)
bcd7f30b79 [net] remove CConnman::MarkAddressGood (John Newbery)
8073673dbc [net] remove CConnman::SetServices (John Newbery)
392a95d393 [net_processing] Keep addrman reference in PeerManager (John Newbery)
1c25adf6d2 [net] Construct addrman outside connman (John Newbery)

Pull request description:

  Addrman is currently a member variable of connman. Make it a top-level component with lifetime owned by node.context, and add a reference to addrman in peerman. This allows us to eliminate some functions in connman that are simply forwarding requests to addrman, and simplifies the connman-peerman interface.

  By constructing the addrman in init, we can also add parameters to the ctor, which allows us to test it better. See #20233, where we enable consistency checking for addrman in our functional tests.

ACKs for top commit:
  MarcoFalke:
    re-ACK 3fc06d3d7b only change is squash 🏀
  vasild:
    ACK 3fc06d3d7b

Tree-SHA512: 17662c65cbedcd9bd1c194914bc4bb4216f4e3581a06222de78f026d6796f1da6fe3e0bf28c2d26a102a12ad4fbf13f815944a297f000e3acf46faea42855e07
2021-03-30 12:28:15 +02:00
John Newbery
01a79ff924 [net processing] Fix overindentation in MaybeSendAddr()
Reviewer hint: review with `git diff --ignore-all-space`.
2021-03-29 12:15:23 +01:00
John Newbery
38c0be5da3 [net processing] Refactor MaybeSendAddr() - early exits
Add early exit guard clauses if node.RelayAddrsWithConn() is false or if
current_time < node.m_next_addr_send. Add comments.

This commit leaves some lines over-indented. Those will be fixed in a
subsequent whitespace-only commit.
2021-03-29 12:15:23 +01:00