pub struct SolanaClientRateLimit {
pub endpoint_amounts: HashMap<RpcRequest, u64>,
pub ignore_endpoints: HashSet<RpcRequest>,
pub last_datetime: i64,
pub interval: i64,
pub consumed_amount: u64,
pub maximum_amount: u64,
pub default_amount_per_endpoint: u64,
}
Expand description
Limit for rates like requests per second or compute units per interval.
Fields§
§endpoint_amounts: HashMap<RpcRequest, u64>
Map that contains the amount given to each endpoint.
ignore_endpoints: HashSet<RpcRequest>
Set of endpoints ignored by this limit.
last_datetime: i64
The last date this limit was updated.
interval: i64
Interval between rate resets expressed in milliseconds.
consumed_amount: u64
The number of requests or compute units already consumed in the current interval.
maximum_amount: u64
The maximum number of requests or compute units allowed per interval.
default_amount_per_endpoint: u64
The default amount for each endpoint if not specified in endpoint_amounts
.
Implementations§
Source§impl SolanaClientRateLimit
impl SolanaClientRateLimit
Sourcepub fn new(
interval: u64,
maximum_amount: u64,
default_amount_per_endpoint: u64,
) -> Self
pub fn new( interval: u64, maximum_amount: u64, default_amount_per_endpoint: u64, ) -> Self
Examples found in repository?
11async fn main() {
12 let default_rpc = Arc::new(RpcClient::new(
13 "https://api.mainnet-beta.solana.com".to_string(),
14 ));
15 let genesysgo_rpc = Arc::new(RpcClient::new("<your-genesysgo-rpc-url>".to_string()));
16 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
17 SolanaClientRpc::new(genesysgo_rpc)
18 // Requests per second limit.
19 .add_limit(
20 SolanaClientRateLimit::new(
21 1000, /* 1 second */
22 1, /* 1 request per second */
23 1, /* all requests count the same */
24 )
25 // Ignore GetMultipleAccounts requests here to track them in the next limit.
26 .ignore_endpoint(RpcRequest::GetMultipleAccounts),
27 )
28 // Requests per second limit for GetMultipleAccounts.
29 .add_limit(
30 SolanaClientRateLimit::new(
31 60 * 1000, /* 1 minute */
32 6, /* 6 request per minute */
33 1, /* all requests count the same */
34 )
35 // Ignore all endpoints and include only GetMultipleAccounts requests here.
36 .ignores_all_endpoints()
37 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 1),
38 ),
39 );
40
41 let version = client.get_version().await.unwrap();
42
43 println!("Cluster version: {}", version.solana_core);
44}
More examples
12async fn main() {
13 let default_rpc = Arc::new(RpcClient::new(
14 "https://api.mainnet-beta.solana.com".to_string(),
15 ));
16 let quicknode_rpc = Arc::new(RpcClient::new("<your-quicknode-rpc-url>".to_string()));
17 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
18 SolanaClientRpc::new(quicknode_rpc)
19 // Credits / month limits.
20 .add_limit(
21 SolanaClientRateLimit::new(
22 30 * 24 * 60 * 60 * 1000, /* 30 days */
23 10_000_000, /* credits per month */
24 1, /* default cost in credits for endpoints */
25 )
26 // List of all endpoints whose credits are different than the default value.
27 .add_endpoint_amount(RpcRequest::GetAccountInfo, 2)
28 .add_endpoint_amount(RpcRequest::GetBlockTime, 2)
29 .add_endpoint_amount(RpcRequest::GetClusterNodes, 2)
30 .add_endpoint_amount(RpcRequest::GetBlock, 23)
31 .add_endpoint_amount(RpcRequest::GetEpochInfo, 2)
32 .add_endpoint_amount(RpcRequest::GetFirstAvailableBlock, 3)
33 .add_endpoint_amount(RpcRequest::GetHealth, 2)
34 .add_endpoint_amount(RpcRequest::GetHighestSnapshotSlot, 2)
35 .add_endpoint_amount(RpcRequest::GetInflationGovernor, 2)
36 .add_endpoint_amount(RpcRequest::GetLatestBlockhash, 2)
37 .add_endpoint_amount(RpcRequest::GetMinimumBalanceForRentExemption, 3)
38 .add_endpoint_amount(RpcRequest::GetProgramAccounts, 35)
39 .add_endpoint_amount(RpcRequest::GetRecentPerformanceSamples, 4)
40 .add_endpoint_amount(RpcRequest::GetSignaturesForAddress, 3)
41 .add_endpoint_amount(RpcRequest::GetTokenSupply, 2)
42 .add_endpoint_amount(RpcRequest::GetTransaction, 3)
43 .add_endpoint_amount(RpcRequest::GetVersion, 2)
44 .add_endpoint_amount(RpcRequest::SimulateTransaction, 4)
45 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 10)
46 .add_endpoint_amount(RpcRequest::GetLargestAccounts, 259),
47 )
48 // Requests / second limit.
49 .add_limit(SolanaClientRateLimit::new(
50 1000, /* 1 second */
51 25, /* 25 requests per second */
52 1, /* all requests count the same */
53 )),
54 );
55
56 let version = client.get_version().await.unwrap();
57
58 println!("Cluster version: {}", version.solana_core);
59}
Sourcepub fn add_endpoint_amount(self, endpoint: RpcRequest, amount: u64) -> Self
pub fn add_endpoint_amount(self, endpoint: RpcRequest, amount: u64) -> Self
Adds a RpcRequest
to the map of endpoints to their amounts.
Examples found in repository?
11async fn main() {
12 let default_rpc = Arc::new(RpcClient::new(
13 "https://api.mainnet-beta.solana.com".to_string(),
14 ));
15 let genesysgo_rpc = Arc::new(RpcClient::new("<your-genesysgo-rpc-url>".to_string()));
16 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
17 SolanaClientRpc::new(genesysgo_rpc)
18 // Requests per second limit.
19 .add_limit(
20 SolanaClientRateLimit::new(
21 1000, /* 1 second */
22 1, /* 1 request per second */
23 1, /* all requests count the same */
24 )
25 // Ignore GetMultipleAccounts requests here to track them in the next limit.
26 .ignore_endpoint(RpcRequest::GetMultipleAccounts),
27 )
28 // Requests per second limit for GetMultipleAccounts.
29 .add_limit(
30 SolanaClientRateLimit::new(
31 60 * 1000, /* 1 minute */
32 6, /* 6 request per minute */
33 1, /* all requests count the same */
34 )
35 // Ignore all endpoints and include only GetMultipleAccounts requests here.
36 .ignores_all_endpoints()
37 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 1),
38 ),
39 );
40
41 let version = client.get_version().await.unwrap();
42
43 println!("Cluster version: {}", version.solana_core);
44}
More examples
12async fn main() {
13 let default_rpc = Arc::new(RpcClient::new(
14 "https://api.mainnet-beta.solana.com".to_string(),
15 ));
16 let quicknode_rpc = Arc::new(RpcClient::new("<your-quicknode-rpc-url>".to_string()));
17 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
18 SolanaClientRpc::new(quicknode_rpc)
19 // Credits / month limits.
20 .add_limit(
21 SolanaClientRateLimit::new(
22 30 * 24 * 60 * 60 * 1000, /* 30 days */
23 10_000_000, /* credits per month */
24 1, /* default cost in credits for endpoints */
25 )
26 // List of all endpoints whose credits are different than the default value.
27 .add_endpoint_amount(RpcRequest::GetAccountInfo, 2)
28 .add_endpoint_amount(RpcRequest::GetBlockTime, 2)
29 .add_endpoint_amount(RpcRequest::GetClusterNodes, 2)
30 .add_endpoint_amount(RpcRequest::GetBlock, 23)
31 .add_endpoint_amount(RpcRequest::GetEpochInfo, 2)
32 .add_endpoint_amount(RpcRequest::GetFirstAvailableBlock, 3)
33 .add_endpoint_amount(RpcRequest::GetHealth, 2)
34 .add_endpoint_amount(RpcRequest::GetHighestSnapshotSlot, 2)
35 .add_endpoint_amount(RpcRequest::GetInflationGovernor, 2)
36 .add_endpoint_amount(RpcRequest::GetLatestBlockhash, 2)
37 .add_endpoint_amount(RpcRequest::GetMinimumBalanceForRentExemption, 3)
38 .add_endpoint_amount(RpcRequest::GetProgramAccounts, 35)
39 .add_endpoint_amount(RpcRequest::GetRecentPerformanceSamples, 4)
40 .add_endpoint_amount(RpcRequest::GetSignaturesForAddress, 3)
41 .add_endpoint_amount(RpcRequest::GetTokenSupply, 2)
42 .add_endpoint_amount(RpcRequest::GetTransaction, 3)
43 .add_endpoint_amount(RpcRequest::GetVersion, 2)
44 .add_endpoint_amount(RpcRequest::SimulateTransaction, 4)
45 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 10)
46 .add_endpoint_amount(RpcRequest::GetLargestAccounts, 259),
47 )
48 // Requests / second limit.
49 .add_limit(SolanaClientRateLimit::new(
50 1000, /* 1 second */
51 25, /* 25 requests per second */
52 1, /* all requests count the same */
53 )),
54 );
55
56 let version = client.get_version().await.unwrap();
57
58 println!("Cluster version: {}", version.solana_core);
59}
Sourcepub fn ignore_endpoint(self, endpoint: RpcRequest) -> Self
pub fn ignore_endpoint(self, endpoint: RpcRequest) -> Self
Adds a RpcRequest
to the list of ignored endpoints.
Examples found in repository?
11async fn main() {
12 let default_rpc = Arc::new(RpcClient::new(
13 "https://api.mainnet-beta.solana.com".to_string(),
14 ));
15 let genesysgo_rpc = Arc::new(RpcClient::new("<your-genesysgo-rpc-url>".to_string()));
16 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
17 SolanaClientRpc::new(genesysgo_rpc)
18 // Requests per second limit.
19 .add_limit(
20 SolanaClientRateLimit::new(
21 1000, /* 1 second */
22 1, /* 1 request per second */
23 1, /* all requests count the same */
24 )
25 // Ignore GetMultipleAccounts requests here to track them in the next limit.
26 .ignore_endpoint(RpcRequest::GetMultipleAccounts),
27 )
28 // Requests per second limit for GetMultipleAccounts.
29 .add_limit(
30 SolanaClientRateLimit::new(
31 60 * 1000, /* 1 minute */
32 6, /* 6 request per minute */
33 1, /* all requests count the same */
34 )
35 // Ignore all endpoints and include only GetMultipleAccounts requests here.
36 .ignores_all_endpoints()
37 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 1),
38 ),
39 );
40
41 let version = client.get_version().await.unwrap();
42
43 println!("Cluster version: {}", version.solana_core);
44}
Sourcepub fn ignores_all_endpoints(self) -> Self
pub fn ignores_all_endpoints(self) -> Self
Adds all RpcRequest
to the list of ignored endpoints.
Examples found in repository?
11async fn main() {
12 let default_rpc = Arc::new(RpcClient::new(
13 "https://api.mainnet-beta.solana.com".to_string(),
14 ));
15 let genesysgo_rpc = Arc::new(RpcClient::new("<your-genesysgo-rpc-url>".to_string()));
16 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
17 SolanaClientRpc::new(genesysgo_rpc)
18 // Requests per second limit.
19 .add_limit(
20 SolanaClientRateLimit::new(
21 1000, /* 1 second */
22 1, /* 1 request per second */
23 1, /* all requests count the same */
24 )
25 // Ignore GetMultipleAccounts requests here to track them in the next limit.
26 .ignore_endpoint(RpcRequest::GetMultipleAccounts),
27 )
28 // Requests per second limit for GetMultipleAccounts.
29 .add_limit(
30 SolanaClientRateLimit::new(
31 60 * 1000, /* 1 minute */
32 6, /* 6 request per minute */
33 1, /* all requests count the same */
34 )
35 // Ignore all endpoints and include only GetMultipleAccounts requests here.
36 .ignores_all_endpoints()
37 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 1),
38 ),
39 );
40
41 let version = client.get_version().await.unwrap();
42
43 println!("Cluster version: {}", version.solana_core);
44}
Sourcepub fn check_endpoint(&mut self, endpoint: RpcRequest) -> bool
pub fn check_endpoint(&mut self, endpoint: RpcRequest) -> bool
Checks whether the endpoint can be executed according to the current limits.
Sourcepub fn check_endpoints(&mut self, endpoints: &[RpcRequest]) -> bool
pub fn check_endpoints(&mut self, endpoints: &[RpcRequest]) -> bool
Checks whether the endpoints can be executed according to the current limits.
Sourcepub fn apply_endpoint(&mut self, endpoint: RpcRequest)
pub fn apply_endpoint(&mut self, endpoint: RpcRequest)
Applies the changes of executing the endpoint.
Sourcepub fn apply_endpoints(&mut self, endpoints: &[RpcRequest])
pub fn apply_endpoints(&mut self, endpoints: &[RpcRequest])
Applies the changes of executing the endpoints.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SolanaClientRateLimit
impl RefUnwindSafe for SolanaClientRateLimit
impl Send for SolanaClientRateLimit
impl Sync for SolanaClientRateLimit
impl Unpin for SolanaClientRateLimit
impl UnwindSafe for SolanaClientRateLimit
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more