fix(web): a window segment names its unit, or it is just a height
`/quantus/3600` sent the standings straight to block 3,600. `isBlockRef` matches
any bare run of digits and is consulted two lines before the window is even
considered, so the rename walked into a collision that already existed — and
this module's own header warns about exactly it:
Shape works until two kinds of thing can look alike... Naming the kind
costs six characters and removes the whole class of problem.
Naming the window for its block count was right; leaving it as a bare number was
not. The segment is `3600-blocks` now, in the standings path and as the miner
suffix both, which is a distinct shape from a height and from a hash and says
what the number counts.
Bare counts are deliberately not accepted back, though the site emitted them for
about an hour: `/quantus/3600` cannot be told from block 3,600, and guessing
would make one of the two silently open the wrong page. The duration names from
before the rename still resolve and are still rewritten.
Checked in a browser against the live chain:
/quantus/six_hours -> /quantus/3600-blocks last 3,600 blocks · 11 h
/quantus/week -> /quantus/100800-blocks last 100,800 blocks · 29 h
/quantus/600-blocks -> unchanged last 600 blocks · 2 h
/quantus/block/3600 -> canonicalised to a hash #3,600
/planck/3600-blocks -> unchanged last 3,600 blocks · 32 h
That last line is the one this whole thread was about.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jp6a8EDar9ueEhAxzep4V5
This commit is contained in:
+32
-8
@@ -46,7 +46,7 @@ export const DEFAULT_WINDOW: WindowName = '3600'
|
||||
* Window names this site used to emit, mapped to what they became.
|
||||
*
|
||||
* A link somebody sent last week still has to land on the right page. The
|
||||
* router rewrites these to the block count rather than serving them, so the
|
||||
* router rewrites these to the current form rather than serving them, so the
|
||||
* address bar never keeps a name the site no longer stands behind.
|
||||
*/
|
||||
export const LEGACY_WINDOWS: Record<string, WindowName> = {
|
||||
@@ -57,6 +57,23 @@ export const LEGACY_WINDOWS: Record<string, WindowName> = {
|
||||
week: '100800',
|
||||
}
|
||||
|
||||
/**
|
||||
* The window as a path segment: `3600-blocks`.
|
||||
*
|
||||
* The unit is in the segment because the count alone is not a distinct shape —
|
||||
* a bare `3600` is also a perfectly good block height, and `isBlockRef` says so
|
||||
* two lines before the window is even considered. Shipping `/quantus/3600`
|
||||
* sent the standings straight to block 3,600.
|
||||
*
|
||||
* That is the trap this module's own header warns about: "Shape works until two
|
||||
* kinds of thing can look alike... Naming the kind costs six characters and
|
||||
* removes the whole class of problem." A window named for its block count had
|
||||
* to name the unit too, or it was just a number again.
|
||||
*/
|
||||
export function windowPath(window: WindowName): string {
|
||||
return `${window}-blocks`
|
||||
}
|
||||
|
||||
/** What the address bar currently says the page should show. */
|
||||
export interface Route {
|
||||
/** `null` means "whichever chain the backend puts first". */
|
||||
@@ -123,15 +140,22 @@ export const EMPTY: Route = {
|
||||
}
|
||||
|
||||
function asWindow(segment: string | undefined): WindowName | null {
|
||||
const current = WINDOWS.find((w) => w.id === segment)?.id
|
||||
// The empty segment is checked first rather than leaning on `&&`: that form
|
||||
// returns `''` for an empty path, which is neither a window nor null.
|
||||
if (!segment) return null
|
||||
|
||||
const suffixed = segment.endsWith('-blocks') ? segment.slice(0, -'-blocks'.length) : null
|
||||
const current = WINDOWS.find((w) => w.id === suffixed)?.id
|
||||
if (current) return current
|
||||
|
||||
// A link from before the rename. Resolved here rather than rejected, so an
|
||||
// address somebody shared still opens the page it named — `href` will then
|
||||
// write the block count back into the bar.
|
||||
// write the current form back into the bar.
|
||||
//
|
||||
// The empty segment is checked separately rather than leaning on `&&`: that
|
||||
// form returns `''` for an empty path, which is neither a window nor null.
|
||||
if (!segment) return null
|
||||
// Bare counts are deliberately *not* accepted, though the site briefly
|
||||
// emitted them: `/quantus/3600` is indistinguishable from block 3,600, and
|
||||
// guessing between them would make one of the two silently open the wrong
|
||||
// page. A window that cannot be told apart from a height is not a window.
|
||||
return LEGACY_WINDOWS[segment] ?? null
|
||||
}
|
||||
|
||||
@@ -222,7 +246,7 @@ export function href(route: Partial<Route>): string {
|
||||
const chain = route.chain ?? ''
|
||||
if (route.block) return `/${chain}/block/${route.block}`
|
||||
if (route.miner) {
|
||||
const window = route.window ?? DEFAULT_WINDOW
|
||||
const window = windowPath(route.window ?? DEFAULT_WINDOW)
|
||||
return chain ? `/${chain}/miner/${route.miner}/${window}` : `/miner/${route.miner}/${window}`
|
||||
}
|
||||
if (route.call) return `/${chain}/call/${route.call[0]}/${route.call[1]}`
|
||||
@@ -232,7 +256,7 @@ export function href(route: Partial<Route>): string {
|
||||
if (route.runtime !== null && route.runtime !== undefined) {
|
||||
return chain ? `/${chain}/runtime/${route.runtime}` : `/runtime/${route.runtime}`
|
||||
}
|
||||
return `/${chain}/${route.window ?? DEFAULT_WINDOW}`
|
||||
return `/${chain}/${windowPath(route.window ?? DEFAULT_WINDOW)}`
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user