Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Set account to default if the balance reaches 0 in a checkpoint bank #1932

Merged
merged 1 commit into from
Nov 27, 2018

Conversation

pgarg66
Copy link
Contributor

@pgarg66 pgarg66 commented Nov 27, 2018

Problem

Checkpoint'ed bank doesn't drop the account when the balance reaches 0. It updates the balance to 0, and retains the account. However, it also retains the program assignments and userdata for the account, consuming RAM and resources.

Summary of Changes

When the balance drop to 0, replace the account with Account::default()

Fixes #1931


let account = bank.get_account(&alice.pubkey()).unwrap();
let default_account = Account::default();
assert_eq!(account.tokens, default_account.tokens);
Copy link
Contributor

Choose a reason for hiding this comment

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

these assertions should also apply to a brand new bank, too, right?

can you compare bank.get_account() and Default::default() directly, instead of comparing each field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, assertions should apply to fresh bank accounts.
I tried comparing get_account() to default(). It's not implemented.

Copy link
Contributor

@rob-solana rob-solana left a comment

Choose a reason for hiding this comment

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

nits, otherwise, yay!

@pgarg66 pgarg66 merged commit 8947c5a into solana-labs:master Nov 27, 2018
@pgarg66 pgarg66 deleted the enclave branch November 27, 2018 22:17
@rob-solana
Copy link
Contributor

I was hoping you'd add a pre-condition, that asking for an account in an un-checkpointed Bank gives you exactly the same answers (though maybe that's captured in another test)

@pgarg66
Copy link
Contributor Author

pgarg66 commented Nov 28, 2018

Sorry, I'll push a new change with the additional checks.

@pgarg66
Copy link
Contributor Author

pgarg66 commented Nov 28, 2018

#1943

vkomenda pushed a commit to vkomenda/solana that referenced this pull request Aug 29, 2021
)

Bumps [@solana/web3.js](https://github.com/solana-labs/solana-web3.js) from 1.16.1 to 1.18.0.
- [Release notes](https://github.com/solana-labs/solana-web3.js/releases)
- [Changelog](https://github.com/solana-labs/solana-web3.js/blob/master/.releaserc.json)
- [Commits](solana-foundation/solana-web3.js@v1.16.1...v1.18.0)

---
updated-dependencies:
- dependency-name: "@solana/web3.js"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants