mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-01-13 00:25:18 +00:00
8790fe1d66
Some checks are pending
abi-consistent-check / build-and-compare (push) Waiting to run
code-coverage / unittest-cov (push) Waiting to run
rust / check (push) Waiting to run
rust / test (push) Waiting to run
rust / lints (push) Waiting to run
functional-test / test (push) Waiting to run
* Upgrade rust toolchain to avoid macro-proc issue of latest rust analyzer * Update random sync metrics * Adjust default config for sync layer * Cache the recent announced file for random sync with priority * Fix clippy * fix auto sync failure reason issue * Add cached ready txs info in rpc * fix lint
132 lines
4.5 KiB
Rust
132 lines
4.5 KiB
Rust
#[macro_use]
|
|
extern crate tracing;
|
|
|
|
pub mod auto_sync;
|
|
mod context;
|
|
mod controllers;
|
|
mod service;
|
|
pub mod test_util;
|
|
|
|
use auto_sync::{batcher_random::RandomBatcherState, batcher_serial::SerialBatcherState};
|
|
pub use controllers::FileSyncInfo;
|
|
use duration_str::deserialize_duration;
|
|
use serde::{Deserialize, Serialize};
|
|
pub use service::{SyncMessage, SyncReceiver, SyncRequest, SyncResponse, SyncSender, SyncService};
|
|
use std::{
|
|
fmt::Debug,
|
|
time::{Duration, Instant},
|
|
};
|
|
|
|
#[derive(Clone, Copy, Debug, Deserialize)]
|
|
#[serde(default)]
|
|
pub struct Config {
|
|
// sync service config
|
|
/// Indicates whether to sync file from neighbor nodes only.
|
|
/// This is to avoid flooding file announcements in the whole network,
|
|
/// which leads to high latency or even timeout to sync files.
|
|
pub neighbors_only: bool,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub heartbeat_interval: Duration,
|
|
pub auto_sync_enabled: bool,
|
|
pub max_sync_files: usize,
|
|
pub sync_file_by_rpc_enabled: bool,
|
|
pub sync_file_on_announcement_enabled: bool,
|
|
|
|
// serial sync config
|
|
pub max_chunks_to_request: u64,
|
|
pub max_request_failures: usize,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub peer_connect_timeout: Duration,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub peer_disconnect_timeout: Duration,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub peer_find_timeout: Duration,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub peer_chunks_download_timeout: Duration,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub peer_wait_outgoing_connection_timeout: Duration,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub peer_next_chunks_request_wait_timeout: Duration,
|
|
pub max_bandwidth_bytes: u64,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub bandwidth_wait_timeout: Duration,
|
|
|
|
// auto sync config
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub auto_sync_idle_interval: Duration,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub auto_sync_error_interval: Duration,
|
|
pub max_sequential_workers: usize,
|
|
pub max_random_workers: usize,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub sequential_find_peer_timeout: Duration,
|
|
#[serde(deserialize_with = "deserialize_duration")]
|
|
pub random_find_peer_timeout: Duration,
|
|
pub ready_txs_cache_cap: usize,
|
|
}
|
|
|
|
impl Default for Config {
|
|
fn default() -> Self {
|
|
Self {
|
|
// sync service config
|
|
neighbors_only: true,
|
|
heartbeat_interval: Duration::from_secs(3),
|
|
auto_sync_enabled: false,
|
|
max_sync_files: 16,
|
|
sync_file_by_rpc_enabled: true,
|
|
sync_file_on_announcement_enabled: false,
|
|
|
|
// serial sync config
|
|
max_chunks_to_request: 2 * 1024,
|
|
max_request_failures: 3,
|
|
peer_connect_timeout: Duration::from_secs(15),
|
|
peer_disconnect_timeout: Duration::from_secs(15),
|
|
peer_find_timeout: Duration::from_secs(5),
|
|
peer_chunks_download_timeout: Duration::from_secs(15),
|
|
peer_wait_outgoing_connection_timeout: Duration::from_secs(10),
|
|
peer_next_chunks_request_wait_timeout: Duration::from_secs(3),
|
|
max_bandwidth_bytes: 0,
|
|
bandwidth_wait_timeout: Duration::from_secs(5),
|
|
|
|
// auto sync config
|
|
auto_sync_idle_interval: Duration::from_secs(3),
|
|
auto_sync_error_interval: Duration::from_secs(10),
|
|
max_sequential_workers: 0,
|
|
max_random_workers: 8,
|
|
sequential_find_peer_timeout: Duration::from_secs(5),
|
|
random_find_peer_timeout: Duration::from_secs(5),
|
|
ready_txs_cache_cap: 1_000_000,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
|
pub struct InstantWrapper(Instant);
|
|
|
|
impl Debug for InstantWrapper {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "\"{} seconds ago\"", self.0.elapsed().as_secs())
|
|
}
|
|
}
|
|
|
|
impl From<Instant> for InstantWrapper {
|
|
fn from(value: Instant) -> Self {
|
|
Self(value)
|
|
}
|
|
}
|
|
|
|
impl InstantWrapper {
|
|
pub fn elapsed(&self) -> Duration {
|
|
self.0.elapsed()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct SyncServiceState {
|
|
pub num_syncing: usize,
|
|
pub catched_up: Option<bool>,
|
|
pub auto_sync_serial: Option<SerialBatcherState>,
|
|
pub auto_sync_random: Option<RandomBatcherState>,
|
|
}
|