log_utxos.bt raw

   1  #!/usr/bin/env bpftrace
   2  
   3  /*
   4  
   5    USAGE:
   6  
   7    bpftrace contrib/tracing/log_utxos.bt
   8  
   9    This script requires a 'bitcoind' binary compiled with eBPF support and the
  10    'utxocache' tracepoints. By default, it's assumed that 'bitcoind' is
  11    located in './build/bin/bitcoind'. This can be modified in the script below.
  12  
  13    NOTE: requires bpftrace v0.12.0 or above.
  14  */
  15  
  16  BEGIN
  17  {
  18      printf("%-7s %-71s %16s %7s %8s\n",
  19            "OP", "Outpoint", "Value", "Height", "Coinbase");
  20  }
  21  
  22  /*
  23    Attaches to the 'utxocache:add' tracepoint and prints additions to the UTXO set cache.
  24  */
  25  usdt:./build/bin/bitcoind:utxocache:add
  26  {
  27    $txid = arg0;
  28    $index = (uint32)arg1;
  29    $height = (uint32)arg2;
  30    $value = (int64)arg3;
  31    $isCoinbase = arg4;
  32  
  33    printf("Added   ");
  34    $p = $txid + 31;
  35    unroll(32) {
  36      $b = *(uint8*)$p;
  37      printf("%02x", $b);
  38      $p-=1;
  39    }
  40  
  41    printf(":%-6d %16ld %7d %s\n", $index, $value, $height, ($isCoinbase ? "Yes" : "No" ));
  42  }
  43  
  44  /*
  45    Attaches to the 'utxocache:spent' tracepoint and prints spents from the UTXO set cache.
  46  */
  47  usdt:./build/bin/bitcoind:utxocache:spent
  48  {
  49    $txid = arg0;
  50    $index = (uint32)arg1;
  51    $height = (uint32)arg2;
  52    $value = (int64)arg3;
  53    $isCoinbase = arg4;
  54  
  55    printf("Spent   ");
  56    $p = $txid + 31;
  57    unroll(32) {
  58      $b = *(uint8*)$p;
  59      printf("%02x", $b);
  60      $p-=1;
  61    }
  62  
  63    printf(":%-6d %16ld %7d %s\n", $index, $value, $height, ($isCoinbase ? "Yes" : "No" ));
  64  }
  65  
  66  /*
  67    Attaches to the 'utxocache:uncache' tracepoint and uncache UTXOs from the UTXO set cache.
  68  */
  69  usdt:./build/bin/bitcoind:utxocache:uncache
  70  {
  71    $txid = arg0;
  72    $index = (uint32)arg1;
  73    $height = (uint32)arg2;
  74    $value = (int64)arg3;
  75    $isCoinbase = arg4;
  76  
  77    printf("Uncache ");
  78    $p = $txid + 31;
  79    unroll(32) {
  80      $b = *(uint8*)$p;
  81      printf("%02x", $b);
  82      $p-=1;
  83    }
  84  
  85    printf(":%-6d %16ld %7d %s\n", $index, $value, $height, ($isCoinbase ? "Yes" : "No" ));
  86  }
  87