Skip to content

Type discrepancy between corepc-types and Bitcoin Core #429

Closed

Description

@deadmanoz

I'm not sure if the types in corepc-types are supposed to faithfully match what Bitcoin Core RPC returns, but I noticed a discrepancy with tx_rate in GetChainTxStats. Bitcoin Core returns txrate as a double value (and has since the RPC was introduced in v0.15 PR #9733):

{
  "txrate": 5.153020888909642
}

The current types use i64 in the JSON structs and u32 in the model, yet f64 should be used if matching Bitcoin Core's output type is the goal?

I understand that this is a breaking change to the interface that people might already be using so wanted to raise it as an issue first before doing anything further.

And, in general, is the intent for the types to always match Bitcoin Core?

I found this as I was looking to extend some of the RPC extraction functionality being built out in peer-observer

Activity

  1. tcharding commented on Dec 16, 2025

    @tcharding
    Member

    Thanks for the issue! corepc-types definitely should match what Core returns, you found a bug! I'll happily review any PRs you raise.

  2. deadmanoz commented on Dec 16, 2025

    @deadmanoz
    ContributorAuthor

    No problem, I will open PR

  3. 0xB10C commented on Dec 16, 2025

    @0xB10C
    Contributor

    for reference, PR is #430

  4. deadmanoz commented on Dec 17, 2025

    @deadmanoz
    ContributorAuthor

    Ok I have found a few other type inconsistencies tangential to my peer-observer related work.

    Me and my mate Claude hacked together an audit tool to uncover any similar inconsistencies between Bitcoin Core's RPC types and corepc's Rust types across all supported versions (v17-v30).

    Status Issue Versions PR
    ✅ Merged getchaintxstats.txrate should be f64 v17, v19 #430
    ✅ Merged getmininginfo.networkhashps should be f64 v17, v28-v30 #440
    ✅ Merged decodepsbt.fee should be f64 v17, v23, v24, v30 #431
    📋 TODO decodepsbt.psbt_version should be u64 v23, v24, v30

    The first three are the same pattern - Bitcoin Core returns double but corepc uses integer types, causing deserialisation failures. The last one is a width mismatch (u32 vs u64) - unlikely to cause issues in practice but worth fixing for correctness.

    I am intending to open separate PRs to fix each?

  5. jamillambert commented on Dec 17, 2025

    @jamillambert
    Collaborator

    Nice work, after seeing your first PR on it we planned to look for other cases.

    I am intending to open separate PRs to fix each?

    It's up to you, separate or all in one, either is fine.

    I haven't finished reviewing #431, but one comment that applies to all these is that in general it's better to fix the existing test of the RPC to check the type instead of adding a second one. Unless of course there is a real need to have two.

  6. tcharding commented on Dec 29, 2025

    @tcharding
    Member

    @deadmanoz legendary, thanks for the help man!

  7. tcharding commented on Dec 30, 2025

    @tcharding
    Member

    While reviewing #440 it became clear that basically any int field we have in types is potentially wrong if the integration test gets back JSON from Core that has the field set to 0.

    ref: #440 (comment)

  8. added a commit that references this issue on Dec 31, 2025
  9. deadmanoz commented on Dec 31, 2025

    @deadmanoz
    ContributorAuthor

    While reviewing #440 it became clear that basically any int field we have in types is potentially wrong if the integration test gets back JSON from Core that has the field set to 0.

    ref: #440 (comment)

    Good point..

    Does this mean there should be more use of node.fund_wallet() or other means to ensure some value initialisation in integration tests (where appropriate)?

  10. tcharding commented on Jan 1, 2026

    @tcharding
    Member

    What ever means necessary to ensure non-zero values. I think the easiest way is to work on testing this repo with all the same tests that Core uses for testing the RPC code. I thought we had an issue for that but I couldn't find it.

    Basically the idea is to come up with a way to pull all the python test code out of Core and use it here to test our serde logic instead of actually hitting a Core node.

    But just going through and adding fund_wallet() wouldn't hurt. Perhaps we can add this as part of the wallet creation logic? (Just an idea, I didn't look at the code just now.)

  11. added a commit that references this issue on Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions