Skip to content
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

Merged
merged 6 commits into from
Jan 5, 2021

Conversation

niftynei
Copy link
Collaborator

A few small things found while testing the dual-funding pathways.

Copy link
Member

@cdecker cdecker left a 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
Copy link
Member

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))

Copy link
Member

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.

Copy link
Collaborator Author

@niftynei niftynei Dec 22, 2020

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.

Copy link
Collaborator Author

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)

Copy link
Member

@cdecker cdecker Dec 23, 2020

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.

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

@@ -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",
Copy link
Member

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)"

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
@niftynei
Copy link
Collaborator Author

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.
@cdecker
Copy link
Member

cdecker commented Jan 5, 2021

ACK 5617305

@cdecker cdecker merged commit 0c90722 into ElementsProject:master Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants