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

Calls inspect_account() on the fee payer #2718

Merged
merged 6 commits into from
Aug 31, 2024

Conversation

brooksprumo
Copy link

Problem

#2678 added a callback to inspect accounts prior to transaction processing. Unfortunately this did not include the fee payer, which is loaded separately.

Summary of Changes

Also inspect the fee payer.

@brooksprumo brooksprumo self-assigned this Aug 23, 2024
@brooksprumo brooksprumo marked this pull request as ready for review August 23, 2024 14:09
@brooksprumo
Copy link
Author

@HaoranYi - we missed this one earlier
@buffalojoec - you had reviewed the first PR, so wanted to include you on this one too
@jstarry - I asked you about where to put the call to inspect_account(), so wanted your review on the actual PR

HaoranYi
HaoranYi previously approved these changes Aug 23, 2024
Copy link

@HaoranYi HaoranYi left a comment

Choose a reason for hiding this comment

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

Ah. I missed this one. Looks like it is a recent refactoring that moved the fee accounts out of transaction account loading.

Good catch.

@brooksprumo brooksprumo requested a review from 2501babe August 23, 2024 17:34
2501babe
2501babe previously approved these changes Aug 23, 2024
buffalojoec
buffalojoec previously approved these changes Aug 23, 2024
Copy link

@jstarry jstarry left a comment

Choose a reason for hiding this comment

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

Are there any tests for this inspect account feature? We should have a test to ensure all writable accounts are now inspected after this bug fix.

svm/src/transaction_processor.rs Outdated Show resolved Hide resolved
@brooksprumo brooksprumo dismissed stale reviews from buffalojoec, 2501babe, and HaoranYi via f3efdd4 August 27, 2024 19:16
@brooksprumo
Copy link
Author

Are there any tests for this inspect account feature? We should have a test to ensure all writable accounts are now inspected after this bug fix.

Good call. I've added tests in f3efdd4.

@brooksprumo brooksprumo requested a review from jstarry August 27, 2024 20:30
Copy link

@jstarry jstarry left a comment

Choose a reason for hiding this comment

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

The new tests look great but I was actually hoping for a test that would have caught this bug at a higher level. Namely an integration test that tests that all accounts in a transaction were inspected. Actually it would be nice to have two integration tests.. one for a fully loaded transaction and one for a transaction which only validated the fee payer but is still able to be committed (named FeesOnlyTransaction)


let message = Message {
account_keys: vec![address0, address1, address2, address3],
header: MessageHeader::default(),
Copy link

Choose a reason for hiding this comment

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

So I guess this default header is causing all accounts to be loaded as writable because it means there are 0 signers and 0 readonly non-signers? And the program is loaded as readonly because it was demoted by demote_program_id? Do you mind adding comments describing this behavior?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I can add a comment. I'm not familiar with these specifics; why is that information germane to this test?

Copy link

Choose a reason for hiding this comment

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

Because it's important that account inspection correctly captures whether an account is loaded with a write lock, right?

Copy link
Author

Choose a reason for hiding this comment

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

I think no, not this test. This test only cares that the accounts are being inspected. The writability is assumed to be correct. (I imagine there are tests that are test this, yes?)

Copy link

Choose a reason for hiding this comment

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

Ok that seems reasonable to me

@HaoranYi
Copy link

Looking at the code, I think we might miss sysvar too.

@brooksprumo
Copy link
Author

Looking at the code, I think we might miss sysvar too.

inspect_account() will only "see" accounts loaded by transactions**. Any other account that is modified outside of transaction processing will need to be handled separately. For our lt hash work, yeah, we'll need to handle some extra stuff. For this PR, I don't think we need anything special, right?

**: we should see all the accounts in the transactions, right?

@HaoranYi
Copy link

Looking at the code, I think we might miss sysvar too.

inspect_account() will only "see" accounts loaded by transactions**. Any other account that is modified outside of transaction processing will need to be handled separately. For our lt hash work, yeah, we'll need to handle some extra stuff. For this PR, I don't think we need anything special, right?

**: we should see all the accounts in the transactions, right?

Yeah. we will handle them specially in lt-hash work. Feel free to ignore the comments. It is out the scope of this PR.

@brooksprumo
Copy link
Author

The new tests look great but I was actually hoping for a test that would have caught this bug at a higher level. Namely an integration test that tests that all accounts in a transaction were inspected.

Done! I've added an integration test in a401c5f.

Actually it would be nice to have two integration tests.. one for a fully loaded transaction and one for a transaction which only validated the fee payer but is still able to be committed (named FeesOnlyTransaction)

I'm not sure what this would be testing. Should the transaction not load the other accounts in the FeesOnlyTransaction case? If that's true, then I think it should be a test on load_transaction_accounts() then, and not inspect_accounts(). Wdyt?

@jstarry
Copy link

jstarry commented Aug 30, 2024

I'm not sure what this would be testing. Should the transaction not load the other accounts in the FeesOnlyTransaction case? If that's true, then I think it should be a test on load_transaction_accounts() then, and not inspect_accounts(). Wdyt?

Yeah I'm not really sure either. Maybe it can come later? I'm just thinking about how loading could bail halfway through and so some accounts would be recorded as inspected but others would not be. And in the end we will only be committing state changes for fee payer / nonce.

@@ -90,6 +93,19 @@ impl TransactionProcessingCallback for MockBankCallback {
.unwrap()
.insert(*program_id, account_data);
}

fn inspect_account(&self, address: &Pubkey, account_state: AccountState, is_writable: bool) {
Copy link

Choose a reason for hiding this comment

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

Do we want the mock to push read-only accounts here?

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking 'yes', but I guess doesn't need to. What would you prefer here?

Copy link

Choose a reason for hiding this comment

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

I don't have any preference, we can keep it as is

Comment on lines 526 to 863
// Ensure all the expected inspected accounts were inspected
let actual_inspected_accounts = mock_bank.inspected_accounts.read().unwrap().clone();
for (expected_pubkey, expected_account) in expected_inspected_accounts {
let actual_account = actual_inspected_accounts.get(&expected_pubkey).unwrap();
assert_eq!(
expected_account, *actual_account,
"pubkey: {expected_pubkey}",
);
}
Copy link

Choose a reason for hiding this comment

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

Should also assert that len of actual and expected accounts is the same. In your test, the actual inspected accounts includes extra read only accounts.

Copy link
Author

Choose a reason for hiding this comment

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

Good call. I've added a len check, and also added read-only accounts in 877a38c.

@brooksprumo
Copy link
Author

PR #2623 refactored the svm integration tests, so I need to rebase and rewrite the integration test in this PR.

@brooksprumo brooksprumo force-pushed the lthash/inspect-accounts branch from 877a38c to b19d98c Compare August 30, 2024 18:31
@brooksprumo brooksprumo merged commit 4659342 into anza-xyz:master Aug 31, 2024
40 checks passed
@brooksprumo brooksprumo deleted the lthash/inspect-accounts branch September 2, 2024 14:04
ray-kast pushed a commit to abklabs/agave that referenced this pull request Nov 27, 2024
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.

5 participants