Skip to content

feat(svm): add patch_raw in set_account#404

Merged
MicaiahReid merged 20 commits intosolana-foundation:mainfrom
aspnxdd:feat/patch-set-account-mutation
Apr 10, 2026
Merged

feat(svm): add patch_raw in set_account#404
MicaiahReid merged 20 commits intosolana-foundation:mainfrom
aspnxdd:feat/patch-set-account-mutation

Conversation

@aspnxdd
Copy link
Copy Markdown
Contributor

@aspnxdd aspnxdd commented Mar 30, 2026

Closes #401

Note: This is one of two PRs that together address #401. Splitting into separate branches makes each change easier to review in isolation.

Overview

This PR adds support for raw byte-level patching of account data during the setup_surfnet set_account setup phase. This allows precise, typed mutations to specific offsets within an account's data; useful when you need to update fields like public keys or numeric values at known byte positions.

Example Usage

action "setup_surfnet" "svm::setup_surfnet" {
  set_account {
    public_key = "3BznENHP5KkRikLZqCLGLTaVGcDBsWDTLjSCbHZD2qTA"
    patch_raw = [
      {
        offset      = 8
        length      = 32
        field_value = "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
        field_type  = "pubkey"
      },
      {
        offset      = 7960
        length      = 32
        field_value = "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
        field_type  = "pubkey"
      },
      {
        offset      = 7936
        length      = 8
        field_value = 5
        field_type  = "u64"
      }
    ]
  }
}

Changes

New type: SET_ACCOUNT_PATCH_RAW (addons/svm/types/src/lib.rs)

  • Defines a patch descriptor with offset, length, field_value, and field_type fields
  • Enables granular, typed mutations at arbitrary byte offsets within account data
  • Supported field_type values include pubkey, u64, and others (see known limitation below)

Extended type: SET_ACCOUNT_MAP

  • Added an optional patch_raw field accepting an array of SET_ACCOUNT_PATCH_RAW objects
  • Multiple patches can be applied to a single account in one update

Updated: SetupSurfpool command

  • Pre-fetches existing account data when patch_raw is present, providing the required context for mutations
  • Passes fetched data to SurfpoolAccountUpdate::parse_value_store so patches are applied correctly

Known Limitation

The typing of field_value is currently loose: it accepts a String, Int, Bytes, Pubkey, etc., but this is not yet well-reflected in the documentation or type definitions. A follow-up issue should be opened to tighten the type signature and improve the developer experience here.

How to test it:

I tested it/played around it outside of rust tests, using surfpool: Please view this branch of my surfpool fork to see how I used it. In this branch I use a Meteora DLMM account and I switch some data, then I later see it on a TS script:

Copy link
Copy Markdown
Collaborator

@MicaiahReid MicaiahReid left a comment

Choose a reason for hiding this comment

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

This is so awesome!! Love this. This is a really well-written PR.

I've left a few comments, I also have a preference on syntax, for consistency with other actions. Instead of an array:

action "setup_surfnet" "svm::setup_surfnet" {
  set_account {
    public_key = "3BznENHP5KkRikLZqCLGLTaVGcDBsWDTLjSCbHZD2qTA"
    patch_raw = [
      {
        offset      = 8
        length      = 32
        field_value = "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
        field_type  = "pubkey"
      },
      ...
    ]
  }
}

a map type:

action "setup_surfnet" "svm::setup_surfnet" {
  set_account {
    public_key = "3BznENHP5KkRikLZqCLGLTaVGcDBsWDTLjSCbHZD2qTA"
    patch_raw {
        offset      = 8
        length      = 32
        field_value = "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
        field_type  = "pubkey"
      }
      patch_raw {
        offset      = 7960
        length      = 32
        field_value = "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
        field_type  = "pubkey"
      }
     ...
  }
}

It's the same result, but a slightly cleaner and more "HCL" interface (IMO).

Also! Thoughts on just value / type instead of field_value & field_type?

Comment thread addons/svm/core/src/commands/setup_surfnet/set_account.rs Outdated
Comment thread addons/svm/core/src/commands/setup_surfnet/set_account.rs
Comment thread addons/svm/core/src/commands/setup_surfnet/set_account.rs Outdated
@aspnxdd aspnxdd requested a review from MicaiahReid April 2, 2026 21:07
Copy link
Copy Markdown
Collaborator

@MicaiahReid MicaiahReid left a comment

Choose a reason for hiding this comment

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

LFG, awesome stuff, thanks @aspnxdd!

@MicaiahReid MicaiahReid merged commit f8eb9dc into solana-foundation:main Apr 10, 2026
2 checks passed
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.

SVM: Feature - On-the-Fly Account Mutation

2 participants