Skip to content

electrs: 0.11.0 -> 0.12.0 - #137

Merged
prusnak merged 6 commits into
masterfrom
electrs/0.12
Oct 24, 2026
Merged

prusnak merged 6 commits into
masterfrom
electrs/0.12

Conversation

@seberm

@seberm seberm commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Blocked by:


Two commits: electrs: 0.11.0 -> 0.12.0 and
electrs: refuse to start on an index of electrs < 0.12.

What changes

electrs 0.12.0 switched to bindex:

  • Reindex required: a few hours up to about a day, depending on the hardware. The
    final index is ~7% of blocks/*.dat, up to ~14% during the sync. Meanwhile electrs,
    and mempool if it uses electrs, answers with incomplete history and balances. See
    "Old index" below.
  • Bitcoin Core 31+ required: bindex uses the /rest/blockpart endpoint. An
    eval-time assertion on nix-bitcoin.pkgs.bitcoind fails evaluation for an older
    Core ("electrs requires Bitcoin Core 31 or later."), e.g. with
    useVersionLockedPkgs = false.
  • Reads blocks through bitcoind's REST interface: the module enables
    services.bitcoind.rest.enable. REST is unauthenticated: if rpc.allowip has
    non-local sources, evaluation fails unless rest.allowNonLocal is set, which means
    accepting unauthenticated REST for those sources. Raw rpcallowip/includeconf in
    extraConfig need rest.allowUncheckedConfig. The versioning entry and docs say so.
  • --daemon-p2p-addr was removed upstream, so electrs no longer enables bitcoind's
    whitelisted p2p listener (btcpayserver still enables it for itself).
  • pkgs/pinned.nix is regenerated by helper/update-flake.sh, which moves electrs to
    unstable (the pin update held it on stable by hand until this lands).
  • Docs: "Upgrading to config version 0.1.3" (steps, disk, downtime, REST) and rest=1
    on the other node when using a remote bitcoind.

Old index: manual reindex, no crash loop

electrs 0.12.0 doesn't convert or delete the old index, which uses the same path
(<dataDir>/bitcoin, or regtest). On it, bindex panics with Unsupported DB format (0 < 1) - please reindex!, and with Restart=on-failure the unit would restart every
10 s.

The reindex stays manual: it takes up to a day on a big node, so the operator picks
the moment, and nothing deletes user data from a start script. A 0.1.3 versioning entry
gives the steps: systemctl stop electrs, rm -r <dataDir>/<network>, then deploy.

If the old index is still there, the unit fails once with a clear message instead of
crash-looping:

  • A marker <dataDir>/<network>.bindex identifies a 0.12 index. It is written when
    electrs starts and no index directory exists yet (fresh install, or after the rm -r).
  • If the index directory exists without the marker, the start wrapper prints the reindex
    steps and exits with status 78, which RestartPreventExitStatus excludes from
    restarts. Nothing is deleted.
  • The check runs in the main process (a wrapper that execs electrs), not in
    preStart: a failing ExecStartPre still triggers Restart=on-failure, and
    RestartPreventExitStatus only applies to the main process.

Tests

  • The regtest test now waits until electrs has indexed all blocks (0.12 serves requests
    while it is still indexing) and queries the history of the address that mined the
    regtest blocks over the Electrum protocol. That exercises bindex's REST block fetches
    end to end.
  • The electrs test removes the marker and checks that the unit ends failed (not
    auto-restarting) with exit status 78 and the reindex message, then restores the marker
    and checks that electrs starts again.
  • electrs now enables REST in all CI scenarios, so the "REST disabled ⇒ 404" path of the
    bitcoind-rest test only runs in scenarios without electrs (e.g. lndPruned).

On the current head: -s electrs and netnsRegtest passed locally, nix flake check
passed.

@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix area: packages pkgs/ and flake pins labels Oct 23, 2026

@ostermayer ostermayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I ran the adversarial review on this branch at f1e0944: DeepSeek V4.1 Flash 1017 and GLM 5.3, both at max thinking, with GPT-6 Astra at xhigh reasoning as the second opinion. In the electrs commit they found only the point you already settled in #135, that rest.enable = true turns on an unauthenticated interface on bitcoind's RPC listener for every source in rpc.allowip, which Astra rated informational. Everything else they flagged is master code that open issues already track. I also read the commit by hand and have three notes, none blocking.

  1. The versioning entry says REST is enabled automatically, but users who have a non-local source in rpc.allowip will hit the #135 assertion at evaluation and be told to set rest.allowNonLocal. It would help to say that in the entry, so they understand they're accepting unauthenticated REST for that source rather than just silencing an error.

  2. On manual versus automatic: I'd keep it manual, because the index is a day of work on a big node and the operator should pick the moment, but the crash loop is avoidable. A preStart check that recognises the old index (a directory that exists while a .bindex style marker doesn't) and exits with the same message as the versioning entry gives a single clear failure in the journal instead of a restart every 10 s, and it still deletes nothing. Writing the marker after the first successful 0.12 start keeps the check cheap.

  3. Dropping listenWhitelisted is right for electrs, and btcpayserver sets it for itself, so nothing else loses the whitelisted P2P port. The versionAtLeast 31 assertion makes electrs plus Knots a hard stop, which the entry explains, so that's fine as long as the release notes repeat it.

The scripthash test is a good addition, and bitcoin-cli as root works through the -datadir wrapper like the existing calls.

@seberm
seberm requested a review from ostermayer October 23, 2026 18:31
@seberm seberm added breaking Changes existing user config; needs a versioning.nix entry type: maintenance No user-visible change: refactor, CI, deps, tooling, docs-only labels Oct 23, 2026
@seberm
seberm marked this pull request as ready for review October 23, 2026 19:36
@seberm

seberm commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Rebased onto master (after #125) and addressed all three:

  1. The versioning entry and docs now say that setting rest.allowNonLocal means those sources can read blocks, transactions, the UTXO set and the mempool without authentication. They also cover rest.allowUncheckedConfig for raw rpcallowip/includeconf in extraConfig.

  2. Kept manual, and nothing is deleted. Three differences from your suggestion:

    • The check runs in the main process, not preStart. A failing ExecStartPre still triggers Restart=on-failure, and RestartPreventExitStatus only applies to the main process. A wrapper does the check, then execs electrs. On an old index it prints the reindex steps and exits 78, which is excluded from restarts: one failure, unit stays failed.
    • The marker <dataDir>/<network>.bindex is written just before the first start, when no index directory exists yet, rather than after the first successful start. Any directory that appears after that is a 0.12 index, and if electrs dies before creating it, the next start writes the marker again.
    • The runtime message gives the same steps as the versioning entry (stop, rm -r, start) and links the docs section. It isn't the same text, because the entry's "delete before deploying" wording doesn't fit a unit that already runs the new config.

    The electrs VM test covers it: no marker → exit 78, failed, no restart; marker restored → electrs starts.

  3. Agreed. The 0.1.2 release notes will repeat that electrs no longer works with Knots.

@prusnak

prusnak commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Maybe we should just drop bitcoind-knots from bitcoinix first (with proper documentation and versioning.nix entry) and afterwards merge this. That way we save lot of explaning that electrs does not work with bitcoind-knots.

@seberm

seberm commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Maybe we should just drop bitcoind-knots from bitcoinix first (with proper documentation and versioning.nix entry) and afterwards merge this. That way we save lot of explaning that electrs does not work with bitcoind-knots.

I completely agree with the removal.

BTW:


Let's release v0.1.2 now without this PR, and ship it in v0.1.3.

master already has security updates (Core Lightning, Node.js, BTCPay Server, RTL, Go) that users should get soon. This PR forces a full electrs reindex, which can take up to a day, so users should be able to take those fixes without it.

After v0.1.2 is tagged, I'll rebase this PR and move its versioning entry, the docs section and configVersion in the examples from 0.1.2 to 0.1.3. Please don't merge it before then.


Agree?

@seberm seberm added the status: blocked Cannot proceed until something else lands label Oct 23, 2026
@prusnak

prusnak commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Let's release v0.1.2 now without this PR, and ship it in v0.1.3.

Agreed

@ostermayer ostermayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rechecked the rebased head c6d5c00. All three notes from my first review are addressed, and I read the wrapper and the new test.

Three things from the second pass, none blocking:

  1. modules/electrs.nix: the wrapper has no set -e, so a failing touch of the marker still reaches exec. If electrs then builds its index, the next start rejects it as pre-0.12. touch '${bindexMarker}' || exit 1 closes it.

  2. The marker outlives a rollback. If 0.12 writes the marker but dies before it creates the database, and the operator rolls back to 0.11, which then builds an old index, the next upgrade trusts the marker and skips the guard, so electrs fails on the old format and restarts every 10 s. That is rare enough to document rather than fix, but a line in the versioning message would help: if you roll back after the first 0.12 start, remove the marker too.

  3. The versioning entry says electrs is unavailable while it reindexes. In 0.12 src/server.rs binds the Electrum listener before the sync loop and handles requests between sync batches, so clients connect and get incomplete history and balances until indexing finishes. "Answers are incomplete until indexing finishes" is the safer warning, and the same sentence in docs/configuration.md.

GLM 5.3 run at max reasoning reviewed the rebased head and found nothing in the files this PR changes. The DeepSeek V4.1 Flash 1017 run timed out without a verdict. Codex (GPT-6 Astra, xhigh) read the diff against master and raised the three points above, which I checked against the code and against electrs 0.12's server.rs.

@seberm

seberm commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Hello @ostermayer , thanks for the second pass review!

Three things from the second pass, none blocking:

Could you please prepare patches/fixups for these? That would be very helpful. No need to open a PR - just push them somewhere and I'll cherry-pick them here.

@ostermayer

Copy link
Copy Markdown
Collaborator

Pushed the three fixups to ostermayer/bitcoinix, branch fixups/pr-137, on top of c6d5c00. One commit per note so you can pick what you want:

  • e34b338 electrs: stop the wrapper when the marker can't be written
  • 8e09adc electrs: say that answers are incomplete during the 0.12 reindex
  • af6f69b electrs: tell operators to remove the 0.12 marker after a rollback

The first adds || exit 1 after the touch, so a failed touch restarts the unit instead of letting electrs build an index that the next start rejects. The other two only change text in modules/versioning.nix and docs/configuration.md. Both modules parse and Codex (GPT-6 Astra, xhigh) read the diff and found nothing.

@bobberb

bobberb commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

On electrs being in nixos unstable already, and whether bitcoinix is on stable:

  • bitcoinix runs on stable (nixos-26.05) and pulls some packages from nixpkgs-unstable.
  • helper/update-flake.sh takes a package from stable when both versions match and from unstable when they differ.
  • In the current flake.lock, electrs is 0.11.0 on stable and 0.12.0 on unstable.
  • This PR moves electrs to unstable in pkgs/pinned.nix, which is that rule's normal output. The pin update in flake: update pins for the clightning, Node.js, BTCPay and Go security releases #125 had kept electrs on stable by hand.
  • bitcoind is 31.1 in both, so electrs 0.12's need for Core 31 or later is met.
  • bitcoind-knots is 29.x in both (29.3 / 29.4.2), so electrs doesn't work with Knots either way. The PR's evaluation check catches that.
  • The question still open is the suggestion above to remove Knots before merging this PR.

@bobberb

bobberb commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

+1 vote to remove knots

@ostermayer

Copy link
Copy Markdown
Collaborator

I agree with dropping bitcoind-knots first. electrs 0.12 needs Core 31 and the REST interface, so a Knots option that only works without electrs would need a warning in every place that mentions it. A versioning.nix entry that tells Knots users to switch the package back to bitcoind is enough.

@seberm seberm removed the status: blocked Cannot proceed until something else lands label Oct 24, 2026
seberm and others added 6 commits October 24, 2026 18:57
electrs 0.12.0 switched to bindex: it reads blocks through bitcoind's
REST interface, requires Bitcoin Core 31+ and removed
`--daemon-p2p-addr`. Enable `services.bitcoind.rest.enable`, drop the
p2p address and the whitelisted p2p listener, and assert the bitcoind
version (bitcoind-knots 29.x lacks the `/rest/blockpart` endpoint).

The new index format requires a full reindex. electrs 0.12.0 doesn't
convert or delete the old index, which uses the same path, and fails at
startup until it is removed, so add a versioning entry with the manual
steps.

pinned.nix is regenerated by helper/update-flake.sh.

In the regtest test, wait until electrs has indexed all blocks and look
up the history of the address that mined them.

Assisted-by: Claude Code (Claude Opus 5.5)
electrs 0.12 can't read the index of earlier versions, which uses the
same path, and exits at startup until it is removed. With
Restart=on-failure, the unit then restarts every 10 s.

Mark a 0.12 index with a file next to it, created when electrs starts
without an index. When an index exists without the marker, exit with a
dedicated status that is excluded from restarts and print the reindex
steps. Nothing is deleted: the operator picks the moment for the
reindex.

Do the check in the main process: RestartPreventExitStatus doesn't
apply to a failing ExecStartPre.

Assisted-by: Claude Code (Claude Opus 5.5)
0.1.2 was released without electrs 0.12, so its versioning entry, the
refusal message and the upgrade notes move to 0.1.3, next to the Knots
removal. Knots is gone, so the notes no longer mention it.

Assisted-by: Claude Code (claude-opus-5-5)
@seberm

seberm commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author
  • Rebased onto master after @prusnak's Knots removal in bitcoind: remove Knots and package selection #145. The Core 31+ check now reads nix-bitcoin.pkgs.bitcoind, since services.bitcoind.package is gone, and the PR no longer mentions Knots.
  • The versioning entry, the refusal message and the upgrade notes now target 0.1.3. The notes are in the same docs section as the Knots removal.

@prusnak, feel free to take another look. I think it's ready for merge. Thanks!

@prusnak
prusnak merged commit b7ebfdc into master Oct 24, 2026
9 checks passed
@prusnak
prusnak deleted the electrs/0.12 branch October 24, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix area: packages pkgs/ and flake pins breaking Changes existing user config; needs a versioning.nix entry type: maintenance No user-visible change: refactor, CI, deps, tooling, docs-only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants