-
Notifications
You must be signed in to change notification settings - Fork 111
Add account access tracking to help debug missing accounts #241
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
base: master
Are you sure you want to change the base?
Add account access tracking to help debug missing accounts #241
Conversation
When testing programs with liteSVM, if a transaction fails with AccountNotFound, there's no way to know which account is missing. This is especially painful with programs that do CPI calls. Added optional .with_account_tracking(true) that tracks all account accesses during execution, including those made via CPI. The transaction result includes accessed_accounts field with all pubkeys that were accessed. - Added accessed_accounts field to TransactionMetadata - Tracks accesses in AccountsDb::get_account() when enabled - Disabled by default (zero overhead) - Works with both send_transaction and simulate_transaction - Added 8 comprehensive tests Fully backward compatible.
- Tracking now enabled immediately when .with_account_tracking(true) is called - Added public get_accessed_accounts() method for manual retrieval - Useful for debugging setup failures (program loading, etc) - Added test for manual retrieval - Updated README with setup failure example - All 9 tests passing
|
I think the logging already covers this? If replace |
Good catch on the logging! You're right that The main use case I ran into was with CPI calls. When my program calls another program and that fails with a generic For example, if I call a program that internally accesses a PDA or oracle account I didn't know about, the log might just say "Program failed" but tracking shows me The other benefit is programmatic access - I can do That said, if you think this is too niche or overlaps too much with logging, I totally understand. Just wanted to share the use case that led me to build it. |
here is an example for what im using |
Problem
When testing programs with liteSVM, if a transaction fails with
AccountNotFound, there's no way to know which account is missing. You just have to guess or read through program source code to figure it out.This is especially painful with programs that do CPI calls - the called program might access PDAs, oracles, or config accounts that you didn't know it needed.
Solution
Added optional account tracking. When you enable it with
.with_account_tracking(true), the transaction result includes all the accounts that were accessed.Now you can see exactly which accounts are missing instead of guessing.
Important: This tracks ALL account accesses, including those made by programs called via CPI. If Program A calls Program B, and Program B tries to access an account, it shows up in the list. This is the most useful part - you can see what accounts nested program calls need without reading their source code.
Implementation
accessed_accounts: Option<Vec<Pubkey>>field toTransactionMetadataAccountsDb::get_account()when enabledsend_transactionandsimulate_transactionget_accessed_accounts()method for manual retrieval (useful for debugging setup failures)Backward compatible - existing code doesn't need to change.
Tests
Added 9 tests covering the various cases (default disabled, enabled, missing accounts, simulations, manual retrieval, etc). All passing.