solana-labs / solana

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
https://solanalabs.com
Apache License 2.0
13.18k stars 4.27k forks source link

Allow multiple disjoint slices of account data when fetching account data using `dataSlice` #32100

Closed steveluscher closed 2 months ago

steveluscher commented 1 year ago

Problem

You can use an API like getAccountInfo to fetch only a slice of account data by supplying a dataSlice param. If you want to fetch disjoint slices of account data, you have to make multiple RPC calls.

Originally suggested by @jarry-xiao.

Proposed Solution

Update the dataSlice parameter to take an array of {length: number, offset: number}. Return an array of encoded data slices, in the same order.

Example:


// getAccountInfo('...', {dataSlice: [{length: 123, offset: 0}, {length: 456, offset: 1024}]})
{
  "jsonrpc": "2.0",
  "result": { /* ... */ },
    "value": {
      "data": [
        [
"11116bv5nS2h3y12kD1yUKeMZvGcKLSjQgX6BeV7u1FrjeJcKfsHRTPuR3oZ1EioKtYGiYxpxMG5vpbZLsbcBYBEmZZcMKaSoGx9JZeAuWf",
"fsHZvGcKLSjQgoKtYGiYxpxRTPuR3oZ1EiKaSoGx9JZeAuWf11116bv5nS2h3y12kD1yUKeMMG5vpbZLsbcBYBEmZZcMX6BeV7u1FrjeJcK",
        ]
        "base58"
      ],
       /* ... */ 
    }
  },
  "id":  /* ... */ 
}
steveluscher commented 1 year ago

cc/ @Lichtso, @alessandrod somewhat related to the stuff you were talking about today regarding partial account loading.