Skip to content

feat: keep fork lanes stable when a fork overtakes the best block - #188

Merged
voliva merged 2 commits into
polkadot-api:mainfrom
sharmis-tp:feat/stable-fork-lanes
Oct 13, 2026
Merged

voliva merged 2 commits into
polkadot-api:mainfrom
sharmis-tp:feat/stable-fork-lanes

Conversation

@sharmis-tp

Copy link
Copy Markdown
Contributor

Closes #172.

Replaces the top-down fork layout in the block explorer with a bottom-up one so lanes stay stable when a fork overtakes the best block:

  • a block keeps its parent's lane if it's the first child discovered for that parent (blocksByHeight maps are already in discovery order);
  • other children branch out to a free lane on the right;
  • best-chain blocks move back to the leftmost free lane, so the winning fork returns left once the branch that held the lane stops.

The layout lives in blockLayout.ts as a pure function, one pass per height(about 0.7 ms for 660 blocks). BlockTable draws a diagonal whenever a block's lane differs from its parent's, and uses a canonical flag for best-chain styling since lane 0 no longer always means best chain.

Tested with synthetic fork scenarios (linear, losing fork, fork overtaking, two forks from one parent) and live on Polkadot (screenshot attached).

papi-172-live-polkadot

@vercel

vercel Bot commented Oct 10, 2026

Copy link
Copy Markdown

@sharmis-tp is attempting to deploy a commit to the Streamsphere Labs Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
papi-console Ready Ready Preview Oct 13, 2026 8:40am UTC

Request Review

@voliva

voliva commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Overall I like it, thank you very much for this!

Something I noticed is that new branches appear in inverse order: blocks are normally in chronological order, but within the same-block-number group, then it's in inverse order, which makes other blocks jump further down

untitled.mp4

I think this is a good compromise though, as it simplifies massively the view when branching and it's probably what kept me from finishing it. I like it.

Another thing I noticed is the double-line when there are branches:
image

Is this something easy to fix? I'd rather if this artifact wasn't there.

The code LGTM, I have no comments on that. Really good that you achieved this without increasing the complexity.

@sharmis-tp

Copy link
Copy Markdown
Contributor Author

Thanks for the review! The double line came from siblings sharing the line to their parent: each child added the same lane to the rows in between, so two semi-transparent strokes stacked up. Each lane is now drawn once per row (just pushed). Screenshot from Polkadot after the fix attached.
papi-188-fix-live-polkadot

@josepot
josepot self-requested a review October 13, 2026 07:51

@josepot josepot left a comment

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.

LGTM! Thanks a lot @sharmis-tp for this, really nice work!

Although, I want to make sure that we have @voliva's green-light before we merge.

@voliva voliva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's great, thanks again!

@voliva
voliva merged commit 6dc26f5 into polkadot-api:main Oct 13, 2026
2 checks passed
@sharmis-tp

Copy link
Copy Markdown
Contributor Author

Thanks both, glad it landed!

This branch was successfully deployed

1 active deployment
Preview — a4ad6103 Deployed Oct 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smol UI improvement for forks

3 participants