Off-Chain Accounts Resolution for Transaction Creation
Summary
This RFC proposes a solution for collecting all the Accounts needed for a Solana transaction before the transaction is sent to the network. By introducing a new field to the Anchor IDL called invocations
and providing a mechanism to insert accounts directly from an on-chain account, we aim to enable clients to resolve all required accounts for a transaction with a single round-trip call to RPC operators for on-chain information.
Goals
- Enable clients to resolve all required accounts for a transaction using a single round-trip call to RPC operators.
- Provide a deterministic account ordering during transaction creation, allowing programs on-chain to unpack accounts deterministically.
Background
Currently, Solana transactions require all accounts used during execution to be passed in when the transaction is created by the client. Programs can expose information about how to deserialize and serialize their state information and program instructions through their IDL (interface description language).
Proposed Implementation
We propose adding a new field to each instruction
description in the Anchor IDL called invocations
. This field is an ordered array of program address, instruction data, and accounts. Clients can then recursively traverse this list to determine the accounts each invoked program needs to complete execution.
Anchor IDL with invocations
field
{
"name": "transfer",
"accounts": [...],
"args": [...],
"invocations": [
{
"program_address": "pubkey",
"instruction_data": "data",
"accounts": [...]
},
...
]
}
To handle cases where accounts have to be hardcoded, we should provide a mechanism that allows clients to insert accounts into a transaction directly from an on-chain account. This can be helpful but may also present a potential vector for crafting malicious transactions.
With these two tools, it should be possible to symbolically define the invocations
ordered list so that clients can determine the full list of accounts that a program uses in a single RPC call. The full symbolic language will need further specification and design, focusing on conditionals based on instruction data and account names.
Example IDL Instruction for NFT Program’s “transfer”
{
"name": "transfer",
"accounts": [
...
],
"args": [
...
],
"invocations": [
{
"program_address": "pubkey",
"instruction_data": "data",
"accounts": [...]
},
...
]
}
By implementing the proposed solution, we aim to improve the process of resolving accounts required for a Solana transaction and ensure deterministic ordering for unpacking accounts by programs on-chain.
Implementation
TBD