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

refactor: stake withdraw logic #3468

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jstarry
Copy link

@jstarry jstarry commented Nov 4, 2024

Problem

The stake withdraw logic is hard to follow

Summary of Changes

No functional changes or error variants should change as a result of this change.

  • eccb68d straightforward logical refactor
  • cebea2f pull out full withdrawal special case and check it first. Note that if lamports == stake_account.get_lamports(), then it's impossible for checked_add(lamports, reserve)? to fail
  • 84a5994 straightforward logical refactor

Fixes #

Copy link

mergify bot commented Nov 4, 2024

The Firedancer team maintains a line-for-line reimplementation of the
native programs, and until native programs are moved to BPF, those
implementations must exactly match their Agave counterparts.
If this PR represents a change to a native program implementation (not
tests), please include a reviewer from the Firedancer team. And please
keep refactors to a minimum.

@jstarry jstarry requested a review from 2501babe November 4, 2024 21:50
@jstarry jstarry requested a review from lheeger-jump November 5, 2024 16:11
@jstarry
Copy link
Author

jstarry commented Nov 5, 2024

@lheeger-jump can someone from your team review this change please? It's not that important to merge if you feel strongly against it but this refactoring makes the behavior and error cases for stake withdraws a lot clearer.

@jstarry
Copy link
Author

jstarry commented Nov 5, 2024

Note that if lamports == stake_account.get_lamports(), then it's impossible for checked_add(lamports, reserve)? to fail

And to elaborate on the above note from the PR description. The reason this is impossible is because it's not possible in the SVM to even temporarily give an account near u64::MAX lamports because the runtime does lamport accounting checks before and after every instruction boundary which prohibit creating lamports out of thin air.

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