Skip to content

Commit 3861284

Browse files
authored
fix: revisit config schema, remove rpc client from state (#71)
1 parent 7ddb86a commit 3861284

File tree

19 files changed

+391
-381
lines changed

19 files changed

+391
-381
lines changed

Cargo.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace.package]
2-
version = "0.1.13"
2+
version = "0.1.14"
33
edition = "2021"
44
description = "Surfpool is the best place to train before surfing Solana."
55
license = "Apache-2.0"
@@ -11,7 +11,7 @@ categories = ["cryptography"]
1111
[workspace]
1212
members = [
1313
"crates/cli",
14-
"crates/core",
14+
"crates/core",
1515
"crates/gql",
1616
"crates/subgraph",
1717
"crates/types"

crates/cli/src/cli/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ impl StartSimnet {
208208
RpcConfig {
209209
bind_host: self.network_host.clone(),
210210
bind_port: self.simnet_port,
211-
remote_rpc_url,
212211
}
213212
}
214213

@@ -244,7 +243,7 @@ impl StartSimnet {
244243
plugin_config_path.push(PathBuf::from("plugins"));
245244
}
246245
SurfpoolConfig {
247-
simnet: self.simnet_config(airdrop_addresses),
246+
simnets: vec![self.simnet_config(airdrop_addresses)],
248247
rpc: self.rpc_config(),
249248
subgraph: self.subgraph_config(),
250249
plugin_config_path,

crates/cli/src/cli/simnet/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub async fn handle_start_simnet_command(cmd: &StartSimnet, ctx: &Context) -> Re
5050

5151
// Build config
5252
let config = cmd.surfpool_config(airdrop_addresses);
53-
let remote_rpc_url = config.rpc.remote_rpc_url.clone();
53+
let remote_rpc_url = config.simnets[0].remote_rpc_url.clone();
5454
let local_rpc_url = config.rpc.get_socket_address();
5555

5656
let network_binding = format!("{}:{}", cmd.network_host, DEFAULT_EXPLORER_PORT);

crates/cli/src/tui/simnet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use txtx_core::kit::types::frontend::BlockEvent;
2626
use txtx_core::kit::{channel::Receiver, types::frontend::ProgressBarStatusColor};
2727

2828
const HELP_TEXT: &str = "(Esc) quit | (↑) move up | (↓) move down";
29-
const SURFPOOL_LINK: &str = "https://surfpool.run";
29+
const SURFPOOL_LINK: &str = "Help: https://docs.surfpool.run/surfpool/tui";
3030

3131
const ITEM_HEIGHT: usize = 1;
3232

@@ -582,7 +582,7 @@ fn render_scrollbar(f: &mut Frame, app: &mut App, area: Rect) {
582582
fn render_footer(f: &mut Frame, app: &mut App, area: Rect) {
583583
let rects = Layout::horizontal([
584584
Constraint::Min(30), // Help
585-
Constraint::Length(20), // https://txtx.run
585+
Constraint::Length(50), // https://txtx.run
586586
])
587587
.split(area);
588588

crates/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ libloading = "0.7.4"
7373
json5 = "0.4.1"
7474
txtx-addon-network-svm-types = { workspace = true }
7575
uuid = "1.7.0"
76-
76+
blake3 = "1.8.2"
7777

7878
[dev-dependencies]
7979
test-case = "^3.3.1"

crates/core/src/rpc/accounts_data.rs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use jsonrpc_derive::rpc;
1010
use solana_account::Account;
1111
use solana_account_decoder::parse_token::UiTokenAmount;
1212
use solana_account_decoder::{encode_ui_account, UiAccount, UiAccountEncoding};
13+
use solana_client::nonblocking::rpc_client::RpcClient;
1314
use solana_client::rpc_config::RpcAccountInfoConfig;
1415
use solana_client::rpc_response::RpcBlockCommitment;
1516
use solana_client::rpc_response::RpcResponseContext;
@@ -30,16 +31,16 @@ pub trait AccountsData {
3031
/// This method queries the blockchain for the account associated with the provided
3132
/// public key string. It can be used to inspect balances, ownership, and program-related metadata.
3233
///
33-
/// # Parameters
34+
/// ## Parameters
3435
/// - `pubkey_str`: A base-58 encoded string representing the account's public key.
3536
/// - `config`: Optional configuration that controls encoding, commitment level,
3637
/// data slicing, and other response details.
3738
///
38-
/// # Returns
39+
/// ## Returns
3940
/// A [`RpcResponse`] containing an optional [`UiAccount`] object if the account exists.
4041
/// If the account does not exist, the response will contain `null`.
4142
///
42-
/// # Example Request (JSON-RPC)
43+
/// ## Example Request (JSON-RPC)
4344
/// ```json
4445
/// {
4546
/// "jsonrpc": "2.0",
@@ -55,7 +56,7 @@ pub trait AccountsData {
5556
/// }
5657
/// ```
5758
///
58-
/// # Example Response
59+
/// ## Example Response
5960
/// ```json
6061
/// {
6162
/// "jsonrpc": "2.0",
@@ -80,11 +81,11 @@ pub trait AccountsData {
8081
/// }
8182
/// ```
8283
///
83-
/// # Errors
84+
/// ## Errors
8485
/// - Returns an error if the public key is malformed or invalid
8586
/// - Returns an internal error if the ledger cannot be accessed
8687
///
87-
/// # See also
88+
/// ## See also
8889
/// - [`UiAccount`]: A readable structure representing on-chain accounts
8990
#[rpc(meta, name = "getAccountInfo")]
9091
fn get_account_info(
@@ -100,15 +101,15 @@ pub trait AccountsData {
100101
/// and with what level of lockout. This can be used to analyze consensus progress and
101102
/// determine finality confidence.
102103
///
103-
/// # Parameters
104+
/// ## Parameters
104105
/// - `block`: The target slot (block) to query.
105106
///
106-
/// # Returns
107+
/// ## Returns
107108
/// A [`RpcBlockCommitment`] containing a [`BlockCommitmentArray`], which is an array of 32
108109
/// integers representing the number of votes at each lockout level for that block. Each index
109110
/// corresponds to a lockout level (i.e., confidence in finality).
110111
///
111-
/// # Example Request (JSON-RPC)
112+
/// ## Example Request (JSON-RPC)
112113
/// ```json
113114
/// {
114115
/// "jsonrpc": "2.0",
@@ -118,7 +119,7 @@ pub trait AccountsData {
118119
/// }
119120
/// ```
120121
///
121-
/// # Example Response
122+
/// ## Example Response
122123
/// ```json
123124
/// {
124125
/// "jsonrpc": "2.0",
@@ -130,11 +131,11 @@ pub trait AccountsData {
130131
/// }
131132
/// ```
132133
///
133-
/// # Errors
134+
/// ## Errors
134135
/// - If the slot is not found in the current bank or has been purged, this call may return an error.
135136
/// - May fail if the RPC node is lagging behind or doesn't have voting history for the slot.
136137
///
137-
/// # See also
138+
/// ## See also
138139
/// - [`BlockCommitmentArray`]: An array representing votes by lockout level
139140
/// - [`RpcBlockCommitment`]: Wrapper struct for the full response
140141
#[rpc(meta, name = "getBlockCommitment")]
@@ -150,16 +151,16 @@ pub trait AccountsData {
150151
/// network roundtrips. It returns a list of `UiAccount` values in the same order as
151152
/// the provided public keys.
152153
///
153-
/// # Parameters
154+
/// ## Parameters
154155
/// - `pubkey_strs`: A list of base-58 encoded public key strings representing accounts to query.
155156
/// - `config`: Optional configuration to control encoding, commitment level, data slicing, etc.
156157
///
157-
/// # Returns
158+
/// ## Returns
158159
/// A [`RpcResponse`] wrapping a vector of optional [`UiAccount`] objects.
159160
/// Each element in the response corresponds to the public key at the same index in the request.
160161
/// If an account is not found, the corresponding entry will be `null`.
161162
///
162-
/// # Example Request (JSON-RPC)
163+
/// ## Example Request (JSON-RPC)
163164
/// ```json
164165
/// {
165166
/// "jsonrpc": "2.0",
@@ -178,7 +179,7 @@ pub trait AccountsData {
178179
/// }
179180
/// ```
180181
///
181-
/// # Example Response
182+
/// ## Example Response
182183
/// ```json
183184
/// {
184185
/// "jsonrpc": "2.0",
@@ -204,11 +205,11 @@ pub trait AccountsData {
204205
/// }
205206
/// ```
206207
///
207-
/// # Errors
208+
/// ## Errors
208209
/// - If any public key is malformed or invalid, the entire call may fail.
209210
/// - Returns an internal error if the ledger cannot be accessed or some accounts are purged.
210211
///
211-
/// # See also
212+
/// ## See also
212213
/// - [`UiAccount`]: Human-readable representation of an account
213214
/// - [`get_account_info`]: Use when querying a single account
214215
#[rpc(meta, name = "getMultipleAccounts")]
@@ -225,15 +226,15 @@ pub trait AccountsData {
225226
/// user-friendly information (like the UI amount in human-readable format). It is useful
226227
/// for token-related applications, such as checking balances in wallets or exchanges.
227228
///
228-
/// # Parameters
229+
/// ## Parameters
229230
/// - `pubkey_str`: The base-58 encoded string of the public key of the token account.
230231
/// - `commitment`: Optional commitment configuration to specify the desired confirmation level of the query.
231232
///
232-
/// # Returns
233+
/// ## Returns
233234
/// A [`RpcResponse`] containing the token balance in a [`UiTokenAmount`] struct.
234235
/// If the account doesn't hold any tokens or is invalid, the response will contain `null`.
235236
///
236-
/// # Example Request (JSON-RPC)
237+
/// ## Example Request (JSON-RPC)
237238
/// ```json
238239
/// {
239240
/// "jsonrpc": "2.0",
@@ -248,7 +249,7 @@ pub trait AccountsData {
248249
/// }
249250
/// ```
250251
///
251-
/// # Example Response
252+
/// ## Example Response
252253
/// ```json
253254
/// {
254255
/// "jsonrpc": "2.0",
@@ -267,11 +268,11 @@ pub trait AccountsData {
267268
/// }
268269
/// ```
269270
///
270-
/// # Errors
271+
/// ## Errors
271272
/// - If the provided public key is invalid or does not exist.
272273
/// - If the account is not a valid token account or does not hold any tokens.
273274
///
274-
/// # See also
275+
/// ## See also
275276
/// - [`UiTokenAmount`]: Represents the token balance in user-friendly format.
276277
#[rpc(meta, name = "getTokenAccountBalance")]
277278
fn get_token_account_balance(
@@ -287,15 +288,15 @@ pub trait AccountsData {
287288
/// amount and human-readable UI-formatted values. It can be useful for tracking token issuance
288289
/// and verifying the supply of a token on-chain.
289290
///
290-
/// # Parameters
291+
/// ## Parameters
291292
/// - `mint_str`: The base-58 encoded string of the mint address for the token.
292293
/// - `commitment`: Optional commitment configuration to specify the desired confirmation level of the query.
293294
///
294-
/// # Returns
295+
/// ## Returns
295296
/// A [`RpcResponse`] containing the total token supply in a [`UiTokenAmount`] struct.
296297
/// If the token does not exist or is invalid, the response will return an error.
297298
///
298-
/// # Example Request (JSON-RPC)
299+
/// ## Example Request (JSON-RPC)
299300
/// ```json
300301
/// {
301302
/// "jsonrpc": "2.0",
@@ -310,7 +311,7 @@ pub trait AccountsData {
310311
/// }
311312
/// ```
312313
///
313-
/// # Example Response
314+
/// ## Example Response
314315
/// ```json
315316
/// {
316317
/// "jsonrpc": "2.0",
@@ -329,11 +330,11 @@ pub trait AccountsData {
329330
/// }
330331
/// ```
331332
///
332-
/// # Errors
333+
/// ## Errors
333334
/// - If the mint address is invalid or does not correspond to a token.
334335
/// - If the token supply cannot be fetched due to network issues or node synchronization problems.
335336
///
336-
/// # See also
337+
/// ## See also
337338
/// - [`UiTokenAmount`]: Represents the token balance or supply in a user-friendly format.
338339
#[rpc(meta, name = "getTokenSupply")]
339340
fn get_token_supply(
@@ -369,7 +370,8 @@ impl AccountsData for SurfpoolAccountsDataRpc {
369370

370371
// Drop the lock on the state while we fetch accounts
371372
let absolute_slot = state_reader.epoch_info.absolute_slot;
372-
let rpc_client = state_reader.rpc_client.clone();
373+
374+
let rpc_client = RpcClient::new(state_reader.rpc_url.clone());
373375
let encoding = config.encoding.clone();
374376
let data_slice = config.data_slice.clone();
375377
drop(state_reader);
@@ -444,7 +446,7 @@ impl AccountsData for SurfpoolAccountsDataRpc {
444446

445447
// Drop the lock on the state while we fetch accounts
446448
let absolute_slot = state_reader.epoch_info.absolute_slot;
447-
let rpc_client = state_reader.rpc_client.clone();
449+
let rpc_client = RpcClient::new(state_reader.rpc_url.clone());
448450
let encoding = config.encoding.clone();
449451
let data_slice = config.data_slice.clone();
450452
drop(state_reader);

0 commit comments

Comments
 (0)