5

For example, the getProgramAccounts RPC method allows one to query accounts. There are two parameters in particular which I think could be useful here:

  • program-id
  • memcap, which refers to a byte predicate in the account data

A validator can index accounts on program-id, but I am not aware of any way to index accounts on memcap using any validator parameter or RPC provider.

Is there any way an RPC node can maintain an index of accounts per a certain query?

3
  • You seem to have asked the same question twice?
    – trent.sol
    Commented Jul 25, 2022 at 5:13
  • @trent.sol I ask about two different capabilities, as applied to the same problem. The capabilities are relevant to a partially disjoint set of problems. I believe yamen's answer, while great here, would not be particularly relevant to my former question.
    – agrippa
    Commented Jul 27, 2022 at 20:09
  • Hello, I think this question is better suited to: solana.meta.stackexchange.com
    – MmmHmm
    Commented Jul 28, 2022 at 16:47

2 Answers 2

8

There is neither an 'on chain' or a 'native in validator' way to do this.

Due to the underlying nature of how data is stored on Solana - as key-value pairs - anything that requires high performance query based on the value will need a reverse index of some sort.

As you've mentioned, the validator lets you build a few specific reverse indexes (program id -> accounts, token mint -> accounts, token account owner -> accounts), but these are a fixed list and are held in memory (much slower node startup).

The accepted methods for building custom indices for your own use cases are:

  1. Build a Geyser plugin that can be run 'embedded' on validators or RPCs, which can subscribe inline to new transactions / accounts / blocks, and write to an external store in any manner you like. See https://docs.solana.com/developing/plugins/geyser-plugins

  2. Use the RPC to download and process finalized blocks to achieve the same.

In both cases, high availability and idempotency will need to be architected at the application level (make sure you run on enough nodes, use backend stores that are resilient, deal with duplicate processing of same block etc).

There are two 'external provider' options I'm aware of, and probably others too:

0

It appears that Holaplex has built a Geyser plugin for this. https://github.com/holaplex/indexer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.