Skip to content

feat: add getchaintips.#862

Draft
jaoleal wants to merge 3 commits intogetfloresta:masterfrom
jaoleal:rpcsaga_getchaintips
Draft

feat: add getchaintips.#862
jaoleal wants to merge 3 commits intogetfloresta:masterfrom
jaoleal:rpcsaga_getchaintips

Conversation

@jaoleal
Copy link
Copy Markdown
Member

@jaoleal jaoleal commented Feb 25, 2026

Description and Notes

This pr adds the getchaintips method with integration tests.

There was already an BlockChainInterface::get_chain_tips() which returned the known tips, i just had to identify each blockhash and return data about its state.

addresses: #858

I also changed the timeout to 30 seconds because my pc struggled with the tests. It would be nice to get it merged, but i understand thats already being handled on #794 and i can remove it later.

How to verify the changes you have done?

  • Read and run the tests

@jaoleal
Copy link
Copy Markdown
Member Author

jaoleal commented Feb 25, 2026

cc @0xB10C

@@ -0,0 +1,125 @@
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test could generate some forks to test with more than one tip

"""

TIMEOUT: int = 15 # seconds
TIMEOUT: int = 30 # seconds
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unrelated change

@Davidson-Souza Davidson-Souza added enhancement New feature or request new rpc This issue/PR implements a new json-rpc endpoint labels Feb 27, 2026
@jaoleal jaoleal force-pushed the rpcsaga_getchaintips branch from 5fe93cd to cdeee33 Compare March 9, 2026 19:51
@moisesPompilio moisesPompilio self-requested a review March 9, 2026 23:19
@jaoleal
Copy link
Copy Markdown
Member Author

jaoleal commented Mar 10, 2026

Turning this back on draft.

Im expanding this to contain the suggested test case but i need #881 for that.

"need" is a strong word, it helps a lot to avoid gambiarra

Another piece that i have to push expands getchaintips to also expose invalid and headersonly blocks.

@jaoleal jaoleal marked this pull request as draft March 10, 2026 19:57
jaoleal added 3 commits March 19, 2026 16:59
Implement the getchaintips RPC method that returns information about all
known tips in the block tree, including the main chain and orphaned
branches.
- Add ChainTipStatus enum and ChainTip struct to floresta-rpc types
- Add get_chain_tips() to FlorestaRPC trait
- Add server-side handler in floresta-node json_rpc
- Wire dispatch for "getchaintips" in the JSON-RPC server
- Add doc/rpc/getchaintips.md documentation
Add integration test exercising `getchaintips` on both florestad and bitcoind,
comparing their outputs across six scenarios.

A) Genesis only
B) Synced 10-block chain
C) submit_header for an unknown block
D) invalidateblock to produce an invalid tip
E) Fork via invalidation at height 5 + mining 10 new blocks
F) Second fork via invalidation at height 8 + mining 10 more

Add get_chain_tips, invalidate_block and submit_header wrappers to the
BitcoinRPC class so bitcoind can be exercised in the same way.
…ing block validation state,

Add ChainTipInfo and ChainTipStatus types to floresta-chain so that
get_chain_tips() returns validation state (Active, ValidFork,
HeadersOnly, Invalid) alongside each tip hash.

mark_chain_as_active: preserve FullyValid status for blocks that were
already validated instead of overwriting as HeadersOnly.

reorg: properly manage alternative_tips during chain reorganizations.
Remove entries that become ancestors of the new active chain, and only
add the old active tip when it is a true leaf (not an ancestor of any
existing alternative tip).

getchaintips: fix branchlen calculation by using a FindFork-style ancestor
walk that checks heights are within the active chain, preventing stale block
index entries from producing branchlen=0.
@jaoleal jaoleal force-pushed the rpcsaga_getchaintips branch from cdeee33 to c5e7304 Compare March 19, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request new rpc This issue/PR implements a new json-rpc endpoint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants