lssa/sequencer_core/src/config.rs

83 lines
2.4 KiB
Rust
Raw Normal View History

use std::{
fs::File,
io::BufReader,
path::{Path, PathBuf},
};
2024-11-25 07:26:16 +02:00
use anyhow::Result;
pub use bedrock_client::BackoffConfig;
use common::config::BasicAuth;
2026-01-27 08:13:53 +02:00
use logos_blockchain_core::mantle::ops::channel::ChannelId;
use nssa::AccountId;
2025-11-26 00:27:20 +03:00
use serde::{Deserialize, Serialize};
use url::Url;
2025-11-26 00:27:20 +03:00
2025-07-29 14:20:03 +03:00
#[derive(Debug, Serialize, Deserialize, Clone)]
2025-11-26 00:27:20 +03:00
/// Helperstruct for account serialization
2025-07-29 14:20:03 +03:00
pub struct AccountInitialData {
pub account_id: AccountId,
2025-08-07 15:19:06 -03:00
pub balance: u128,
2025-07-29 14:20:03 +03:00
}
2025-09-24 14:29:56 +03:00
#[derive(Debug, Serialize, Deserialize, Clone)]
/// Helperstruct to initialize commitments
2025-09-24 14:29:56 +03:00
pub struct CommitmentsInitialData {
pub npk: nssa_core::NullifierPublicKey,
pub account: nssa_core::account::Account,
}
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 {
2025-11-26 00:27:20 +03:00
/// Home dir of sequencer storage
2024-11-25 07:26:16 +02:00
pub home: PathBuf,
2025-11-26 00:27:20 +03:00
/// Override rust log (env var logging level)
pub override_rust_log: Option<String>,
2025-11-26 00:27:20 +03:00
/// Genesis id
2024-11-25 07:26:16 +02:00
pub genesis_id: u64,
2025-11-26 00:27:20 +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,
2025-11-26 00:27:20 +03:00
/// Maximum number of transactions in block
2024-11-25 07:26:16 +02:00
pub max_num_tx_in_block: usize,
2025-11-26 00:27:20 +03:00
/// Mempool maximum size
2025-10-23 16:23:47 -03:00
pub mempool_max_size: usize,
2025-11-26 00:27:20 +03:00
/// Interval in which blocks produced
pub block_create_timeout_millis: u64,
/// Interval in which pending blocks are retried
pub retry_pending_blocks_timeout_millis: u64,
2025-11-26 00:27:20 +03:00
/// Port to listen
pub port: u16,
2025-11-26 00:27:20 +03:00
/// List of initial accounts data
2025-07-29 14:20:03 +03:00
pub initial_accounts: Vec<AccountInitialData>,
2025-11-26 00:27:20 +03:00
/// List of initial commitments
2025-09-24 14:29:56 +03:00
pub initial_commitments: Vec<CommitmentsInitialData>,
2025-11-26 00:27:20 +03:00
/// Sequencer own signing key
2025-09-03 10:29:51 +03:00
pub signing_key: [u8; 32],
2026-01-13 16:53:00 -03:00
/// Bedrock configuration options
pub bedrock_config: BedrockConfig,
/// Indexer RPC URL
pub indexer_rpc_url: Url,
2026-01-13 16:53:00 -03:00
}
#[derive(Clone, Serialize, Deserialize)]
pub struct BedrockConfig {
/// Fibonacci backoff retry strategy configuration
#[serde(default)]
pub backoff: BackoffConfig,
2026-01-13 16:53:00 -03:00
/// Bedrock channel ID
2026-01-15 15:44:48 +02:00
pub channel_id: ChannelId,
2026-01-13 16:53:00 -03:00
/// Bedrock Url
pub node_url: Url,
2026-01-27 09:46:31 +02:00
/// Bedrock auth
pub auth: Option<BasicAuth>,
2024-11-25 07:26:16 +02:00
}
impl SequencerConfig {
pub fn from_path(config_home: &Path) -> Result<SequencerConfig> {
let file = File::open(config_home)?;
let reader = BufReader::new(file);
Ok(serde_json::from_reader(reader)?)
}
}