-
Notifications
You must be signed in to change notification settings - Fork 913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small fixes: dual-funding #4295
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rounding change bothers me, because it directly inverts the implicit semantics. Should really push the decision down to the caller about which direction to round to.
""" | ||
return Decimal(self.millisatoshis) / 1000 | ||
return (Decimal(self.millisatoshis) + 999) // 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import math
Decimal(math.ceil(self.millisatoshi / 1000))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that we should just be rounding up or down on a whim, we need to keep the Millisatoshi
as precise as possible, and then let the final step in the computation specify whether we want to round up or down.
Any attempt to do so implicitly will likely cause issues because what might seem intuitive now, may not be when looked at from another side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo it's a mistake to return a non-rounded response from to_satoshi
-- a partial value satoshi isn't correct. Taking a millisatoshi to a satoshi should be the last step in any millisatoshi operations. If you wanted precision you'd have left it in Millisatoshi
format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the better solution here is to change the interface to accept an optional whole
argument.
e.g.
def to_satoshi(self, whole=False)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, however you're also inverting the semantics of the rounding of an existing API, which may break callers. Adding the whole
argument doesn't make it less breaking :-)
I was thinking more of deprecating to_satoshi
as is and then add floor()
and ceil()
methods to the Millisatoshi
class that returns the msat amount rounded in the desired direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if to_satoshi
returns a Decimal
we should not round internally at all, and defer the rounding to the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, modifying to_satoshi
is the wrong approach, especially given that it does return the Decmial
type.
Added a new method to_whole_satoshi
, which returns an int
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw I wasn't a hugely into adding a call to import math
, but if you think it's better than the inline math version I'd be happy to update/change it.
openingd/dualopend.c
Outdated
@@ -585,7 +585,13 @@ static char *check_balances(const tal_t *ctx, | |||
initiator_weight); | |||
|
|||
if (!amount_sat_greater_eq(accepter_diff, accepter_fee)) { | |||
return "accepter fee not covered"; | |||
return tal_fmt(ctx, "accepter fee %s not covered %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be clearer by showing the comparison directly:
"accepter fee not covered (need %s > have %s)"
d339e4b
to
0646ffa
Compare
0646ffa
to
b9d93bc
Compare
We need to use it for the 'df_accepter' plugin, so we get the feerate correct. Changelog-Added: pyln-client: `fundpsbt`/`utxopsbt` now support `min_witness_weight` param
Updated. |
A fractional satoshi value isn't really useful; rounding up loses precision but that's why you called "whole satoshi", wasn't it? Changelog-Changed: pyln-client: Millisatoshi has new method, `to_whole_satoshi`; *rounds value up* to the nearest whole satoshi
Makes things a bit cleaner elsewhere
We're the accepter, so we look up which inputs we need to sign and only sign those.
b9d93bc
to
5617305
Compare
ACK 5617305 |
A few small things found while testing the dual-funding pathways.