mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-09 20:40:01 +00:00
move more config values
This commit is contained in:
parent
1c93ea14b4
commit
05d0cf2295
4 changed files with 58 additions and 47 deletions
|
@ -1,7 +1,6 @@
|
||||||
//! Blockchain
|
//! Blockchain
|
||||||
//!
|
//!
|
||||||
//! Will contain the chain manager and syncer.
|
//! Will contain the chain manager and syncer.
|
||||||
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
|
@ -25,11 +24,13 @@ use types::{
|
||||||
ConsensusBlockchainReadHandle,
|
ConsensusBlockchainReadHandle,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Checks if the genesis block is in the blockchain and adds it if not.
|
||||||
pub async fn check_add_genesis(
|
pub async fn check_add_genesis(
|
||||||
blockchain_read_handle: &mut BlockchainReadHandle,
|
blockchain_read_handle: &mut BlockchainReadHandle,
|
||||||
blockchain_write_handle: &mut BlockchainWriteHandle,
|
blockchain_write_handle: &mut BlockchainWriteHandle,
|
||||||
network: &Network,
|
network: &Network,
|
||||||
) {
|
) {
|
||||||
|
// Try to get the chain height, will fail if the genesis block is not in the DB.
|
||||||
if blockchain_read_handle
|
if blockchain_read_handle
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
|
@ -67,6 +68,7 @@ pub async fn check_add_genesis(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initializes the consensus services.
|
||||||
pub async fn init_consensus(
|
pub async fn init_consensus(
|
||||||
blockchain_read_handle: BlockchainReadHandle,
|
blockchain_read_handle: BlockchainReadHandle,
|
||||||
context_config: ContextConfig,
|
context_config: ContextConfig,
|
||||||
|
@ -92,13 +94,14 @@ pub async fn init_consensus(
|
||||||
Ok((block_verifier_svc, tx_verifier_svc, ctx_service))
|
Ok((block_verifier_svc, tx_verifier_svc, ctx_service))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initializes the blockchain manager task and syncer.
|
||||||
pub fn init_blockchain_manager(
|
pub fn init_blockchain_manager(
|
||||||
clearnet_interface: NetworkInterface<ClearNet>,
|
clearnet_interface: NetworkInterface<ClearNet>,
|
||||||
block_downloader_config: BlockDownloaderConfig,
|
|
||||||
blockchain_write_handle: BlockchainWriteHandle,
|
blockchain_write_handle: BlockchainWriteHandle,
|
||||||
blockchain_read_handle: BlockchainReadHandle,
|
blockchain_read_handle: BlockchainReadHandle,
|
||||||
blockchain_context_service: BlockChainContextService,
|
blockchain_context_service: BlockChainContextService,
|
||||||
block_verifier_service: ConcreteBlockVerifierService,
|
block_verifier_service: ConcreteBlockVerifierService,
|
||||||
|
block_downloader_config: BlockDownloaderConfig,
|
||||||
) {
|
) {
|
||||||
let (batch_tx, batch_rx) = mpsc::channel(1);
|
let (batch_tx, batch_rx) = mpsc::channel(1);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
//! cuprated config
|
//! cuprated config
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use cuprate_blockchain::config::{
|
use cuprate_blockchain::config::{
|
||||||
Config as BlockchainConfig, ConfigBuilder as BlockchainConfigBuilder,
|
Config as BlockchainConfig, ConfigBuilder as BlockchainConfigBuilder,
|
||||||
};
|
};
|
||||||
|
use cuprate_consensus::ContextConfig;
|
||||||
|
use cuprate_p2p::{block_downloader::BlockDownloaderConfig, AddressBookConfig, P2PConfig};
|
||||||
|
use cuprate_p2p_core::{ClearNet, Network};
|
||||||
|
|
||||||
pub fn config() -> CupratedConfig {
|
pub fn config() -> CupratedConfig {
|
||||||
// TODO: read config options from the conf files & cli args.
|
// TODO: read config options from the conf files & cli args.
|
||||||
|
@ -18,4 +22,41 @@ impl CupratedConfig {
|
||||||
pub fn blockchain_config(&self) -> BlockchainConfig {
|
pub fn blockchain_config(&self) -> BlockchainConfig {
|
||||||
BlockchainConfigBuilder::new().fast().build()
|
BlockchainConfigBuilder::new().fast().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clearnet_config(&self) -> P2PConfig<ClearNet> {
|
||||||
|
P2PConfig {
|
||||||
|
network: Network::Mainnet,
|
||||||
|
outbound_connections: 64,
|
||||||
|
extra_outbound_connections: 0,
|
||||||
|
max_inbound_connections: 0,
|
||||||
|
gray_peers_percent: 0.7,
|
||||||
|
server_config: None,
|
||||||
|
p2p_port: 0,
|
||||||
|
rpc_port: 0,
|
||||||
|
address_book_config: AddressBookConfig {
|
||||||
|
max_white_list_length: 1000,
|
||||||
|
max_gray_list_length: 5000,
|
||||||
|
peer_store_file: "p2p_state.bin".into(),
|
||||||
|
peer_save_period: Duration::from_secs(60),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn block_downloader_config(&self) -> BlockDownloaderConfig {
|
||||||
|
BlockDownloaderConfig {
|
||||||
|
buffer_size: 50_000_000,
|
||||||
|
in_progress_queue_size: 50_000_000,
|
||||||
|
check_client_pool_interval: Duration::from_secs(45),
|
||||||
|
target_batch_size: 10_000_000,
|
||||||
|
initial_batch_size: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn network(&self) -> Network {
|
||||||
|
Network::Mainnet
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn context_config(&self) -> ContextConfig {
|
||||||
|
ContextConfig::main_net()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
use crate::blockchain::check_add_genesis;
|
|
||||||
use crate::config::CupratedConfig;
|
|
||||||
use clap::Parser;
|
|
||||||
use cuprate_p2p::block_downloader::BlockDownloaderConfig;
|
|
||||||
use cuprate_p2p::P2PConfig;
|
|
||||||
use cuprate_p2p_core::Network;
|
|
||||||
use std::time::Duration;
|
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
|
|
||||||
|
@ -14,6 +7,9 @@ mod p2p;
|
||||||
mod rpc;
|
mod rpc;
|
||||||
mod txpool;
|
mod txpool;
|
||||||
|
|
||||||
|
use blockchain::check_add_genesis;
|
||||||
|
use config::CupratedConfig;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let config = config::config();
|
let config = config::config();
|
||||||
|
|
||||||
|
@ -25,38 +21,32 @@ fn main() {
|
||||||
let async_rt = init_tokio_rt(&config);
|
let async_rt = init_tokio_rt(&config);
|
||||||
|
|
||||||
async_rt.block_on(async move {
|
async_rt.block_on(async move {
|
||||||
check_add_genesis(&mut bc_read_handle, &mut bc_write_handle, &Network::Mainnet).await;
|
check_add_genesis(&mut bc_read_handle, &mut bc_write_handle, &config.network()).await;
|
||||||
|
|
||||||
let (block_verifier, _tx_verifier, context_svc) = blockchain::init_consensus(
|
let (block_verifier, _tx_verifier, context_svc) =
|
||||||
bc_read_handle.clone(),
|
blockchain::init_consensus(bc_read_handle.clone(), config.context_config())
|
||||||
cuprate_consensus::ContextConfig::main_net(),
|
.await
|
||||||
)
|
.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let net = cuprate_p2p::initialize_network(
|
let net = cuprate_p2p::initialize_network(
|
||||||
p2p::request_handler::P2pProtocolRequestHandler,
|
p2p::request_handler::P2pProtocolRequestHandler,
|
||||||
p2p::core_sync_svc::CoreSyncService(context_svc.clone()),
|
p2p::core_sync_svc::CoreSyncService(context_svc.clone()),
|
||||||
p2p::dummy_config(),
|
config.clearnet_config(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
blockchain::init_blockchain_manager(
|
blockchain::init_blockchain_manager(
|
||||||
net,
|
net,
|
||||||
BlockDownloaderConfig {
|
|
||||||
buffer_size: 50_000_000,
|
|
||||||
in_progress_queue_size: 50_000_000,
|
|
||||||
check_client_pool_interval: Duration::from_secs(45),
|
|
||||||
target_batch_size: 10_000_000,
|
|
||||||
initial_batch_size: 1,
|
|
||||||
},
|
|
||||||
bc_write_handle,
|
bc_write_handle,
|
||||||
bc_read_handle,
|
bc_read_handle,
|
||||||
context_svc,
|
context_svc,
|
||||||
block_verifier,
|
block_verifier,
|
||||||
|
config.block_downloader_config(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: this can be removed as long as the main thread does not exit, so when command handling
|
||||||
|
// is added
|
||||||
futures::future::pending::<()>().await;
|
futures::future::pending::<()>().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,28 +2,5 @@
|
||||||
//!
|
//!
|
||||||
//! Will handle initiating the P2P and contains a protocol request handler.
|
//! Will handle initiating the P2P and contains a protocol request handler.
|
||||||
|
|
||||||
use cuprate_p2p::AddressBookConfig;
|
|
||||||
use cuprate_p2p_core::Network;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
pub mod core_sync_svc;
|
pub mod core_sync_svc;
|
||||||
pub mod request_handler;
|
pub mod request_handler;
|
||||||
|
|
||||||
pub fn dummy_config<N: cuprate_p2p_core::NetworkZone>() -> cuprate_p2p::P2PConfig<N> {
|
|
||||||
cuprate_p2p::P2PConfig {
|
|
||||||
network: Network::Mainnet,
|
|
||||||
outbound_connections: 64,
|
|
||||||
extra_outbound_connections: 0,
|
|
||||||
max_inbound_connections: 0,
|
|
||||||
gray_peers_percent: 0.7,
|
|
||||||
server_config: None,
|
|
||||||
p2p_port: 0,
|
|
||||||
rpc_port: 0,
|
|
||||||
address_book_config: AddressBookConfig {
|
|
||||||
max_white_list_length: 1000,
|
|
||||||
max_gray_list_length: 5000,
|
|
||||||
peer_store_file: "p2p_state.bin".into(),
|
|
||||||
peer_save_period: Duration::from_secs(60),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue