tracing: drop GetHash().ToString() argument from the `validation:block_connected` tracepoint #23302

pull 0xB10C wants to merge 1 commits into bitcoin:master from 0xB10C:2021-10-connect-block-drop-hash-toString changing 4 files +19 −26
  1. 0xB10C commented at 12:42 PM on October 18, 2021: member

    The tracepoint validation:block_connected was introduced in #22006. The first argument was the hash of the connected block as a pointer to a C-like String. The last argument passed the hash of the connected block as a pointer to 32 bytes. The hash was only passed as string to allow bpftrace scripts to print the hash. It was (incorrectly) assumed that bpftrace cannot hex-format and print the block hash given only the hash as bytes.

    The block hash can be printed in bpftrace by calling printf("%02x") for each byte of the hash in an unroll () {...}. By starting from the last byte of the hash, it can be printed in big-endian (the block-explorer format).

      $p = $hash + 31;
      unroll(32) {
          $b = *(uint8*)$p;
          printf("%02x", $b);
          $p -= 1;
      }
    

    See also: #22902 (comment)

    This is a breaking change to the block_connected tracepoint API, however this tracepoint has not yet been included in a release.

  2. tracing: drop block_connected hash.toString() arg
    The tracepoint `validation:block_connected` was introduced in #22006.
    The first argument was the hash of the connected block as a pointer
    to a C-like String. The last argument passed the hash of the
    connected block as a pointer to 32 bytes. The hash was only passed as
    string to allow `bpftrace` scripts to print the hash. It was
    (incorrectly) assumed that `bpftrace` cannot hex-format and print the
    block hash given only the hash as bytes.
    
    The block hash can be printed in `bpftrace` by calling
    `printf("%02x")` for each byte of the hash in an `unroll () {...}`.
    By starting from the last byte of the hash, it can be printed in
    big-endian (the block-explorer format).
    
    ```C
      $p = $hash + 31;
      unroll(32) {
          $b = *(uint8*)$p;
          printf("%02x", $b);
          $p -= 1;
      }
    ```
    
    See also: https://github.com/bitcoin/bitcoin/pull/22902#discussion_r705176691
    
    This is a breaking change to the block_connected tracepoint API, however
    this tracepoint has not yet been included in a release.
    53c9fa9e62
  3. DrahtBot added the label Scripts and tools on Oct 18, 2021
  4. DrahtBot added the label Validation on Oct 18, 2021
  5. laanwj commented at 1:06 PM on October 18, 2021: member

    Concept and code review ACK 53c9fa9e6253ea89ba1057b35e018ad1a25fb97e

    Trace point invocations should be as light as possible to avoid overhead when they are disabled (the common case). Creating an intermediate string and deallocating it, as well as formatting overhead is something that should be avoided.

  6. practicalswift commented at 1:09 PM on October 18, 2021: contributor

    Concept ACK

  7. jb55 commented at 1:16 PM on October 18, 2021: member

    ACK 53c9fa9e6253ea89ba1057b35e018ad1a25fb97e

    this is the way.

    If anyone is looking at the unroll and thinking that's a funny way to print something, it's because the BPF virtual machine inside the kernel requires guaranteed termination, you can't have infinite loops in BPF programs. unroll is a simple way that bpftrace implements fixed length looping via an integer literal. Printing data this way works great for fixed sized pieces of data, but you can't unroll on passed arguments.

    I'm not familiar enough with BPF bytecode but I assume there is just no "jump" operation to implement loops, which is why you need to unroll them.

  8. fanquake commented at 8:05 AM on October 19, 2021: member

    This is a breaking change to the block_connected tracepoint API, however this tracepoint has not yet been included in a release.

    I would hate to think we are already at a point where we have to worry about backwards compatibility for tracepoints. Consumers should understand that they are still new/experimental and are very likely change over the next few releases, as improvements like this are made.

  9. fanquake merged this on Oct 19, 2021
  10. fanquake closed this on Oct 19, 2021

  11. 0xB10C deleted the branch on Oct 19, 2021
  12. sidhujag referenced this in commit 230bd8aef6 on Oct 19, 2021
  13. DrahtBot locked this on Oct 30, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-30 21:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me