Warn when bitcoind has not whitelisted electrs#1291
Closed
PeterXMR wants to merge 1 commit into
Closed
Conversation
If electrs is not whitelisted with `download` permission, bitcoind silently ignores its `getheaders` messages during IBD and may disconnect it when `maxuploadtarget` is reached, leading to opaque sync failures. After the p2p handshake, query `getpeerinfo`, locate electrs's own peer entry by matching the local socket address, and `warn!` if the `permissions` array does not contain `"download"`, suggesting `whitelist=download@127.0.0.1` in bitcoin.conf. Detection failures (RPC error, no matching peer, missing field) are logged at `debug!` only and never affect startup. Closes romanz#400
Owner
|
#1252 will fetch blocks using REST API instead of p2p. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #400.
If electrs is not granted the
downloadpermission by bitcoind,getheadersis silently ignored during IBD and the connection can be dropped oncemaxuploadtargetis reached — both leading to opaque sync failures (see #399 for the original report).This change makes electrs detect that condition at startup and emit a single clear warning, modeled on NBXplorer's behavior (referenced in the issue thread):
How it works
After the p2p version handshake completes, electrs calls
getpeerinfo, finds its own peer entry by matchingaddragainst the local socket address, and checks whether thepermissionsarray contains"download". Any failure mode (RPC error, no matching peer, missing field, address mismatch) is logged atdebug!only and never affects startup.The parsing logic is factored into a pure
check_whitelist_status(peers, local_addr)helper for unit testing.Scope
Detection + warning only. The "ideally fall back to RPC" half of the original ask is out of scope here — that design space is already explored in #1274 (ZMQ+REST) and #1252 (bindex), so a third design in this PR would conflict.
Test plan
check_whitelist_status(download present/absent, no matching peer, missingpermissionsfield, IPv4-mapped-IPv6 normalization, outbound-peer skip, multi-peer, empty list)cargo test --lib— 29/29 passcargo clippy --all-targets -- -D warnings— cleancargo fmt --check— cleanwhitelist=download@127.0.0.1→ no warning, startup proceeds normallygetpeerinfo[].addrmatches electrs'slocal_addrbyte-for-byte (127.0.0.1:<ephemeral>) andpermissions: ["download"]when whitelisted