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

fix: add back rights conservation invariant check #1891

Closed
wants to merge 2 commits into from

Conversation

katelynsills
Copy link
Contributor

Here's a version of the lexical-balance PR that retains the rights conservation invariant check. I think we might be able to improve the signature of reallocate further.

@Chris-Hibbert
Copy link
Contributor

This is still legible, but it doesn't seem like an improvement to me.

I like converting reallocate's parameter from a record to separate parameters.

Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @katelynsills and @Chris-Hibbert that the new reallocate should have positional rather than named parameters.

Aside from that, I think this delta PR moves in the wrong direction. To make an easy-to-inspect-for invariant more likely to be upheld under maintenance, it restores code that was harder to understand. But I do agree that I should draw attention to the multiple locations in the code that must be coordinated to uphold the invariant. I'll add comments to do so and ask for another round of review.

Comment on lines 109 to 110
reallocate([srcPayment], undefined, currentBalance, newPurseBalance);
currentBalance = newPurseBalance;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see we are thinking along similar lines. I went through a draft like that as well. I rejected it because reallocate is no longer conserving the rights by itself. It requires the following assignment. reallocate is now only checking that the rights would be conserved if followed by that assignment.

The previous idea we both thought about --- having reallocate return the balance --- also has the same problem. Rights are only actually conserved if that assignment happens. But this problem only jumped out at me with the pattern you show here.

Comment on lines 118 to 124
const [payment] = reallocate(
undefined,
[amount],
currentBalance,
newPurseBalance,
);
currentBalance = newPurseBalance;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here of course.

Base automatically changed from lexical-balance to master October 22, 2020 02:09
@katelynsills katelynsills deleted the rights-conservation-check branch October 22, 2020 18:57
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.

3 participants