Commit graph

135 commits

Author SHA1 Message Date
Anthony Towns
1e78f566d5 net: add NetEventsInterface::g_msgproc_mutex
There are many cases where we assume message processing is
single-threaded in order for how we access node-related memory to be
safe. Add an explicit mutex that we can use to document this, which allows
the compiler to catch any cases where we try to access that memory from
other threads and break that assumption.
2022-09-15 14:44:38 +10:00
Suhas Daftuar
03712dddfb Expose HeadersSyncState::m_current_height in getpeerinfo() 2022-08-29 08:10:35 -04:00
John Newbery
d9079fe18d [net processing] Remove CNode::nServices
Use Peer::m_their_services instead
2022-07-14 14:50:44 +02:00
MacroFake
fa8aa0aa81
Pass Peer& to Misbehaving()
`Misbehaving` has several coding related issues (ignoring the conceptual
issues here for now):
* It is public, but it is not supposed to be called from outside of
  net_processing. Fix that by making it private and creating a public
  `UnitTestMisbehaving` method for unit testing only.
* It doesn't do anything if a `nullptr` is passed. It would be less
  confusing to just skip the call instead. Fix that by passing `Peer&`
  to `Misbehaving()`.
* It calls `GetPeerRef`, causing `!m_peer_mutex` lock annotations to be
  propagated. This is harmless, but verbose. Fix it by removing the no
  longer needed call to `GetPeerRef` and the no longer needed lock
  annotations.
2022-05-27 16:59:45 +02:00
MacroFake
fa30234be8
Do not pass CChainParams& to PeerManager::make 2022-05-18 18:46:27 +02:00
dergoegge
a292df283a [net processing] Move mapNodeState into PeerManagerImpl 2022-04-20 13:33:07 +02:00
John Newbery
1066d10f71 scripted-diff: rename TxRelay members
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren cs_filter             m_bloom_filter_mutex
ren fRelayTxes            m_relay_txs
ren pfilter               m_bloom_filter
ren cs_tx_inventory       m_tx_inventory_mutex
ren filterInventoryKnown  m_tx_inventory_known_filter
ren setInventoryTxToSend  m_tx_inventory_to_send
ren fSendMempool          m_send_mempool
ren nNextInvSend          m_next_inv_send_time
ren minFeeFilter          m_fee_filter_received
ren lastSentFeeFilter     m_fee_filter_sent
-END VERIFY SCRIPT-
2022-03-18 11:35:58 +00:00
John Newbery
575bbd0dea [net processing] Move tx relay data to Peer 2022-03-18 11:35:56 +00: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
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
0e3d7c5ee1
refactor: drop redundant hash argument from FetchBlock 2021-12-24 16:28:53 +01:00
Sjors Provoost
dce8c4c381
rpc: getblockfrompeer
Co-authored-by: John Newbery <john@johnnewbery.com>
2021-12-02 13:16:18 +07: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
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
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
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
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
MarcoFalke
faabeb854a
refactor: Mark member functions const 2021-04-17 20:13:34 +02:00
John Newbery
392a95d393 [net_processing] Keep addrman reference in PeerManager 2021-03-20 10:24:40 +00:00
fanquake
e057e01b7b
Merge #21162: Net Processing: Move RelayTransaction() into PeerManager
680eb56d82 [net processing] Don't pass CConnman to RelayTransactions (John Newbery)
a38a4e8f03 [net processing] Move RelayTransaction into PeerManager (John Newbery)

Pull request description:

  This is the first part of #21160. It moves the RelayTransaction() function to be a member function of the PeerManager class. This is required in order to move the transaction inventory data into the Peer object, since Peer objects are only accessible from within PeerManager.

ACKs for top commit:
  ajtowns:
    ACK 680eb56d82

Tree-SHA512: 8c93491a4392b6369bb7f090de326a63cd62a088de59026e202f226f64ded50a0cf1a95ed703328860f02a9d2f64d3a87ca1bca9a6075b978bd111d384766235
2021-03-18 14:57:50 +08:00
fanquake
33921379b6
Merge #21015: Make all of net_processing (and some of net) use std::chrono types
0eaea66e8b Make tx relay data structure use std::chrono types (Pieter Wuille)
55e82881a1 Make all Poisson delays use std::chrono types (Pieter Wuille)
c733ac4d8a Convert block/header sync timeouts to std::chrono types (Pieter Wuille)
4d98b401fb Change all ping times to std::chrono types (Pieter Wuille)

Pull request description:

  (Picking up #20044. Rebased against master.)

  This changes various uses of integers to represent timestamps and durations to `std::chrono` duration types with type-safe conversions, getting rid of various `.count()`, constructors, and conversion factors.

ACKs for top commit:
  jnewbery:
    utACK 0eaea66e8b
  vasild:
    ACK 0eaea66e8b
  MarcoFalke:
    re-ACK 0eaea66e8b, only changes: minor rename, using C++11 member initializer, using 2min chrono literal, rebase 🤚
  ajtowns:
    utACK 0eaea66e8b

Tree-SHA512: 2dbd8d53bf82e98f9b4611e61dc14c448e8957d1a02575b837fadfd59f80e98614d0ccf890fc351f960ade76a6fb8051b282e252e81675a8ee753dba8b1d7f57
2021-03-04 20:13:43 +08:00
John Newbery
680eb56d82 [net processing] Don't pass CConnman to RelayTransactions
Use the local m_connman instead
2021-03-04 10:22:57 +00:00
John Newbery
a38a4e8f03 [net processing] Move RelayTransaction into PeerManager
We don't mark RelayTransaction as const. Even though it doesn't mutate
PeerManagerImpl state, it _is_ mutating the internal state of a CNode
object, by updating setInventoryTxToSend. In a subsequent commit, that
field will be moved to the Peer object, which is owned by
PeerMangerImpl.

This requires PeerManagerImpl::ReattemptInitialBroadcast() to no longer
be const.
2021-03-04 10:22:42 +00:00
Pieter Wuille
4d98b401fb Change all ping times to std::chrono types 2021-03-03 09:48:07 -08:00
Anthony Towns
9d5313df7e move-only: Add txorphanage module
This module captures orphan tracking code for tx relay.

Can be reviewed with --color-moved=dimmed-zebra
2021-02-26 23:55:03 +10:00
John Newbery
45dcf22661 [net processing] Move ping data fields to net processing 2021-02-15 16:15:51 +00:00
Anthony Towns
c97f70c861 net_processing: move Peer definition to .cpp 2021-01-09 23:27:45 +10:00
Anthony Towns
e0f2e6d2df net_processing: move PeerManagerImpl into cpp file 2021-01-09 23:27:45 +10:00
Anthony Towns
a568b82feb net_processing: split PeerManager into interface and implementation classes 2021-01-09 23:27:45 +10:00
Anthony Towns
0df3d3fd6b net_processing: make more of PeerManager private 2021-01-09 23:27:45 +10:00
Anthony Towns
0d246a59b6 net, net_processing: move NetEventsInterface method docs to net.h 2021-01-09 23:27:45 +10:00
Ikko Ashimine
1112035d32
doc: fix various typos
Co-authored-by: Peter Yordanov <ppyordanov@yahoo.com>
2021-01-04 12:31:31 +08:00
MarcoFalke
faaa4f2b6a
refactor: Remove nMyStartingHeight from CNode/Connman 2021-01-02 10:24:45 +01:00
Amiti Uttarwar
094c3beaa4 [rpc] Remove deprecated "banscore" field from getpeerinfo 2020-12-26 13:30:08 -08:00
John Newbery
3002b4af2b [net processing] Guard m_continuation_block with m_block_inv_mutex 2020-12-20 10:06:14 +00:00
John Newbery
184557e8e0 [net processing] Move hashContinue to net processing
Also rename to m_continuation_block to better communicate meaning.
2020-12-20 10:03:38 +00:00
John Newbery
c853ef002e scripted-diff: rename vBlockHashesToAnnounce and vInventoryBlockToSend
-BEGIN VERIFY SCRIPT-
sed -i 's/vBlockHashesToAnnounce/m_blocks_for_headers_relay/g' src/net_processing.*
sed -i 's/vInventoryBlockToSend/m_blocks_for_inv_relay/g' src/net_processing.*
-END VERIFY SCRIPT-
2020-12-20 10:01:48 +00:00
John Newbery
53b7ac1b7d [net processing] Move block inventory data to Peer 2020-12-20 10:01:48 +00:00
John Newbery
78040f9168 [net processing] Rename nStartingHeight to m_starting_height
Not done as a scripted diff to avoid misnaming the local variable in
ProcessMessage().
2020-12-20 10:01:46 +00:00
John Newbery
77a2c2f8f9 [net processing] Move nStartingHeight to Peer 2020-12-20 10:01:26 +00:00
John Newbery
717a374e74 [net processing] Improve documentation for Peer destruction/locking
Suggested here:

- https://github.com/bitcoin/bitcoin/pull/19607#discussion_r467071878
- https://github.com/bitcoin/bitcoin/pull/19829#discussion_r546116786
2020-12-19 14:49:03 +00:00
Suhas Daftuar
daffaf03fb Periodically make block-relay connections and sync headers
To make eclipse attacks more difficult, regularly initiate outbound connections
and stay connected long enough to sync headers and potentially learn of new
blocks. If we learn a new block, rotate out an existing block-relay peer in
favor of the new peer.

This augments the existing outbound peer rotation that exists -- currently we
make new full-relay connections when our tip is stale, which we disconnect
after waiting a small time to see if we learn a new block.  As block-relay
connections use minimal bandwidth, we can make these connections regularly and
not just when our tip is stale.

Like feeler connections, these connections are not aggressive; whenever our
timer fires (once every 5 minutes on average), we'll try to initiate a new
block-relay connection as described, but if we fail to connect we just wait for
our timer to fire again before repeating with a new peer.
2020-12-10 08:46:39 -05:00
John Newbery
68334b3944 [net processing] Add m_ignores_incoming_txs to PeerManager and use internally 2020-12-09 18:13:37 +00:00
John Newbery
f3f61d0eb9 [net processing] Add IgnoresIncomingTxs() function to PeerManager 2020-12-09 18:10:38 +00:00
John Newbery
5805b8299f [net processing] Move PushNodeVersion into PeerManager 2020-12-09 18:09:42 +00:00
John Newbery
3025ca9e77 [net processing] Add RemovePeer()
This allows us to avoid repeated locking in FinalizeNode()
2020-12-07 11:59:24 +00:00
John Newbery
a20ab22786 [net processing] Make GetPeerRef const 2020-12-07 11:57:12 +00:00