pub mod bps;
pub mod constants;
pub mod genesis;
pub mod params;
use kaspa_utils::networking::{ContextualNetAddress, NetAddress};
#[cfg(feature = "devnet-prealloc")]
use crate::utxo::utxo_collection::UtxoCollection;
#[cfg(feature = "devnet-prealloc")]
use std::sync::Arc;
use std::ops::Deref;
use {
constants::perf::{PerfParams, PERF_PARAMS},
params::Params,
};
#[derive(Clone, Debug)]
pub struct Config {
pub params: Params,
pub perf: PerfParams,
pub process_genesis: bool,
pub is_archival: bool,
pub enable_sanity_checks: bool,
pub utxoindex: bool,
pub unsafe_rpc: bool,
pub enable_unsynced_mining: bool,
pub enable_mainnet_mining: bool,
pub user_agent_comments: Vec<String>,
pub p2p_listen_address: ContextualNetAddress,
pub externalip: Option<NetAddress>,
pub block_template_cache_lifetime: Option<u64>,
#[cfg(feature = "devnet-prealloc")]
pub initial_utxo_set: Arc<UtxoCollection>,
pub disable_upnp: bool,
pub ram_scale: f64,
}
impl Config {
pub fn new(params: Params) -> Self {
Self::with_perf(params, PERF_PARAMS)
}
pub fn with_perf(params: Params, perf: PerfParams) -> Self {
Self {
params,
perf,
process_genesis: true,
is_archival: false,
enable_sanity_checks: false,
utxoindex: false,
unsafe_rpc: false,
enable_unsynced_mining: false,
enable_mainnet_mining: false,
user_agent_comments: Default::default(),
externalip: None,
p2p_listen_address: ContextualNetAddress::unspecified(),
block_template_cache_lifetime: None,
#[cfg(feature = "devnet-prealloc")]
initial_utxo_set: Default::default(),
disable_upnp: false,
ram_scale: 1.0,
}
}
pub fn to_builder(&self) -> ConfigBuilder {
ConfigBuilder { config: self.clone() }
}
}
impl AsRef<Params> for Config {
fn as_ref(&self) -> &Params {
&self.params
}
}
impl Deref for Config {
type Target = Params;
fn deref(&self) -> &Self::Target {
&self.params
}
}
pub struct ConfigBuilder {
config: Config,
}
impl ConfigBuilder {
pub fn new(params: Params) -> Self {
Self { config: Config::new(params) }
}
pub fn set_perf_params(mut self, perf: PerfParams) -> Self {
self.config.perf = perf;
self
}
pub fn adjust_perf_params_to_consensus_params(mut self) -> Self {
self.config.perf.adjust_to_consensus_params(&self.config.params);
self
}
pub fn edit_consensus_params<F>(mut self, edit_func: F) -> Self
where
F: Fn(&mut Params),
{
edit_func(&mut self.config.params);
self
}
pub fn apply_args<F>(mut self, edit_func: F) -> Self
where
F: Fn(&mut Config),
{
edit_func(&mut self.config);
self
}
pub fn skip_proof_of_work(mut self) -> Self {
self.config.params.skip_proof_of_work = true;
self
}
pub fn set_archival(mut self) -> Self {
self.config.is_archival = true;
self
}
pub fn enable_sanity_checks(mut self) -> Self {
self.config.enable_sanity_checks = true;
self
}
pub fn skip_adding_genesis(mut self) -> Self {
self.config.process_genesis = false;
self
}
pub fn build(self) -> Config {
self.config
}
}