Skip to content

Commit

Permalink
small improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
kobayurii committed Jan 4, 2025
1 parent 024c59d commit 6f4871e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 47 deletions.
14 changes: 7 additions & 7 deletions rpc-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ impl ServerContext {
// crate::utils::gigabytes_to_bytes(rpc_server_config.general.contract_code_cache_size)
// .await;

// For contract code cache we use 1GB. make it configurable. temporary hardcoded
let contract_code_cache_size_in_bytes = crate::utils::gigabytes_to_bytes(1.0).await;
// For contract code cache we use 0.5GB. make it configurable. temporary hardcoded
let contract_code_cache_size_in_bytes = crate::utils::gigabytes_to_bytes(0.5).await;
let contract_code_cache = std::sync::Arc::new(crate::cache::RwLockLruMemoryCache::new(
contract_code_cache_size_in_bytes,
));

// let block_cache_size_in_bytes =
// crate::utils::gigabytes_to_bytes(rpc_server_config.general.block_cache_size).await;

// For chunk block we use 5GB. make it configurable. temporary hardcoded
let block_cache_size_in_bytes = crate::utils::gigabytes_to_bytes(2.0).await;
// For chunk block we use 1GB. make it configurable. temporary hardcoded
let block_cache_size_in_bytes = crate::utils::gigabytes_to_bytes(1.0).await;
let blocks_cache = std::sync::Arc::new(crate::cache::RwLockLruMemoryCache::new(
block_cache_size_in_bytes,
));

// For chunk cache we use 5GB. make it configurable. temporary hardcoded
// For chunk cache we use 2GB. make it configurable. temporary hardcoded
let chunk_cache_size_in_bytes = crate::utils::gigabytes_to_bytes(2.0).await;
let chunks_cache = std::sync::Arc::new(crate::cache::RwLockLruMemoryCache::new(
chunk_cache_size_in_bytes,
Expand Down Expand Up @@ -165,9 +165,9 @@ impl ServerContext {
)
.await?;

// For compiled contract code cache we use 2GB. make it configurable. temporary hardcoded
// For compiled contract code cache we use 1.5GB. make it configurable. temporary hardcoded
let compiled_contract_code_cache_size_in_bytes =
crate::utils::gigabytes_to_bytes(2.0).await;
crate::utils::gigabytes_to_bytes(1.5).await;

let compiled_contract_code_cache = std::sync::Arc::new(CompiledCodeCache::new(
compiled_contract_code_cache_size_in_bytes,
Expand Down
52 changes: 12 additions & 40 deletions rpc-server/src/modules/blocks/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn fetch_chunk_from_fastnear(
) -> Result<near_primitives::views::ChunkView, near_jsonrpc::primitives::types::chunks::RpcChunkError>
{
tracing::debug!(
"`fetch_chunk_from_s3` call: block_height {}, shard_id {}",
"`fetch_chunk_from_fastnear` call: block_height {}, shard_id {}",
block_height,
shard_id
);
Expand All @@ -63,46 +63,18 @@ pub async fn fetch_chunk_from_fastnear(
)
.await
{
Ok(shard) => match shard.chunk {
Some(chunk) => {
// We collect a list of local receipt ids to filter out local receipts from the chunk
let local_receipt_ids: Vec<near_indexer_primitives::CryptoHash> = chunk
.transactions
.iter()
.filter(|indexer_tx| {
indexer_tx.transaction.signer_id == indexer_tx.transaction.receiver_id
})
.map(|indexer_tx| {
*indexer_tx
.outcome
.execution_outcome
.outcome
.receipt_ids
.first()
.expect("Conversion receipt_id must be present in transaction outcome")
})
.collect();
Ok(near_primitives::views::ChunkView {
author: chunk.author,
header: chunk.header,
transactions: chunk
.transactions
.into_iter()
.map(|indexer_transaction| indexer_transaction.transaction)
.collect(),
receipts: chunk
.receipts
.into_iter()
.filter(|receipt| !local_receipt_ids.contains(&receipt.receipt_id))
.collect(),
})
Ok(shard) => {
let chunk_info = crate::modules::blocks::ChunkInfo::from(shard);
if let Some(chunk) = chunk_info.chunk {
Ok(chunk)
} else {
Err(
near_jsonrpc::primitives::types::chunks::RpcChunkError::InternalError {
error_message: "Unavailable chunk".to_string(),
},
)
}
None => Err(
near_jsonrpc::primitives::types::chunks::RpcChunkError::InternalError {
error_message: "Unavailable chunk".to_string(),
},
),
},
}
Err(err) => Err(
near_jsonrpc::primitives::types::chunks::RpcChunkError::InternalError {
error_message: err.to_string(),
Expand Down

0 comments on commit 6f4871e

Please sign in to comment.