Commit graph

63 commits

Author SHA1 Message Date
fusion44
d694f8498a
refactor(api): handle warmup fetch errors explicitly in _handle (#245)
Some checks failed
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
The warmup consumer already avoids the old .dict()-on-HTTPException crash,
but HTTPException/Err results fell through the 'unknown data type' arm,
double-logging and mislabelling known errors. Give them explicit match
arms: HTTPException logs at info (the real error is already logged in
_convert_warmup_exceptions) and Err forwards report.format() instead of
its repr. Error event payload is unchanged ({"error": <string>}).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 19:13:56 +02:00
fusion44
6b29239cc0
refactor(api): hoist api_startup_status into a shared leaf module
Move the in-process startup-state singleton out of app.main into
app.api.startup_status so app.system can read it without a circular
import. No behavior change - main mutates the same shared object.

Also lands the design spec and implementation plan for the
system/health endpoint work (#145).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 18:41:18 +02:00
fusion44
6b4f3abc20
feat(api): normalize all error responses to the ErrorMessage shape
Route HTTPException (app- and framework-raised), RequestValidationError
and uncaught exceptions through build_error_response so every error body
is {detail, error_code, report?, trace?}. Fixes the bare-string body that
string HTTPException details produced, and registers the handler on the
Starlette base HTTPException so framework 404/405/415 also carry the full
envelope.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 18:41:18 +02:00
fusion44
5089925c88
feat(api): serve realtime updates over /ws WebSocket
Replace the /sse/subscribe endpoint with a /ws WebSocket endpoint backed
by ws_mgr, and port the warmup helper (_send_sse_event -> _send_ws_event,
SSE -> Event, broadcast_sse_msg -> broadcast_msg). Also fixes two tests
left over from the prior SSE->Event/broadcast_msg rename that still
referenced the old names and were failing collection/execution.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 18:41:18 +02:00
fusion44
868457ffa5
fix(api): replace deprecated asyncio.get_event_loop()
get_event_loop() is deprecated on Python 3.11+ when there is no running
loop and is slated to change behaviour further.

- SSEManager.setup() ran at import time (app.api.utils) via
  get_event_loop(); this only worked because uvicorn imports the app
  inside its loop and would break when imported without a running loop
  (e.g. a Celery worker). Start the broadcast consumer lazily from
  within a running loop instead.
- everywhere else the pattern was get_event_loop().create_task(x)
  inside a coroutine; replace with asyncio.create_task(x).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 22:34:44 +02:00
fusion44
49d5fcb9bf
fix: send bitcoin-only warmup app status as app_state_update_message
The WebUI only listens for the app_state_update_message SSE event to
populate the Apps tab. In bitcoin-only mode the warmup data was sent
under installed_app_status, which no client listens to, so the Apps
tab was stuck on the loading screen whenever the app status cache was
warm. Installing LND made it work again because the lightning warmup
path already used the correct event (raspiblitz#3608, raspiblitz#5141).

Also hardens the warmup path:
- reset the warmup_running flag on errors so a single failure no
  longer starves all future SSE clients of warmup data
- convert per-source exceptions in the bitcoin-only warmup gather
  instead of discarding the whole data set
- don't fall through to the partial-data branches when the API is
  fully initialized with lightning disabled
- remove the now-unused INSTALLED_APP_STATUS event and the dead
  cached_status_raw variable

Adds regression tests plus a conftest.py providing test env defaults
so the suite runs without a developer .env file.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 15:30:17 +02:00
fusion44
07d2bfbc76
feat: update Python and Devenv deps
- Updated all dependencies to their latest versions
- Vendored fastapi-plugins[redis] as it looks unmaintained
2026-02-03 11:04:41 +01:00
fusion44
bda5d565ee fix: don't stop app status listener 2025-05-06 09:16:46 +02:00
fusion44
4e038e8fc7 feat: fetch app status via a celery task
This is a feature that allows to fetch the app status via a celery
task which stores the result in the Redis database and notifies the API
of the change. The API sends a notification to connected clients via the
SSE mechanism.

Using a background task allows to avoid crashing the whole API if the
script call fails.

The by default the cache is refreshed every 30 minutes. This can be
changed by setting the `BAPI_APP_STATUS_UPDATE_INTERVAL_MIN` environment
variable.

refs #123
2025-05-06 09:16:46 +02:00
fusion44
691d5da6b9 feat: update formatting of errors sent to clients
refs #123
2025-05-06 09:16:46 +02:00
fusion44
25e4be8441 feat: make config loading more flexible
If the environment variable BAPI_ENV_PATH is set, the config system will
try to read configs from the given path instead of .env in pwd

If no file is found .env in pwd will be used as a fallback

Env variables will always override settings in .env files.
2025-03-23 17:43:39 +01:00
fusion44
803587180e fix: result array index access 2024-10-06 14:18:01 +02:00
Christoph Stenglein
cf4ab3963c remove ln_info_lite 2024-10-06 14:18:01 +02:00
Christoph Stenglein
408f432133 fix: send installed_app_status correctly for bitcoin only nodes 2024-10-06 11:42:00 +02:00
fusion44
9d589a19d7
feat: improve error handling warmup data gathering
refs #245
2024-02-25 09:52:17 +01:00
fusion44
b7e9ae29fb
fix: adapt code to recent dependeny upgrades 2024-02-24 15:30:32 +01:00
fusion44
699bcaa912
fix: remove versioning and fix a linter warnings
The versioning package was incompatible with the latest FastAPI updates
2024-02-22 20:43:15 +01:00
fusion44
d0d1380eea
feat: implement remote debugging on a remote machine (#207)
closes #206 

* feat: implement remote debugging on a RaspiBlitz
* docs: reverse the prep steps
* fix: ruff line length warning
2023-06-25 08:01:43 +02:00
fusion44
adf472ac8b feat: implement Ruff as a linter; fix given errors 2023-06-25 07:17:00 +02:00
pre-commit-ci[bot]
3d1dfd919c
[pre-commit.ci] pre-commit autoupdate (#187)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-02-11 13:47:34 +01:00
fusion44
bd06a3cc6f
feat: improve logging by using loguru package 2022-12-18 20:55:31 +01:00
fusion44
b0226dab01
fix: crash when ln node type is an empty string
fixes #169
2022-12-01 18:51:03 +01:00
fusion44
cebbdfb0d1
fix: BOOTSTRAPPING_AFTER_UNLOCK event handling
fixes #166
2022-11-26 14:03:52 +01:00
Christoph Stenglein
2053f0ea3b
remove some unused imports, send correct message on warmup 2022-10-22 14:17:13 +02:00
fusion44
3ce6c1e549
refactor: port changes from #152 2022-10-22 11:08:54 +02:00
fusion44
fe65568f55
Revert "chore: merge changes from main"
This reverts commit e3f0350c72, reversing
changes made to a448dbda8d.
2022-10-19 21:32:47 +02:00
fusion44
e3f0350c72
chore: merge changes from main 2022-10-19 21:19:43 +02:00
fusion44
beba4332e7
fix: null access crash when no token was supplied
fixes #158
2022-10-18 19:54:14 +02:00
fusion44
4393132d1c
fix: properly check token on sse requests 2022-10-17 22:11:17 +02:00
Christoph Stenglein
32c7c4a23c
feat: allow cookie & JWT auth for sse/subscribe (#152)
* return cookie on login and check cookie in sse/subscribe

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* allow cookie & JWT auth for sse/subscribe

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* return token object on login to preserve compatibility

* remove unused import

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-16 21:58:23 +02:00
fusion44
ba453e7bdb
refactor: switch to domain driven directory layout 2022-10-03 20:22:00 +02:00
fusion44
e1d5e23db7
refactor: setup implementation decoupling 2022-10-03 19:04:44 +02:00
fusion44
52edecd0c9
refactor: app implementation decoupling 2022-09-10 22:14:37 +02:00
fusion44
6098c70eee
refactor: send_sse_message to broadcast_sse_msg 2022-09-10 15:52:11 +02:00
fusion44
69d8032900
refactor: sse code into dedicated SSEManager class 2022-09-10 15:48:03 +02:00
fusion44
49bdbab66d
refactor: use a Queue instead of Redis for SSE
refs #60
2022-09-10 13:53:09 +02:00
fusion44
f282e3af8d
fix: add missing imports 2022-07-25 18:07:35 +02:00
fusion44
f940551409
feat: add JWT token auth to SSE endpoint 2022-07-24 21:26:29 +02:00
/rootzoll
67a9242301
fix bitcoin-only Warumup info (#114) 2022-06-16 15:30:14 +02:00
/rootzoll
cb71b26431
fix setup block (#113) 2022-06-14 14:44:55 +02:00
fusion44
c08e604d55
feat: send warmup data as available
When neither BTC nor LN is running:
send hardware_info

When BTC is running and LN is not:
send hardware_info and btc_info

When both are running:
send the full package

This code doesn't keep track of which connection has received
which data already, so it may send data twice data to the client
when the startup state changes. Especially the hardware info
is rather data intensive. This is OK for now, to keep the code simple.

closes #110
2022-06-12 07:59:40 +02:00
fusion44
eb87b0501b
refactor: send warmup data to SSE clients
refs #97
2022-06-10 19:45:55 +02:00
fusion44
4f33bdfc79
fix: send a disabled msg when ln_node is "none"
refs #97
2022-06-08 20:39:12 +02:00
fusion44
493d8039fa
refactor: improve startup procedure
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 obsolete.

Sample:
--------------------------
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"}
--------------------------

refs #97
2022-06-06 19:29:21 +02:00
fusion44
887d44be44
chores: remove unused health messages; Fix typos
closes remove confusing "health" message in system_info #95
2022-06-04 14:46:03 +02:00
/rootzoll
ce7f82c106
Installapps (#78)
Adding functionallity for setup & installing additional apps ... run with the latest raspiblitz dev scripts.
2022-05-05 13:27:59 +02:00
fusion44
85d2de19e4
chore: fix some naming issues 2022-03-23 21:03:50 +01:00
fusion44
b1dc854dd2
refactor: use app.utils.redis_get() everywhere 2022-03-19 12:36:03 +01:00
fusion44
9665d694b7
feat: check defer starting LN and Bitcoin handlers
This really applies only to RaspiBlitz. Depending on the current
setup step there still isn't a Bitcoin Deamon or Lightning Node running.
We must defer the registration of all those handlers until later when
everything is properly setup.

Since there is a final reboot after the setup there is no need to
check in the background whether setup is finished. The API server
is restartet anyway.

refs #71
2022-03-19 09:29:09 +01:00
Stefan Stammberger
927bffa701
fix: add fee data to SSE warmup package 2022-01-22 20:47:28 +01:00