This commit is contained in:
Boog900 2024-10-06 20:08:11 +01:00
parent dc3a3c5adb
commit cb960abfab
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
5 changed files with 81 additions and 33 deletions

28
Cargo.lock generated
View file

@ -1884,16 +1884,6 @@ dependencies = [
"tokio",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "num-traits"
version = "0.2.19"
@ -1931,12 +1921,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "page_size"
version = "0.6.0"
@ -2552,15 +2536,6 @@ dependencies = [
"keccak",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "shlex"
version = "1.3.0"
@ -2949,9 +2924,6 @@ version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"nu-ansi-term",
"sharded-slab",
"thread_local",
"tracing-core",
]

View file

@ -1,5 +1,6 @@
//! cuprated config
use serde::{Deserialize, Serialize};
use cuprate_consensus::ContextConfig;
use cuprate_helper::network::Network;
use cuprate_p2p_core::ClearNet;
@ -24,7 +25,11 @@ pub struct Config {
}
impl Config {
fn clearnet_p2p_config(&self) -> cuprate_p2p::P2PConfig<ClearNet> {
pub fn network(&self) -> Network {
self.network
}
pub fn clearnet_p2p_config(&self) -> cuprate_p2p::P2PConfig<ClearNet> {
cuprate_p2p::P2PConfig {
network: self.network,
outbound_connections: self.p2p.clear_net.general.outbound_connections,
@ -37,6 +42,14 @@ impl Config {
address_book_config: self.p2p.clear_net.general.address_book_config.clone(),
}
}
pub fn context_config(&self) -> ContextConfig {
match self.network {
Network::Mainnet => ContextConfig::main_net(),
Network::Stagenet => ContextConfig::stage_net(),
Network::Testnet => ContextConfig::test_net()
}
}
pub fn blockchain_config(&self) -> cuprate_blockchain::config::Config {
self.storage.blockchain.clone()

View file

@ -39,16 +39,27 @@ fn main() {
let async_rt = init_tokio_rt(&config);
async_rt.block_on(async move {
blockchain:: check_add_genesis(&mut bc_read_handle, &mut bc_write_handle, &config.network()).await;
blockchain:: check_add_genesis(&mut bc_read_handle, &mut bc_write_handle, config.network()).await;
let (block_verifier, _tx_verifier, context_svc) =
blockchain::init_consensus(bc_read_handle.clone(), config.context_config())
.await
.unwrap();
}
// TODO: everything else.
todo!()
let net = cuprate_p2p::initialize_network(
p2p::request_handler:: {
blockchain_read_handle: bc_read_handle.clone(),
},
p2p::core_sync_service::CoreSyncService(context_svc.clone()),
config.clearnet_p2p_config(),
)
.await
.unwrap();
// TODO: this can be removed as long as the main thread does not exit, so when command handling
// is added
futures::future::pending::<()>().await;
});
}
fn init_log(_config: &Config) {

View file

@ -3,3 +3,4 @@
//! Will handle initiating the P2P and contains a protocol request handler.
pub mod request_handler;
pub mod core_sync_service;

View file

@ -0,0 +1,51 @@
use cuprate_blockchain::cuprate_database::RuntimeError;
use cuprate_blockchain::service::BlockchainReadHandle;
use cuprate_consensus::{
BlockChainContextRequest, BlockChainContextResponse, BlockChainContextService,
};
use cuprate_p2p_core::services::{CoreSyncDataRequest, CoreSyncDataResponse};
use cuprate_p2p_core::CoreSyncData;
use cuprate_types::blockchain::BlockchainReadRequest;
use futures::future::{BoxFuture, MapErr, MapOk};
use futures::{FutureExt, TryFutureExt};
use std::task::{Context, Poll};
use tower::Service;
#[derive(Clone)]
pub struct CoreSyncService(pub BlockChainContextService);
impl Service<CoreSyncDataRequest> for CoreSyncService {
type Response = CoreSyncDataResponse;
type Error = tower::BoxError;
type Future = MapOk<
<BlockChainContextService as Service<BlockChainContextRequest>>::Future,
fn(BlockChainContextResponse) -> CoreSyncDataResponse,
>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.0.poll_ready(cx)
}
fn call(&mut self, _: CoreSyncDataRequest) -> Self::Future {
self.0
.call(BlockChainContextRequest::GetContext)
.map_ok(|res| {
let BlockChainContextResponse::Context(ctx) = res else {
panic!("blockchain context service returned wrong response.");
};
let raw_ctx = ctx.unchecked_blockchain_context();
// TODO: the hardfork here should be the version of the top block not the current HF,
// on HF boundaries these will be different.
CoreSyncDataResponse(CoreSyncData::new(
raw_ctx.cumulative_difficulty,
// TODO:
raw_ctx.chain_height as u64,
0,
raw_ctx.top_hash,
raw_ctx.current_hf.as_u8(),
))
})
}
}