Skip to content

Commit

Permalink
Merge pull request #3405 from demox-labs/rps-fix
Browse files Browse the repository at this point in the history
Fix requests per second, proper error responses, compilation related to the curl-sys library
  • Loading branch information
zosorock authored Oct 26, 2024
2 parents c7ccc4f + fc2905f commit b544b7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions node/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,18 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
// Prepare the rate limiting setup.
let governor_config = Box::new(
GovernorConfigBuilder::default()
.per_second(1)
.per_nanosecond((1_000_000_000 / rest_rps) as u64)
.burst_size(rest_rps)
.error_handler(|error| Response::new(error.to_string().into()))
.error_handler(|error| {
// Properly return a 429 Too Many Requests error
let error_message = error.to_string();
let mut response = Response::new(error_message.clone().into());
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
if error_message.contains("Too Many Requests") {
*response.status_mut() = StatusCode::TOO_MANY_REQUESTS;
}
response
})
.finish()
.expect("Couldn't set up rate limiting for the REST server!"),
);
Expand Down
2 changes: 1 addition & 1 deletion node/router/src/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
use snarkvm::prelude::Network;

use colored::Colorize;
use rand::{prelude::IteratorRandom, rngs::OsRng, Rng};
use rand::{Rng, prelude::IteratorRandom, rngs::OsRng};

/// A helper function to compute the maximum of two numbers.
/// See Rust issue 92391: https://github.com/rust-lang/rust/issues/92391.
Expand Down

0 comments on commit b544b7a

Please sign in to comment.