Skip to content

Commit

Permalink
config improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
kobayurii committed Jan 23, 2024
1 parent 58c0696 commit 802e951
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 78 deletions.
38 changes: 8 additions & 30 deletions configuration/example.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ near_rpc_url = "https://beta.rpc.mainnet.near.org"
#near_archival_rpc_url = "https://beta.rpc.mainnet.near.org"

### Rpc server general configuration
#[general.rpc_server]
[general.rpc_server]

## Referer header value
## We want to set a custom referer to let NEAR JSON RPC nodes know that we are a read-rpc instance
Expand Down Expand Up @@ -48,7 +48,7 @@ near_rpc_url = "https://beta.rpc.mainnet.near.org"
#block_cache_size = 0.125

### Tx indexer general configuration
#[general.tx_indexer]
[general.tx_indexer]

## Indexer ID to handle meta data about the instance
## Unique indexer ID
Expand All @@ -67,7 +67,7 @@ near_rpc_url = "https://beta.rpc.mainnet.near.org"
#cache_restore_blocks_range = 1000

### State indexer general configuration
#[general.state_indexer]
[general.state_indexer]

## Indexer ID to handle meta data about the instance
## Unique indexer ID
Expand All @@ -84,7 +84,7 @@ near_rpc_url = "https://beta.rpc.mainnet.near.org"
#concurrency = 1

## Epoch indexer general configuration
#[general.epoch_indexer]
[general.epoch_indexer]

## Indexer ID to handle meta data about the instance
## Unique indexer ID
Expand All @@ -93,7 +93,7 @@ near_rpc_url = "https://beta.rpc.mainnet.near.org"
#indexer_id = "epoch-indexer"

### Tracking acconunts and state changes configuration
#[rightsizing]
[rightsizing]

## Accounts to track. By default we track all accounts.
## You can specify a list of accounts to track.
Expand Down Expand Up @@ -159,7 +159,7 @@ database_url = "postgresql://postgres:password@localhost:5432/near-indexer"
#database_password = "password"

### Database configuration for rpc server
#[database.rpc_server]
[database.rpc_server]

## ScyllaDB preferred DataCenter
## Accepts the DC name of the ScyllaDB to filter the connection to that DC only (preferrably).
Expand All @@ -186,7 +186,7 @@ database_url = "postgresql://postgres:password@localhost:5432/near-indexer"
#keepalive_interval = 60

### Database configuration for tx indexer
#[database.tx_indexer]
[database.tx_indexer]

## ScyllaDB preferred DataCenter
## Accepts the DC name of the ScyllaDB to filter the connection to that DC only (preferrably).
Expand All @@ -213,7 +213,7 @@ database_url = "postgresql://postgres:password@localhost:5432/near-indexer"
#max_db_parallel_queries = 144

## Database configuration for state indexer
#[database.state_indexer]
[database.state_indexer]

## ScyllaDB preferred DataCenter
## Accepts the DC name of the ScyllaDB to filter the connection to that DC only (preferrably).
Expand All @@ -233,25 +233,3 @@ database_url = "postgresql://postgres:password@localhost:5432/near-indexer"
## before giving up, and moving to the next piece of data
## For indexers we use true by default
#strict_mode = true

## Database configuration for epoch indexer
#[database.epoch_indexer]

## ScyllaDB preferred DataCenter
## Accepts the DC name of the ScyllaDB to filter the connection to that DC only (preferrably).
## If you connect to multi-DC cluter, you might experience big latencies while working with the DB.
## This is due to the fact that ScyllaDB driver tries to connect to any of the nodes in the cluster disregarding of the location of the DC.
## This option allows to filter the connection to the DC you need.
## Example: "DC1" where DC1 is located in the same region as the application.
## Default value is None
#preferred_dc = "DC1" # Optional

## Max retry count for ScyllaDB if `strict_mode` is `false`
## For indexers we use 5 attempts by default
#max_retry = 5

## Attempts to store data in the database should be infinite to ensure no data is missing.
## Disable it to perform a limited write attempts (`max_retry`)
## before giving up, and moving to the next piece of data
## For indexers we use true by default
#strict_mode = true
38 changes: 0 additions & 38 deletions configuration/src/configs/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub struct DatabaseConfig {
pub tx_indexer: DatabaseTxIndexerConfig,
#[serde(default)]
pub state_indexer: DatabaseStateIndexerConfig,
#[serde(default)]
pub epoch_indexer: DatabaseEpochIndexerConfig,
}

#[derive(Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -148,39 +146,3 @@ impl Default for DatabaseStateIndexerConfig {
}
}
}

#[derive(Deserialize, Debug, Clone)]
pub struct DatabaseEpochIndexerConfig {
#[serde(deserialize_with = "deserialize_data_or_env", default)]
pub preferred_dc: Option<String>,
#[serde(
deserialize_with = "deserialize_data_or_env",
default = "DatabaseEpochIndexerConfig::default_max_retry"
)]
pub max_retry: u32,
#[serde(
deserialize_with = "deserialize_data_or_env",
default = "DatabaseEpochIndexerConfig::default_strict_mode"
)]
pub strict_mode: bool,
}

impl DatabaseEpochIndexerConfig {
pub fn default_max_retry() -> u32 {
5
}

pub fn default_strict_mode() -> bool {
true
}
}

impl Default for DatabaseEpochIndexerConfig {
fn default() -> Self {
Self {
preferred_dc: Default::default(),
max_retry: Self::default_max_retry(),
strict_mode: Self::default_strict_mode(),
}
}
}
16 changes: 8 additions & 8 deletions rpc-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::modules::blocks::FinalBlockInfo;
use crate::utils::{
get_final_cache_block, gigabytes_to_bytes, update_final_block_height_regularly,
};
use crate::utils::{gigabytes_to_bytes, update_final_block_height_regularly};
use jsonrpc_v2::{Data, Server};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
Expand Down Expand Up @@ -87,10 +85,6 @@ async fn main() -> anyhow::Result<()> {
.clone(),
)?;

let final_block = get_final_cache_block(&near_rpc_client)
.await
.expect("Error to get final block");

let limit_memory_cache_in_bytes =
if let Some(limit_memory_cache) = rpc_server_config.general.rpc_server.limit_memory_cache {
Some(gigabytes_to_bytes(limit_memory_cache).await)
Expand Down Expand Up @@ -131,7 +125,13 @@ async fn main() -> anyhow::Result<()> {
.call(near_jsonrpc_client::methods::EXPERIMENTAL_genesis_config::RpcGenesisConfigRequest)
.await?;
let lake_config = rpc_server_config
.to_lake_config(final_block.block_height)
.to_lake_config(
finale_block_info
.read()
.await
.final_block_cache
.block_height,
)
.await?;
let lake_s3_client = rpc_server_config.to_s3_client().await;

Expand Down
7 changes: 5 additions & 2 deletions rpc-server/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DEFAULT_RETRY_COUNT: u8 = 3;

/// JsonRpcClient represents a client capable of interacting with NEAR JSON-RPC endpoints,
/// The client is capable of handling requests to both regular and archival nodes.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct JsonRpcClient {
regular_client: near_jsonrpc_client::JsonRpcClient,
archival_client: near_jsonrpc_client::JsonRpcClient,
Expand Down Expand Up @@ -108,7 +108,10 @@ pub async fn get_final_cache_block(near_rpc_client: &JsonRpcClient) -> Option<Ca
epoch_id: block_view.header.epoch_id,
})
}
Err(_) => None,
Err(err) => {
tracing::warn!("Error to get final block: {:?}", err);
None
},
}
}

Expand Down

0 comments on commit 802e951

Please sign in to comment.