lnworker: keep watchtower sync alive on invalid get_ctn replies - #10857
lnworker: keep watchtower sync alive on invalid get_ctn replies#10857rdymac wants to merge 1 commit into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Not sure who already sent you comments and where. Was that on Github? Or is it just your AI referring to comments you gave to it?
This is overkill. If the watchtower is deliberately trying to send a ctn that causes an exception, then there is no reason to catch this exception inside AND outside the loop; outside is sufficient. More generally, I am not convinced this PR is useful at all. If the watchtower has decided to be misbehaving, then it will crash The only reason to keep |
|
If switching to another watchtower while the session is running is not easy for the user to do, maybe this overkill is not needed for such edge case. |
| if type(watchtower_ctn) is not int or watchtower_ctn < 0: | ||
| self.logger.warning(f'watchtower get_ctn returned invalid ctn {watchtower_ctn!r} for {outpoint}') | ||
| return |
There was a problem hiding this comment.
You could keep only this part so users could do the change on the fly, remove the need to kill the app and start again to then change the watchtower in that new app run.
Summary
get_ctnfrom a remote watchtower (must be a non-negativeint) before feeding it torange()/assert ctn >= 0.while Truesync loop so one bad reply cannot kill watchtower updates for the rest of the session.A JSON-RPC
get_ctnresult was used unvalidated. A negative or non-int value (including HTTP non-200 returning an'Error: …'string) escaped the loop'sexcept aiohttp.ClientError. The coroutine is spawned once instart_network, so syncing then stopped for all channels until restart.Tests
Optional tests live on a separate branch, not in this PR: watchtower_invalid_ctn-test. Pull that if you want the unit tests as well.
Comments already received on the suggested fix
util.py:763already hasis_non_negative_integer, andlnworker.py:38already imports from.util.is_integeris justisinstance(val, int), so the helper acceptsTrue/False.type(watchtower_ctn) is not intrejects them. A watchtower answering JSONtruewould otherwise becomerange(2, n)silently treated as ctn=1.Suggested in-code comment:
python