Connection Resolver
The Connection Resolver is a specialized library designed to facilitate the resolution of RPC connections for Solana blockchain requests. It dynamically determines the appropriate RPC client for processing requests based on the delegation status of the accounts involved. This is accomplished by maintaining an up-to-date record of account delegation statuses through real-time synchronization with the Solana base chain, achieved via WebSocket subscriptions or on-demand data retrieval.
Upon encountering a new account through the resolve* or
track_account functions, the Resolver fetches the account's
delegation status directly from the blockchain and initiates a
WebSocket subscription to capture subsequent updates. This ensures
that the Resolver reflects the most current state of the blockchain
(which acts as a single source of truth), enabling it to deliver the
appropriate RPC client for any request
involving a given account. This mechanism allows developers to
seamlessly direct transactions and requests to the correct endpoints,
thereby facilitating the interaction with the ephemeral rollups.
Basic Setup
To begin using the Connection Resolver, configure it with the necessary parameters including the base chain, websocket, and your routing table for validators:
use ;
use Resolver;
use ;
use Pubkey;
const DEVNET: &str = "https://api.devnet.solana.com/";
async
Tracking Account Delegation
To track an account's delegation status, use the track_account method. This will cache the delegation status and set up a WebSocket subscription for updates:
use Pubkey;
let pda = from_str.unwrap;
resolver.track_account.await?;
Note that, the utilization of this method is optional and only serves to decrease the latency of resolve* methods when they first encouter any given account.
Resolving Connection for a Single Account
You can resolve the appropriate RPC client for a specific account using its public key:
let client = resolver.resolve.await?;
println!;
Resolving Connection for a Transaction
The resolver can also determine the correct RPC endpoint for a transaction, ensuring all writable accounts are delegated consistently:
use Transaction;
use ;
let increment_instruction = new_with_bincode;
// no need to sign, as we don't have blockhash yet
let tx = new_with_payer;
// the client can be then used to fetch latest blockhash,
// sign and send the transaction to appropriate endpoint
let client = resolver.resolve_for_transaction.await?;
println!;