Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# User-space, Statically Defined Tracing (USDT) for Bitcoin Core3Bitcoin Core includes statically defined tracepoints to allow for more4observability during development, debugging, code review, and production usage.5These tracepoints make it possible to keep track of custom statistics and6enable detailed monitoring of otherwise hidden internals. They have7little to no performance impact when unused.9```10eBPF and USDT Overview11======================13┌──────────────────┐ ┌──────────────┐14│ tracing script │ │ bitcoind │15│==================│ 2. │==============│16│ eBPF │ tracing │ hooks │ │17│ code │ logic │ into┌─┤►tracepoint 1─┼───┐ 3.18└────┬───┴──▲──────┘ ├─┤►tracepoint 2 │ │ pass args191. │ │ 4. │ │ ... │ │ to eBPF20User compiles │ │ pass data to │ └──────────────┘ │ program21Space & loads │ │ tracing script │ │22─────────────────┼──────┼─────────────────┼────────────────────┼───23Kernel │ │ │ │24Space ┌──┬─▼──────┴─────────────────┴────────────┐ │25│ │ eBPF program │◄──────┘26│ └───────────────────────────────────────┤27│ eBPF kernel Virtual Machine (sandboxed) │28└──────────────────────────────────────────┘301. The tracing script compiles the eBPF code and loads the eBPF program into a kernel VM312. The eBPF program hooks into one or more tracepoints323. When the tracepoint is called, the arguments are passed to the eBPF program334. The eBPF program processes the arguments and returns data to the tracing script34```36The Linux kernel can hook into the tracepoints during runtime and pass data to37sandboxed [eBPF] programs running in the kernel. These eBPF programs can, for38example, collect statistics or pass data back to user-space scripts for further39processing.41[eBPF]: https://ebpf.io/43The two main eBPF front-ends with support for USDT are [bpftrace] and44[BPF Compiler Collection (BCC)]. BCC is used for complex tools and daemons and45`bpftrace` is preferred for one-liners and shorter scripts. Examples for both can46be found in [contrib/tracing].48[bpftrace]: https://github.com/bpftrace/bpftrace49[BPF Compiler Collection (BCC)]: https://github.com/iovisor/bcc50[contrib/tracing]: ../contrib/tracing/52## Tracepoint documentation54The currently available tracepoints are listed here.56### Context `net`58[^address-length]: An Onion v3 address with a `:` and a five digit port has 6859chars. However, addresses of peers added with host names might be longer.61#### Tracepoint `net:inbound_message`63Is called when a message is received from a peer over the P2P network. Passes64information about our peer, the connection and the message as arguments.66Arguments passed:671. Peer ID as `int64`682. Peer Address and Port (IPv4, IPv6, Tor v3, I2P, ...) as `pointer to C-style String` (normally up to 68 characters[^address-length])693. Connection Type (inbound, feeler, outbound-full-relay, ...) as `pointer to C-style String` (max. length 20 characters)704. Message Type (inv, ping, getdata, addrv2, ...) as `pointer to C-style String` (max. length 20 characters)715. Message Size in bytes as `uint64`726. Message Bytes as `pointer to unsigned chars` (i.e. bytes)74Note: The message is passed to the tracepoint in full, however, due to space75limitations in the eBPF kernel VM it might not be possible to pass the message76to user-space in full. Messages longer than 32kb might be cut off. This can77be detected in tracing scripts by comparing the message size to the length of78the passed message.80#### Tracepoint `net:outbound_message`82Is called when a message is sent to a peer over the P2P network. Passes83information about our peer, the connection and the message as arguments.85Arguments passed:861. Peer ID as `int64`872. Peer Address and Port (IPv4, IPv6, Tor v3, I2P, ...) as `pointer to C-style String` (normally up to 68 characters[^address-length])883. Connection Type (inbound, feeler, outbound-full-relay, ...) as `pointer to C-style String` (max. length 20 characters)894. Message Type (inv, ping, getdata, addrv2, ...) as `pointer to C-style String` (max. length 20 characters)905. Message Size in bytes as `uint64`916. Message Bytes as `pointer to unsigned chars` (i.e. bytes)93Note: The message is passed to the tracepoint in full, however, due to space94limitations in the eBPF kernel VM it might not be possible to pass the message95to user-space in full. Messages longer than 32kb might be cut off. This can96be detected in tracing scripts by comparing the message size to the length of97the passed message.99#### Tracepoint `net:inbound_connection`101Is called when a new inbound connection is opened to us. Passes information about102the peer and the number of inbound connections including the newly opened connection.104Arguments passed:1051. Peer ID as `int64`1062. Peer address and port (IPv4, IPv6, Tor v3, I2P, ...) as `pointer to C-style String` (normally up to 68 characters[^address-length])1073. Connection Type (inbound, feeler, outbound-full-relay, ...) as `pointer to C-style String` (max. length 20 characters)1084. Network the peer connects from as `uint32` (1 = IPv4, 2 = IPv6, 3 = Onion, 4 = I2P, 5 = CJDNS). See `Network` enum in `netaddress.h`.1095. Number of existing inbound connections as `uint64` including the newly opened inbound connection.111#### Tracepoint `net:outbound_connection`113Is called when a new outbound connection is opened by us. Passes information about114the peer and the number of outbound connections including the newly opened connection.116Arguments passed:1171. Peer ID as `int64`1182. Peer address and port (IPv4, IPv6, Tor v3, I2P, ...) as `pointer to C-style String` (normally up to 68 characters[^address-length])1193. Connection Type (inbound, feeler, outbound-full-relay, ...) as `pointer to C-style String` (max. length 20 characters)1204. Network of the peer as `uint32` (1 = IPv4, 2 = IPv6, 3 = Onion, 4 = I2P, 5 = CJDNS). See `Network` enum in `netaddress.h`.1215. Number of existing outbound connections as `uint64` including the newly opened outbound connection.123#### Tracepoint `net:evicted_inbound_connection`125Is called when an inbound connection is evicted by us. Passes information about the evicted peer and the time at connection establishment.127Arguments passed:1281. Peer ID as `int64`1292. Peer address and port (IPv4, IPv6, Tor v3, I2P, ...) as `pointer to C-style String` (normally up to 68 characters[^address-length])1303. Connection Type (inbound, feeler, outbound-full-relay, ...) as `pointer to C-style String` (max. length 20 characters)1314. Network the peer connects from as `uint32` (1 = IPv4, 2 = IPv6, 3 = Onion, 4 = I2P, 5 = CJDNS). See `Network` enum in `netaddress.h`.1325. Connection established UNIX epoch timestamp in seconds as `uint64`.134#### Tracepoint `net:misbehaving_connection`136Is called when a connection is misbehaving. Passes the peer id and a137reason for the peers misbehavior.139Arguments passed:1401. Peer ID as `int64`.1412. Reason why the peer is misbehaving as `pointer to C-style String` (max. length 128 characters).143#### Tracepoint `net:closed_connection`145Is called when a connection is closed. Passes information about the closed peer146and the time at connection establishment.148Arguments passed:1491. Peer ID as `int64`1502. Peer address and port (IPv4, IPv6, Tor v3, I2P, ...) as `pointer to C-style String` (normally up to 68 characters[^address-length])1513. Connection Type (inbound, feeler, outbound-full-relay, ...) as `pointer to C-style String` (max. length 20 characters)1524. Network the peer connects from as `uint32` (1 = IPv4, 2 = IPv6, 3 = Onion, 4 = I2P, 5 = CJDNS). See `Network` enum in `netaddress.h`.1535. Connection established UNIX epoch timestamp in seconds as `uint64`.155### Context `validation`157#### Tracepoint `validation:block_connected`159Is called *after* a block is connected to the chain. Can, for example, be used160to benchmark block connections together with `-reindex`.162Arguments passed:1631. Block Header Hash as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)1642. Block Height as `int32`1653. Transactions in the Block as `uint64`1664. Inputs spend in the Block as `int32`1675. SigOps in the Block (excluding coinbase SigOps) `uint64`1686. Time it took to connect the Block in nanoseconds (ns) as `uint64`170### Context `utxocache`172The following tracepoints cover the in-memory UTXO cache. UTXOs are, for example,173added to and removed (spent) from the cache when we connect a new block.174**Note**: Bitcoin Core uses temporary clones of the _main_ UTXO cache175(`chainstate.CoinsTip()`). For example, the RPCs `generateblock` and176`getblocktemplate` call `TestBlockValidity()`, which applies the UTXO set177changes to a temporary cache. Similarly, mempool consistency checks, which are178frequent on regtest, also apply the UTXO set changes to a temporary cache.179Changes to the _main_ UTXO cache and to temporary caches trigger the tracepoints.180We can't tell if a temporary cache or the _main_ cache was changed.182#### Tracepoint `utxocache:flush`184Is called *after* the in-memory UTXO cache is flushed.186Arguments passed:1871. Time it took to flush the cache microseconds as `int64`1882. Flush state mode as `uint32`. It's an enumerator class with values189`0` (`NONE`), `1` (`IF_NEEDED`), `2` (`PERIODIC`), `3` (`FORCE_FLUSH`), `4` (`FORCE_SYNC`)1903. Cache size (number of coins) before the flush as `uint64`1914. Cache memory usage in bytes as `uint64`1925. If pruning caused the flush as `bool`194#### Tracepoint `utxocache:add`196Is called when a coin is added to a UTXO cache. This can be a temporary UTXO cache too.198Arguments passed:1991. Transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)2002. Output index as `uint32`2013. Block height the coin was added to the UTXO-set as `uint32`2024. Value of the coin as `int64`2035. If the coin is a coinbase as `bool`205#### Tracepoint `utxocache:spent`207Is called when a coin is spent from a UTXO cache. This can be a temporary UTXO cache too.209Arguments passed:2101. Transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)2112. Output index as `uint32`2123. Block height the coin was spent, as `uint32`2134. Value of the coin as `int64`2145. If the coin is a coinbase as `bool`216#### Tracepoint `utxocache:uncache`218Is called when a coin is purposefully unloaded from a UTXO cache. This219happens, for example, when we load an UTXO into a cache when trying to accept220a transaction that turns out to be invalid. The loaded UTXO is uncached to avoid221filling our UTXO cache up with irrelevant UTXOs.223Arguments passed:2241. Transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)2252. Output index as `uint32`2263. Block height the coin was uncached, as `uint32`2274. Value of the coin as `int64`2285. If the coin is a coinbase as `bool`230### Context `coin_selection`232#### Tracepoint `coin_selection:selected_coins`234Is called when `SelectCoins` completes.236Arguments passed:2371. Wallet name as `pointer to C-style string`2382. Coin selection algorithm name as `pointer to C-style string`2393. Selection target value as `int64`2404. Calculated waste metric of the solution as `int64`2415. Total value of the selected inputs as `int64`243#### Tracepoint `coin_selection:normal_create_tx_internal`245Is called when the first `CreateTransactionInternal` completes.247Arguments passed:2481. Wallet name as `pointer to C-style string`2492. Whether `CreateTransactionInternal` succeeded as `bool`2503. The expected transaction fee as an `int64`
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.