mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-30 07:37:39 +00:00
With reset_reserved_balance_on_startup (default true) every boot called reset_all_reserved_balances, which marked every active ReservationRelease released and set every ApiKey.reserved_balance to 0. A second process on the same database (a replica, a rolling deploy, a one-off container started against the live DB) therefore released the reservations of requests the running process was still serving. Those requests were then served unbilled (release is terminal, so the finalizer cannot charge), and the reserved funds became spendable again while the request ran. The setting is persisted in each node's settings row on first boot, so changing its default would not reach existing nodes. Instead the startup step now runs the lease-guarded sweep the background task already uses (release_stale_reservations with stale_reservation_timeout_seconds): in-flight reservations, whose leases the heartbeat renews, survive; a reservation whose lease expired is released and only its own msats are subtracted from its keys' reserved_balance. reset_all_reserved_balances had no other caller and is removed. Trade-off: after a crash, the dead process's reservations are released once their lease expires (up to stale_reservation_timeout_seconds, 300 s by default) instead of at boot, the same delay a client disconnect already gets.