lssa/sequencer/core/src/config.rs

79 lines
2.2 KiB
Rust
Raw Normal View History

use std::{
fs::File,
io::BufReader,
path::{Path, PathBuf},
time::Duration,
};
2024-11-25 07:26:16 +02:00
use anyhow::Result;
use bedrock_client::BackoffConfig;
2026-02-24 19:41:01 +03:00
use bytesize::ByteSize;
2026-01-30 12:51:18 +02:00
use common::{
2026-02-04 14:57:38 +02:00
block::{AccountInitialData, CommitmentsInitialData},
config::BasicAuth,
};
use humantime_serde;
2026-01-27 08:13:53 +02:00
use logos_blockchain_core::mantle::ops::channel::ChannelId;
2025-11-26 00:27:20 +03:00
use serde::{Deserialize, Serialize};
use url::Url;
2025-11-26 00:27:20 +03:00
2025-11-18 19:31:03 +03:00
// TODO: Provide default values
2025-07-25 10:00:27 +03:00
#[derive(Clone, Serialize, Deserialize)]
2024-11-25 07:26:16 +02:00
pub struct SequencerConfig {
2026-03-10 00:17:43 +03:00
/// Home dir of sequencer storage.
2024-11-25 07:26:16 +02:00
pub home: PathBuf,
2026-03-10 00:17:43 +03:00
/// Genesis id.
2024-11-25 07:26:16 +02:00
pub genesis_id: u64,
2026-03-10 00:17:43 +03:00
/// If `True`, then adds random sequence of bytes to genesis block.
2024-11-25 07:26:16 +02:00
pub is_genesis_random: bool,
2026-03-10 00:17:43 +03:00
/// Maximum number of transactions in block.
2024-11-25 07:26:16 +02:00
pub max_num_tx_in_block: usize,
2026-03-10 00:17:43 +03:00
/// Maximum block size (includes header and transactions).
2026-02-24 19:41:01 +03:00
#[serde(default = "default_max_block_size")]
pub max_block_size: ByteSize,
2026-03-10 00:17:43 +03:00
/// Mempool maximum size.
2025-10-23 16:23:47 -03:00
pub mempool_max_size: usize,
2026-03-10 00:17:43 +03:00
/// Interval in which blocks produced.
#[serde(with = "humantime_serde")]
pub block_create_timeout: Duration,
2026-03-10 00:17:43 +03:00
/// Interval in which pending blocks are retried.
#[serde(with = "humantime_serde")]
pub retry_pending_blocks_timeout: Duration,
2026-03-10 00:17:43 +03:00
/// List of initial accounts data.
2025-07-29 14:20:03 +03:00
pub initial_accounts: Vec<AccountInitialData>,
2026-03-10 00:17:43 +03:00
/// List of initial commitments.
2025-09-24 14:29:56 +03:00
pub initial_commitments: Vec<CommitmentsInitialData>,
2026-03-10 00:17:43 +03:00
/// Sequencer own signing key.
2025-09-03 10:29:51 +03:00
pub signing_key: [u8; 32],
2026-03-10 00:17:43 +03:00
/// Bedrock configuration options.
pub bedrock_config: BedrockConfig,
2026-03-10 00:17:43 +03:00
/// Indexer RPC URL.
pub indexer_rpc_url: Url,
2026-01-13 16:53:00 -03:00
}
#[derive(Clone, Serialize, Deserialize)]
pub struct BedrockConfig {
2026-03-10 00:17:43 +03:00
/// Fibonacci backoff retry strategy configuration.
#[serde(default)]
pub backoff: BackoffConfig,
2026-03-10 00:17:43 +03:00
/// Bedrock channel ID.
2026-01-15 15:44:48 +02:00
pub channel_id: ChannelId,
2026-03-10 00:17:43 +03:00
/// Bedrock Url.
pub node_url: Url,
2026-03-10 00:17:43 +03:00
/// Bedrock auth.
2026-01-27 09:46:31 +02:00
pub auth: Option<BasicAuth>,
2024-11-25 07:26:16 +02:00
}
impl SequencerConfig {
2026-03-09 18:27:56 +03:00
pub fn from_path(config_home: &Path) -> Result<Self> {
let file = File::open(config_home)?;
let reader = BufReader::new(file);
Ok(serde_json::from_reader(reader)?)
}
}
2026-02-24 19:41:01 +03:00
2026-03-09 18:27:56 +03:00
const fn default_max_block_size() -> ByteSize {
2026-02-24 19:41:01 +03:00
ByteSize::mib(1)
}