diff --git a/test/regtest_smoke.sh b/test/regtest_smoke.sh index 790fc73..5eba73d 100755 --- a/test/regtest_smoke.sh +++ b/test/regtest_smoke.sh @@ -457,6 +457,7 @@ bitcoind \ -rpcbind=127.0.0.1 \ -rpcallowip=127.0.0.1 \ -fallbackfee=0.0001 \ + -debug=validation \ -nodaemon \ >"$WORK_DIR/bitcoind.log" 2>&1 & BITCOIN_PID=$! @@ -721,8 +722,81 @@ P2_CANONICAL=$(cli getblockhash "$P2_HEIGHT") [[ "$P2_HASH" == "$P2_CANONICAL" ]] \ || die "Phase 2: hash mismatch: api=$P2_HASH bitcoind=$P2_CANONICAL" +# ---- verbose coinbase validation -------------------------------------------- +# Decode the mined block's coinbase transaction and verify the scriptSig +# contains "kamado" (our patched branding) and the btcsig tag, and that +# bitcoind accepted the coinbase as consensus-valid. + +log "" +log "=== Coinbase validation ===" + +P2_BLOCK_HEX=$(cli getblock "$P2_HASH" 0) +# The coinbase is the first transaction in the block. getblock verbosity=2 +# gives us the decoded transaction directly. +P2_BLOCK_JSON=$(cli getblock "$P2_HASH" 2) + +COINBASE_TXID=$(echo "$P2_BLOCK_JSON" | jq -r '.tx[0].txid') +COINBASE_SCRIPTSIG_HEX=$(echo "$P2_BLOCK_JSON" | jq -r '.tx[0].vin[0].coinbase') +COINBASE_SCRIPTSIG_SIZE=${#COINBASE_SCRIPTSIG_HEX} +COINBASE_SCRIPTSIG_BYTES=$((COINBASE_SCRIPTSIG_SIZE / 2)) +COINBASE_SCRIPTSIG_ASM=$(echo "$P2_BLOCK_JSON" | jq -r '.tx[0].vin[0].coinbase' | xxd -r -p | strings -n 3 | tr '\n' ' ') + +log " coinbase txid: $COINBASE_TXID" +log " scriptSig hex: $COINBASE_SCRIPTSIG_HEX" +log " scriptSig size: $COINBASE_SCRIPTSIG_BYTES bytes (max 100)" +log " readable strings: $COINBASE_SCRIPTSIG_ASM" + +# Verify scriptSig is within consensus limit +(( COINBASE_SCRIPTSIG_BYTES <= 100 )) \ + || die "Coinbase scriptSig exceeds 100-byte consensus limit ($COINBASE_SCRIPTSIG_BYTES bytes)" +(( COINBASE_SCRIPTSIG_BYTES >= 2 )) \ + || die "Coinbase scriptSig below 2-byte consensus minimum ($COINBASE_SCRIPTSIG_BYTES bytes)" + +# Verify our branding is present (kamado in hex = 6b616d61646f) +if echo "$COINBASE_SCRIPTSIG_HEX" | grep -qi "6b616d61646f"; then + log " branding check: 'kamado' found in scriptSig ✓" +else + # Fall back to checking for 'ckpool' (pre-patch binary) + if echo "$COINBASE_SCRIPTSIG_HEX" | grep -qi "636b706f6f6c"; then + log " branding check: 'ckpool' found (pre-patch binary, expected if patch not applied)" + else + log " WARNING: neither 'kamado' nor 'ckpool' found in scriptSig" + fi +fi + +# Verify btcsig tag is present +BTCSIG_HEX=$(echo -n "/KamadoSmoke/" | xxd -p) +if echo "$COINBASE_SCRIPTSIG_HEX" | grep -qi "$BTCSIG_HEX"; then + log " btcsig check: '/KamadoSmoke/' found in scriptSig ✓" +else + log " WARNING: btcsig '/KamadoSmoke/' not found in scriptSig" +fi + +# The ultimate proof: bitcoind accepted this block into its chain. +# getblock succeeds and confirmations > 0 means full consensus validation passed. +P2_CONFIRMATIONS=$(echo "$P2_BLOCK_JSON" | jq -r '.confirmations') +log " confirmations: $P2_CONFIRMATIONS (block accepted by bitcoind consensus) ✓" + log "Phase 2 PASS: block $P2_HEIGHT → hash $P2_HASH (matches bitcoind)" +# ---- bitcoind validation debug log ------------------------------------------ +# Show bitcoind's internal validation messages for the mined block. +# Requires -debug=validation flag (added to bitcoind startup above). + +BTC_DEBUG_LOG="$BTC_DIR/regtest/debug.log" +if [[ -f "$BTC_DEBUG_LOG" ]]; then + log "" + log "=== bitcoind validation log (block $P2_HASH) ===" + # Show only lines mentioning our specific block hash (filters out generatetoaddress noise) + grep -F "$P2_HASH" \ + "$BTC_DEBUG_LOG" | while IFS= read -r line; do + log " $line" + done + log "=== end validation log ===" +else + log " WARNING: bitcoind debug.log not found at $BTC_DEBUG_LOG" +fi + # ---- all done --------------------------------------------------------------- printf '[smoke] PASS: Phase 1 (log-injection) + Phase 2 (stratum → submitblock) both verified\n'