-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* read body in chunks * fix test * add test
- Loading branch information
Showing
15 changed files
with
133 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
pub(crate) const STATUS_ENDPOINT_TAG: &str = "status"; | ||
pub(crate) const REGISTER_VALIDATOR_ENDPOINT_TAG: &str = "register_validator"; | ||
pub(crate) const SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG: &str = "submit_blinded_block"; | ||
pub(crate) const GET_HEADER_ENDPOINT_TAG: &str = "get_header"; | ||
pub const STATUS_ENDPOINT_TAG: &str = "status"; | ||
pub const REGISTER_VALIDATOR_ENDPOINT_TAG: &str = "register_validator"; | ||
pub const SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG: &str = "submit_blinded_block"; | ||
pub const GET_HEADER_ENDPOINT_TAG: &str = "get_header"; | ||
|
||
/// For metrics recorded when a request times out | ||
pub(crate) const TIMEOUT_ERROR_CODE: u16 = 555; | ||
pub(crate) const TIMEOUT_ERROR_CODE_STR: &str = "555"; | ||
pub const TIMEOUT_ERROR_CODE: u16 = 555; | ||
pub const TIMEOUT_ERROR_CODE_STR: &str = "555"; | ||
|
||
/// 20 MiB to cover edge cases for heavy blocks and also add a bit of slack for | ||
/// any Ethereum upgrades in the near future | ||
pub const MAX_SIZE_SUBMIT_BLOCK: usize = 20 * 1024 * 1024; | ||
|
||
/// 10 KiB, headers are around 700 bytes + buffer for encoding | ||
pub const MAX_SIZE_GET_HEADER: usize = 10 * 1024; | ||
|
||
pub const MAX_SIZE_DEFAULT: usize = 1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use cb_common::pbs::error::PbsError; | ||
use futures::StreamExt; | ||
use reqwest::Response; | ||
|
||
pub async fn read_chunked_body_with_max( | ||
res: Response, | ||
max_size: usize, | ||
) -> Result<Vec<u8>, PbsError> { | ||
let mut stream = res.bytes_stream(); | ||
let mut response_bytes = Vec::new(); | ||
|
||
while let Some(chunk) = stream.next().await { | ||
let chunk = chunk?; | ||
if response_bytes.len() + chunk.len() > max_size { | ||
// avoid spamming logs if the message is too large | ||
response_bytes.truncate(1024); | ||
return Err(PbsError::PayloadTooLarge { | ||
max: max_size, | ||
raw: String::from_utf8_lossy(&response_bytes).into_owned(), | ||
}); | ||
} | ||
|
||
response_bytes.extend_from_slice(&chunk); | ||
} | ||
|
||
Ok(response_bytes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.