Skip to content

Conversation

@Shradhesh71
Copy link
Contributor

Changes

Flat Key/Value Dump with Slot Tracking

  • Added account_update_slots: HashMap<Pubkey, Slot> field to SurfnetSvm to track when each account was last modified.
  • Updated set_account() method to record the modification slot for each account update.
  • Implemented export_accounts_as_fixtures() method that exports all accounts as a flat map with slot information.
  • Added AccountFixture struct with the following fields:
    • pubkey: Account public key
    • lamports: Account balance
    • owner: Program owner
    • executable: Executable flag
    • rent_epoch: Rent epoch
    • data: Account data (encoded based on specified encoding)
    • parsed_data: Optional parsed data (when using JsonParsed encoding)
    • slot: Absolute slot index when the account was last updated

RPC Method

  • Added surfnet_exportSnapshot RPC method to SurfnetCheatcodes trait.
  • Accepts optional encoding parameter (defaults to Base64).
  • Returns HashMap<String, AccountFixture> with all accounts.

Test Coverage

  • test_export_accounts_as_fixtures — Basic export with Base64 encoding
  • test_export_accounts_as_fixtures_with_json_parsed — Export with JsonParsed encoding for token accounts
  • test_export_accounts_at_different_slots — Verify slot tracking across multiple slot updates

/// A cheat code to export all accounts as fixtures for testing.
///
/// ## Parameters
/// - `meta`: Metadata passed with the request, such as the client's request context.
Copy link
Member

Choose a reason for hiding this comment

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

Apologies, this param meta being here is a copy-pasta in the first place, could you please get rid of it?
This docstring is meant to be documenting the RPC endpoint, not the rust method.

Copy link
Member

@lgalabru lgalabru left a comment

Choose a reason for hiding this comment

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

Love it, thank you @Shradhesh71 !
Some small feedback!

@Shradhesh71
Copy link
Contributor Author

@lgalabru Pushed updates addressing all feedback

@lgalabru
Copy link
Member

Thanks @Shradhesh71 ! Could you run the command

cargo +nightly fmt --all

on your machine? that should fix the CI!

I just added this button in the studio, looking forward to get this new cheat code in the next release :)

Screenshot 2025-10-15 at 06 39 35

Copy link
Member

@lgalabru lgalabru left a comment

Choose a reason for hiding this comment

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

Thanks so much for your contribution @Shradhesh71, the code looks good to me!

@lgalabru
Copy link
Member

hey @Shradhesh71! I talked with @MicaiahReid and it looks like your approach could be missing something. If a transaction is updating the state of an account, it looks like the current approach would not capture that.
Do you think you could look into this issue?

@Shradhesh71
Copy link
Contributor Author

hey @Shradhesh71! I talked with @MicaiahReid and it looks like your approach could be missing something. If a transaction is updating the state of an account, it looks like the current approach would not capture that. Do you think you could look into this issue?

yep, I’ll look into why transactions that update account state aren’t being captured, reproduce the case, and push a follow up here

@lgalabru
Copy link
Member

@Shradhesh71 we'd love to get this feature wrapped-up for our incoming release, would you have some bandwidth to take it to the finish line or would you like us to takeover?
Thanks again!!

@Shradhesh71
Copy link
Contributor Author

yeah, everything looks perfect now and is ready for incoming release

/// - `config`: An optional `ExportSnapshotConfig` to customize the export behavior. The config fields are:
/// - `includeParsedAccounts`: If true, includes parsed account data in the snapshot.
/// - `filter`: An optional filter config to limit which accounts are included in the snapshot. Fields include:
/// - `includeProgramAccounts`: A list of program IDs to include accounts for.
Copy link
Member

Choose a reason for hiding this comment

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

Copy pasta, this is a bool?
We know that at some point we'll differentiate local vs fetched, should we already introduce this distinction? It could be an enum instead - all (supported with this version), (remoteOnly to be supported)

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExportSnapshotFilter {
pub include_program_accounts: Option<bool>,
Copy link
Member

Choose a reason for hiding this comment

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

include_program_accounts or include_executable_accounts ?

Copy link
Member

Choose a reason for hiding this comment

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

include_executable_accounts doesn't cover it - a buffer account or a programdata account (which stores the bulk of program data) isn't executable, but it's a program account (owned by one of the bpf loader programs)

Copy link
Member

@lgalabru lgalabru left a comment

Choose a reason for hiding this comment

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

Looking great, added some no strongly opinionated feedback will leave it up to you!

@MicaiahReid MicaiahReid changed the title feat: Add surfnet_exportSnapshot RPC endpoint with slot tracking and IDL decoding feat: introduce the surfnet_exportSnapshot cheatcode Oct 22, 2025
@MicaiahReid MicaiahReid merged commit 01e1235 into txtx:main Oct 22, 2025
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.

3 participants