← Back to Pull requests

btcjson: apply defaults to optional params passed as null #2644

Open
Lrifton92 opened this pull request with 76 lines diff across 4 files
View on GitHub
Lrifton92 Lrifton92 commented on Oct 16, 2026 10:28 UTC
Author

Change Description

UnmarshalCmd only applies jsonrpcdefault values to trailing parameters that are omitted (populateDefaults, btcjson/cmdparse.go). An optional parameter sent as an explicit JSON null is unmarshalled into a nil pointer instead, so the handler sees a different value than if the parameter had been left out.

Example: verifychain [null, null] reaches handleVerifyChain with nil level and depth, which it turns into level 0 over the whole chain instead of the defaults (level 3, depth 288). The getblock panic in #2597 had the same root cause; #2600 fixed it in that one handler.

This change treats a null optional parameter the same as an omitted one and assigns its default value. Bitcoin Core also treats null as "use the default" for optional RPC arguments. Required parameters and optional parameters without a default are unchanged.

Two existing test vectors (searchrawtransactions with a null vinextra, createwallet - optional2) expected nil for a null optional parameter; they now expect the default.

Found with a FuzzUnmarshalCmd round-trip harness over all registered methods.

Steps to Test

go test ./btcjson -run TestUnmarshalCmdNullOptional -v
go test ./btcjson .

Without the fix, TestUnmarshalCmdNullOptional fails with e.g. got {"CheckLevel":null,"CheckDepth":null}, want {"CheckLevel":3,"CheckDepth":288}.

Pull Request Checklist


Testing


  • Your PR passes all CI checks.

  • Tests covering the positive and negative (error paths) are included.

  • Bug fixes contain tests triggering the bug to prevent regressions.
  • Code Style and Documentation


  • The change is not insubstantial. Typo fixes are not accepted to fight bot spam.

  • The change obeys the Code Documentation and Commenting guidelines, and lines wrap at 80.

  • Commits follow the Ideal Git Commit Structure.

  • Any new logging statements use an appropriate subsystem and logging level.
  • 🤖 Generated with Claude Code

    Diff: 76 lines (+73 / -3) across 4 files Reviewer: allocz Review duration: 70952m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.40) × (1 − Review Confidence (0.66)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 76 lines diff across 4 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.35 · 1 substantive comment(s)
    0.35
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    65%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.260
    Real PR Conversation Timeline
    2 items
    allocz allocz approved these changes on Oct 22, 2026 14:03 UTC
    Approved Reviewer

    Nice catch. LGTM.

    Reviewers
    Assignees
    Lrifton92 Lrifton92
    Labels
    risk: low confidence: 65.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 65.5% · Lower = rushed or shallow review
    65.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 13.9% · Safe to merge
    13.9%
    Repository