Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit d49b481

Browse files
authored
Cleanup tempoary pub modules (#30268)
Clean up temporary_pub_modules in tpu_client and thin_client
1 parent 8770b15 commit d49b481

File tree

5 files changed

+90
-106
lines changed

5 files changed

+90
-106
lines changed

client/src/nonblocking/tpu_client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use {
1313
transaction::{Transaction, TransactionError},
1414
transport::Result as TransportResult,
1515
},
16-
solana_tpu_client::nonblocking::tpu_client::{temporary_pub::*, TpuClient as BackendTpuClient},
16+
solana_tpu_client::nonblocking::tpu_client::{Result, TpuClient as BackendTpuClient},
1717
std::sync::Arc,
1818
};
1919

client/src/tpu_client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use {
1212
transaction::{Transaction, TransactionError},
1313
transport::Result as TransportResult,
1414
},
15-
solana_tpu_client::tpu_client::{temporary_pub::Result, TpuClient as BackendTpuClient},
15+
solana_tpu_client::tpu_client::{Result, TpuClient as BackendTpuClient},
1616
std::sync::Arc,
1717
};
1818
pub use {

thin-client/src/thin_client.rs

+50-55
Original file line numberDiff line numberDiff line change
@@ -43,77 +43,72 @@ use {
4343
},
4444
};
4545

46-
pub mod temporary_pub {
47-
use super::*;
46+
struct ClientOptimizer {
47+
cur_index: AtomicUsize,
48+
experiment_index: AtomicUsize,
49+
experiment_done: AtomicBool,
50+
times: RwLock<Vec<u64>>,
51+
num_clients: usize,
52+
}
4853

49-
pub struct ClientOptimizer {
50-
cur_index: AtomicUsize,
51-
experiment_index: AtomicUsize,
52-
experiment_done: AtomicBool,
53-
times: RwLock<Vec<u64>>,
54-
num_clients: usize,
55-
}
56-
57-
impl ClientOptimizer {
58-
pub fn new(num_clients: usize) -> Self {
59-
Self {
60-
cur_index: AtomicUsize::new(0),
61-
experiment_index: AtomicUsize::new(0),
62-
experiment_done: AtomicBool::new(false),
63-
times: RwLock::new(vec![std::u64::MAX; num_clients]),
64-
num_clients,
65-
}
54+
impl ClientOptimizer {
55+
fn new(num_clients: usize) -> Self {
56+
Self {
57+
cur_index: AtomicUsize::new(0),
58+
experiment_index: AtomicUsize::new(0),
59+
experiment_done: AtomicBool::new(false),
60+
times: RwLock::new(vec![std::u64::MAX; num_clients]),
61+
num_clients,
6662
}
63+
}
6764

68-
pub fn experiment(&self) -> usize {
69-
if self.experiment_index.load(Ordering::Relaxed) < self.num_clients {
70-
let old = self.experiment_index.fetch_add(1, Ordering::Relaxed);
71-
if old < self.num_clients {
72-
old
73-
} else {
74-
self.best()
75-
}
65+
fn experiment(&self) -> usize {
66+
if self.experiment_index.load(Ordering::Relaxed) < self.num_clients {
67+
let old = self.experiment_index.fetch_add(1, Ordering::Relaxed);
68+
if old < self.num_clients {
69+
old
7670
} else {
7771
self.best()
7872
}
73+
} else {
74+
self.best()
7975
}
76+
}
8077

81-
pub fn report(&self, index: usize, time_ms: u64) {
82-
if self.num_clients > 1
83-
&& (!self.experiment_done.load(Ordering::Relaxed) || time_ms == std::u64::MAX)
84-
{
78+
fn report(&self, index: usize, time_ms: u64) {
79+
if self.num_clients > 1
80+
&& (!self.experiment_done.load(Ordering::Relaxed) || time_ms == std::u64::MAX)
81+
{
82+
trace!(
83+
"report {} with {} exp: {}",
84+
index,
85+
time_ms,
86+
self.experiment_index.load(Ordering::Relaxed)
87+
);
88+
89+
self.times.write().unwrap()[index] = time_ms;
90+
91+
if index == (self.num_clients - 1) || time_ms == std::u64::MAX {
92+
let times = self.times.read().unwrap();
93+
let (min_time, min_index) = min_index(&times);
8594
trace!(
86-
"report {} with {} exp: {}",
87-
index,
88-
time_ms,
89-
self.experiment_index.load(Ordering::Relaxed)
95+
"done experimenting min: {} time: {} times: {:?}",
96+
min_index,
97+
min_time,
98+
times
9099
);
91100

92-
self.times.write().unwrap()[index] = time_ms;
93-
94-
if index == (self.num_clients - 1) || time_ms == std::u64::MAX {
95-
let times = self.times.read().unwrap();
96-
let (min_time, min_index) = min_index(&times);
97-
trace!(
98-
"done experimenting min: {} time: {} times: {:?}",
99-
min_index,
100-
min_time,
101-
times
102-
);
103-
104-
// Only 1 thread should grab the num_clients-1 index, so this should be ok.
105-
self.cur_index.store(min_index, Ordering::Relaxed);
106-
self.experiment_done.store(true, Ordering::Relaxed);
107-
}
101+
// Only 1 thread should grab the num_clients-1 index, so this should be ok.
102+
self.cur_index.store(min_index, Ordering::Relaxed);
103+
self.experiment_done.store(true, Ordering::Relaxed);
108104
}
109105
}
106+
}
110107

111-
pub fn best(&self) -> usize {
112-
self.cur_index.load(Ordering::Relaxed)
113-
}
108+
fn best(&self) -> usize {
109+
self.cur_index.load(Ordering::Relaxed)
114110
}
115111
}
116-
use temporary_pub::*;
117112

118113
/// An object for querying and sending transactions to the network.
119114
pub struct ThinClient<

tpu-client/src/nonblocking/tpu_client.rs

+31-37
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
#[cfg(feature = "spinner")]
2-
use {
3-
crate::tpu_client::temporary_pub::{SEND_TRANSACTION_INTERVAL, TRANSACTION_RESEND_INTERVAL},
4-
indicatif::ProgressBar,
5-
solana_rpc_client::spinner,
6-
solana_rpc_client_api::request::MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS,
7-
solana_sdk::{message::Message, signers::Signers, transaction::TransactionError},
8-
};
1+
pub use crate::tpu_client::Result;
92
use {
103
crate::tpu_client::{RecentLeaderSlots, TpuClientConfig, MAX_FANOUT_SLOTS},
114
bincode::serialize,
@@ -48,37 +41,38 @@ use {
4841
time::{sleep, timeout, Duration, Instant},
4942
},
5043
};
44+
#[cfg(feature = "spinner")]
45+
use {
46+
crate::tpu_client::{SEND_TRANSACTION_INTERVAL, TRANSACTION_RESEND_INTERVAL},
47+
indicatif::ProgressBar,
48+
solana_rpc_client::spinner,
49+
solana_rpc_client_api::request::MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS,
50+
solana_sdk::{message::Message, signers::Signers, transaction::TransactionError},
51+
};
5152

52-
pub mod temporary_pub {
53-
use super::*;
54-
55-
pub type Result<T> = std::result::Result<T, TpuSenderError>;
56-
57-
#[cfg(feature = "spinner")]
58-
pub fn set_message_for_confirmed_transactions(
59-
progress_bar: &ProgressBar,
60-
confirmed_transactions: u32,
61-
total_transactions: usize,
62-
block_height: Option<u64>,
63-
last_valid_block_height: u64,
64-
status: &str,
65-
) {
66-
progress_bar.set_message(format!(
67-
"{:>5.1}% | {:<40}{}",
68-
confirmed_transactions as f64 * 100. / total_transactions as f64,
69-
status,
70-
match block_height {
71-
Some(block_height) => format!(
72-
" [block height {}; re-sign in {} blocks]",
73-
block_height,
74-
last_valid_block_height.saturating_sub(block_height),
75-
),
76-
None => String::new(),
77-
},
78-
));
79-
}
53+
#[cfg(feature = "spinner")]
54+
fn set_message_for_confirmed_transactions(
55+
progress_bar: &ProgressBar,
56+
confirmed_transactions: u32,
57+
total_transactions: usize,
58+
block_height: Option<u64>,
59+
last_valid_block_height: u64,
60+
status: &str,
61+
) {
62+
progress_bar.set_message(format!(
63+
"{:>5.1}% | {:<40}{}",
64+
confirmed_transactions as f64 * 100. / total_transactions as f64,
65+
status,
66+
match block_height {
67+
Some(block_height) => format!(
68+
" [block height {}; re-sign in {} blocks]",
69+
block_height,
70+
last_valid_block_height.saturating_sub(block_height),
71+
),
72+
None => String::new(),
73+
},
74+
));
8075
}
81-
use temporary_pub::*;
8276

8377
#[derive(Error, Debug)]
8478
pub enum TpuSenderError {

tpu-client/src/tpu_client.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,14 @@ pub const DEFAULT_TPU_ENABLE_UDP: bool = false;
2323
pub const DEFAULT_TPU_USE_QUIC: bool = true;
2424
pub const DEFAULT_TPU_CONNECTION_POOL_SIZE: usize = 4;
2525

26-
pub mod temporary_pub {
27-
use super::*;
28-
29-
pub type Result<T> = std::result::Result<T, TpuSenderError>;
26+
pub type Result<T> = std::result::Result<T, TpuSenderError>;
3027

31-
/// Send at ~100 TPS
32-
#[cfg(feature = "spinner")]
33-
pub const SEND_TRANSACTION_INTERVAL: Duration = Duration::from_millis(10);
34-
/// Retry batch send after 4 seconds
35-
#[cfg(feature = "spinner")]
36-
pub const TRANSACTION_RESEND_INTERVAL: Duration = Duration::from_secs(4);
37-
}
38-
use temporary_pub::*;
28+
/// Send at ~100 TPS
29+
#[cfg(feature = "spinner")]
30+
pub(crate) const SEND_TRANSACTION_INTERVAL: Duration = Duration::from_millis(10);
31+
/// Retry batch send after 4 seconds
32+
#[cfg(feature = "spinner")]
33+
pub(crate) const TRANSACTION_RESEND_INTERVAL: Duration = Duration::from_secs(4);
3934

4035
/// Default number of slots used to build TPU socket fanout set
4136
pub const DEFAULT_FANOUT_SLOTS: u64 = 12;

0 commit comments

Comments
 (0)