Struct SolanaClientRateLimit

Source
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

Source

pub fn new( interval: u64, maximum_amount: u64, default_amount_per_endpoint: u64, ) -> Self

Examples found in repository?
examples/genesysgo.rs (lines 20-24)
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
Hide additional examples
examples/quicknode.rs (lines 21-25)
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}
Source

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?
examples/genesysgo.rs (line 37)
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
Hide additional examples
examples/quicknode.rs (line 27)
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}
Source

pub fn ignore_endpoint(self, endpoint: RpcRequest) -> Self

Adds a RpcRequest to the list of ignored endpoints.

Examples found in repository?
examples/genesysgo.rs (line 26)
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}
Source

pub fn ignores_all_endpoints(self) -> Self

Adds all RpcRequest to the list of ignored endpoints.

Examples found in repository?
examples/genesysgo.rs (line 36)
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}
Source

pub fn check_endpoint(&mut self, endpoint: RpcRequest) -> bool

Checks whether the endpoint can be executed according to the current limits.

Source

pub fn check_endpoints(&mut self, endpoints: &[RpcRequest]) -> bool

Checks whether the endpoints can be executed according to the current limits.

Source

pub fn apply_endpoint(&mut self, endpoint: RpcRequest)

Applies the changes of executing the endpoint.

Source

pub fn apply_endpoints(&mut self, endpoints: &[RpcRequest])

Applies the changes of executing the endpoints.

Trait Implementations§

Source§

impl Debug for SolanaClientRateLimit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AbiExample for T

Source§

default fn example() -> T

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,