Skip to content

Conversation

@moisesPompilio
Copy link
Collaborator

What is the purpose of this pull request?

  • Bug fix
  • Documentation update
  • New feature
  • Test
  • Other:

Which crates are being modified?

  • floresta-chain
  • floresta-common
  • floresta-compact-filters
  • floresta-electrum
  • floresta-node
  • floresta-rpc
  • floresta-watch-only
  • floresta-wire
  • bin/florestad
  • bin/floresta-cli
  • Other:

Description and Notes

Adjusted the get_block RPC output to match Bitcoin Core’s behavior.
Changes include:

  • Fixed strippedsize to correctly exclude witness data.
  • Ensured bits, chainwork, and version_hex fields use big-endian hexadecimal encoding.
  • Updated difficulty calculation for accurate floating-point results.
  • Added the missing target field returning the block target in big-endian hexadecimal.

How to verify the changes you have done?

The changes can be verified by comparing the get_block RPC output from Floresta with Bitcoin Core’s reference output and documentation.
For the genesis block (0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206), Bitcoin Core returns:

{
  "hash": "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",
  "confirmations": 1,
  "height": 0,
  "version": 1,
  "versionHex": "00000001",
  "merkleroot": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
  "time": 1296688602,
  "mediantime": 1296688602,
  "nonce": 2,
  "bits": "207fffff",
  "target": "7fffff0000000000000000000000000000000000000000000000000000000000",
  "difficulty": 4.656542373906925e-10,
  "chainwork": "0000000000000000000000000000000000000000000000000000000000000002",
  "nTx": 1,
  "nextblockhash": "5a31f5b914660757c24e62459b8905f64c7b9ee64740da333eaf8372aed81c82",
  "strippedsize": 285,
  "size": 285,
  "weight": 1140,
  "tx": [
    "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
  ]
}

The reference behavior and expected field serialization can be cross-checked directly in Bitcoin Core’s implementation
src/rpc/blockchain.cpp and its official RPC documentation.

@jaoleal
Copy link
Collaborator

jaoleal commented Oct 20, 2025

LGTM, I still need to check that everything is correct but overall it looks good.

@jaoleal
Copy link
Collaborator

jaoleal commented Oct 20, 2025

@Davidson-Souza can you approve CI ?

@Davidson-Souza Davidson-Souza added the RPC Changes something with our JSON-RPC interface label Oct 20, 2025
@Davidson-Souza Davidson-Souza moved this to Outstanding Pull Requests in RPC Saga Oct 20, 2025
@Davidson-Souza
Copy link
Member

@moisesPompilio this needs rebase

@moisesPompilio moisesPompilio force-pushed the adjust-get-block-rpc branch 2 times, most recently from 4d46fd1 to bda4e4d Compare November 17, 2025 18:08
@moisesPompilio moisesPompilio force-pushed the adjust-get-block-rpc branch 3 times, most recently from 0799ba5 to 8b03898 Compare November 21, 2025 00:05
@moisesPompilio moisesPompilio force-pushed the adjust-get-block-rpc branch 2 times, most recently from f4c78d3 to 33d0e5c Compare November 22, 2025 19:31
@Davidson-Souza
Copy link
Member

I've tested this on block 00000000000000000000fa2dc17a14860712e9c852e9cbf4c5a61b5df25b94d2 and the MTP is different:

Core: 1763994343
Floresta: 1763994302

@moisesPompilio
Copy link
Collaborator Author

I've tested this on block 00000000000000000000fa2dc17a14860712e9c852e9cbf4c5a61b5df25b94d2 and the MTP is different:

Core: 1763994343 Floresta: 1763994302

I adjusted the calculation based on what Bitcoin Core does, and the tests now produce the correct values.

Copy link
Member

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about how to expose things like MTP and chainwork in a reusable way, since we'll use it in other places. The best way I thought is an extended trait implemented for Block that takes a BlockchainInterface as argument. So we would have something like:

impl BlockExt {
   fn mtp(&self, chain: &impl BlockchainInterface);

   fn chain_work(&self, chain: &impl BlockchainInterface); 

   fn alt_tips(&self, chain: &impl BlockchainInterface);
  
  // what else??
}

This way we don't pollute BlockchainInterface too much. What do you guys think? (This is not supposed to be implemented here, just thinking out loud)

@moisesPompilio
Copy link
Collaborator Author

I've been thinking about how to expose things like MTP and chainwork in a reusable way, since we'll use it in other places. The best way I thought is an extended trait implemented for Block that takes a BlockchainInterface as argument. So we would have something like:

impl BlockExt {
   fn mtp(&self, chain: &impl BlockchainInterface);

   fn chain_work(&self, chain: &impl BlockchainInterface); 

   fn alt_tips(&self, chain: &impl BlockchainInterface);
  
  // what else??
}

This way we don't pollute BlockchainInterface too much. What do you guys think? (This is not supposed to be implemented here, just thinking out loud)

It makes sense. Using Header instead of Block seems more appropriate, since these functions only need header data. That would also let getblockheader use them without requiring a full Block. Should we open an issue to handle this more cleanly, or address it directly in this PR?

@Davidson-Souza
Copy link
Member

Using Header instead of Block seems more appropriate, since these functions only need header data. That would also let getblockheader use them without requiring a full Block

Right!

Should we open an issue to handle this more cleanly, or address it directly in this PR?

I think we can do it in another PR

@moisesPompilio
Copy link
Collaborator Author

bf1a571 I added documentation for the getblock RPC and adjusted the verbosity default value to 1. Verbosity is no longer required, because in Bitcoin Core's documentation, verbosity is optional and the default value is 1.

@moisesPompilio moisesPompilio force-pushed the adjust-get-block-rpc branch 4 times, most recently from eeff358 to 461b7a3 Compare January 12, 2026 18:21
Davidson-Souza
Davidson-Souza previously approved these changes Jan 14, 2026
Copy link
Member

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 1df8140

Copy link
Collaborator

@jaoleal jaoleal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but it needs some changes...

sry for the late response

Fix strippedsize to correctly calculate and return
the block size excluding witness data
- Use corepc GetBlockVerboseOne instead of local verbose type.
- Make get_block RPC field names/types compatible with Bitcoin Core.
- Update functional tests to mine blocks (avoid genesis) and compare
 field-by-field.
- update GetBlockRes enum variants to One and Zero
In the Bitcoin Core documentation, the default value of verbosity is 1. So I adjusted the values in `floresta-rpc` and `floresta-node`. Verbosity is no longer required in `floresta-node`
@moisesPompilio
Copy link
Collaborator Author

ce45338 I fixed a problem in the getblock.py test during sync, it was failing because Floresta wasn't able to finish downloading all blocks. I just moved block generation to before the peers connect. I also added a new test feature in getblock.py, which is the ability to check by block height instead of by the last known block hash. So I added a test target that picks a random block to compare. Now the test compares the genesis block, the last block in the chain, and a random block.

@jaoleal
Copy link
Collaborator

jaoleal commented Jan 20, 2026

ACK ce45338

Copy link
Member

@Davidson-Souza Davidson-Souza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ce45338

@Davidson-Souza Davidson-Souza merged commit 1905cb1 into getfloresta:master Jan 20, 2026
9 checks passed
@github-project-automation github-project-automation bot moved this from Outstanding Pull Requests to Implemented, tested in RPC Saga Jan 20, 2026
Davidson-Souza added a commit that referenced this pull request Feb 9, 2026
b37772d chore(rpcserver): Match signature of getblock to its rpc (jaoleal)

Pull request description:

  ### Description and Notes

   #682 introduced changes that brought getblock rpc method closer to bitcoin core behavior. The changes presented here make the internal method signature to match the specification.

ACKs for top commit:
  moisesPompilio:
    ACK b37772d
  Davidson-Souza:
    ACK b37772d

Tree-SHA512: e5c72bf24daf795e853c284b4ef14738ffb6f3779e75a660ab85e86da98a3e48e184853c264054a832f9efc077cb86cf53e886b575e80fafd01b85e6b9a54625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC Changes something with our JSON-RPC interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants