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

simplify bank drop calls#24142

Merged
HaoranYi merged 21 commits intosolana-labs:masterfrom
HaoranYi:simplify_drop
Apr 14, 2022
Merged

simplify bank drop calls#24142
HaoranYi merged 21 commits intosolana-labs:masterfrom
HaoranYi:simplify_drop

Conversation

@HaoranYi
Copy link
Copy Markdown
Contributor

@HaoranYi HaoranYi commented Apr 6, 2022

Problem

The extra parameter, is_from_abs in purge_slot function is only used for assert. It seems unnecessary. Furthermore, it is also a bit confusing since caller from block_store also set it to true.

is_bank_drop_callback_enabled flag seems also unnecessary since the call back is an Option. Besides, this flag is set in a callback create function, which seems not to be the right place. The right place should be at the caller, which installed the drop callback to the root bank.

Summary of Changes

simplify the bank drop calls.

Fixes #

@brooksprumo
Copy link
Copy Markdown
Contributor

Some quick comments; I still need to review more carefully.

Furthermore, it is also a bit confusing since caller from block_store also set it to true.

Yes, it's confusingly named currently. This code path was just recently changed to fix #23976 in PR #23999. So is_abs is the legacy name, and could use an update. The concept is still correct as far as I can tell though.

Besides, this flag is set in a callback create function, which seems not to be the right place. The right place should be at the caller, which installed the drop callback to the root bank.

I agree that setting the is_bank_drop_callback_enabled is not correct. I made this PR up to fix it: #23970. There are conflicts because PR #23999 got merged and I intended to resolve & update my PR.

Comment thread runtime/src/bank.rs
@HaoranYi
Copy link
Copy Markdown
Contributor Author

HaoranYi commented Apr 6, 2022

My reading of the code is that - it seems that is_from_abs and is_bank_drop_callback_enabled is only used to panic.
The only place that is_from_abs is set to false is here https://github.com/solana-labs/solana/pull/24142/files#r844202353, which we already checked for the existence of the callback.
Therefore, we don't need is_from_abs and is_bank_drop_callback_enabled any more. Likely, this is from the legacy code and with recent changes, now these are no longer needed.

Copy link
Copy Markdown
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

Ok, I'm on board with this change now. I think it's now safe since #23999 sets the bank drop callback on load, before any new banks are created or any bank refs are passed out.

I had some nits below, but otherwise looks good. Once the changes are in and the CI passes coverage, please re-request a review. Thanks!

Comment thread runtime/src/accounts.rs Outdated
Comment on lines 1159 to 1163
/// Purge a slot if it is not a root
/// Root slots cannot be purged
/// `is_from_abs` is true if the caller is the AccountsBackgroundService
pub fn purge_slot(&self, slot: Slot, bank_id: BankId, is_from_abs: bool) {
self.accounts_db.purge_slot(slot, bank_id, is_from_abs);
pub fn purge_slot(&self, slot: Slot, bank_id: BankId) {
self.accounts_db.purge_slot(slot, bank_id);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just remove this whole function. I'll mark the caller next.

Comment thread ledger/src/blockstore_processor.rs Outdated
Comment thread runtime/src/accounts_background_service.rs Outdated
Comment thread runtime/src/accounts_db.rs Outdated

/// This should only be called after the `Bank::drop()` runs in bank.rs, See BANK_DROP_SAFETY
/// comment below for more explanation.
/// `is_from_abs` is true if the caller is the AccountsBackgroundService
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Please remove this comment now that is_from_abs has been removed.

Comment thread runtime/src/bank.rs
Comment thread runtime/src/bank.rs Outdated
HaoranYi and others added 5 commits April 7, 2022 11:42
Co-authored-by: Brooks Prumo <brooks@prumo.org>
Co-authored-by: Brooks Prumo <brooks@prumo.org>
Co-authored-by: Brooks Prumo <brooks@prumo.org>
@HaoranYi HaoranYi requested a review from brooksprumo April 7, 2022 19:38
brooksprumo
brooksprumo previously approved these changes Apr 7, 2022
Copy link
Copy Markdown
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

This looks good to me. I think it'd probably be worthwhile to have another person approve as well; to make sure I didn't miss anything.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2022

Codecov Report

Merging #24142 (aa6a105) into master (2da4e3e) will decrease coverage by 0.1%.
The diff coverage is 80.5%.

@@            Coverage Diff            @@
##           master   #24142     +/-   ##
=========================================
- Coverage    81.8%    81.6%   -0.2%     
=========================================
  Files         581      590      +9     
  Lines      158312   160999   +2687     
=========================================
+ Hits       129518   131469   +1951     
- Misses      28794    29530    +736     

@HaoranYi
Copy link
Copy Markdown
Contributor Author

HaoranYi commented Apr 7, 2022

@carllin @jeffwashington Can you help to review this? Thanks!

@jeffwashington
Copy link
Copy Markdown
Contributor

@carllin I think this needs to be you.

@carllin
Copy link
Copy Markdown
Contributor

carllin commented Apr 7, 2022

The flag serves a few purposes I think which are still useful:

  1. Documenting that the function needs to be serialized with all the other background account processes
  2. Forcing anybody calling this code to reason about whether their function is always serialized with said background processes
  3. If in step 2, the developer makes a mistake in their reasoning, the code will panic instead of silently corrupting the state. For instance, this was useful to catch that this code:
    .purge_slot(self.slot(), self.bank_id(), false);
    could run concurrently with ABS on startup

That being said, the is_abs flag could maybe be more clearly renamed to is_serialized_with_abs to better convey its purpose

@HaoranYi
Copy link
Copy Markdown
Contributor Author

HaoranYi commented Apr 7, 2022

OK. Close the pull request. Let's leave the code as it is.

@HaoranYi HaoranYi closed this Apr 7, 2022
@HaoranYi HaoranYi reopened this Apr 8, 2022
@HaoranYi
Copy link
Copy Markdown
Contributor Author

HaoranYi commented Apr 8, 2022

Reopen the pull request for more discussion.

Ideally, the check shouldn't be on the purge_slot fn. It should be inside the drop_callback.
I can imagine that we add a bool flag into the bank to indicates that we are 'dropping' then have the drop_callback to assert that flag. However, this is difficult because we can't change the bank struct. I wonder if there is any unused fields in the bank that can be repurposed for using as the "dropping" flag.

Or maybe we could use the msb the bank_id to indicates that we are dropping (659af56)? This will limit that the range of bank_id will only be 63bit.

@mergify mergify Bot dismissed brooksprumo’s stale review April 8, 2022 16:18

Pull request has been modified.

@brooksprumo
Copy link
Copy Markdown
Contributor

However, this is difficult because we can't change the bank struct.

Why can't we change the Bank struct?

@HaoranYi
Copy link
Copy Markdown
Contributor Author

HaoranYi commented Apr 8, 2022

/// Manager for the state of all accounts and programs after processing its entries.

In the comments, it is saying that serialization/deserialization are implemented elsewhere. I assume that Bank is embedded in some other serialized struct?

@carllin
Copy link
Copy Markdown
Contributor

carllin commented Apr 8, 2022

Ideally, the check shouldn't be on the purge_slot fn. It should be inside the drop_callback.
I can imagine that we add a bool flag into the bank to indicates that we are 'dropping' then have the drop_callback to assert that flag.

I think it makes sense to leave the flag in the purge_slot() function because that's the exact function that needs to be serialized with ABS

From my comment above: #24142 (comment), one of the purposes is Forcing anybody calling this code to reason about whether their function is always serialized with said background processes, which can only be enforced if the flag is in purge_slot(). It may not be guaranteed that the only caller of purge_slot() is Bank::drop() in the future

@HaoranYi
Copy link
Copy Markdown
Contributor Author

HaoranYi commented Apr 8, 2022

what do you mean by always serialized with said background processes?

@carllin
Copy link
Copy Markdown
Contributor

carllin commented Apr 8, 2022

It means that the purge_slot() function and all the clean+shrink+flush cache functions in AccountsBackgroundService cannot run concurrently, they must run in a serial fashion

@HaoranYi
Copy link
Copy Markdown
Contributor Author

Ok. Added back the bool param for fn purge_slot. Rename is to is_serialized_with_abs for clarity.

carllin
carllin previously approved these changes Apr 13, 2022
@mergify mergify Bot dismissed carllin’s stale review April 13, 2022 18:31

Pull request has been modified.

@HaoranYi HaoranYi merged commit e3ef074 into solana-labs:master Apr 14, 2022
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
* simplify bank drop calls

* clippy: import

* Update ledger/src/blockstore_processor.rs

Co-authored-by: Brooks Prumo <brooks@prumo.org>

* Update runtime/src/accounts_background_service.rs

Co-authored-by: Brooks Prumo <brooks@prumo.org>

* Update runtime/src/bank.rs

Co-authored-by: Brooks Prumo <brooks@prumo.org>

* cleanup

* format

* use msb of bank_id to indicates that we are dropping

* clippy

* restore bank id

* clippy

* revert is-serialized_with_abs flag

* assert

* clippy

* whitespace

* fix bank drop callback check

* more fix

* remove msb dropping implementation

* fix

Co-authored-by: Brooks Prumo <brooks@prumo.org>
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 30, 2022
* simplify bank drop calls

* clippy: import

* Update ledger/src/blockstore_processor.rs

Co-authored-by: Brooks Prumo <brooks@prumo.org>

* Update runtime/src/accounts_background_service.rs

Co-authored-by: Brooks Prumo <brooks@prumo.org>

* Update runtime/src/bank.rs

Co-authored-by: Brooks Prumo <brooks@prumo.org>

* cleanup

* format

* use msb of bank_id to indicates that we are dropping

* clippy

* restore bank id

* clippy

* revert is-serialized_with_abs flag

* assert

* clippy

* whitespace

* fix bank drop callback check

* more fix

* remove msb dropping implementation

* fix

Co-authored-by: Brooks Prumo <brooks@prumo.org>
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.

4 participants