Add mempool tracepoints

Tracepoints for added, removed, replaced, and rejected transactions.

The removal reason is passed as string instead of a numeric value, since
the benefits of not having to maintain a redundant enum-string mapping
seem to outweigh the small cost of string generation.  The reject reason
is passed as string as well, although here the string does not have to
be generated but is readily available.

So far, tracepoint PRs typically included two demo scripts: a naive
bpftrace script to show raw tracepoint data and a bcc script for a more
refined view. However, as some of the ongoing changes to bpftrace
introduce a certain degree of unreliability (running some of the
existing bpftrace scripts was not possible with standard kernels and
bpftrace packages on latest stable Ubuntu, Debian, and NixOS), this PR
includes only a single bcc script that fuses the functionality of former
bpftrace and bcc scripts.
This commit is contained in:
virtu
2022-11-18 12:56:46 +00:00
parent 635f1900d0
commit 4b7aec2951
7 changed files with 845 additions and 0 deletions

View File

@@ -211,6 +211,58 @@ Arguments passed:
4. The expected transaction fee as an `int64`
5. The position of the change output as an `int32`
### Context `mempool`
#### Tracepoint `mempool:added`
Is called when a transaction is added to the node's mempool. Passes information
about the transaction.
Arguments passed:
1. Transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)
2. Transaction virtual size as `uint64`
3. Transaction fee as `int64`
#### Tracepoint `mempool:removed`
Is called when a transaction is removed from the node's mempool. Passes information
about the transaction.
Arguments passed:
1. Transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)
2. Removal reason as `pointer to C-style String` (max. length 9 characters)
3. Transaction virtual size as `uint64`
4. Transaction fee as `int64`
5. Transaction mempool entry time (epoch) as `uint64`
#### Tracepoint `mempool:replaced`
Is called when a transaction in the node's mempool is getting replaced by another.
Passes information about the replaced and replacement transactions.
Arguments passed:
1. Replaced transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)
2. Replaced transaction virtual size as `uint64`
3. Replaced transaction fee as `int64`
4. Replaced transaction mempool entry time (epoch) as `uint64`
5. Replacement transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)
6. Replacement transaction virtual size as `uint64`
7. Replacement transaction fee as `int64`
Note: In cases where a single replacement transaction replaces multiple
existing transactions in the mempool, the tracepoint is called once for each
replaced transaction, with data of the replacement transaction being the same
in each call.
#### Tracepoint `mempool:rejected`
Is called when a transaction is not permitted to enter the mempool. Passes
information about the rejected transaction.
Arguments passed:
1. Transaction ID (hash) as `pointer to unsigned chars` (i.e. 32 bytes in little-endian)
2. Reject reason as `pointer to C-style String` (max. length 118 characters)
## Adding tracepoints to Bitcoin Core
To add a new tracepoint, `#include <util/trace.h>` in the compilation unit where