romanz / electrs

An efficient re-implementation of Electrum Server in Rust
MIT License
1.02k stars 373 forks source link

Bug: Failure when bitcoind has not yet loaded mempool #1040

Open haarp opened 1 month ago

haarp commented 1 month ago

Describe the bug Hello!

bitcoind can take a LONG time to load the mempool after a start. This can take several hours (especially on HDDs it seems) (corroborated here). This is evident by Progress loading mempool transactions from disk: 10% messages (after bitcoin/bitcoin#29227).

In this state, bitcoind will answer getmempoolinfo with loaded: false.

electrs is close to unusable in this state and log things like mempool sync failed: batch getmempoolentry/getrawtransaction request failed: transport error: Couldn't connect to host: Resource temporarily unavailable (os error 11). Clients will be unable to connect, and fail in very mysterious ways (unless Electrum's verbose logs are enabled and closely looked at)

electrs will eventually give up/time out and quit. If however mempool becomes available before electrs quits, it'll keep running but complain about a LOT of missing mempool entry that it couldn't load up to this point.

Electrs version git as of 74b868c6e

To Reproduce Steps to reproduce the behavior:

  1. Restart bitcoind and electrs shortly after
  2. Try to connect with clients
  3. Wait
  4. See error

Expected behavior If it's not possible to gracefully work around the lack of mempool (e.g. by checking getmempoolinfo and not trying if it's unavailable yet), electrs should refuse to start until the mempool is loaded. Kind of how it also refuses to start until IBD is done. This would prevent many of the weird problems related to this.

Configuration Nothing special

Electrum client Electrum 4.5.4

Thanks!

romanz commented 1 month ago

Good idea - thanks for reporting the issue and suggesting a solution :)