fusion44 / blitz_api

A management backend for the RaspiBlitz project written in Python / FastAPI
MIT License
19 stars 18 forks source link

Handle LND startup correctly #97

Closed fusion44 closed 2 years ago

fusion44 commented 2 years ago

On low power systems like RaspiBlitz it can take longer to start up LND. Refactor the startup sequence to take this properly into account.

LND message sequence on startup:

image

Possible solution: Add a _handle_lightning_ready function before checking for wallet locked. Each lightning implementation should have their own checking function.

fusion44 commented 2 years ago

During startup the API will try to connect to Bitcoin Core and the Lightning Node. If it can't connect it will check every n seconds (currently 2s) and connect when available. A new SSE event called "system_startup_info" is introduced. This event contains all startup status information during the startup procedure.

The old wallet_locked event is no more, thus the Frontend will require a bit of a modification to account for the changes. This is much more robust and future proof than the hack we had before.

known issues:

Event samples:

event: system_startup_info
data: {"bitcoin": "offline", "bitcoin_msg": "", "lightning": "offline", "lightning_msg": "Unable to connect to LND daemon, waiting..."}
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "offline", "lightning_msg": "Unable to connect to LND daemon, waiting..."}
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "locked", "lightning_msg": "Wallet locked, unlock it to enable full RPC access"}
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "done", "lightning_msg": ""}
event: system_startup_info
data: {"bitcoin": "done", "bitcoin_msg": "", "lightning": "bootstraping", "lightning_msg": "RPC not yet available"}