Skip to content

Conversation

@moisesPompilio
Copy link
Collaborator

Description and Notes

Introduces HeaderExtension, a trait that adds shared helper functions to bitcoin::Header. As suggested in PR #682 , the goal is to centralize logic that depends on block headers and is reused across different RPC methods. This includes calculations such as chain work, median time past, and other header-derived values.

By consolidating this logic in a single place, we reduce duplication, ensure consistent behavior across RPC calls, and lower the chances of errors caused by incorrect variable handling.

How to verify the changes

Check the Floresta RPC outputs for getblockchaininfo and getblock. The returned fields must match the corresponding values from Bitcoin Core’s RPCs for the same blocks.

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.

Strong ACK.

Here some suggestion, nice idea @Davidson-Souza.

@Davidson-Souza Davidson-Souza added the enhancement New feature or request label Dec 2, 2025
@Davidson-Souza
Copy link
Member

Extension traits usually have the suffix Ext, so HeaderExt

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.

just more these and i think well be at the finals

@moisesPompilio moisesPompilio force-pushed the add-block-ext branch 2 times, most recently from 3d84e46 to 88acd41 Compare December 5, 2025 14:11
@moisesPompilio moisesPompilio force-pushed the add-block-ext branch 3 times, most recently from 6503a07 to f9821eb Compare December 9, 2025 17:50
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.

Some suggestions

@moisesPompilio moisesPompilio force-pushed the add-block-ext branch 3 times, most recently from 8e8d56a to 31bdd1d Compare December 17, 2025 01:58
@moisesPompilio
Copy link
Collaborator Author

@jaoleal I implemented your code suggestion, but I had to make some small changes because there were some errors in the chunking function you used, so I had to adjust that part.

- Added methods for calculating median time past, chain work, and retrieving block details.
- Introduced HeaderExtension trait for improved header operations.
- Updated GetBlockResVerbose to use f64 for difficulty and added target field.
- Enhanced error handling in JsonRpcError for chain work calculations.
- Updated tests to reflect changes in difficulty and chain work representation.
@jaoleal
Copy link
Collaborator

jaoleal commented Dec 18, 2025

ACK 98b5219

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 98b5219

@Davidson-Souza Davidson-Souza merged commit a81d70e into getfloresta:master Dec 23, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants