mirror of
https://github.com/aljazceru/plugins.git
synced 2026-01-10 00:34:23 +01:00
drain: fix Millisatoshi from float bug
This was compatible in the past but pyln changed and doing e.g. `10000msat * 0.01 * percentage` became unreliable on rounding errors.
This commit is contained in:
committed by
Christian Decker
parent
9ee7006de2
commit
7ae25feb1f
@@ -140,7 +140,7 @@ def test_or_set_chunks(plugin, payload):
|
||||
cmd = payload['command']
|
||||
spendable, receivable = spendable_from_scid(plugin, payload)
|
||||
total = spendable + receivable
|
||||
amount = total * 0.01 * payload['percentage']
|
||||
amount = Millisatoshi(int(int(total) * (0.01 * payload['percentage'])))
|
||||
|
||||
# if capacity exceeds, limit amount to full or empty channel
|
||||
if cmd == "drain" and amount > spendable:
|
||||
@@ -345,7 +345,7 @@ def read_params(command: str, scid: str, percentage: float,
|
||||
if command == 'setbalance':
|
||||
spendable, receivable = spendable_from_scid(plugin, payload)
|
||||
total = spendable + receivable
|
||||
target = total * 0.01 * payload['percentage']
|
||||
target = Millisatoshi(int(int(total) * (0.01 * payload['percentage'])))
|
||||
if target == spendable:
|
||||
raise RpcError(payload['command'], payload, {'message': 'target already reached, nothing to do.'})
|
||||
if spendable > target:
|
||||
@@ -373,7 +373,7 @@ def execute(payload: dict):
|
||||
# as fees from previous chunks affect reserves
|
||||
spendable, receivable = spendable_from_scid(plugin, payload)
|
||||
total = spendable + receivable
|
||||
amount = total * 0.01 * payload['percentage'] / payload['chunks']
|
||||
amount = Millisatoshi(int(int(total) * (0.01 * payload['percentage'] / payload['chunks'])))
|
||||
if amount == Millisatoshi(0):
|
||||
raise RpcError(payload['command'], payload, {'message': 'Cannot process chunk. Amount would be 0msat.'})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user