Skip to content

explorer: a failed block is retried at the poll's pace, and a block fluxd does not hold yet is waited for - #1873

Merged
MorningLightMountain713 merged 5 commits into
developmentfrom
fix/explorer-waits-for-blocks
Nov 26, 2026
Merged

MorningLightMountain713 merged 5 commits into
developmentfrom
fix/explorer-waits-for-blocks

Conversation

@MorningLightMountain713

@MorningLightMountain713 MorningLightMountain713 commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A block that fails in processBlock goes to recovery with no wait, and recovery restores the explorer's database and asks for the same block again with no wait. The only brake is fluxd's sync state, which FluxOS reads from a cache that turns "not synced" only after fluxd has not answered for 300 s, or once its height is more than 5 blocks below the highest header seen. A block fluxd keeps refusing is therefore retried, with a database restore each time, as fast as fluxd answers:

  • fluxd answering everything but that block, as it does for a block above its chain (-8 "Block height out of range"): 80–130 retries a second, until fluxd holds the block.
  • fluxd refusing every call (restarting): 115–150 a second, about 39,000 in all, until the sync check stops it after 5 minutes.

Fix

  • A block fluxd answers out of range (-8) is asked for again by the poller after POLL_INTERVAL_MS. The check sits at the getblock call, before anything is written for the block, so there is nothing to restore; a -8 raised later in the block goes to recovery.
  • Any other failure recovers after POLL_INTERVAL_MS, so a block fluxd keeps refusing is retried at the poll's pace (5 s in production).
  • recoverAndRestart counts each recovery it runs (explorer:recovery, read by the harness).
  • The daemon stub answers getblock above the asking node's chain with -8, as fluxd does, and passes a handler's RPC code through.
  • Harness suite 2268's setup waits for both standbys to hold the stale files before the primary deletes them, and reads the other standby's sequence once the directory is gone there and its folder is idle with nothing needed.

Verification

  • Unit, tests/unit/explorerService.test.js: a -8 from getblock returns the poll step with nothing written; another error returns the recovery step after POLL_INTERVAL_MS; a -8 raised after the block was fetched returns the recovery step.
  • Harness suite 4005:
    • fluxd refuses getblock for one node: between two of the node's reads of fluxd's height the explorer asks at most window / explorerPollIntervalMs + 1 times, then processes the block once fluxd gives it. Without the fix: getblock asked 485 times in 4993ms against a poll of 833ms.
    • the explorer's request for the next block is answered after fluxd's chain is taken back to the tip: the recovery count does not move, and the block is processed once fluxd holds it. Without the -8 branch: expected 10 to equal +0.
  • Harness suite 2268, with the other standby's syncthing traffic held until after the primary's rm: green with this setup; the setup that does not wait for both standbys fails test 2 with the stranded copy gone.
  • Full harness gate at 13f9deca97: 343 suites passed, 0 failed.

🤖 Generated with Claude Code

@Cabecinha84 Cabecinha84 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.

Must-fix (small):

  1. Delay the catch-branch poll. Replace the immediate pollForNewBlocks() with pollTimeout =
    setTimeout(pollForNewBlocks, POLL_INTERVAL_MS).
    • Today, if the cached isDaemonSynced().data.height is ever ahead of what getblock can serve, it loops poll →
      processBlock → -8 → poll with no wait and now no logging. That can happen after a daemon rollback or
      re-bootstrap.
    • I couldn't construct that case from code alone, so call it should-fix if you prefer, but it's a one-line change.
  2. Rebase onto development, dropping the bootstrap hunk.
  3. Put the new test inside the processBlock tests describe, where the stubs are in scope. A naive merge puts it in the
    "fluxnode address record" describe, where it fails with ReferenceError: daemonServiceMiscRpcsStub is not defined.
  4. Update the PR body and re-measure on the rebased head.

Non-blocking:

  • The -8 match covers the whole try. A -8 thrown after partial processInsight writes would skip the DB restore. A
    narrower check, such as blockHeight > syncStatus.data.height before the fetch, would avoid that.
  • The test only asserts that a log line is absent, so a bare return would also pass. Better to assert that the poller
    ran and no restore happened.
  • The recoverAndRestart hunk has no test.
  • The catch no longer logs the -8. That's fine, but a debug line would help diagnose if the delay is added.

@MorningLightMountain713
MorningLightMountain713 force-pushed the fix/explorer-waits-for-blocks branch from 62cf8bc to d31907e Compare November 18, 2026 13:54
@MorningLightMountain713 MorningLightMountain713 changed the title explorer: wait for a not-yet-connected block instead of spinning on out-of-range explorer: a failed block is retried at the poll's pace, and a block fluxd does not hold yet is waited for Nov 18, 2026
…ock fluxd does not hold yet is waited for

A block fluxd refuses was recovered from with no wait, and recovery asked
for it again with none, so the processor restored its database and
retried as fast as fluxd answered for as long as fluxd read as synced.
Recovery from a failed block now waits POLL_INTERVAL_MS. A block fluxd
answers out of range (-8) is asked for again by the poller, before
anything is written for it, with nothing restored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ace of the explorer's poll

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s chain as fluxd does

getblock by height above the node's chain answers -8 "Block height out of
range", and a handler's thrown RPC code reaches the caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a recovery

recoverAndRestart counts each recovery it runs (explorer:recovery).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ied it whole

Setup waits for both standbys to hold the stale files before the primary
deletes them, and reads the other standby's sequence only once the
directory is gone there and its folder is idle with nothing needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MorningLightMountain713
MorningLightMountain713 force-pushed the fix/explorer-waits-for-blocks branch from 0326c9b to 13f9dec Compare November 26, 2026 07:21
@MorningLightMountain713

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. The branch is rebased onto development, and the fix now sits in the explorer's step machine.

Must-fix

  1. Delay after a failed block. Done at both places a block can fail. A -8 from getblock returns to the poll after POLL_INTERVAL_MS; any other failure goes to recovery after POLL_INTERVAL_MS. Without it, a node asked getblock 485 times in 5 s while fluxd refused it; suite 4005 now holds it to at most one ask per poll.
  2. Rebase, drop the bootstrap hunk. Done. Development's bootstrap stops below fluxd's tip, so the hunk is gone.
  3. Test placement. The new tests are in processBlock tests (a block fluxd does not give).
  4. PR body and re-measure. The body is rewritten, and the full harness gate at the rebased head 13f9deca97 passed 343/343.

Non-blocking

  • Narrow the -8. The check wraps only the getblock fetch, before anything is written. A -8 raised later in the block goes to recovery and the database is restored; a unit test covers that case.
  • Assert the poller ran and no restore happened. The unit tests assert the returned step and that nothing was written. Suite 4005 asserts the recovery count does not move while fluxd lacks the block; with the -8 branch removed it fails with expected 10 to equal +0.
  • recoverAndRestart hunk untested. That hunk is gone. recoverAndRestart only gains the harness counter 4005 reads.
  • Debug line for the -8. Left out: while fluxd is behind it would log every 5 s for as long as the re-sync takes. Every other failure still logs as an error.

@Cabecinha84 Cabecinha84 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.

ACK (code) at head 13f9dec, reviewed against current development tip 218f72d (the PR sits directly on it; MERGEABLE). This supersedes my earlier CHANGES_REQUESTED from 11-03.

Prior findings, re-verified

  • Bootstrap hunk: gone.
  • Catch-branch spin: fixed at both exits. A -8 from getblock and any other failure each wait POLL_INTERVAL_MS, so poll -> block(h) -> -8 -> wait -> poll is one getblock per poll even if the cached sync height runs ahead of fluxd.
  • -8 scope: the check now wraps only the getVerboseBlock fetch, before anything is written. A -8 raised later goes to recovery with a DB restore, and a unit test covers it.
  • Test placement: now in processBlock tests. It asserts the returned step and waitMs, and suite 4005 asserts the recovery counter does not move.
  • PR body: rewritten and consistent with the diff.

Verified locally (scratch worktree at the head)

  • explorerService.test.js: 135 passing, 0 failing. ESLint clean on the changed JS files.
  • The 3 new unit tests fail with development's explorerService.js and pass with the PR's.
  • error.code does reach the check: getVerboseBlock throws blockInfo.data, which executeCall builds with the RPC code.
  • The stub's -8 applies only to numeric heights above the asking node's chain; hash lookups and callers with no source IP are unaffected.

Remaining, non-blocking

  • I did not rerun the harness. The author's 343/343 gate at this head applies directly to the merge result, but re-running 4005 and 2268 before merge would be ideal.
  • Release note: a non--8 block failure now waits 5 s before the DB restore and retry (before: immediate).
  • Nit: the -8 path logs nothing. Leaving it out to avoid 5 s log spam is reasonable.

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.

2 participants