From eaee585f169cb905fa47cfbc1e421548ad737e63 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Thu, 5 Mar 2020 19:38:11 +0100 Subject: [PATCH] drain: fix zero division edge cases --- drain/drain.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drain/drain.py b/drain/drain.py index a7f3d95..6d14ff6 100755 --- a/drain/drain.py +++ b/drain/drain.py @@ -135,6 +135,8 @@ def test_or_set_chunks(plugin, payload, my_id): amount = spendable if cmd == "fill" and amount > receivable: amount = receivable + if amount == Millisatoshi(0): + raise RpcError(payload['command'], payload, {'message': 'Cannot detect required chunks to perform operation. Amount would be 0msat.'}) # get all spendable/receivables for our channels channels = {} @@ -356,6 +358,8 @@ def execute(payload: dict): spendable, receivable = spendable_from_scid(plugin, payload) total = spendable + receivable amount = total * 0.01 * payload['percentage'] / payload['chunks'] + if amount == Millisatoshi(0): + raise RpcError(payload['command'], payload, {'message': 'Cannot process chunk. Amount would be 0msat.'}) # if capacity exceeds, limit amount to full or empty channel if payload['command'] == "drain" and amount > spendable: