Skip to content

Conversation

serejke
Copy link
Contributor

@serejke serejke commented Oct 13, 2025

The getMultipleAccounts RPC endpoint was returning accounts in incorrect order when mixing local and remote results. The bug was in the underlying get_multiple_accounts_local_then_remote method, which was appending all found accounts first, then all remote accounts, breaking the original request order.

Root cause:

  • get_multiple_accounts_local_then_remote split results into found/missing arrays
  • Combined results as [all_found, all_remote] instead of preserving original order
  • Example: requesting [pk1, pk2, pk3] with pk2 missing would return [pk1, pk3, pk2]

Changes:

  • Renamed get_multiple_accounts_local_then_remote → get_multiple_accounts_with_remote_fallback
  • Fixed order preservation by explicitly iterating through original pubkeys array
  • Optimized to avoid cloning accounts: only clone remote results, move found accounts
  • Simplified RPC handler by removing HashMap workaround (no longer needed)
  • Updated documentation to clarify order preservation guarantee

Implementation:

  • Build remote_map only for missing accounts
  • Zip through (pubkeys, local_results) to merge in correct order
  • Early return path when all found locally now has zero clones

This fixes the issue at the source, benefiting all callers of the method, and ensures the response array matches the request array order exactly as required by the Solana RPC specification.

…back

The getMultipleAccounts RPC endpoint was returning accounts in incorrect order
when mixing local and remote results. The bug was in the underlying
get_multiple_accounts_local_then_remote method, which was appending all found
accounts first, then all remote accounts, breaking the original request order.

Root cause:
- get_multiple_accounts_local_then_remote split results into found/missing arrays
- Combined results as [all_found, all_remote] instead of preserving original order
- Example: requesting [pk1, pk2, pk3] with pk2 missing would return [pk1, pk3, pk2]

Changes:
- Renamed get_multiple_accounts_local_then_remote → get_multiple_accounts_with_remote_fallback
- Fixed order preservation by explicitly iterating through original pubkeys array
- Optimized to avoid cloning accounts: only clone remote results, move found accounts
- Simplified RPC handler by removing HashMap workaround (no longer needed)
- Updated documentation to clarify order preservation guarantee

Implementation:
- Build remote_map only for missing accounts
- Zip through (pubkeys, local_results) to merge in correct order
- Early return path when all found locally now has zero clones

This fixes the issue at the source, benefiting all callers of the method,
and ensures the response array matches the request array order exactly as
required by the Solana RPC specification.
@serejke
Copy link
Contributor Author

serejke commented Oct 13, 2025

Alternative to #366

Copy link
Member

@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.

Dude @serejke, this is awesome! Fixed a bug while improving performance AND included tests. 🏆

Thanks!

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 @serejke!

@lgalabru lgalabru merged commit 4c2049a into txtx:main Oct 16, 2025
3 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.

3 participants