-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinspect-coinbase.sh
More file actions
executable file
·62 lines (54 loc) · 2.12 KB
/
Copy pathinspect-coinbase.sh
File metadata and controls
executable file
·62 lines (54 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# Read the current tip's coinbase from bitcoind and parse its outputs,
# asserting the drivechain-deposit shape the pool is supposed to emit
# in pool_mode=pps. Run this after simplepool mines a block.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
REGTEST="${REGTEST_DIR:-$ROOT/.regtest}"
BIN="${REGTEST_BIN_DIR:-$REGTEST/bin}"
DATA="$REGTEST/data"
cli() { "$BIN/bitcoin-cli" -datadir="$DATA/bitcoind" -regtest -rpcuser=user -rpcpassword=password "$@"; }
TIP="$(cli getbestblockhash)"
BLOCK="$(cli getblock "$TIP" 2)"
CB="$(echo "$BLOCK" | python3 -c "
import json, sys
b = json.loads(sys.stdin.read())
cb = b['tx'][0]
print(json.dumps(cb))
")"
echo "==> tip: $TIP"
echo "==> coinbase outputs:"
# Pass CB via env var because a heredoc would steal stdin from the pipe.
CB="$CB" python3 - <<'PY'
import json, os, sys
cb = json.loads(os.environ['CB'])
outs = cb['vout']
print(f' output count: {len(outs)}')
for i, o in enumerate(outs):
spk = o['scriptPubKey']
asm = spk.get('asm', '')
hex_ = spk.get('hex', '')
val = o['value']
print(f' [{i}] value={val} BTC type={spk.get("type")} asm={asm[:80]} hex={hex_[:80]}')
# Look for OP_NOP5 (0xb4) + push1 + sidechain + OP_TRUE = pattern b4 01 09 51
dc_idx = None
for i, o in enumerate(outs):
h = o['scriptPubKey']['hex'].lower()
if h.startswith('b401') and len(h) == 8 and h.endswith('51'):
dc_idx = i
side = int(h[4:6], 16)
print(f'\n >>> OP_DRIVECHAIN found at output [{i}], sidechain={side}')
if dc_idx is None:
print('\n !!! NO OP_DRIVECHAIN OUTPUT FOUND — pool did not emit a drivechain coinbase')
sys.exit(2)
# Verify next output is OP_RETURN.
nxt = outs[dc_idx + 1]
nxt_hex = nxt['scriptPubKey']['hex'].lower()
if not nxt_hex.startswith('6a'):
print(f' !!! output [{dc_idx + 1}] is not OP_RETURN; enforcer will reject')
sys.exit(3)
print(f' >>> OP_RETURN payload immediately follows; hex={nxt_hex}')
PY
echo ""
echo "==> recent enforcer log lines mentioning deposit/sidechain:"
grep -iE 'deposit|sidechain|m5' "$REGTEST/logs/bip300301_enforcer.log" | tail -20 || echo " (none yet)"