Skip to content

Bug fixes for Orleans Bank Account sample. #7019

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Rossimac
Copy link

Balance now updates after Deposit or Withdraw operations.

Withdraw decrements now instead of incorrectly incrementing.

Balance now updates after Deposit or Withdraw operations.

Withdraw decrements now instead of incorrectly incrementing.
@oising
Copy link

oising commented May 8, 2025

Removing the immutability of the Balance class sets a bad precedent for this sample. The idea of immutability is to prevent the class of bugs where grain A makes a change to a instance, then sends it to grain B -- on the same silo -- and then makes another change to the instance, which, because it's a reference/byref, will change the instance in grain B also.

@@ -34,7 +34,7 @@ public Task Withdraw(int amount) =>
$" This account has {balance.Value} credits.");
}

return balance with { Value = balance.Value + amount };
balance = balance.Value -= amount;
Copy link
Member

Choose a reason for hiding this comment

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

The balance = part here is unnecessary - the balance variable goes out of scope immediately after this statement

@ReubenBond
Copy link
Member

@oising I believe this is the correct change, due to how the transactions API works: The delegate passed to PerformUpdate receives a copy of state and it's expected to mutate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants